From 5334b639c9f97793bcae4f50f7b47c7a2ada4e2f Mon Sep 17 00:00:00 2001 From: wimpie Date: Fri, 02 Apr 2004 18:29:49 +0000 Subject: First import of NS2 app --- (limited to 'noncore/settings/networksettings2/network/networkrun.cpp') diff --git a/noncore/settings/networksettings2/network/networkrun.cpp b/noncore/settings/networksettings2/network/networkrun.cpp new file mode 100644 index 0000000..e732bfa --- a/dev/null +++ b/noncore/settings/networksettings2/network/networkrun.cpp @@ -0,0 +1,63 @@ +#include +#include +#include "networkrun.h" + +void NetworkRun::detectState( NodeCollection * NC ) { + RuntimeInfo * RI = netNode()->nextNode()->runtime(); + AsDevice * Next = RI->asDevice(); + InterfaceInfo * II = Next->assignedInterface(); + + if( II ) { + // device has assigned interface + NC->setCurrentState( (( II->IsUp ) ? IsUp : Available) ); + } + + // has no interface -> delegate + RI->detectState( NC ); +} + +bool NetworkRun::setState( NodeCollection * NC, Action_t A ) { + // we handle UP and DOWN + RuntimeInfo * RI = netNode()->nextNode()->runtime(); + AsDevice * Next = RI->asDevice(); + InterfaceInfo * II = Next->assignedInterface(); + + if( A == Up ) { + // we can bring UP if lower level is available + if( NC->currentState() == Available ) { + QString S; + S.sprintf( "ifup %s=manual", II->Name.latin1() ); + NSResources->system().execute( S ); + NC->setCurrentState( IsUp ); + } + return 1; + } else if( A == Down ) { + if( NC->currentState() == IsUp ) { + QString S; + S.sprintf( "ifdown %s", II->Name.latin1() ); + NSResources->system().execute( S ); + NC->setCurrentState( Available ); + } + return 1; + } + // delegate + return RI->setState( NC, A ); +} + +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); +} -- cgit v0.9.0.2