summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/nsdata.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/nsdata.cpp252
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,4 +1,5 @@
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>
4#include <qdir.h> 5#include <qdir.h>
@@ -6,7 +7,7 @@
6#include <qfileinfo.h> 7#include <qfileinfo.h>
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
12static QString CfgFile; 13static QString CfgFile;
@@ -27,8 +28,46 @@ NetworkSettingsData::NetworkSettingsData( void ) {
27 Log(( "Cfg from %s\n", CfgFile.latin1() )); 28 Log(( "Cfg from %s\n", CfgFile.latin1() ));
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
34// saving is done by caller 73// saving is done by caller
@@ -44,6 +83,8 @@ void NetworkSettingsData::loadSettings( void ) {
44 QFile F( CfgFile ); 83 QFile F( CfgFile );
45 QTextStream TS( &F ); 84 QTextStream TS( &F );
46 85
86 ForceModified = 0;
87
47 do { 88 do {
48 89
49 if( ! F.open(IO_ReadOnly) ) 90 if( ! F.open(IO_ReadOnly) )
@@ -85,11 +126,9 @@ void NetworkSettingsData::loadSettings( void ) {
85 S = deQuote(S); 126 S = deQuote(S);
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
95 if( NN == 0 && NNI == 0 ) { 134 if( NN == 0 && NNI == 0 ) {
@@ -138,9 +177,13 @@ void NetworkSettingsData::loadSettings( void ) {
138 177
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 }
146 189
@@ -220,7 +263,13 @@ QString NetworkSettingsData::saveSettings( void ) {
220 // proper files AND system files regenerated 263 // proper files AND system files regenerated
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}
226 275
@@ -231,8 +280,7 @@ QString NetworkSettingsData::generateSettings( void ) {
231 NodeCollection * NC; 280 NodeCollection * NC;
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;
238 long DevCtStart; 286 long DevCtStart;
@@ -241,49 +289,109 @@ QString NetworkSettingsData::generateSettings( void ) {
241 // regenerate system files 289 // regenerate system files
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 }
279 } 385 }
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
289 // reset all 397 // reset all
@@ -306,7 +414,7 @@ QString NetworkSettingsData::generateSettings( void ) {
306 ncit.current()->setDone(0); 414 ncit.current()->setDone(0);
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;
312 420
@@ -318,7 +426,7 @@ QString NetworkSettingsData::generateSettings( void ) {
318 426
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
324 // are there instances of this node ? 432 // are there instances of this node ?
@@ -345,7 +453,12 @@ QString NetworkSettingsData::generateSettings( void ) {
345 } 453 }
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
351 if( ! SF->preSection() ) { 464 if( ! SF->preSection() ) {
@@ -367,7 +480,7 @@ QString NetworkSettingsData::generateSettings( void ) {
367 continue; 480 continue;
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;
373 } 486 }
@@ -375,17 +488,13 @@ QString NetworkSettingsData::generateSettings( void ) {
375 Log(("Generating %s for connection %s\n", 488 Log(("Generating %s for connection %s\n",
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
381 CurDev = NC->device(); 494 CurDev = NC->device();
382 // class of that node 495 // class of that node
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
391 if( ! SF->preDeviceSection( CurDevNN ) ) { 500 if( ! SF->preDeviceSection( CurDevNN ) ) {
@@ -396,7 +505,9 @@ QString NetworkSettingsData::generateSettings( void ) {
396 } 505 }
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>" ).
402 arg( SF->name() ). 513 arg( SF->name() ).
@@ -404,6 +515,9 @@ QString NetworkSettingsData::generateSettings( void ) {
404 return S; 515 return S;
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
409 NoOfDevs = 0; 523 NoOfDevs = 0;
@@ -414,17 +528,13 @@ QString NetworkSettingsData::generateSettings( void ) {
414 NoOfDevs = CurDevNN->instanceCount(); 528 NoOfDevs = CurDevNN->instanceCount();
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
423 // generate common device specific part 533 // generate common device specific part
424 for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { 534 for( int i = DevCtStart; i < NoOfDevs ; i ++ ) {
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>" ).
430 arg( SF->name() ). 540 arg( SF->name() ).
@@ -433,6 +543,11 @@ QString NetworkSettingsData::generateSettings( void ) {
433 } 543 }
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
438 // generate profile specific info 553 // generate profile specific info
@@ -446,9 +561,11 @@ QString NetworkSettingsData::generateSettings( void ) {
446 continue; 561 continue;
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 ) ) {
454 S = qApp->translate( "NetworkSettings", 571 S = qApp->translate( "NetworkSettings",
@@ -458,8 +575,7 @@ QString NetworkSettingsData::generateSettings( void ) {
458 return S; 575 return S;
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;
465 break; 581 break;
@@ -569,9 +685,14 @@ bool NetworkSettingsData::canStart( const char * Interface ) {
569 break; 685 break;
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
577 case Available : 698 case Available :
@@ -589,15 +710,16 @@ bool NetworkSettingsData::canStart( const char * Interface ) {
589 return 0; 710 return 0;
590} 711}
591 712
592/* 713bool NetworkSettingsData::isModified( void ) {
593 Called by the system to regenerate config files 714 if( ForceModified )
594*/
595
596bool 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;
603} 725}