Diffstat (limited to 'noncore/settings/networksettings2/usb/usbrun.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/usb/usbrun.cpp | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp index 0a46642..eb439c1 100644 --- a/noncore/settings/networksettings2/usb/usbrun.cpp +++ b/noncore/settings/networksettings2/usb/usbrun.cpp | |||
@@ -1,34 +1,36 @@ | |||
1 | #include <qfile.h> | 1 | #include <qfile.h> |
2 | #include <qfileinfo.h> | 2 | #include <qfileinfo.h> |
3 | #include <qtextstream.h> | 3 | #include <qtextstream.h> |
4 | #include <resources.h> | 4 | #include <resources.h> |
5 | #include "usbrun.h" | 5 | #include "usbrun.h" |
6 | 6 | ||
7 | State_t USBRun::detectState( void ) { | 7 | State_t USBRun::detectState( void ) { |
8 | |||
8 | // unavailable : no card found | 9 | // unavailable : no card found |
9 | // available : card found and assigned to us or free | 10 | // available : card found and assigned to us or free |
10 | // up : card found and assigned to us and up | 11 | // up : card found and assigned to us and up |
12 | |||
11 | NodeCollection * NC = nodeCollection(); | 13 | NodeCollection * NC = nodeCollection(); |
12 | QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); | 14 | QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); |
13 | System & Sys = NSResources->system(); | 15 | System & Sys = NSResources->system(); |
14 | InterfaceInfo * Run; | 16 | InterfaceInfo * Run; |
15 | QFile F( S ); | 17 | QFile F( S ); |
16 | Log(("Detecting for %s\n", NC->name().latin1() )); | 18 | Log(("Detecting for %s\n", NC->name().latin1() )); |
17 | 19 | ||
18 | if( F.open( IO_ReadOnly ) ) { | 20 | if( F.open( IO_ReadOnly ) ) { |
19 | // could open file -> read interface and assign | 21 | // could open file -> read interface and assign |
20 | QString X; | 22 | QString X; |
21 | QTextStream TS(&F); | 23 | QTextStream TS(&F); |
22 | X = TS.readLine(); | 24 | X = TS.readLine(); |
23 | Log(("%s exists\n", S.latin1() )); | 25 | Log(("%s exists\n", S.latin1() )); |
24 | // find interface | 26 | // find interface |
25 | if( handlesInterface( X ) ) { | 27 | if( handlesInterface( X ) ) { |
26 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); | 28 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); |
27 | It.current(); | 29 | It.current(); |
28 | ++It ) { | 30 | ++It ) { |
29 | Run = It.current(); | 31 | Run = It.current(); |
30 | if( X == Run->Name ) { | 32 | if( X == Run->Name ) { |
31 | NC->assignInterface( Run ); | 33 | NC->assignInterface( Run ); |
32 | return IsUp; | 34 | return IsUp; |
33 | } | 35 | } |
34 | } | 36 | } |
@@ -43,68 +45,61 @@ State_t USBRun::detectState( void ) { | |||
43 | return Available; | 45 | return Available; |
44 | } // else interface is up but NOT us -> some other profile | 46 | } // else interface is up but NOT us -> some other profile |
45 | } | 47 | } |
46 | 48 | ||
47 | // nothing (valid) assigned to us | 49 | // nothing (valid) assigned to us |
48 | NC->assignInterface( 0 ); | 50 | NC->assignInterface( 0 ); |
49 | 51 | ||
50 | // find possible interface | 52 | // find possible interface |
51 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); | 53 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); |
52 | It.current(); | 54 | It.current(); |
53 | ++It ) { | 55 | ++It ) { |
54 | Run = It.current(); | 56 | Run = It.current(); |
55 | 57 | ||
56 | Log(("%s %d %d=%d %d\n", | 58 | Log(("%s %d %d=%d %d\n", |
57 | Run->Name.latin1(), | 59 | Run->Name.latin1(), |
58 | handlesInterface( Run->Name ), | 60 | handlesInterface( Run->Name ), |
59 | Run->CardType, ARPHRD_ETHER, | 61 | Run->CardType, ARPHRD_ETHER, |
60 | ! Run->IsUp )); | 62 | ! Run->IsUp )); |
61 | 63 | ||
62 | if( handlesInterface( Run->Name ) && | 64 | if( handlesInterface( Run->Name ) && |
63 | Run->CardType == ARPHRD_ETHER && | 65 | Run->CardType == ARPHRD_ETHER && |
64 | ! Run->IsUp | 66 | ! Run->IsUp |
65 | ) { | 67 | ) { |
66 | // proper type, and Not UP -> free | 68 | // proper type, and Not UP -> free |
67 | return Off; | 69 | // usb cables are currently always available when requested |
70 | // until we can detect if we are plugged in | ||
71 | return Available; | ||
68 | } | 72 | } |
69 | } | 73 | } |
70 | 74 | ||
71 | return Unavailable; | 75 | return Unavailable; |
72 | } | 76 | } |
73 | 77 | ||
74 | QString USBRun::setMyState( NodeCollection * NC, Action_t A, bool ) { | 78 | QString USBRun::setMyState( NodeCollection * NC, Action_t A, bool ) { |
75 | 79 | ||
76 | // nothing needs to be done to 'activate' or 'deactivate' | 80 | // nothing needs to be done to 'activate' or 'deactivate' |
77 | // a cable | 81 | // a cable |
78 | |||
79 | // perhaps (later) we can figure out if the device is IN the | ||
80 | // cradle | ||
81 | if( A == Activate ) { | ||
82 | NC->setCurrentState( Available ); | ||
83 | } else if ( A == Deactivate ) { | ||
84 | NC->setCurrentState( Unavailable ); | ||
85 | } | ||
86 | |||
87 | return QString(); | 82 | return QString(); |
88 | } | 83 | } |
89 | 84 | ||
90 | // get interface that is free or assigned to us | 85 | // get interface that is free or assigned to us |
91 | InterfaceInfo * USBRun::getInterface( void ) { | 86 | InterfaceInfo * USBRun::getInterface( void ) { |
92 | 87 | ||
93 | System & S = NSResources->system(); | 88 | System & S = NSResources->system(); |
94 | InterfaceInfo * best = 0, * Run; | 89 | InterfaceInfo * best = 0, * Run; |
95 | QRegExp R( "usb[0-9abcdef]" ); | 90 | QRegExp R( "usb[0-9abcdef]" ); |
96 | 91 | ||
97 | for( QDictIterator<InterfaceInfo> It(S.interfaces()); | 92 | for( QDictIterator<InterfaceInfo> It(S.interfaces()); |
98 | It.current(); | 93 | It.current(); |
99 | ++It ) { | 94 | ++It ) { |
100 | Run = It.current(); | 95 | Run = It.current(); |
101 | if( handlesInterface( Run->Name ) && | 96 | if( handlesInterface( Run->Name ) && |
102 | Run->CardType == ARPHRD_ETHER | 97 | Run->CardType == ARPHRD_ETHER |
103 | ) { | 98 | ) { |
104 | // this is a USB card | 99 | // this is a USB card |
105 | if( Run->assignedConnection() == netNode()->connection() ) { | 100 | if( Run->assignedConnection() == netNode()->connection() ) { |
106 | // assigned to us | 101 | // assigned to us |
107 | return Run; | 102 | return Run; |
108 | } else if( Run->assignedConnection() == 0 ) { | 103 | } else if( Run->assignedConnection() == 0 ) { |
109 | // free | 104 | // free |
110 | best = Run; | 105 | best = Run; |