summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/network/networkrun.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings2/network/networkrun.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/network/networkrun.cpp91
1 files changed, 32 insertions, 59 deletions
diff --git a/noncore/settings/networksettings2/network/networkrun.cpp b/noncore/settings/networksettings2/network/networkrun.cpp
index 3e24c5f..c17aa7f 100644
--- a/noncore/settings/networksettings2/network/networkrun.cpp
+++ b/noncore/settings/networksettings2/network/networkrun.cpp
@@ -1,26 +1,24 @@
#include <system.h>
-#include <asdevice.h>
+#include <netnode.h>
+#include <resources.h>
#include "networkrun.h"
-void NetworkRun::detectState( NodeCollection * NC ) {
- RuntimeInfo * RI = netNode()->nextNode()->runtime();
- AsDevice * Next = RI->asDevice();
- InterfaceInfo * II = Next->assignedInterface();
+State_t NetworkRun::detectState( void ) {
+ InterfaceInfo * II = nodeCollection()->assignedInterface();
- if( II ) {
+ Log(( "Interface %p : %d\n", II, (II) ? II->IsUp : 0 ));
+ if( II && II->IsUp ) {
// device has assigned interface
- NC->setCurrentState( (( II->IsUp ) ? IsUp : Available) );
- return;
+ return IsUp;
}
- Log(( "%s not ! UP or ava\n", NC->name().latin1() ));
- // has no interface -> delegate
- RI->detectState( NC );
+ // had no interface or interface is no longer up -> release
+ nodeCollection()->assignInterface( 0 );
+
+ return Unknown;
}
-bool NetworkRun::setState( NodeCollection * NC, Action_t A, bool Force ) {
+QString NetworkRun::setMyState( NodeCollection * NC, Action_t A, bool ) {
// we handle UP and DOWN
- RuntimeInfo * RI = netNode()->nextNode()->runtime();
- AsDevice * Next = RI->asDevice();
- InterfaceInfo * II = Next->assignedInterface();
+ InterfaceInfo * II = NC->assignedInterface();
@@ -28,51 +26,26 @@ bool NetworkRun::setState( NodeCollection * NC, Action_t A, bool Force ) {
// we can bring UP if lower level is available
- if( NC->currentState() == Available || Force ) {
- QString S;
- S.sprintf( "ifup %s=%s-c%d-allowed",
- II->Name.latin1(), II->Name.latin1(),
- connection()->number() );
- NSResources->system().runAsRoot( S );
+ QStringList SL;
+ SL << "ifup"
+ << QString().sprintf( "%s=%s-c%d-allowed",
+ II->Name.latin1(), II->Name.latin1(),
+ nodeCollection()->number() );
+ if( ! NSResources->system().runAsRoot( SL ) ) {
+ return QString("Cannot call %1").arg(SL.join(" "));
}
- return 1;
- } else if( A == Down ) {
- QString S;
- if( Force ) {
- Log(("Force mode %d\n", Force ));
- for( int i = 0;
- i < RI->netNode()->nodeClass()->instanceCount();
- i ++ ) {
- S.sprintf( "ifdown %s",
- RI->netNode()->nodeClass()->genNic( i ).latin1() );
- NSResources->system().runAsRoot( S );
+ return QString();
+ }
+
+ if( A == Down ) {
+ QStringList SL;
+ if( II ) {
+ SL << "ifdown"
+ << II->Name.latin1();
+ if( ! NSResources->system().runAsRoot( SL ) ) {
+ return QString( "Cannot call %1" ).arg( SL.join( " " ));
}
} else {
- if( NC->currentState() == IsUp ) {
- S.sprintf( "ifdown %s=%s-c%d-allowed",
- II->Name.latin1(), II->Name.latin1(),
- connection()->number() );
- NSResources->system().runAsRoot( S );
- }
+ Log(( "no interface assigned." ));
}
- return 1;
- }
- // delegate
- return RI->setState( NC, A, Force );
-}
-
-bool NetworkRun::canSetState( State_t Curr, Action_t A ) {
- // we handle UP and DOWN
- RuntimeInfo * RI = netNode()->nextNode()->runtime();
-
- if( A == Up ) {
- return ( Curr == Available );
- } else if( A == Down ) {
- return ( Curr == IsUp );
}
- // delegate
- return RI->canSetState( Curr, A );
-}
-
-bool NetworkRun::handlesInterface( const QString & S ) {
- // donno -> pass deeper
- return netNode()->nextNode()->runtime()->handlesInterface(S);
+ return QString();
}