summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/usb/usbrun.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/usb/usbrun.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/usb/usbrun.cpp43
1 files changed, 22 insertions, 21 deletions
diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp
index eb439c1..de8c8a2 100644
--- a/noncore/settings/networksettings2/usb/usbrun.cpp
+++ b/noncore/settings/networksettings2/usb/usbrun.cpp
@@ -38,6 +38,7 @@ State_t USBRun::detectState( void ) {
38 } 38 }
39 39
40 Log(("Assigned %p\n", NC->assignedInterface() )); 40 Log(("Assigned %p\n", NC->assignedInterface() ));
41
41 if( ( Run = NC->assignedInterface() ) ) { 42 if( ( Run = NC->assignedInterface() ) ) {
42 // we already have an interface assigned -> still present ? 43 // we already have an interface assigned -> still present ?
43 if( ! Run->IsUp ) { 44 if( ! Run->IsUp ) {
@@ -50,35 +51,28 @@ State_t USBRun::detectState( void ) {
50 NC->assignInterface( 0 ); 51 NC->assignInterface( 0 );
51 52
52 // find possible interface 53 // find possible interface
53 for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); 54 if( getInterface() ) {
54 It.current();
55 ++It ) {
56 Run = It.current();
57
58 Log(("%s %d %d=%d %d\n",
59 Run->Name.latin1(),
60 handlesInterface( Run->Name ),
61 Run->CardType, ARPHRD_ETHER,
62 ! Run->IsUp ));
63
64 if( handlesInterface( Run->Name ) &&
65 Run->CardType == ARPHRD_ETHER &&
66 ! Run->IsUp
67 ) {
68 // proper type, and Not UP -> free 55 // proper type, and Not UP -> free
69 // usb cables are currently always available when requested 56 // usb cables are currently always available when requested
70 // until we can detect if we are plugged in 57 // until we can detect if we are plugged in
71 return Available; 58 return Available;
72 } 59 }
73 }
74 60
75 return Unavailable; 61 return Unavailable;
76} 62}
77 63
78QString USBRun::setMyState( NodeCollection * NC, Action_t A, bool ) { 64QString USBRun::setMyState( NodeCollection * NC, Action_t A, bool ) {
79 65
80 // nothing needs to be done to 'activate' or 'deactivate' 66 InterfaceInfo * I = getInterface();
81 // a cable 67
68 if( ! I ) {
69 return QString("No usb device available");
70 }
71
72 Log(( "Grabbed USB interface %s\n", I->Name.latin1() ));
73 // grab this interface
74 NC->assignInterface( I );
75
82 return QString(); 76 return QString();
83} 77}
84 78
@@ -87,12 +81,18 @@ InterfaceInfo * USBRun::getInterface( void ) {
87 81
88 System & S = NSResources->system(); 82 System & S = NSResources->system();
89 InterfaceInfo * best = 0, * Run; 83 InterfaceInfo * best = 0, * Run;
90 QRegExp R( "usb[0-9abcdef]" );
91 84
92 for( QDictIterator<InterfaceInfo> It(S.interfaces()); 85 for( QDictIterator<InterfaceInfo> It(S.interfaces());
93 It.current(); 86 It.current();
94 ++It ) { 87 ++It ) {
95 Run = It.current(); 88 Run = It.current();
89
90 Log(("%s %d %d=%d %d\n",
91 Run->Name.latin1(),
92 handlesInterface( Run->Name ),
93 Run->CardType, ARPHRD_ETHER,
94 ! Run->IsUp ));
95
96 if( handlesInterface( Run->Name ) && 96 if( handlesInterface( Run->Name ) &&
97 Run->CardType == ARPHRD_ETHER 97 Run->CardType == ARPHRD_ETHER
98 ) { 98 ) {
@@ -100,10 +100,11 @@ InterfaceInfo * USBRun::getInterface( void ) {
100 if( Run->assignedConnection() == netNode()->connection() ) { 100 if( Run->assignedConnection() == netNode()->connection() ) {
101 // assigned to us 101 // assigned to us
102 return Run; 102 return Run;
103 } else if( Run->assignedConnection() == 0 ) { 103 } else if( ! Run->IsUp &&
104 Run->assignedConnection() == 0 ) {
104 // free 105 // free
105 best = Run; 106 best = Run;
106 } 107 } // UP or not assigned to us
107 } 108 }
108 } 109 }
109 return best; // can be 0 110 return best; // can be 0