summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/usb/usbrun.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings2/usb/usbrun.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/usb/usbrun.cpp102
1 files changed, 18 insertions, 84 deletions
diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp
index b8ac8a8..f8824e0 100644
--- a/noncore/settings/networksettings2/usb/usbrun.cpp
+++ b/noncore/settings/networksettings2/usb/usbrun.cpp
@@ -4,10 +4,11 @@
#include <resources.h>
#include "usbrun.h"
-void USBRun::detectState( NodeCollection * NC ) {
+State_t USBRun::detectState( void ) {
// unavailable : no card found
// available : card found and assigned to us or free
// up : card found and assigned to us and up
+ NodeCollection * NC = nodeCollection();
QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number());
System & Sys = NSResources->system();
InterfaceInfo * Run;
@@ -27,27 +28,24 @@ void USBRun::detectState( NodeCollection * NC ) {
++It ) {
Run = It.current();
if( X == Run->Name ) {
- Run->assignNode( netNode() );
- assignInterface( Run );
- NC->setCurrentState( IsUp );
- return;
+ NC->assignInterface( Run );
+ return IsUp;
}
}
}
}
- Log(("Assigned %p\n", assignedInterface() ));
- if( ( Run = assignedInterface() ) ) {
+ Log(("Assigned %p\n", NC->assignedInterface() ));
+ if( ( Run = NC->assignedInterface() ) ) {
// we already have an interface assigned -> still present ?
if( ! Run->IsUp ) {
// usb is still free -> keep assignment
- NC->setCurrentState( Available );
- return;
+ return Available;
} // else interface is up but NOT us -> some other profile
}
// nothing (valid) assigned to us
- assignInterface( 0 );
+ NC->assignInterface( 0 );
// find possible interface
for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
@@ -65,84 +63,16 @@ void USBRun::detectState( NodeCollection * NC ) {
Run->CardType == ARPHRD_ETHER &&
! Run->IsUp
) {
- Log(("Released(OFF)\n" ));
// proper type, and Not UP -> free
- NC->setCurrentState( Off );
- return;
+ return Off;
}
}
- // no free found
- Log(("UNA\n" ));
- NC->setCurrentState( Unavailable );
+ return Unavailable;
}
-bool USBRun::setState( NodeCollection * NC, Action_t A, bool ) {
-
- // we only handle activate and deactivate
- switch( A ) {
- case Activate :
- {
- if( NC->currentState() != Off ) {
- return 0;
- }
- InterfaceInfo * N = getInterface();
- if( ! N ) {
- // no interface available
- NC->setCurrentState( Unavailable );
- return 0;
- }
- // because we were OFF the interface
- // we get back is NOT assigned
- N->assignNode( netNode() );
- assignInterface( N );
- Log(("Assing %p\n", N ));
- NC->setCurrentState( Available );
- return 1;
- }
- case Deactivate :
- if( NC->currentState() == IsUp ) {
- // bring down first
- if( ! connection()->setState( Down ) )
- // could not ...
- return 0;
- } else if( NC->currentState() != Available ) {
- return 1;
- }
- assignedInterface()->assignNode( 0 ); // release
- assignInterface( 0 );
- NC->setCurrentState( Off );
- return 1;
- default :
- // FT
- break;
- }
- return 0;
-}
-
-bool USBRun::canSetState( State_t Curr, Action_t A ) {
- // we only handle up down activate and deactivate
- switch( A ) {
- case Activate :
- { // at least available
- if( Curr == Available ) {
- return 1;
- }
- // or we can make one available
- InterfaceInfo * N = getInterface();
- if( ! N || N->assignedNode() != 0 ) {
- // non available or assigned
- return 0;
- }
- return 1;
- }
- case Deactivate :
- return ( Curr >= Available );
- default :
- // FT
- break;
- }
- return 0;
+QString USBRun::setMyState( NodeCollection *, Action_t , bool ) {
+ return QString();
}
// get interface that is free or assigned to us
@@ -160,10 +90,10 @@ InterfaceInfo * USBRun::getInterface( void ) {
Run->CardType == ARPHRD_ETHER
) {
// this is a USB card
- if( Run->assignedNode() == netNode() ) {
+ if( Run->assignedConnection() == netNode()->connection() ) {
// assigned to us
return Run;
- } else if( Run->assignedNode() == 0 ) {
+ } else if( Run->assignedConnection() == 0 ) {
// free
best = Run;
}
@@ -176,3 +106,7 @@ bool USBRun::handlesInterface( const QString & S ) {
return Pat.match( S ) >= 0;
}
+bool USBRun::handlesInterface( InterfaceInfo * I ) {
+ return handlesInterface( I->Name );
+}
+