Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/nsdata.cpp | 476 |
1 files changed, 248 insertions, 228 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index 3b17548..d709c0a 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp | |||
@@ -19,9 +19,8 @@ NetworkSettingsData::NetworkSettingsData( void ) { | |||
19 | NSResources->currentUser().HomeDir.latin1() ); | 19 | NSResources->currentUser().HomeDir.latin1() ); |
20 | Log(( "Cfg from %s\n", CfgFile.latin1() )); | 20 | Log(( "Cfg from %s\n", CfgFile.latin1() )); |
21 | 21 | ||
22 | // load settings | 22 | // load settings |
23 | Force = 0; | ||
24 | IsModified = 0; | 23 | IsModified = 0; |
25 | loadSettings(); | 24 | loadSettings(); |
26 | } | 25 | } |
27 | 26 | ||
@@ -217,168 +216,290 @@ QString NetworkSettingsData::saveSettings( void ) { | |||
217 | setModified( 0 ); | 216 | setModified( 0 ); |
218 | return ErrS; | 217 | return ErrS; |
219 | } | 218 | } |
220 | 219 | ||
221 | QString NetworkSettingsData::generateSettings( bool ForceReq ) { | 220 | QString NetworkSettingsData::generateSettings( void ) { |
222 | bool ForceIt; | ||
223 | QString S = ""; | 221 | QString S = ""; |
224 | 222 | Name2SystemFile_t & SFM = NSResources->systemFiles(); | |
225 | // include own force flag | 223 | Name2Connection_t & M = NSResources->connections(); |
226 | ForceIt = (Force) ? 1 : ForceReq; | 224 | NodeCollection * NC; |
227 | 225 | ANetNodeInstance * NNI; | |
228 | if( ! ForceIt && ! isModified() ) | 226 | ANetNodeInstance * FirstWithData; |
229 | return S; | 227 | SystemFile * SF; |
228 | AsDevice * CurDev; | ||
229 | ANetNode * NN, * CurDevNN = 0; | ||
230 | long NoOfDevs; | ||
231 | long DevCtStart; | ||
232 | bool needToGenerate; | ||
230 | 233 | ||
231 | // regenerate system files | 234 | // regenerate system files |
232 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); | 235 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); |
233 | 236 | ||
234 | { Name2SystemFile_t & SFM = NSResources->systemFiles(); | 237 | // |
235 | Name2Connection_t & M = NSResources->connections(); | 238 | // generate files proper to each netnodeinstance |
236 | NodeCollection * NC; | 239 | // |
237 | ANetNodeInstance * NNI; | 240 | { Name2Instance_t & NNIs = NSResources->netNodeInstances(); |
238 | SystemFile * SF; | 241 | |
239 | AsDevice * CurDev; | 242 | for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); |
240 | ANetNode * CurDevNN; | 243 | NNIIt.current(); |
241 | bool needToRegenerate = ForceIt; | 244 | ++NNIIt ) { |
242 | 245 | // for all nodes find those that are modified | |
243 | // | 246 | NNI = NNIIt.current(); |
244 | // check if we need to generate at least one of the system files | 247 | |
245 | // | 248 | { // get list of proper files for this nodeclass (if any) |
246 | if( ! ForceIt ) { | 249 | QStringList * PF = NNI->nodeClass()->properFiles(); |
247 | for( QDictIterator<SystemFile> sfit(SFM); | 250 | |
248 | sfit.current(); | 251 | if( PF ) { |
249 | ++sfit ) { | 252 | for ( QStringList::Iterator it = PF->begin(); |
250 | SF = sfit.current(); | 253 | it != PF->end(); |
251 | 254 | ++it ) { | |
252 | // check if there are nodes that are modified and require | 255 | QFile * F = NNI->openFile( (*it) ); |
253 | // data for this system file | 256 | if( F ) { |
254 | 257 | QTextStream TS( F ); | |
255 | // for all connections | 258 | if( NNI->generateFile( (*it), F->name(), TS, -1 ) == 2 ) { |
256 | for( QDictIterator<NodeCollection> ncit(M); | 259 | // problem generating |
257 | ncit.current(); | 260 | S = qApp->translate( "NetworkSettings", |
258 | ++ncit ) { | 261 | "<p>Cannot generate files proper to \"%1\"</p>" ). |
259 | NC = ncit.current(); | 262 | arg(NNI->nodeClass()->name()) ; |
260 | 263 | delete F; | |
261 | if( NC->isModified() ) { | 264 | return S; |
262 | // does this connection 'touch' this system file ? | ||
263 | for( QListIterator<ANetNodeInstance> cncit(*NC); | ||
264 | cncit.current(); | ||
265 | ++cncit ) { | ||
266 | NNI = cncit.current(); | ||
267 | if( ( NNI->nodeClass()->hasDataFor( SF->name() ) || | ||
268 | NNI->hasDataFor( SF->name() ) | ||
269 | ) && | ||
270 | NNI->isModified() ) { | ||
271 | needToRegenerate = 1; | ||
272 | break; | ||
273 | } | 265 | } |
266 | delete F; | ||
274 | } | 267 | } |
275 | } | 268 | } |
276 | if( needToRegenerate ) | ||
277 | break; | ||
278 | } | 269 | } |
279 | if( needToRegenerate ) | ||
280 | break; | ||
281 | } | 270 | } |
282 | } | 271 | } |
272 | } | ||
283 | 273 | ||
284 | // | 274 | // |
285 | // generate files proper to each netnodeinstance | 275 | // generate all system files |
286 | // | 276 | // |
287 | { Name2Instance_t & NNIs = NSResources->netNodeInstances(); | 277 | for( QDictIterator<SystemFile> sfit(SFM); |
288 | 278 | sfit.current(); | |
289 | for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); | 279 | ++sfit ) { |
290 | NNIIt.current(); | 280 | SF = sfit.current(); |
291 | ++NNIIt | 281 | |
292 | ){ | 282 | // reset all |
293 | // for all nodes find those that are modified | 283 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); |
294 | NNI = NNIIt.current(); | 284 | nnit.current(); |
295 | 285 | ++nnit ) { | |
296 | if( ForceIt || NNI->isModified() ) { | 286 | nnit.current()->NetNode->setDone(0); |
297 | if( NNI->nodeClass()->generateProperFilesFor( NNI ) ) { | 287 | } |
298 | // problem generating | 288 | |
299 | S = qApp->translate( "NetworkSettings", | 289 | for( QDictIterator<ANetNodeInstance> nniit( |
300 | "<p>Cannot generate files proper to \"%1\"</p>" ). | 290 | NSResources->netNodeInstances() ); |
301 | arg(NNI->nodeClass()->name()) ; | 291 | nniit.current(); |
302 | return S; | 292 | ++nniit ) { |
293 | nniit.current()->setDone(0); | ||
294 | } | ||
295 | |||
296 | for( QDictIterator<NodeCollection> ncit(M); | ||
297 | ncit.current(); | ||
298 | ++ncit ) { | ||
299 | ncit.current()->setDone(0); | ||
300 | } | ||
301 | |||
302 | Log( ( "Generating %s\n", SF->name().latin1() )); | ||
303 | |||
304 | needToGenerate = 0; | ||
305 | |||
306 | // are there netnodes that have instances and need | ||
307 | // to write data in this system file ? | ||
308 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); | ||
309 | ! needToGenerate && nnit.current(); | ||
310 | ++nnit ) { | ||
311 | |||
312 | NN = nnit.current()->NetNode; | ||
313 | |||
314 | if( NN->hasDataForFile( SF->name() ) ) { | ||
315 | // netnode can have data | ||
316 | |||
317 | // are there instances of this node ? | ||
318 | for( QDictIterator<ANetNodeInstance> nniit( | ||
319 | NSResources->netNodeInstances() ); | ||
320 | ! needToGenerate && nniit.current(); | ||
321 | ++nniit ) { | ||
322 | if( nniit.current()->nodeClass() == NN ) { | ||
323 | // yes | ||
324 | Log(("Node %s has data\n", | ||
325 | nniit.current()->name() )); | ||
326 | needToGenerate = 1; | ||
327 | break; | ||
303 | } | 328 | } |
304 | } | 329 | } |
305 | } | 330 | } |
306 | } | 331 | } |
307 | 332 | ||
308 | // | 333 | if( ! needToGenerate ) { |
309 | // generate all system files | 334 | // no instances found that might need to write data |
310 | // | 335 | // in this systemfile |
311 | for( QDictIterator<SystemFile> sfit(SFM); | 336 | Log(("No nodes for systemfile %s\n", SF->name().latin1() )); |
312 | sfit.current(); | 337 | continue; |
313 | ++sfit ) { | 338 | } |
314 | SF = sfit.current(); | ||
315 | 339 | ||
316 | Log( ( "Generating %s\n", SF->name().latin1() )); | 340 | // ok generate this system file |
317 | SF->open(); | 341 | SF->open(); |
318 | 342 | ||
319 | do { // so we can break; | 343 | // global presection for this system file |
344 | if( ! SF->preSection() ) { | ||
345 | S = qApp->translate( "NetworkSettings", | ||
346 | "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). | ||
347 | arg( SF->name() ); | ||
348 | return S; | ||
349 | } | ||
320 | 350 | ||
321 | // global presection for this system file | 351 | // find connections that want to write to this file |
322 | if( SF->preSection() ) { | 352 | for( QDictIterator<NodeCollection> ncit(M); |
353 | ncit.current(); | ||
354 | ++ncit ) { | ||
355 | |||
356 | NC = ncit.current(); | ||
357 | |||
358 | if( NC->done() ) { | ||
359 | // already done | ||
360 | continue; | ||
361 | } | ||
362 | |||
363 | if( ! NC->hasDataForFile( SF->name() ) ) { | ||
364 | // no data | ||
365 | continue; | ||
366 | } | ||
367 | |||
368 | Log(("Generating %s for connection %s\n", | ||
369 | SF->name().latin1(), NC->name().latin1() )); | ||
370 | // find highest item that wants to write data to this file | ||
371 | FirstWithData = NC->firstWithDataForFile( SF->name() ); | ||
372 | |||
373 | // find device on which this connection works | ||
374 | CurDev = NC->device(); | ||
375 | // class of that node | ||
376 | CurDevNN = CurDev->netNode()->nodeClass(); | ||
377 | |||
378 | Log(( "%s is done %d\n", | ||
379 | FirstWithData->nodeClass()->name(), | ||
380 | FirstWithData->nodeClass()->done() )); | ||
381 | |||
382 | if( ! FirstWithData->nodeClass()->done() ) { | ||
383 | // generate fixed part | ||
384 | if( ! SF->preDeviceSection( CurDevNN ) ) { | ||
323 | S = qApp->translate( "NetworkSettings", | 385 | S = qApp->translate( "NetworkSettings", |
324 | "<p>Error in preSection for file \"%1\"</p>" ). | 386 | "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). |
325 | arg( SF->name() ); | 387 | arg( SF->name() ); |
326 | return S; | 388 | return S; |
327 | } | 389 | } |
328 | 390 | ||
329 | // find all netnodes and figure out if | 391 | if( FirstWithData->nodeClass()->generateFile( |
330 | // for that node there are instances | 392 | SF->name(), SF->path(), *SF, -1 ) == 2 ) { |
331 | for( QDictIterator<NetNode_t> nnit( | 393 | S = qApp->translate( "NetworkSettings", |
332 | NSResources->netNodes() ); | 394 | "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). |
333 | nnit.current(); | 395 | arg( SF->name() ). |
334 | ++nnit ) { | 396 | arg( CurDevNN->name() ); |
335 | 397 | return S; | |
336 | CurDevNN = nnit.current()->NetNode; | 398 | } |
337 | 399 | FirstWithData->nodeClass()->setDone( 1 ); | |
338 | // are there instances for this netnode ? | 400 | } |
339 | NNI = 0; | 401 | |
340 | for( QDictIterator<ANetNodeInstance> nniit( | 402 | NoOfDevs = 0; |
341 | NSResources->netNodeInstances() ); | 403 | DevCtStart = -1; |
342 | nniit.current(); | 404 | |
343 | ++nniit ) { | 405 | if( SF->knowsDeviceInstances() ) { |
344 | if( nniit.current()->nodeClass() == CurDevNN ) { | 406 | DevCtStart = 0; |
345 | NNI = nniit.current(); | 407 | NoOfDevs = CurDevNN->instanceCount(); |
346 | break; | 408 | } |
347 | } | 409 | |
410 | Log(( "Node %s is done %d\n", | ||
411 | CurDev->netNode()->nodeClass()->name(), | ||
412 | CurDev->netNode()->nodeClass()->done() )); | ||
413 | |||
414 | if( ! CurDev->netNode()->nodeClass()->done() ) { | ||
415 | // first time this device is handled | ||
416 | // generate common device specific part | ||
417 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { | ||
418 | |||
419 | if( FirstWithData->nodeClass()->generateFile( | ||
420 | SF->name(), SF->path(), *SF, CurDev->netNode(), i ) == 2 ) { | ||
421 | S = qApp->translate( "NetworkSettings", | ||
422 | "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). | ||
423 | arg( SF->name() ). | ||
424 | arg( CurDevNN->name() ); | ||
425 | return S; | ||
348 | } | 426 | } |
427 | } | ||
428 | CurDev->netNode()->nodeClass()->setDone( 1 ); | ||
429 | } | ||
349 | 430 | ||
350 | if( ! NNI ) | 431 | // generate profile specific info |
351 | // no instances -> next netnode type | 432 | // for all nodeconnections that work on the same device |
352 | continue; | 433 | for( QDictIterator<NodeCollection> ncit2(M); |
434 | ncit2.current(); | ||
435 | ++ncit2 ) { | ||
353 | 436 | ||
354 | // has this node data for this system file ? | 437 | if( ncit2.current()->device() != CurDev ) { |
355 | if( (CurDev = NNI->runtime()->asDevice() ) ) { | 438 | // different device |
356 | // generate start for this nodetype for all possible devices of this type | 439 | continue; |
357 | for( int i = 0; i < CurDevNN->instanceCount(); i ++ ) { | 440 | } |
358 | S = generateSystemFileNode( *SF, CurDev, NNI, i ); | 441 | |
359 | if( ! S.isEmpty() ) | 442 | Log(("Connection %s of same family\n", ncit2.current()->name().latin1() )); |
360 | return S; | 443 | // generate |
361 | } | 444 | NNI = ncit2.current()->firstWithDataForFile( SF->name() ); |
362 | } else { | 445 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { |
363 | S = generateSystemFileNode( *SF, 0, NNI, -1 ); | 446 | if( ! SF->preNodeSection( NNI, i ) ) { |
364 | if( ! S.isEmpty() ) | 447 | S = qApp->translate( "NetworkSettings", |
448 | "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | ||
449 | arg( SF->name() ). | ||
450 | arg( CurDevNN->name() ); | ||
451 | return S; | ||
452 | } | ||
453 | |||
454 | switch( NNI->generateFile( | ||
455 | SF->name(), SF->path(), *SF, i ) ) { | ||
456 | case 0 : | ||
457 | (*SF) << endl; | ||
458 | break; | ||
459 | case 1 : | ||
460 | break; | ||
461 | case 2 : | ||
462 | S = qApp->translate( "NetworkSettings", | ||
463 | "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). | ||
464 | arg( SF->name() ). | ||
465 | arg( CurDevNN->name() ); | ||
365 | return S; | 466 | return S; |
366 | } | 467 | } |
367 | } | ||
368 | 468 | ||
369 | if( SF->postSection() ) { | 469 | if( ! SF->postNodeSection( NNI, i ) ) { |
370 | S = qApp->translate( "NetworkSettings", | 470 | S = qApp->translate( "NetworkSettings", |
371 | "<p>Error in postSection for file \"%1\"</p>" ). | 471 | "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). |
372 | arg( SF->name() ); | 472 | arg( SF->name() ). |
373 | return S; | 473 | arg( CurDevNN->name() ); |
474 | return S; | ||
475 | } | ||
374 | } | 476 | } |
375 | 477 | ||
376 | } while( 0 ); | 478 | ncit2.current()->setDone( 1 ); |
377 | SF->close(); | 479 | |
480 | } | ||
481 | } | ||
482 | |||
483 | if( ! SF->postDeviceSection( CurDevNN ) ) { | ||
484 | S = qApp->translate( "NetworkSettings", | ||
485 | "<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ). | ||
486 | arg( SF->name() ). | ||
487 | arg( CurDevNN->name() ); | ||
488 | return S; | ||
489 | } | ||
490 | |||
491 | |||
492 | if( ! SF->postSection() ) { | ||
493 | S = qApp->translate( "NetworkSettings", | ||
494 | "<p>Error in section \"Closure\" for file \"%1\"</p>" ). | ||
495 | arg( SF->name() ); | ||
496 | return S; | ||
378 | } | 497 | } |
498 | |||
499 | // end of file | ||
500 | SF->close(); | ||
379 | } | 501 | } |
380 | Force = 0; | ||
381 | return S; | 502 | return S; |
382 | } | 503 | } |
383 | 504 | ||
384 | QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { | 505 | QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { |
@@ -462,112 +583,11 @@ bool NetworkSettingsData::canStart( const char * Interface ) { | |||
462 | Called by the system to regenerate config files | 583 | Called by the system to regenerate config files |
463 | */ | 584 | */ |
464 | 585 | ||
465 | bool NetworkSettingsData::regenerate( void ) { | 586 | bool NetworkSettingsData::regenerate( void ) { |
466 | QString S; | 587 | QString S = generateSettings(); |
467 | // load situation | ||
468 | S = generateSettings( TRUE ); | ||
469 | if( ! S.isEmpty() ) { | 588 | if( ! S.isEmpty() ) { |
470 | fprintf( stdout, "%s\n", S.latin1() ); | 589 | fprintf( stdout, "%s\n", S.latin1() ); |
471 | return 1; | 590 | return 1; |
472 | } | 591 | } |
473 | return 0; | 592 | return 0; |
474 | } | 593 | } |
475 | |||
476 | QString NetworkSettingsData::generateSystemFileNode( | ||
477 | SystemFile &SF, | ||
478 | AsDevice * CurDev, | ||
479 | ANetNodeInstance * DevNNI, | ||
480 | long DevInstNr ) { | ||
481 | |||
482 | QString S=""; | ||
483 | ANetNode * CurDevNN = DevNNI->nodeClass(); | ||
484 | Name2Connection_t & M = NSResources->connections(); | ||
485 | |||
486 | if( SF.preDeviceSection( CurDevNN ) ) { | ||
487 | S = qApp->translate( "NetworkSettings", | ||
488 | "<p>Error in \"Pre-Device Part\" for file \"%1\" and nodetype \"%2\"</p>" ). | ||
489 | arg( SF.name() ). | ||
490 | arg( CurDevNN->name() ); | ||
491 | return S; | ||
492 | } | ||
493 | |||
494 | if( CurDevNN->hasDataFor( SF.name() ) ) { | ||
495 | if( CurDevNN->generateDeviceDataForCommonFile( SF, DevInstNr ) ) { | ||
496 | S = qApp->translate( "NetworkSettings", | ||
497 | "<p>Error in \"Device Part\" for file \"%1\" and node \"%2\"</p>" ). | ||
498 | arg( SF.name() ). | ||
499 | arg( CurDevNN->name() ); | ||
500 | return S; | ||
501 | } | ||
502 | } | ||
503 | |||
504 | // now generate profile specific data for all | ||
505 | // connections working on a device of the current | ||
506 | // netnode type | ||
507 | for( QDictIterator<NodeCollection> ncit(M); | ||
508 | ncit.current(); | ||
509 | ++ncit ) { | ||
510 | NodeCollection * NC = ncit.current(); | ||
511 | |||
512 | // currenly only those connections that work on | ||
513 | // the current device (or on no device if no current) | ||
514 | AsDevice * Dev = NC->device(); | ||
515 | |||
516 | if( CurDev ) { | ||
517 | if( CurDevNN != Dev->netNode()->nodeClass() ) { | ||
518 | // other device type -> later | ||
519 | continue; | ||
520 | } | ||
521 | } else { | ||
522 | if( Dev ) { | ||
523 | // other | ||
524 | continue; | ||
525 | } | ||
526 | } | ||
527 | |||
528 | // generate 'entry' | ||
529 | if( SF.preNodeSection( DevNNI, DevInstNr ) ) { | ||
530 | S = qApp->translate( "NetworkSettings", | ||
531 | "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | ||
532 | arg( SF.name() ). | ||
533 | arg( CurDevNN->name() ); | ||
534 | return S; | ||
535 | } | ||
536 | |||
537 | // ask all nodes in connection | ||
538 | for( QListIterator<ANetNodeInstance> cncit(*NC); | ||
539 | cncit.current(); | ||
540 | ++cncit ) { | ||
541 | ANetNodeInstance * NNI = cncit.current(); | ||
542 | |||
543 | if( NNI->hasDataFor( SF.name() ) ) { | ||
544 | if( NNI->generateDataForCommonFile(SF,DevInstNr) ) { | ||
545 | S = qApp->translate( "NetworkSettings", | ||
546 | "<p>Error in \"Node Part\" for file \"%1\" and node \"%2\"</p>" ). | ||
547 | arg( SF.name() ). | ||
548 | arg( NNI->nodeClass()->name() ); | ||
549 | return S; | ||
550 | } | ||
551 | } | ||
552 | } | ||
553 | |||
554 | if( SF.postNodeSection( DevNNI, DevInstNr ) ) { | ||
555 | S = qApp->translate( "NetworkSettings", | ||
556 | "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | ||
557 | arg( SF.name() ). | ||
558 | arg( CurDevNN->name() ); | ||
559 | return S; | ||
560 | } | ||
561 | SF << endl; | ||
562 | } | ||
563 | |||
564 | if( SF.postDeviceSection( CurDevNN ) ) { | ||
565 | S = qApp->translate( "NetworkSettings", | ||
566 | "<p>Error in \"Post-Device Part\" for file \"%1\" and node \"%2\"</p>" ). | ||
567 | arg( SF.name() ). | ||
568 | arg( CurDevNN->name() ); | ||
569 | return S; | ||
570 | } | ||
571 | |||
572 | return S; | ||
573 | } | ||