Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/nsdata.cpp | 242 |
1 files changed, 182 insertions, 60 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,2 +1,3 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <opie2/odebug.h> | ||
2 | #include <qpe/qpeapplication.h> | 3 | #include <qpe/qpeapplication.h> |
@@ -8,3 +9,3 @@ | |||
8 | #include "nsdata.h" | 9 | #include "nsdata.h" |
9 | #include <asdevice.h> | 10 | #include <netnode.h> |
10 | #include <resources.h> | 11 | #include <resources.h> |
@@ -29,4 +30,42 @@ NetworkSettingsData::NetworkSettingsData( void ) { | |||
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 | } |
@@ -46,2 +85,4 @@ void NetworkSettingsData::loadSettings( void ) { | |||
46 | 85 | ||
86 | ForceModified = 0; | ||
87 | |||
47 | do { | 88 | do { |
@@ -87,3 +128,2 @@ void NetworkSettingsData::loadSettings( void ) { | |||
87 | NN = NSResources->findNetNode( S ); | 128 | NN = NSResources->findNetNode( S ); |
88 | Log( ( "Node %s : %p\n", S.latin1(), NN ) ); | ||
89 | } else { | 129 | } else { |
@@ -91,3 +131,2 @@ void NetworkSettingsData::loadSettings( void ) { | |||
91 | NNI = NSResources->createNodeInstance( S ); | 131 | NNI = NSResources->createNodeInstance( S ); |
92 | Log( ( "NodeInstance %s : %p\n", S.latin1(), NNI )); | ||
93 | } | 132 | } |
@@ -140,2 +179,3 @@ void NetworkSettingsData::loadSettings( void ) { | |||
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 ); |
@@ -143,2 +183,5 @@ void NetworkSettingsData::loadSettings( void ) { | |||
143 | } | 183 | } |
184 | if( NN ) { | ||
185 | Log( ( "Node %s : %p\n", NN->name(), NN ) ); | ||
186 | } | ||
144 | } | 187 | } |
@@ -222,3 +265,9 @@ QString NetworkSettingsData::saveSettings( void ) { | |||
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; |
@@ -233,4 +282,3 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
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; |
@@ -243,34 +291,92 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
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(); | ||
251 | ++NNIIt ) { | ||
252 | // for all nodes find those that are modified | ||
253 | NNI = NNIIt.current(); | ||
254 | 298 | ||
255 | { // get list of proper files for this nodeclass (if any) | 299 | CurDevNN = nnit.current()->NetNode; |
256 | QStringList * PF = NNI->nodeClass()->properFiles(); | 300 | SL = CurDevNN->properFiles(); |
257 | 301 | ||
258 | if( PF ) { | 302 | for ( QStringList::Iterator it = SL.begin(); |
259 | for ( QStringList::Iterator it = PF->begin(); | 303 | it != SL.end(); |
260 | it != PF->end(); | ||
261 | ++it ) { | 304 | ++it ) { |
262 | QFile * F = NNI->openFile( (*it) ); | 305 | |
263 | if( F ) { | 306 | Generated = 0; |
264 | QTextStream TS( F ); | 307 | FirstItem = 1; |
265 | if( NNI->generateFile( (*it), F->name(), TS, -1 ) == 2 ) { | 308 | // iterate over NNI's of this class |
266 | // problem generating | 309 | for( QDictIterator<ANetNodeInstance> nniit( |
310 | NSResources->netNodeInstances() ); | ||
311 | nniit.current(); | ||
312 | ++nniit ) { | ||
313 | if( nniit.current()->nodeClass() != CurDevNN ) | ||
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; | ||
274 | } | 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; | ||
356 | } | ||
357 | } | ||
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; | ||
275 | } | 380 | } |
381 | } // no postamble | ||
276 | } | 382 | } |
@@ -281,3 +387,3 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
281 | // | 387 | // |
282 | // generate all system files | 388 | // generate all registered files |
283 | // | 389 | // |
@@ -286,2 +392,4 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
286 | ++sfit ) { | 392 | ++sfit ) { |
393 | SystemFile * SF; | ||
394 | |||
287 | SF = sfit.current(); | 395 | SF = sfit.current(); |
@@ -308,3 +416,3 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
308 | 416 | ||
309 | Log( ( "Generating %s\n", SF->name().latin1() )); | 417 | Log( ( "Generating system file %s\n", SF->name().latin1() )); |
310 | 418 | ||
@@ -320,3 +428,3 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
320 | 428 | ||
321 | if( NN->hasDataForFile( SF->name() ) ) { | 429 | if( NN->hasDataForFile( *SF ) ) { |
322 | // netnode can have data | 430 | // netnode can have data |
@@ -347,3 +455,8 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
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 | ||
@@ -369,3 +482,3 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
369 | 482 | ||
370 | if( ! NC->hasDataForFile( SF->name() ) ) { | 483 | if( ! NC->hasDataForFile( *SF ) ) { |
371 | // no data | 484 | // no data |
@@ -377,3 +490,3 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
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 | ||
@@ -384,6 +497,2 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
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() ) { |
@@ -398,3 +507,5 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
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", |
@@ -406,2 +517,5 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
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 | } |
@@ -416,6 +530,2 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
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() ) { |
@@ -426,3 +536,3 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
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", |
@@ -435,2 +545,7 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
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 | } |
@@ -448,5 +563,7 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
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 ++ ) { |
@@ -460,4 +577,3 @@ QString NetworkSettingsData::generateSettings( void ) { | |||
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 : |
@@ -571,6 +687,11 @@ bool NetworkSettingsData::canStart( const char * Interface ) { | |||
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() ) { |
690 | // could not bring device Online -> try other alters | ||
691 | Log(( "%s-c%d-disallowed : %s\n", | ||
692 | Interface, NC->number(), S.latin1() )); | ||
574 | break; | 693 | break; |
575 | } | 694 | } |
695 | // interface assigned | ||
696 | } | ||
576 | // FT | 697 | // FT |
@@ -591,12 +712,13 @@ bool NetworkSettingsData::canStart( const char * Interface ) { | |||
591 | 712 | ||
592 | /* | 713 | bool NetworkSettingsData::isModified( void ) { |
593 | Called by the system to regenerate config files | 714 | if( ForceModified ) |
594 | */ | 715 | return 1; |
595 | 716 | ||
596 | bool NetworkSettingsData::regenerate( void ) { | 717 | for( QDictIterator<NodeCollection> it(NSResources->connections()); |
597 | QString S = generateSettings(); | 718 | it.current(); |
598 | if( ! S.isEmpty() ) { | 719 | ++it ) { |
599 | fprintf( stdout, "%s\n", S.latin1() ); | 720 | if( it.current()->isModified() ) { |
600 | return 1; | 721 | return 1; |
601 | } | 722 | } |
723 | } | ||
602 | return 0; | 724 | return 0; |