Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/nsdata.cpp | 206 |
1 files changed, 179 insertions, 27 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index 3f5e958..6541596 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp | |||
@@ -179,24 +179,25 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) { | |||
179 | 179 | ||
180 | if( ! ForceIt && ! isModified() ) | 180 | if( ! ForceIt && ! isModified() ) |
181 | return S; | 181 | return S; |
182 | 182 | ||
183 | // regenerate system files | 183 | // regenerate system files |
184 | printf( "Generating settings from %s\n", CfgFile.latin1() ); | 184 | printf( "Generating settings from %s\n", CfgFile.latin1() ); |
185 | 185 | ||
186 | { Name2SystemFile_t & SFM = NSResources->systemFiles(); | 186 | { Name2SystemFile_t & SFM = NSResources->systemFiles(); |
187 | Name2Connection_t & M = NSResources->connections(); | 187 | Name2Connection_t & M = NSResources->connections(); |
188 | NodeCollection * NC; | 188 | NodeCollection * NC; |
189 | ANetNodeInstance * NNI; | 189 | ANetNodeInstance * NNI; |
190 | SystemFile * SF; | 190 | SystemFile * SF; |
191 | AsDevice * CurDev; | ||
191 | bool needToRegenerate = ForceIt; | 192 | bool needToRegenerate = ForceIt; |
192 | 193 | ||
193 | // | 194 | // |
194 | // check if we need to generate at least one of the system files | 195 | // check if we need to generate at least one of the system files |
195 | // | 196 | // |
196 | if( ! ForceIt ) { | 197 | if( ! ForceIt ) { |
197 | for( QDictIterator<SystemFile> sfit(SFM); | 198 | for( QDictIterator<SystemFile> sfit(SFM); |
198 | sfit.current(); | 199 | sfit.current(); |
199 | ++sfit ) { | 200 | ++sfit ) { |
200 | SF = sfit.current(); | 201 | SF = sfit.current(); |
201 | 202 | ||
202 | // check if there are nodes that are modified and require | 203 | // check if there are nodes that are modified and require |
@@ -205,25 +206,27 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) { | |||
205 | // for all connections | 206 | // for all connections |
206 | for( QDictIterator<NodeCollection> ncit(M); | 207 | for( QDictIterator<NodeCollection> ncit(M); |
207 | ncit.current(); | 208 | ncit.current(); |
208 | ++ncit ) { | 209 | ++ncit ) { |
209 | NC = ncit.current(); | 210 | NC = ncit.current(); |
210 | 211 | ||
211 | if( NC->isModified() ) { | 212 | if( NC->isModified() ) { |
212 | // does this connection 'touch' this system file ? | 213 | // does this connection 'touch' this system file ? |
213 | for( QListIterator<ANetNodeInstance> cncit(*NC); | 214 | for( QListIterator<ANetNodeInstance> cncit(*NC); |
214 | cncit.current(); | 215 | cncit.current(); |
215 | ++cncit ) { | 216 | ++cncit ) { |
216 | NNI = cncit.current(); | 217 | NNI = cncit.current(); |
217 | if( NNI->netNode()->hasDataFor( SF->name() ) && | 218 | if( ( NNI->netNode()->hasDataFor( SF->name(), 1 ) || |
219 | NNI->netNode()->hasDataFor( SF->name(), 0 ) | ||
220 | ) && | ||
218 | NNI->isModified() ) { | 221 | NNI->isModified() ) { |
219 | needToRegenerate = 1; | 222 | needToRegenerate = 1; |
220 | break; | 223 | break; |
221 | } | 224 | } |
222 | } | 225 | } |
223 | } | 226 | } |
224 | if( needToRegenerate ) | 227 | if( needToRegenerate ) |
225 | break; | 228 | break; |
226 | } | 229 | } |
227 | if( needToRegenerate ) | 230 | if( needToRegenerate ) |
228 | break; | 231 | break; |
229 | } | 232 | } |
@@ -232,120 +235,269 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) { | |||
232 | // we cannot renumber with a FORCE request since | 235 | // we cannot renumber with a FORCE request since |
233 | // we probably are NOT going to save the config | 236 | // we probably are NOT going to save the config |
234 | // e.g. when using --regen option | 237 | // e.g. when using --regen option |
235 | if( ! ForceReq && needToRegenerate ) { | 238 | if( ! ForceReq && needToRegenerate ) { |
236 | NSResources->renumberConnections(); | 239 | NSResources->renumberConnections(); |
237 | setModified(1); | 240 | setModified(1); |
238 | } | 241 | } |
239 | 242 | ||
240 | // | 243 | // |
241 | // generate files proper to each netnodeinstance | 244 | // generate files proper to each netnodeinstance |
242 | // | 245 | // |
243 | { Name2Instance_t & NNIs = NSResources->netNodeInstances(); | 246 | { Name2Instance_t & NNIs = NSResources->netNodeInstances(); |
244 | ANetNodeInstance * NNI; | ||
245 | 247 | ||
246 | for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); | 248 | for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); |
247 | NNIIt.current(); | 249 | NNIIt.current(); |
248 | ++NNIIt | 250 | ++NNIIt |
249 | ){ | 251 | ){ |
250 | // for all nodes find those that are modified | 252 | // for all nodes find those that are modified |
251 | NNI = NNIIt.current(); | 253 | NNI = NNIIt.current(); |
252 | 254 | ||
253 | if( ForceIt || NNI->isModified() ) { | 255 | if( ForceIt || NNI->isModified() ) { |
254 | if( ! NNI->netNode()->generateProperFilesFor( NNI ) ) { | 256 | if( ! NNI->netNode()->generateProperFilesFor( NNI ) ) { |
255 | // problem generating | 257 | // problem generating |
256 | S = qApp->translate( "NetworkSettings", | 258 | S = qApp->translate( "NetworkSettings", |
257 | "<p>Cannot generate files proper to %1</p>" ). | 259 | "<p>Cannot generate files proper to %1</p>" ). |
258 | arg(NNI->netNode()->nodeName()) ; | 260 | arg(NNI->netNode()->nodeName()) ; |
259 | return S; | 261 | return S; |
260 | } | 262 | } |
261 | } | 263 | } |
262 | } | 264 | } |
263 | } | 265 | } |
264 | 266 | ||
265 | // | 267 | // |
266 | // generate system files | 268 | // generate all system files |
267 | // | 269 | // |
268 | for( QDictIterator<SystemFile> sfit(SFM); | 270 | for( QDictIterator<SystemFile> sfit(SFM); |
269 | sfit.current(); | 271 | sfit.current(); |
270 | ++sfit ) { | 272 | ++sfit ) { |
271 | SF = sfit.current(); | 273 | SF = sfit.current(); |
272 | 274 | ||
273 | // | ||
274 | // regenerate current file | ||
275 | // | ||
276 | printf( "Generating %s\n", SF->name().latin1() ); | 275 | printf( "Generating %s\n", SF->name().latin1() ); |
277 | SF->open(); | 276 | SF->open(); |
278 | 277 | ||
279 | do { // so we can break; | 278 | do { // so we can break; |
280 | 279 | ||
280 | // global presection for this system file | ||
281 | if( SF->preSection() ) { | 281 | if( SF->preSection() ) { |
282 | S = qApp->translate( "NetworkSettings", | 282 | S = qApp->translate( "NetworkSettings", |
283 | "<p>Error in preSection for file %1</p>" ). | 283 | "<p>Error in preSection for file %1</p>" ). |
284 | arg( SF->name() ); | 284 | arg( SF->name() ); |
285 | return S; | 285 | return S; |
286 | } | 286 | } |
287 | 287 | ||
288 | for( QDictIterator<NodeCollection> ncit(M); | 288 | // find all netnodes and figure out if |
289 | ncit.current(); | 289 | // for that node there are instances |
290 | ++ncit ) { | 290 | for( QDictIterator<NetNode_t> nnit( |
291 | NC = ncit.current(); | 291 | NSResources->netNodes() ); |
292 | 292 | nnit.current(); | |
293 | // get the netnode that serves as the device for this | 293 | ++nnit ) { |
294 | // connection | 294 | ANetNode * NN; |
295 | AsDevice * Dev = NC->device(); | 295 | |
296 | NN = nnit.current()->NetNode; | ||
297 | |||
298 | // are there instances ? | ||
299 | NNI = 0; | ||
300 | for( QDictIterator<ANetNodeInstance> nniit( | ||
301 | NSResources->netNodeInstances() ); | ||
302 | nniit.current(); | ||
303 | ++nniit ) { | ||
304 | if( nniit.current()->netNode() == NN ) { | ||
305 | NNI = nniit.current(); | ||
306 | break; | ||
307 | } | ||
308 | } | ||
296 | 309 | ||
297 | // generate 'entry' for every possible device this profile handles | 310 | if( ! NNI ) |
311 | // no instances | ||
312 | continue; | ||
313 | |||
314 | // has this node data for this system file ? | ||
315 | if( (CurDev = NNI->runtime()->asDevice() ) ) { | ||
316 | // generate start for this nodetype for all possible devices of this type | ||
317 | for( int i = 0; i < CurDev->count(); i ++ ) { | ||
318 | if( SF->preDeviceSection( NNI, i ) ) { | ||
319 | S = qApp->translate( "NetworkSettings", | ||
320 | "<p>Error in preDeviceSection for file %1 and node %2</p>" ). | ||
321 | arg( SF->name() ). | ||
322 | arg( NN->nodeName() ); | ||
323 | return S; | ||
324 | } | ||
298 | 325 | ||
299 | for( QListIterator<ANetNodeInstance> cncit(*NC); | 326 | if( ! NN->hasDataFor( SF->name(), 1 ) ) { |
300 | cncit.current(); | 327 | if( NN->generateDeviceDataForCommonFile( *SF, i, NNI ) ) { |
301 | ++cncit ) { | ||
302 | NNI = cncit.current(); | ||
303 | for( int i = 0; i < Dev->count(); i ++ ) { | ||
304 | if( NNI->netNode()->hasDataFor( SF->name() ) ) { | ||
305 | if( SF->preNodeSection( NNI, i ) ) { | ||
306 | S = qApp->translate( "NetworkSettings", | 328 | S = qApp->translate( "NetworkSettings", |
307 | "<p>Error in preNodeSection for file %1 and node %2</p>" ). | 329 | "<p>Error in node part for file %1 and node %2</p>" ). |
308 | arg( SF->name() ). | 330 | arg( SF->name() ). |
309 | arg( NNI->netNode()->nodeName() ); | 331 | arg( NN->nodeName() ); |
310 | return S; | 332 | return S; |
311 | } | 333 | } |
334 | } | ||
335 | } | ||
336 | } else { | ||
337 | // just request this once | ||
338 | if( SF->preDeviceSection( NNI, -1 ) ) { | ||
339 | S = qApp->translate( "NetworkSettings", | ||
340 | "<p>Error in preDeviceSection for file %1 and node %2</p>" ). | ||
341 | arg( SF->name() ). | ||
342 | arg( NN->nodeName() ); | ||
343 | return S; | ||
344 | } | ||
345 | |||
346 | if( ! NN->hasDataFor( SF->name(), 1 ) ) { | ||
347 | if( NN->generateDeviceDataForCommonFile( *SF, -1, NNI ) ) { | ||
348 | S = qApp->translate( "NetworkSettings", | ||
349 | "<p>Error in node part for file %1 and node %2</p>" ). | ||
350 | arg( SF->name() ). | ||
351 | arg( NN->nodeName() ); | ||
352 | return S; | ||
353 | } | ||
354 | } | ||
355 | } | ||
356 | |||
357 | // now generate profile specific data for all | ||
358 | // connections working on a device of the current | ||
359 | // netnode type | ||
360 | for( QDictIterator<NodeCollection> ncit(M); | ||
361 | ncit.current(); | ||
362 | ++ncit ) { | ||
363 | NC = ncit.current(); | ||
312 | 364 | ||
313 | if( NNI->netNode()->generateDataForCommonFile(*SF,i,NNI) ) { | 365 | NNI = NC->getToplevel(); |
366 | |||
367 | // no output needed | ||
368 | if( ! NNI->netNode()->hasDataFor( SF->name(), 0 ) ) | ||
369 | continue; | ||
370 | |||
371 | // get the netnode that serves as the device for this | ||
372 | // connection | ||
373 | AsDevice * Dev = NC->device(); | ||
374 | |||
375 | if( CurDev ) { | ||
376 | if( CurDev != Dev ) { | ||
377 | // other device -> later | ||
378 | continue; | ||
379 | } | ||
380 | |||
381 | // generate 'entry' for every combination of device and profile | ||
382 | // each node delegates to deeper level | ||
383 | for( int i = 0; i < CurDev->count(); i ++ ) { | ||
384 | if( SF->preNodeSection( NNI, i ) ) { | ||
314 | S = qApp->translate( "NetworkSettings", | 385 | S = qApp->translate( "NetworkSettings", |
315 | "<p>Error in node part for file %1 and node %2</p>" ). | 386 | "<p>Error in preNodeSection for file %1 and node %2</p>" ). |
316 | arg( SF->name() ). | 387 | arg( SF->name() ). |
317 | arg( NNI->netNode()->nodeName() ); | 388 | arg( NNI->netNode()->nodeName() ); |
318 | return S; | 389 | return S; |
319 | } | 390 | } |
320 | 391 | ||
392 | // ask all nodes in connection | ||
393 | |||
394 | for( QListIterator<ANetNodeInstance> cncit(*NC); | ||
395 | cncit.current(); | ||
396 | ++cncit ) { | ||
397 | NNI = cncit.current(); | ||
398 | |||
399 | if( NNI->netNode()->hasDataFor( SF->name(), 0 ) ) { | ||
400 | if( NNI->netNode()->generateDataForCommonFile(*SF,i,NNI) ) { | ||
401 | S = qApp->translate( "NetworkSettings", | ||
402 | "<p>Error in node part for file %1 and node %2</p>" ). | ||
403 | arg( SF->name() ). | ||
404 | arg( NNI->netNode()->nodeName() ); | ||
405 | return S; | ||
406 | } | ||
407 | } | ||
408 | } | ||
409 | |||
321 | if( SF->postNodeSection( NNI, i ) ) { | 410 | if( SF->postNodeSection( NNI, i ) ) { |
322 | S = qApp->translate( "NetworkSettings", | 411 | S = qApp->translate( "NetworkSettings", |
323 | "<p>Error in postNodeSection for file %1 and node %2</p>" ). | 412 | "<p>Error in postNodeSection for file %1 and node %2</p>" ). |
324 | arg( SF->name() ). | 413 | arg( SF->name() ). |
325 | arg( NNI->netNode()->nodeName() ); | 414 | arg( NNI->netNode()->nodeName() ); |
326 | return S; | 415 | return S; |
327 | } | 416 | } |
328 | } | 417 | } |
418 | |||
419 | } else { | ||
420 | if( Dev ) { | ||
421 | // other | ||
422 | continue; | ||
423 | } | ||
424 | |||
425 | // one entry to generate | ||
426 | if( SF->preNodeSection( NNI, -1 ) ) { | ||
427 | S = qApp->translate( "NetworkSettings", | ||
428 | "<p>Error in preNodeSection for file %1 and node %2</p>" ). | ||
429 | arg( SF->name() ). | ||
430 | arg( NNI->netNode()->nodeName() ); | ||
431 | return S; | ||
432 | } | ||
433 | |||
434 | if( NNI->netNode()->generateDataForCommonFile(*SF,-1,NNI) ) { | ||
435 | S = qApp->translate( "NetworkSettings", | ||
436 | "<p>Error in node part for file %1 and node %2</p>" ). | ||
437 | arg( SF->name() ). | ||
438 | arg( NNI->netNode()->nodeName() ); | ||
439 | return S; | ||
440 | } | ||
441 | |||
442 | if( SF->postNodeSection( NNI, -1 ) ) { | ||
443 | S = qApp->translate( "NetworkSettings", | ||
444 | "<p>Error in postNodeSection for file %1 and node %2</p>" ). | ||
445 | arg( SF->name() ). | ||
446 | arg( NNI->netNode()->nodeName() ); | ||
447 | return S; | ||
448 | } | ||
449 | } | ||
450 | |||
451 | // generated some data | ||
452 | if( SF->postNodeSection( NNI, -1 ) ) { | ||
453 | S = qApp->translate( "NetworkSettings", | ||
454 | "<p>Error in postNodeSection for file %1 and node %2</p>" ). | ||
455 | arg( SF->name() ). | ||
456 | arg( NNI->netNode()->nodeName() ); | ||
457 | return S; | ||
458 | } | ||
459 | *SF << endl; | ||
460 | } | ||
461 | |||
462 | if( CurDev ) { | ||
463 | // generate 'entry' for every combination of device and profile | ||
464 | // each node delegates to deeper level | ||
465 | for( int i = 0; i < CurDev->count(); i ++ ) { | ||
466 | if( SF->postDeviceSection( NNI, i ) ) { | ||
467 | S = qApp->translate( "NetworkSettings", | ||
468 | "<p>Error in postDeviceSection for file %1 and node %2</p>" ). | ||
469 | arg( SF->name() ). | ||
470 | arg( NNI->netNode()->nodeName() ); | ||
471 | return S; | ||
472 | } | ||
473 | } | ||
474 | } else { | ||
475 | if( SF->postDeviceSection( NNI, -1 ) ) { | ||
476 | S = qApp->translate( "NetworkSettings", | ||
477 | "<p>Error in postDeviceSection for file %1 and node %2</p>" ). | ||
478 | arg( SF->name() ). | ||
479 | arg( NNI->netNode()->nodeName() ); | ||
480 | return S; | ||
329 | } | 481 | } |
330 | } | 482 | } |
331 | *SF << endl; | ||
332 | } | 483 | } |
333 | 484 | ||
334 | if( SF->postSection() ) { | 485 | if( SF->postSection() ) { |
335 | S = qApp->translate( "NetworkSettings", | 486 | S = qApp->translate( "NetworkSettings", |
336 | "<p>Error in postSection for file %1</p>" ). | 487 | "<p>Error in postSection for file %1</p>" ). |
337 | arg( SF->name() ); | 488 | arg( SF->name() ); |
338 | return S; | 489 | return S; |
339 | } | 490 | } |
491 | |||
340 | } while( 0 ); | 492 | } while( 0 ); |
341 | SF->close(); | 493 | SF->close(); |
342 | } | 494 | } |
343 | } | 495 | } |
344 | Force = 0; | 496 | Force = 0; |
345 | return S; | 497 | return S; |
346 | } | 498 | } |
347 | 499 | ||
348 | QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { | 500 | QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { |
349 | // collect connections that can work on top of this interface | 501 | // collect connections that can work on top of this interface |
350 | NodeCollection * NC; | 502 | NodeCollection * NC; |
351 | QList<NodeCollection> PossibleConnections; | 503 | QList<NodeCollection> PossibleConnections; |