summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/nsdata.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/nsdata.cpp108
1 files changed, 54 insertions, 54 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp
index 39031ed..b4622fc 100644
--- a/noncore/settings/networksettings2/nsdata.cpp
+++ b/noncore/settings/networksettings2/nsdata.cpp
@@ -29,119 +29,119 @@ NetworkSettingsData::NetworkSettingsData( void ) {
// load settings
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;
+ NetworkSetup * NC;
interfacename = TS.readLine();
F->close();
Log(( "Assign interface %s to Profile nr %d\n",
interfacename.latin1(), profilenr ));
- NC = NSResources->getConnection( profilenr );
+ NC = NSResources->getNetworkSetup( profilenr );
if( NC ) {
NC->assignInterface(
NSResources->system().findInterface( interfacename ) );
Log(( "Assign interface %p\n",
NC->assignedInterface() ));
} else {
Log(( "Profile nr %d no longer defined\n",
profilenr ));
}
}
}
}
}
// saving is done by caller
NetworkSettingsData::~NetworkSettingsData( void ) {
delete NSResources;
}
void NetworkSettingsData::loadSettings( void ) {
QString Line, S;
QString Attr, Value;
long idx;
QFile F( CfgFile );
QTextStream TS( &F );
ForceModified = 0;
do {
if( ! F.open(IO_ReadOnly) )
break;
/* load the file ->
FORMAT :
[NETNODETYPE]
Entries ...
<EMPTYLINE>
- [connection]
+ [NetworkSetup]
Name=Name
Node=Name
<EMPTYLINE>
*/
while( ! TS.atEnd() ) {
S = Line = TS.readLine();
if ( S.isEmpty() || S[0] != '[' )
continue;
S = S.mid( 1, S.length()-2 );
if( ! NSResources ) {
continue;
}
- if( S == "connection" ) {
- // load connections -> collections of nodes
+ if( S == "NetworkSetup" ) {
+ // load NetworkSetups -> collections of nodes
bool Dangling;
- NodeCollection * NC = new NodeCollection( TS, Dangling );
- NSResources->addConnection( NC, Dangling );
+ NetworkSetup * NC = new NetworkSetup( TS, Dangling );
+ NSResources->addNetworkSetup( NC, Dangling );
} else {
ANetNode * NN = 0;
ANetNodeInstance* NNI = 0;
if( S.startsWith( "nodetype " ) ) {
S = S.mid( 9, S.length()-9 );
S = deQuote(S);
// try to find netnode
NN = NSResources->findNetNode( S );
} else {
// try to find instance
NNI = NSResources->createNodeInstance( S );
}
if( NN == 0 && NNI == 0 ) {
LeftOvers.append( Line );
do {
Line = TS.readLine();
// store even delimiter
LeftOvers.append( Line );
} while ( ! Line.isEmpty() );
//next section
continue;
}
@@ -230,94 +230,94 @@ QString NetworkSettingsData::saveSettings( void ) {
// save leftovers
for ( QStringList::Iterator it = LeftOvers.begin();
it != LeftOvers.end(); ++it ) {
TS << (*it) << endl;
}
// save all netnode instances
{ ANetNodeInstance * NNI;
for( QDictIterator<ANetNodeInstance> nit(
NSResources->netNodeInstances());
nit.current();
++nit ) {
// header
NNI = nit.current();
TS << '['
<< QString(NNI->nodeClass()->name())
<< ']'
<< endl;
NNI->saveAttributes( TS );
TS << endl;
}
}
- // good connections
- { Name2Connection_t & M = NSResources->connections();
+ // good NetworkSetups
+ { Name2NetworkSetup_t & M = NSResources->networkSetups();
- // for all connections
- for( QDictIterator<NodeCollection> it(M);
+ // for all NetworkSetups
+ for( QDictIterator<NetworkSetup> it(M);
it.current();
++it ) {
- TS << "[connection]" << endl;
+ TS << "[NetworkSetup]" << endl;
it.current()->save(TS);
}
}
- // save dangling connections
- { Name2Connection_t & M = NSResources->danglingConnections();
+ // save dangling NetworkSetups
+ { Name2NetworkSetup_t & M = NSResources->danglingNetworkSetups();
- // for all connections
- for( QDictIterator<NodeCollection> it(M);
+ // for all NetworkSetups
+ for( QDictIterator<NetworkSetup> it(M);
it.current();
++it ) {
- TS << "[connection]" << endl;
+ TS << "[NetworkSetup]" << endl;
it.current()->save(TS);
}
}
QDir D(".");
D.rename( CfgFile + ".bup", CfgFile );
//
// proper files AND system files regenerated
//
- for( QDictIterator<NodeCollection> it(NSResources->connections());
+ for( QDictIterator<NetworkSetup> it(NSResources->networkSetups());
it.current();
++it ) {
it.current()->setModified( 0 );
}
return ErrS;
}
QString NetworkSettingsData::generateSettings( void ) {
QString S = "";
Name2SystemFile_t & SFM = NSResources->systemFiles();
- Name2Connection_t & M = NSResources->connections();
- NodeCollection * NC;
+ Name2NetworkSetup_t & M = NSResources->networkSetups();
+ NetworkSetup * NC;
ANetNodeInstance * NNI;
ANetNodeInstance * FirstWithData;
RuntimeInfo * CurDev;
ANetNode * NN, * CurDevNN = 0;
long NoOfDevs;
long DevCtStart;
bool needToGenerate;
// regenerate system files
Log( ( "Generating settings from %s\n", CfgFile.latin1() ));
for( QDictIterator<ANetNode> nnit( NSResources->netNodes() );
nnit.current();
++nnit ) {
bool FirstItem = 1;
bool Generated = 0;
CurDevNN = nnit.current();
{ QStringList SL;
SL = CurDevNN->properFiles();
for ( QStringList::Iterator it = SL.begin();
it != SL.end();
@@ -407,49 +407,49 @@ QString NetworkSettingsData::generateSettings( void ) {
//
// generate all registered files
//
for( QDictIterator<SystemFile> sfit(SFM);
sfit.current();
++sfit ) {
SystemFile * SF;
SF = sfit.current();
// reset all
for( QDictIterator<ANetNode> nnit( NSResources->netNodes() );
nnit.current();
++nnit ) {
nnit.current()->setDone(0);
}
for( QDictIterator<ANetNodeInstance> nniit(
NSResources->netNodeInstances() );
nniit.current();
++nniit ) {
nniit.current()->setDone(0);
}
- for( QDictIterator<NodeCollection> ncit(M);
+ for( QDictIterator<NetworkSetup> ncit(M);
ncit.current();
++ncit ) {
ncit.current()->setDone(0);
}
Log( ( "Generating system file %s\n", SF->name().latin1() ));
needToGenerate = 0;
// are there netnodes that have instances and need
// to write data in this system file ?
for( QDictIterator<ANetNode> nnit( NSResources->netNodes() );
! needToGenerate && nnit.current();
++nnit ) {
NN = nnit.current();
if( NN->hasDataForFile( *SF ) ) {
// netnode can have data
// are there instances of this node ?
for( QDictIterator<ANetNodeInstance> nniit(
NSResources->netNodeInstances() );
! needToGenerate && nniit.current();
@@ -467,71 +467,71 @@ QString NetworkSettingsData::generateSettings( void ) {
if( ! needToGenerate ) {
// no instances found that might need to write data
// in this systemfile
Log(("No nodes for systemfile %s\n", SF->name().latin1() ));
continue;
}
// ok generate this system file
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",
"<p>Error in section \"Preamble\" for file \"%1\"</p>" ).
arg( SF->name() );
return S;
}
- // find connections that want to write to this file
- for( QDictIterator<NodeCollection> ncit(M);
+ // find NetworkSetups that want to write to this file
+ for( QDictIterator<NetworkSetup> ncit(M);
ncit.current();
++ncit ) {
NC = ncit.current();
if( NC->done() ) {
// already done
continue;
}
if( ! NC->hasDataForFile( *SF ) ) {
// no data
continue;
}
- Log(("Generating %s for connection %s\n",
+ Log(("Generating %s for NetworkSetup %s\n",
SF->name().latin1(), NC->name().latin1() ));
// find highest item that wants to write data to this file
FirstWithData = NC->firstWithDataForFile( *SF );
- // find device on which this connection works
+ // find device on which this NetworkSetup works
CurDev = NC->device();
// class of that node
CurDevNN = CurDev->netNode()->nodeClass();
if( ! FirstWithData->nodeClass()->done() ) {
// generate fixed part
if( ! SF->preDeviceSection( CurDevNN ) ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ).
arg( SF->name() );
return S;
}
if( FirstWithData->nodeClass()->generateFile(
*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 );
@@ -550,59 +550,59 @@ QString NetworkSettingsData::generateSettings( void ) {
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, 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
- for( QDictIterator<NodeCollection> ncit2(M);
+ // for all nodeNetworkSetups that work on the same device
+ for( QDictIterator<NetworkSetup> ncit2(M);
ncit2.current();
++ncit2 ) {
if( ncit2.current()->device() != CurDev ) {
// different device
continue;
}
- Log(("Connection %s of family %s\n",
+ Log(("NetworkSetup %s of family %s\n",
ncit2.current()->name().latin1(),
CurDev->name() ));
// generate
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>" ).
arg( SF->name() ).
arg( CurDevNN->name() );
return S;
}
switch( NNI->generateFile( *SF, i ) ) {
case 0 :
(*SF) << endl;
break;
case 1 :
break;
case 2 :
S = qApp->translate( "NetworkSettings",
"<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ).
arg( SF->name() ).
arg( CurDevNN->name() );
@@ -624,164 +624,164 @@ QString NetworkSettingsData::generateSettings( void ) {
}
if( ! SF->postDeviceSection( CurDevNN ) ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ).
arg( SF->name() ).
arg( CurDevNN->name() );
return S;
}
if( ! SF->postSection() ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in section \"Closure\" for file \"%1\"</p>" ).
arg( SF->name() );
return S;
}
// end of file
SF->close();
}
return S;
}
-QList<NodeCollection> NetworkSettingsData::collectPossible(
+QList<NetworkSetup> NetworkSettingsData::collectPossible(
const QString & Interface ) {
- // collect connections that can work on top of this interface
- NodeCollection * NC;
- QList<NodeCollection> PossibleConnections;
- Name2Connection_t & M = NSResources->connections();
+ // collect NetworkSetups that can work on top of this interface
+ NetworkSetup * NC;
+ QList<NetworkSetup> PossibleNetworkSetups;
+ Name2NetworkSetup_t & M = NSResources->networkSetups();
- // for all connections
- for( QDictIterator<NodeCollection> it(M);
+ // for all NetworkSetups
+ for( QDictIterator<NetworkSetup> it(M);
it.current();
++it ) {
NC = it.current();
// check if this profile handles the requested interface
if( NC->handlesInterface( Interface ) && // if different Intf.
NC->state() != Disabled && // if enabled
NC->state() != IsUp // if already used
) {
Log( ( "Append %s for %s\n",
NC->name().latin1(), Interface.latin1() ));
- PossibleConnections.append( NC );
+ PossibleNetworkSetups.append( NC );
}
}
- return PossibleConnections;
+ return PossibleNetworkSetups;
}
/*
Called by the system to see if interface can be brought UP
if allowed, echo Interface-allowed else Interface-disallowed
*/
bool NetworkSettingsData::canStart( const QString & Interface ) {
// load situation
- NodeCollection * NC = 0;
- QList<NodeCollection> PossibleConnections;
+ NetworkSetup * NC = 0;
+ QList<NetworkSetup> PossibleNetworkSetups;
- PossibleConnections = collectPossible( Interface );
+ PossibleNetworkSetups = collectPossible( Interface );
Log( ( "for %s : Possiblilies %d\n",
- Interface.latin1(), PossibleConnections.count() ));
- switch( PossibleConnections.count() ) {
- case 0 : // no connections
+ Interface.latin1(), PossibleNetworkSetups.count() ));
+ switch( PossibleNetworkSetups.count() ) {
+ case 0 : // no NetworkSetups
break;
- case 1 : // one connection
- NC = PossibleConnections.first();
+ case 1 : // one NetworkSetup
+ NC = PossibleNetworkSetups.first();
break;
default : // need to ask user ?
return 1;
}
if( NC ) {
switch( NC->state() ) {
case Unchecked :
case Unknown :
case Unavailable :
case Disabled :
// this profile does not allow interface to be UP
// -> try others
break;
case Off :
// try to UP the device
{ QString S= NC->setState( Activate );
if( ! S.isEmpty() ) {
// could not bring device Online -> try other alters
Log(( "disallow %ld for %s : %s\n",
NC->number(), Interface.latin1(), S.latin1() ));
break;
}
// interface assigned
}
// FT
case Available :
case IsUp : // also called for 'ifdown'
// device is ready -> done
Log(( "allow %ld for %s\n", NC->number(), Interface.latin1()));
printf( "A%ld%s\n", NC->number(), Interface.latin1() );
return 0;
}
}
// if we come here no alternatives are possible
Log(( "disallow %s\n", Interface.latin1()));
printf( "D-%s\n", Interface.latin1() );
return 0;
}
bool NetworkSettingsData::isModified( void ) {
if( ForceModified )
return 1;
- for( QDictIterator<NodeCollection> it(NSResources->connections());
+ for( QDictIterator<NetworkSetup> it(NSResources->networkSetups());
it.current();
++it ) {
if( it.current()->isModified() ) {
return 1;
}
}
return 0;
}
bool NetworkSettingsData::couldBeTriggered( const QString & Interface ) {
// load situation
- QList<NodeCollection> PossibleTriggered;
+ QList<NetworkSetup> PossibleTriggered;
PossibleTriggered = collectTriggered( Interface );
Log( ( "for %s : Possiblilies %d\n",
Interface.latin1(), PossibleTriggered.count() ));
return ( PossibleTriggered.count() ) ? 1 : 0;
}
-QList<NodeCollection> NetworkSettingsData::collectTriggered(
+QList<NetworkSetup> NetworkSettingsData::collectTriggered(
const QString & Interface ) {
- // collect connections that could be triggered by this interface
- NodeCollection * NC;
- QList<NodeCollection> PossibleTriggered;
+ // collect NetworkSetups that could be triggered by this interface
+ NetworkSetup * NC;
+ QList<NetworkSetup> PossibleTriggered;
- // for all connections
- Name2Connection_t & M = NSResources->connections();
+ // for all NetworkSetups
+ Name2NetworkSetup_t & M = NSResources->networkSetups();
- for( QDictIterator<NodeCollection> it(M);
+ for( QDictIterator<NetworkSetup> it(M);
it.current();
++it ) {
NC = it.current();
// check if this profile handles the requested interface
if( NC->triggeredBy( Interface ) && // if different Intf.
NC->state() != Disabled && // if enabled
NC->state() != IsUp // if already used
) {
Log( ( "Append %s for %s\n",
NC->name().latin1(), Interface.latin1() ));
PossibleTriggered.append( NC );
}
}
return PossibleTriggered;
}