From a9c188235c97e07b0eb96b13adbcdfd4bad64767 Mon Sep 17 00:00:00 2001 From: wimpie Date: Tue, 04 Jan 2005 01:35:26 +0000 Subject: CONTROL files : changed version string NS2 many changes and first release of OT2 --- (limited to 'noncore/settings/networksettings2/network/networkrun.cpp') 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,78 +1,51 @@ #include -#include +#include +#include #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(); if( A == Up ) { // 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(); } -- cgit v0.9.0.2