Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/nsdata.cpp | 252 |
1 files changed, 187 insertions, 65 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index e2dd5b5..698a941 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <opie2/odebug.h> | ||
2 | #include <qpe/qpeapplication.h> | 3 | #include <qpe/qpeapplication.h> |
3 | #include <qtextstream.h> | 4 | #include <qtextstream.h> |
@@ -7,5 +8,5 @@ | |||
7 | 8 | ||
8 | #include "nsdata.h" | 9 | #include "nsdata.h" |
9 | #include <asdevice.h> | 10 | #include <netnode.h> |
10 | #include <resources.h> | 11 | #include <resources.h> |
11 | 12 | ||
@@ -28,6 +29,44 @@ NetworkSettingsData::NetworkSettingsData( void ) { | |||
28 | 29 | ||
29 | // load settings | 30 | // load settings |
30 | IsModified = 0; | ||
31 | loadSettings(); | 31 | loadSettings(); |
32 | |||
33 | // assign interfaces by scanning /tmp/profile-%s.Up files | ||
34 | { QDir D( "/tmp" ); | ||
35 | QFile * F = new QFile; | ||
36 | int profilenr; | ||
37 | QString interfacename; | ||
38 | QTextStream TS ( F ); | ||
39 | |||
40 | QStringList SL = D.entryList( "profile-*.up"); | ||
41 | |||
42 | Log(( "System reports %d interfaces. Found %d up\n", | ||
43 | NSResources->system().interfaces().count(), | ||
44 | SL.count() )); | ||
45 | |||
46 | for ( QStringList::Iterator it = SL.begin(); | ||
47 | it != SL.end(); | ||
48 | ++it ) { | ||
49 | profilenr = atol( (*it).mid( 8 ).latin1() ); | ||
50 | // read the interface store int 'up' | ||
51 | F->setName( D.path() + "/" + (*it) ); | ||
52 | if( F->open( IO_ReadOnly ) ) { | ||
53 | NodeCollection * NC; | ||
54 | interfacename = TS.readLine(); | ||
55 | F->close(); | ||
56 | |||
57 | Log(( "Assign interface %s to Profile nr %d\n", | ||
58 | interfacename.latin1(), profilenr )); | ||
59 | |||
60 | NC = NSResources->getConnection( profilenr ); | ||
61 | if( NC ) { | ||
62 | NC->assignInterface( | ||
63 | NSResources->system().findInterface( interfacename ) ); | ||
64 | } else { | ||
65 | Log(( "Profile nr %d no longer defined\n", | ||
66 | profilenr )); | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | } | ||
32 | } | 71 | } |
33 | 72 | ||
@@ -45,4 +84,6 @@ void NetworkSettingsData::loadSettings( void ) { | |||
45 | QTextStream TS( &F ); | 84 | QTextStream TS( &F ); |
46 | 85 | ||
86 | ForceModified = 0; | ||
87 | |||
47 | do { | 88 | do { |
48 | 89 | ||
@@ -86,9 +127,7 @@ void NetworkSettingsData::loadSettings( void ) { | |||
86 | // try to find netnode | 127 | // try to find netnode |
87 | NN = NSResources->findNetNode( S ); | 128 | NN = NSResources->findNetNode( S ); |
88 | Log( ( "Node %s : %p\n", S.latin1(), NN ) ); | ||
89 | } else { | 129 | } else { |
90 | // try to find instance | 130 | // try to find instance |
91 | NNI = NSResources->createNodeInstance( S ); | 131 | NNI = NSResources->createNodeInstance( S ); |
92 | Log( ( "NodeInstance %s : %p\n", S.latin1(), NNI )); | ||
93 | } | 132 | } |
94 | 133 | ||
@@ -139,7 +178,11 @@ void NetworkSettingsData::loadSettings( void ) { | |||
139 | if( NNI ) { | 178 | if( NNI ) { |
140 | // loading from file -> exists | 179 | // loading from file -> exists |
180 | Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI )); | ||
141 | NNI->setNew( FALSE ); | 181 | NNI->setNew( FALSE ); |
142 | NSResources->addNodeInstance( NNI ); | 182 | NSResources->addNodeInstance( NNI ); |
143 | } | 183 | } |
184 | if( NN ) { | ||
185 | Log( ( "Node %s : %p\n", NN->name(), NN ) ); | ||
186 | } | ||
144 | } | 187 | } |
145 | } | 188 | } |
@@ -221,5 +264,11 @@ QString NetworkSettingsData::saveSettings( void ) { | |||
221 | // | 264 | // |
222 | 265 | ||
223 | setModified( 0 ); | 266 | |
267 | for( QDictIterator<NodeCollection> it(NSResources->connections()); | ||
268 | it.current(); | ||
269 | ++it ) { | ||
270 | it.current()->setModified( 0 ); | ||
271 | } | ||
272 | |||
224 | return ErrS; | 273 | return ErrS; |
225 | } | 274 | } |
@@ -232,6 +281,5 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
232 | ANetNodeInstance * NNI; | 281 | ANetNodeInstance * NNI; |
233 | ANetNodeInstance * FirstWithData; | 282 | ANetNodeInstance * FirstWithData; |
234 | SystemFile * SF; | 283 | RuntimeInfo * CurDev; |
235 | AsDevice * CurDev; | ||
236 | ANetNode * NN, * CurDevNN = 0; | 284 | ANetNode * NN, * CurDevNN = 0; |
237 | long NoOfDevs; | 285 | long NoOfDevs; |
@@ -242,37 +290,95 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
242 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); | 290 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); |
243 | 291 | ||
244 | // | 292 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); |
245 | // generate files proper to each netnodeinstance | 293 | nnit.current(); |
246 | // | 294 | ++nnit ) { |
247 | { Name2Instance_t & NNIs = NSResources->netNodeInstances(); | 295 | { QStringList SL; |
248 | 296 | bool FirstItem = 1; | |
249 | for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); | 297 | bool Generated = 0; |
250 | NNIIt.current(); | 298 | |
251 | ++NNIIt ) { | 299 | CurDevNN = nnit.current()->NetNode; |
252 | // for all nodes find those that are modified | 300 | SL = CurDevNN->properFiles(); |
253 | NNI = NNIIt.current(); | 301 | |
254 | 302 | for ( QStringList::Iterator it = SL.begin(); | |
255 | { // get list of proper files for this nodeclass (if any) | 303 | it != SL.end(); |
256 | QStringList * PF = NNI->nodeClass()->properFiles(); | 304 | ++it ) { |
257 | 305 | ||
258 | if( PF ) { | 306 | Generated = 0; |
259 | for ( QStringList::Iterator it = PF->begin(); | 307 | FirstItem = 1; |
260 | it != PF->end(); | 308 | // iterate over NNI's of this class |
261 | ++it ) { | 309 | for( QDictIterator<ANetNodeInstance> nniit( |
262 | QFile * F = NNI->openFile( (*it) ); | 310 | NSResources->netNodeInstances() ); |
263 | if( F ) { | 311 | nniit.current(); |
264 | QTextStream TS( F ); | 312 | ++nniit ) { |
265 | if( NNI->generateFile( (*it), F->name(), TS, -1 ) == 2 ) { | 313 | if( nniit.current()->nodeClass() != CurDevNN ) |
266 | // problem generating | 314 | // different class |
315 | continue; | ||
316 | |||
317 | // open proper file | ||
318 | { SystemFile SF( (*it) ); | ||
319 | |||
320 | if( ! CurDevNN->openFile( SF, nniit.current()) ) { | ||
321 | // cannot open | ||
322 | S = qApp->translate( "NetworkSettings", | ||
323 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | ||
324 | arg( (*it) ).arg( CurDevNN->name() ); | ||
325 | return S; | ||
326 | } | ||
327 | |||
328 | if( ! SF.open() ) { | ||
329 | S = qApp->translate( "NetworkSettings", | ||
330 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | ||
331 | arg( (*it) ).arg( CurDevNN->name() ); | ||
332 | return S; | ||
333 | } | ||
334 | |||
335 | // preamble on first | ||
336 | if( FirstItem ) { | ||
337 | if( CurDevNN->generatePreamble( SF ) == 2 ) { | ||
267 | S = qApp->translate( "NetworkSettings", | 338 | S = qApp->translate( "NetworkSettings", |
268 | "<p>Cannot generate files proper to \"%1\"</p>" ). | 339 | "<p>Error in section \"preamble\" for proper file \"%1\" and node \"%2\"</p>" ). |
269 | arg(NNI->nodeClass()->name()) ; | 340 | arg( (*it) ). |
270 | delete F; | 341 | arg( CurDevNN->name() ); |
271 | return S; | 342 | return S; |
272 | } | 343 | } |
273 | delete F; | 344 | } |
345 | FirstItem = 0; | ||
346 | Generated = 1; | ||
347 | |||
348 | // item specific | ||
349 | if( nniit.current()->generateFile( SF, -1 ) == 2 ) { | ||
350 | S = qApp->translate( "NetworkSettings", | ||
351 | "<p>Error in section for node \"%1\" for proper file \"%2\" and node class \"%3\"</p>" ). | ||
352 | arg( nniit.current()->name() ). | ||
353 | arg( (*it) ). | ||
354 | arg( CurDevNN->name() ); | ||
355 | return S; | ||
274 | } | 356 | } |
275 | } | 357 | } |
276 | } | 358 | } |
359 | |||
360 | if( Generated ) { | ||
361 | SystemFile SF( (*it) ); | ||
362 | |||
363 | if( CurDevNN->openFile( SF, 0 ) && | ||
364 | ! SF.path().isEmpty() | ||
365 | ) { | ||
366 | |||
367 | if( ! SF.open() ) { | ||
368 | S = qApp->translate( "NetworkSettings", | ||
369 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | ||
370 | arg( (*it) ).arg( CurDevNN->name() ); | ||
371 | return S; | ||
372 | } | ||
373 | |||
374 | if( CurDevNN->generatePostamble( SF ) == 2 ) { | ||
375 | S = qApp->translate( "NetworkSettings", | ||
376 | "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ). | ||
377 | arg( (*it) ). | ||
378 | arg( CurDevNN->name() ); | ||
379 | return S; | ||
380 | } | ||
381 | } // no postamble | ||
382 | } | ||
277 | } | 383 | } |
278 | } | 384 | } |
@@ -280,9 +386,11 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
280 | 386 | ||
281 | // | 387 | // |
282 | // generate all system files | 388 | // generate all registered files |
283 | // | 389 | // |
284 | for( QDictIterator<SystemFile> sfit(SFM); | 390 | for( QDictIterator<SystemFile> sfit(SFM); |
285 | sfit.current(); | 391 | sfit.current(); |
286 | ++sfit ) { | 392 | ++sfit ) { |
393 | SystemFile * SF; | ||
394 | |||
287 | SF = sfit.current(); | 395 | SF = sfit.current(); |
288 | 396 | ||
@@ -307,5 +415,5 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
307 | } | 415 | } |
308 | 416 | ||
309 | Log( ( "Generating %s\n", SF->name().latin1() )); | 417 | Log( ( "Generating system file %s\n", SF->name().latin1() )); |
310 | 418 | ||
311 | needToGenerate = 0; | 419 | needToGenerate = 0; |
@@ -319,5 +427,5 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
319 | NN = nnit.current()->NetNode; | 427 | NN = nnit.current()->NetNode; |
320 | 428 | ||
321 | if( NN->hasDataForFile( SF->name() ) ) { | 429 | if( NN->hasDataForFile( *SF ) ) { |
322 | // netnode can have data | 430 | // netnode can have data |
323 | 431 | ||
@@ -346,5 +454,10 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
346 | 454 | ||
347 | // ok generate this system file | 455 | // ok generate this system file |
348 | SF->open(); | 456 | if( ! SF->open() ) { |
457 | S = qApp->translate( "NetworkSettings", | ||
458 | "<p>Cannot open system file \"%1\"</p>" ). | ||
459 | arg( SF->name() ); | ||
460 | return S; | ||
461 | } | ||
349 | 462 | ||
350 | // global presection for this system file | 463 | // global presection for this system file |
@@ -368,5 +481,5 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
368 | } | 481 | } |
369 | 482 | ||
370 | if( ! NC->hasDataForFile( SF->name() ) ) { | 483 | if( ! NC->hasDataForFile( *SF ) ) { |
371 | // no data | 484 | // no data |
372 | continue; | 485 | continue; |
@@ -376,5 +489,5 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
376 | SF->name().latin1(), NC->name().latin1() )); | 489 | SF->name().latin1(), NC->name().latin1() )); |
377 | // find highest item that wants to write data to this file | 490 | // find highest item that wants to write data to this file |
378 | FirstWithData = NC->firstWithDataForFile( SF->name() ); | 491 | FirstWithData = NC->firstWithDataForFile( *SF ); |
379 | 492 | ||
380 | // find device on which this connection works | 493 | // find device on which this connection works |
@@ -383,8 +496,4 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
383 | CurDevNN = CurDev->netNode()->nodeClass(); | 496 | CurDevNN = CurDev->netNode()->nodeClass(); |
384 | 497 | ||
385 | Log(( "%s is done %d\n", | ||
386 | FirstWithData->nodeClass()->name(), | ||
387 | FirstWithData->nodeClass()->done() )); | ||
388 | |||
389 | if( ! FirstWithData->nodeClass()->done() ) { | 498 | if( ! FirstWithData->nodeClass()->done() ) { |
390 | // generate fixed part | 499 | // generate fixed part |
@@ -397,5 +506,7 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
397 | 506 | ||
398 | if( FirstWithData->nodeClass()->generateFile( | 507 | if( FirstWithData->nodeClass()->generateFile( |
399 | SF->name(), SF->path(), *SF, -1 ) == 2 ) { | 508 | *SF, |
509 | FirstWithData, | ||
510 | -2 ) == 2 ) { | ||
400 | S = qApp->translate( "NetworkSettings", | 511 | S = qApp->translate( "NetworkSettings", |
401 | "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). | 512 | "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). |
@@ -405,4 +516,7 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
405 | } | 516 | } |
406 | FirstWithData->nodeClass()->setDone( 1 ); | 517 | FirstWithData->nodeClass()->setDone( 1 ); |
518 | Log(( "Systemfile %s for node instance %s is done\n", | ||
519 | SF->name().latin1(), | ||
520 | FirstWithData->name() )); | ||
407 | } | 521 | } |
408 | 522 | ||
@@ -415,8 +529,4 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
415 | } | 529 | } |
416 | 530 | ||
417 | Log(( "Node %s is done %d\n", | ||
418 | CurDev->netNode()->nodeClass()->name(), | ||
419 | CurDev->netNode()->nodeClass()->done() )); | ||
420 | |||
421 | if( ! CurDev->netNode()->nodeClass()->done() ) { | 531 | if( ! CurDev->netNode()->nodeClass()->done() ) { |
422 | // first time this device is handled | 532 | // first time this device is handled |
@@ -425,5 +535,5 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
425 | 535 | ||
426 | if( FirstWithData->nodeClass()->generateFile( | 536 | if( FirstWithData->nodeClass()->generateFile( |
427 | SF->name(), SF->path(), *SF, CurDev->netNode(), i ) == 2 ) { | 537 | *SF, CurDev->netNode(), i ) == 2 ) { |
428 | S = qApp->translate( "NetworkSettings", | 538 | S = qApp->translate( "NetworkSettings", |
429 | "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). | 539 | "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). |
@@ -434,4 +544,9 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
434 | } | 544 | } |
435 | CurDev->netNode()->nodeClass()->setDone( 1 ); | 545 | CurDev->netNode()->nodeClass()->setDone( 1 ); |
546 | |||
547 | Log(( "Systemfile %s for Nodeclass %s is done\n", | ||
548 | SF->name().latin1(), | ||
549 | CurDev->netNode()->nodeClass()->name() | ||
550 | )); | ||
436 | } | 551 | } |
437 | 552 | ||
@@ -447,7 +562,9 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
447 | } | 562 | } |
448 | 563 | ||
449 | Log(("Connection %s of same family\n", ncit2.current()->name().latin1() )); | 564 | Log(("Connection %s of family %s\n", |
565 | ncit2.current()->name().latin1(), | ||
566 | CurDev->name() )); | ||
450 | // generate | 567 | // generate |
451 | NNI = ncit2.current()->firstWithDataForFile( SF->name() ); | 568 | NNI = ncit2.current()->firstWithDataForFile( *SF ); |
452 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { | 569 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { |
453 | if( ! SF->preNodeSection( NNI, i ) ) { | 570 | if( ! SF->preNodeSection( NNI, i ) ) { |
@@ -459,6 +576,5 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
459 | } | 576 | } |
460 | 577 | ||
461 | switch( NNI->generateFile( | 578 | switch( NNI->generateFile( *SF, i ) ) { |
462 | SF->name(), SF->path(), *SF, i ) ) { | ||
463 | case 0 : | 579 | case 0 : |
464 | (*SF) << endl; | 580 | (*SF) << endl; |
@@ -570,7 +686,12 @@ bool NetworkSettingsData::canStart( const char * Interface ) { | |||
570 | case Off : | 686 | case Off : |
571 | // try to UP the device | 687 | // try to UP the device |
572 | if( ! NC->setState( Activate ) ) { | 688 | { QString S= NC->setState( Activate ); |
573 | // cannot bring device Online -> try other alters | 689 | if( ! S.isEmpty() ) { |
574 | break; | 690 | // could not bring device Online -> try other alters |
691 | Log(( "%s-c%d-disallowed : %s\n", | ||
692 | Interface, NC->number(), S.latin1() )); | ||
693 | break; | ||
694 | } | ||
695 | // interface assigned | ||
575 | } | 696 | } |
576 | // FT | 697 | // FT |
@@ -590,13 +711,14 @@ bool NetworkSettingsData::canStart( const char * Interface ) { | |||
590 | } | 711 | } |
591 | 712 | ||
592 | /* | 713 | bool NetworkSettingsData::isModified( void ) { |
593 | Called by the system to regenerate config files | 714 | if( ForceModified ) |
594 | */ | ||
595 | |||
596 | bool NetworkSettingsData::regenerate( void ) { | ||
597 | QString S = generateSettings(); | ||
598 | if( ! S.isEmpty() ) { | ||
599 | fprintf( stdout, "%s\n", S.latin1() ); | ||
600 | return 1; | 715 | return 1; |
716 | |||
717 | for( QDictIterator<NodeCollection> it(NSResources->connections()); | ||
718 | it.current(); | ||
719 | ++it ) { | ||
720 | if( it.current()->isModified() ) { | ||
721 | return 1; | ||
722 | } | ||
601 | } | 723 | } |
602 | return 0; | 724 | return 0; |