author | wimpie <wimpie> | 2005-01-04 01:35:26 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2005-01-04 01:35:26 (UTC) |
commit | a9c188235c97e07b0eb96b13adbcdfd4bad64767 (patch) (side-by-side diff) | |
tree | 13f6ae5c499dc0c1d1bd4b763a1973a0fa8635cf /noncore/settings/networksettings2/nsdata.cpp | |
parent | 48b6cd5966ec6cc0b968edf10ba1a1ad96ef165f (diff) | |
download | opie-a9c188235c97e07b0eb96b13adbcdfd4bad64767.zip opie-a9c188235c97e07b0eb96b13adbcdfd4bad64767.tar.gz opie-a9c188235c97e07b0eb96b13adbcdfd4bad64767.tar.bz2 |
CONTROL files : changed version string
NS2 many changes and first release of OT2
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,2 +1,3 @@ #include <stdlib.h> +#include <opie2/odebug.h> #include <qpe/qpeapplication.h> @@ -8,3 +9,3 @@ #include "nsdata.h" -#include <asdevice.h> +#include <netnode.h> #include <resources.h> @@ -29,4 +30,42 @@ NetworkSettingsData::NetworkSettingsData( void ) { // load settings - IsModified = 0; loadSettings(); + + // assign interfaces by scanning /tmp/profile-%s.Up files + { QDir D( "/tmp" ); + QFile * F = new QFile; + int profilenr; + QString interfacename; + QTextStream TS ( F ); + + QStringList SL = D.entryList( "profile-*.up"); + + Log(( "System reports %d interfaces. Found %d up\n", + NSResources->system().interfaces().count(), + SL.count() )); + + for ( QStringList::Iterator it = SL.begin(); + it != SL.end(); + ++it ) { + profilenr = atol( (*it).mid( 8 ).latin1() ); + // read the interface store int 'up' + F->setName( D.path() + "/" + (*it) ); + if( F->open( IO_ReadOnly ) ) { + NodeCollection * NC; + interfacename = TS.readLine(); + F->close(); + + Log(( "Assign interface %s to Profile nr %d\n", + interfacename.latin1(), profilenr )); + + NC = NSResources->getConnection( profilenr ); + if( NC ) { + NC->assignInterface( + NSResources->system().findInterface( interfacename ) ); + } else { + Log(( "Profile nr %d no longer defined\n", + profilenr )); + } + } + } + } } @@ -46,2 +85,4 @@ void NetworkSettingsData::loadSettings( void ) { + ForceModified = 0; + do { @@ -87,3 +128,2 @@ void NetworkSettingsData::loadSettings( void ) { NN = NSResources->findNetNode( S ); - Log( ( "Node %s : %p\n", S.latin1(), NN ) ); } else { @@ -91,3 +131,2 @@ void NetworkSettingsData::loadSettings( void ) { NNI = NSResources->createNodeInstance( S ); - Log( ( "NodeInstance %s : %p\n", S.latin1(), NNI )); } @@ -140,2 +179,3 @@ void NetworkSettingsData::loadSettings( void ) { // loading from file -> exists + Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI )); NNI->setNew( FALSE ); @@ -143,2 +183,5 @@ void NetworkSettingsData::loadSettings( void ) { } + if( NN ) { + Log( ( "Node %s : %p\n", NN->name(), NN ) ); + } } @@ -222,3 +265,9 @@ QString NetworkSettingsData::saveSettings( void ) { - setModified( 0 ); + + for( QDictIterator<NodeCollection> it(NSResources->connections()); + it.current(); + ++it ) { + it.current()->setModified( 0 ); + } + return ErrS; @@ -233,4 +282,3 @@ QString NetworkSettingsData::generateSettings( void ) { ANetNodeInstance * FirstWithData; - SystemFile * SF; - AsDevice * CurDev; + RuntimeInfo * CurDev; ANetNode * NN, * CurDevNN = 0; @@ -243,32 +291,66 @@ QString NetworkSettingsData::generateSettings( void ) { - // - // generate files proper to each netnodeinstance - // - { Name2Instance_t & NNIs = NSResources->netNodeInstances(); - - for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); - NNIIt.current(); - ++NNIIt ) { - // for all nodes find those that are modified - NNI = NNIIt.current(); - - { // get list of proper files for this nodeclass (if any) - QStringList * PF = NNI->nodeClass()->properFiles(); - - if( PF ) { - for ( QStringList::Iterator it = PF->begin(); - it != PF->end(); - ++it ) { - QFile * F = NNI->openFile( (*it) ); - if( F ) { - QTextStream TS( F ); - if( NNI->generateFile( (*it), F->name(), TS, -1 ) == 2 ) { - // problem generating + for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); + nnit.current(); + ++nnit ) { + { QStringList SL; + bool FirstItem = 1; + bool Generated = 0; + + CurDevNN = nnit.current()->NetNode; + SL = CurDevNN->properFiles(); + + for ( QStringList::Iterator it = SL.begin(); + it != SL.end(); + ++it ) { + + Generated = 0; + FirstItem = 1; + // iterate over NNI's of this class + for( QDictIterator<ANetNodeInstance> nniit( + NSResources->netNodeInstances() ); + nniit.current(); + ++nniit ) { + if( nniit.current()->nodeClass() != CurDevNN ) + // different class + continue; + + // open proper file + { SystemFile SF( (*it) ); + + if( ! CurDevNN->openFile( SF, nniit.current()) ) { + // cannot open + S = qApp->translate( "NetworkSettings", + "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). + arg( (*it) ).arg( CurDevNN->name() ); + return S; + } + + if( ! SF.open() ) { + S = qApp->translate( "NetworkSettings", + "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). + arg( (*it) ).arg( CurDevNN->name() ); + return S; + } + + // preamble on first + if( FirstItem ) { + if( CurDevNN->generatePreamble( SF ) == 2 ) { S = qApp->translate( "NetworkSettings", - "<p>Cannot generate files proper to \"%1\"</p>" ). - arg(NNI->nodeClass()->name()) ; - delete F; + "<p>Error in section \"preamble\" for proper file \"%1\" and node \"%2\"</p>" ). + arg( (*it) ). + arg( CurDevNN->name() ); return S; } - delete F; + } + FirstItem = 0; + Generated = 1; + + // item specific + if( nniit.current()->generateFile( SF, -1 ) == 2 ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in section for node \"%1\" for proper file \"%2\" and node class \"%3\"</p>" ). + arg( nniit.current()->name() ). + arg( (*it) ). + arg( CurDevNN->name() ); + return S; } @@ -276,2 +358,26 @@ QString NetworkSettingsData::generateSettings( void ) { } + + if( Generated ) { + SystemFile SF( (*it) ); + + if( CurDevNN->openFile( SF, 0 ) && + ! SF.path().isEmpty() + ) { + + if( ! SF.open() ) { + S = qApp->translate( "NetworkSettings", + "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). + arg( (*it) ).arg( CurDevNN->name() ); + return S; + } + + if( CurDevNN->generatePostamble( SF ) == 2 ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ). + arg( (*it) ). + arg( CurDevNN->name() ); + return S; + } + } // no postamble + } } @@ -281,3 +387,3 @@ QString NetworkSettingsData::generateSettings( void ) { // - // generate all system files + // generate all registered files // @@ -286,2 +392,4 @@ QString NetworkSettingsData::generateSettings( void ) { ++sfit ) { + SystemFile * SF; + SF = sfit.current(); @@ -308,3 +416,3 @@ QString NetworkSettingsData::generateSettings( void ) { - Log( ( "Generating %s\n", SF->name().latin1() )); + Log( ( "Generating system file %s\n", SF->name().latin1() )); @@ -320,3 +428,3 @@ QString NetworkSettingsData::generateSettings( void ) { - if( NN->hasDataForFile( SF->name() ) ) { + if( NN->hasDataForFile( *SF ) ) { // netnode can have data @@ -347,3 +455,8 @@ QString NetworkSettingsData::generateSettings( void ) { // ok generate this system file - SF->open(); + if( ! SF->open() ) { + S = qApp->translate( "NetworkSettings", + "<p>Cannot open system file \"%1\"</p>" ). + arg( SF->name() ); + return S; + } @@ -369,3 +482,3 @@ QString NetworkSettingsData::generateSettings( void ) { - if( ! NC->hasDataForFile( SF->name() ) ) { + if( ! NC->hasDataForFile( *SF ) ) { // no data @@ -377,3 +490,3 @@ QString NetworkSettingsData::generateSettings( void ) { // find highest item that wants to write data to this file - FirstWithData = NC->firstWithDataForFile( SF->name() ); + FirstWithData = NC->firstWithDataForFile( *SF ); @@ -384,6 +497,2 @@ QString NetworkSettingsData::generateSettings( void ) { - Log(( "%s is done %d\n", - FirstWithData->nodeClass()->name(), - FirstWithData->nodeClass()->done() )); - if( ! FirstWithData->nodeClass()->done() ) { @@ -398,3 +507,5 @@ QString NetworkSettingsData::generateSettings( void ) { if( FirstWithData->nodeClass()->generateFile( - SF->name(), SF->path(), *SF, -1 ) == 2 ) { + *SF, + FirstWithData, + -2 ) == 2 ) { S = qApp->translate( "NetworkSettings", @@ -406,2 +517,5 @@ QString NetworkSettingsData::generateSettings( void ) { FirstWithData->nodeClass()->setDone( 1 ); + Log(( "Systemfile %s for node instance %s is done\n", + SF->name().latin1(), + FirstWithData->name() )); } @@ -416,6 +530,2 @@ QString NetworkSettingsData::generateSettings( void ) { - Log(( "Node %s is done %d\n", - CurDev->netNode()->nodeClass()->name(), - CurDev->netNode()->nodeClass()->done() )); - if( ! CurDev->netNode()->nodeClass()->done() ) { @@ -426,3 +536,3 @@ QString NetworkSettingsData::generateSettings( void ) { if( FirstWithData->nodeClass()->generateFile( - SF->name(), SF->path(), *SF, CurDev->netNode(), i ) == 2 ) { + *SF, CurDev->netNode(), i ) == 2 ) { S = qApp->translate( "NetworkSettings", @@ -435,2 +545,7 @@ QString NetworkSettingsData::generateSettings( void ) { CurDev->netNode()->nodeClass()->setDone( 1 ); + + Log(( "Systemfile %s for Nodeclass %s is done\n", + SF->name().latin1(), + CurDev->netNode()->nodeClass()->name() + )); } @@ -448,5 +563,7 @@ QString NetworkSettingsData::generateSettings( void ) { - Log(("Connection %s of same family\n", ncit2.current()->name().latin1() )); + Log(("Connection %s of family %s\n", + ncit2.current()->name().latin1(), + CurDev->name() )); // generate - NNI = ncit2.current()->firstWithDataForFile( SF->name() ); + NNI = ncit2.current()->firstWithDataForFile( *SF ); for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { @@ -460,4 +577,3 @@ QString NetworkSettingsData::generateSettings( void ) { - switch( NNI->generateFile( - SF->name(), SF->path(), *SF, i ) ) { + switch( NNI->generateFile( *SF, i ) ) { case 0 : @@ -571,5 +687,10 @@ bool NetworkSettingsData::canStart( const char * Interface ) { // try to UP the device - if( ! NC->setState( Activate ) ) { - // cannot bring device Online -> try other alters - break; + { QString S= NC->setState( Activate ); + if( ! S.isEmpty() ) { + // could not bring device Online -> try other alters + Log(( "%s-c%d-disallowed : %s\n", + Interface, NC->number(), S.latin1() )); + break; + } + // interface assigned } @@ -591,11 +712,12 @@ bool NetworkSettingsData::canStart( const char * Interface ) { -/* - Called by the system to regenerate config files -*/ - -bool NetworkSettingsData::regenerate( void ) { - QString S = generateSettings(); - if( ! S.isEmpty() ) { - fprintf( stdout, "%s\n", S.latin1() ); +bool NetworkSettingsData::isModified( void ) { + if( ForceModified ) return 1; + + for( QDictIterator<NodeCollection> it(NSResources->connections()); + it.current(); + ++it ) { + if( it.current()->isModified() ) { + return 1; + } } |