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,13 +1,14 @@ #include <stdlib.h> +#include <opie2/odebug.h> #include <qpe/qpeapplication.h> #include <qtextstream.h> #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include "nsdata.h" -#include <asdevice.h> +#include <netnode.h> #include <resources.h> static QString CfgFile; @@ -26,10 +27,48 @@ NetworkSettingsData::NetworkSettingsData( void ) { NSResources->currentUser().HomeDir.latin1() ); Log(( "Cfg from %s\n", CfgFile.latin1() )); // 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 )); + } + } + } + } } // saving is done by caller NetworkSettingsData::~NetworkSettingsData( void ) { @@ -43,8 +82,10 @@ void NetworkSettingsData::loadSettings( void ) { QFile F( CfgFile ); QTextStream TS( &F ); + ForceModified = 0; + do { if( ! F.open(IO_ReadOnly) ) break; @@ -84,13 +125,11 @@ void NetworkSettingsData::loadSettings( void ) { S = S.mid( 9, S.length()-9 ); S = deQuote(S); // try to find netnode NN = NSResources->findNetNode( S ); - Log( ( "Node %s : %p\n", S.latin1(), NN ) ); } else { // try to find instance NNI = NSResources->createNodeInstance( S ); - Log( ( "NodeInstance %s : %p\n", S.latin1(), NNI )); } if( NN == 0 && NNI == 0 ) { LeftOvers.append( Line ); @@ -137,11 +176,15 @@ void NetworkSettingsData::loadSettings( void ) { } while( 1 ); if( NNI ) { // loading from file -> exists + Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI )); NNI->setNew( FALSE ); NSResources->addNodeInstance( NNI ); } + if( NN ) { + Log( ( "Node %s : %p\n", NN->name(), NN ) ); + } } } } while( 0 ); @@ -219,9 +262,15 @@ QString NetworkSettingsData::saveSettings( void ) { // // proper files AND system files regenerated // - setModified( 0 ); + + for( QDictIterator<NodeCollection> it(NSResources->connections()); + it.current(); + ++it ) { + it.current()->setModified( 0 ); + } + return ErrS; } QString NetworkSettingsData::generateSettings( void ) { @@ -230,61 +279,120 @@ QString NetworkSettingsData::generateSettings( void ) { Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; ANetNodeInstance * NNI; ANetNodeInstance * FirstWithData; - SystemFile * SF; - AsDevice * CurDev; + RuntimeInfo * CurDev; ANetNode * NN, * CurDevNN = 0; long NoOfDevs; long DevCtStart; bool needToGenerate; // regenerate system files Log( ( "Generating settings from %s\n", CfgFile.latin1() )); - // - // 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; } } } + + 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 + } } } } // - // generate all system files + // generate all registered files // for( QDictIterator<SystemFile> sfit(SFM); sfit.current(); ++sfit ) { + SystemFile * SF; + SF = sfit.current(); // reset all for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); @@ -305,9 +413,9 @@ QString NetworkSettingsData::generateSettings( void ) { ++ncit ) { ncit.current()->setDone(0); } - Log( ( "Generating %s\n", SF->name().latin1() )); + Log( ( "Generating system file %s\n", SF->name().latin1() )); needToGenerate = 0; // are there netnodes that have instances and need @@ -317,9 +425,9 @@ QString NetworkSettingsData::generateSettings( void ) { ++nnit ) { NN = nnit.current()->NetNode; - if( NN->hasDataForFile( SF->name() ) ) { + if( NN->hasDataForFile( *SF ) ) { // netnode can have data // are there instances of this node ? for( QDictIterator<ANetNodeInstance> nniit( @@ -344,9 +452,14 @@ QString NetworkSettingsData::generateSettings( void ) { continue; } // 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; + } // global presection for this system file if( ! SF->preSection() ) { S = qApp->translate( "NetworkSettings", @@ -366,27 +479,23 @@ QString NetworkSettingsData::generateSettings( void ) { // already done continue; } - if( ! NC->hasDataForFile( SF->name() ) ) { + if( ! NC->hasDataForFile( *SF ) ) { // no data continue; } Log(("Generating %s for connection %s\n", SF->name().latin1(), NC->name().latin1() )); // find highest item that wants to write data to this file - FirstWithData = NC->firstWithDataForFile( SF->name() ); + FirstWithData = NC->firstWithDataForFile( *SF ); // find device on which this connection works CurDev = NC->device(); // class of that node CurDevNN = CurDev->netNode()->nodeClass(); - Log(( "%s is done %d\n", - FirstWithData->nodeClass()->name(), - FirstWithData->nodeClass()->done() )); - if( ! FirstWithData->nodeClass()->done() ) { // generate fixed part if( ! SF->preDeviceSection( CurDevNN ) ) { S = qApp->translate( "NetworkSettings", @@ -395,16 +504,21 @@ QString NetworkSettingsData::generateSettings( void ) { return S; } if( FirstWithData->nodeClass()->generateFile( - SF->name(), SF->path(), *SF, -1 ) == 2 ) { + *SF, + FirstWithData, + -2 ) == 2 ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). arg( SF->name() ). arg( CurDevNN->name() ); return S; } FirstWithData->nodeClass()->setDone( 1 ); + Log(( "Systemfile %s for node instance %s is done\n", + SF->name().latin1(), + FirstWithData->name() )); } NoOfDevs = 0; DevCtStart = -1; @@ -413,27 +527,28 @@ QString NetworkSettingsData::generateSettings( void ) { DevCtStart = 0; NoOfDevs = CurDevNN->instanceCount(); } - Log(( "Node %s is done %d\n", - CurDev->netNode()->nodeClass()->name(), - CurDev->netNode()->nodeClass()->done() )); - if( ! CurDev->netNode()->nodeClass()->done() ) { // first time this device is handled // generate common device specific part for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { if( FirstWithData->nodeClass()->generateFile( - SF->name(), SF->path(), *SF, CurDev->netNode(), i ) == 2 ) { + *SF, CurDev->netNode(), i ) == 2 ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). arg( SF->name() ). arg( CurDevNN->name() ); return S; } } CurDev->netNode()->nodeClass()->setDone( 1 ); + + Log(( "Systemfile %s for Nodeclass %s is done\n", + SF->name().latin1(), + CurDev->netNode()->nodeClass()->name() + )); } // generate profile specific info // for all nodeconnections that work on the same device @@ -445,11 +560,13 @@ QString NetworkSettingsData::generateSettings( void ) { // different device continue; } - 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 ++ ) { if( ! SF->preNodeSection( NNI, i ) ) { S = qApp->translate( "NetworkSettings", "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). @@ -457,10 +574,9 @@ QString NetworkSettingsData::generateSettings( void ) { arg( CurDevNN->name() ); return S; } - switch( NNI->generateFile( - SF->name(), SF->path(), *SF, i ) ) { + switch( NNI->generateFile( *SF, i ) ) { case 0 : (*SF) << endl; break; case 1 : @@ -568,11 +684,16 @@ bool NetworkSettingsData::canStart( const char * Interface ) { // -> try others break; case Off : // 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 } // FT case Available : case IsUp : // also called for 'ifdown' @@ -588,16 +709,17 @@ bool NetworkSettingsData::canStart( const char * Interface ) { printf( "%s-cnn-disallowed\n", Interface ); return 0; } -/* - 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; + } } return 0; } |