author | wimpie <wimpie> | 2004-04-10 13:06:13 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2004-04-10 13:06:13 (UTC) |
commit | db9f0e2a7fd93157d95f421534fcc3015abe53e0 (patch) (unidiff) | |
tree | 001918ca18d0d74f3e49597f766c070bea71e25c /noncore/settings/networksettings2/wlan/wlanrun.cpp | |
parent | 6bcdc8cd41199dce849b800b4296011faf6281df (diff) | |
download | opie-db9f0e2a7fd93157d95f421534fcc3015abe53e0.zip opie-db9f0e2a7fd93157d95f421534fcc3015abe53e0.tar.gz opie-db9f0e2a7fd93157d95f421534fcc3015abe53e0.tar.bz2 |
*** empty log message ***
Diffstat (limited to 'noncore/settings/networksettings2/wlan/wlanrun.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/wlan/wlanrun.cpp | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/wlan/wlanrun.cpp b/noncore/settings/networksettings2/wlan/wlanrun.cpp index 79f11f7..3f1d4a9 100644 --- a/noncore/settings/networksettings2/wlan/wlanrun.cpp +++ b/noncore/settings/networksettings2/wlan/wlanrun.cpp | |||
@@ -1,5 +1,185 @@ | |||
1 | |||
2 | #include <qfile.h> | ||
3 | #include <qtextstream.h> | ||
4 | #include <qstringlist.h> | ||
5 | #include <resources.h> | ||
1 | #include "wlanrun.h" | 6 | #include "wlanrun.h" |
2 | 7 | ||
8 | void WLanRun::detectState( NodeCollection * NC ) { | ||
9 | |||
10 | // unavailable : no card found | ||
11 | // available : card found and assigned to us or free | ||
12 | // up : card found and assigned to us and up | ||
13 | |||
14 | QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); | ||
15 | System & Sys = NSResources->system(); | ||
16 | InterfaceInfo * Run; | ||
17 | |||
18 | QFile F( S ); | ||
19 | |||
20 | if( F.open( IO_ReadOnly ) ) { | ||
21 | // could open file -> read interface and assign | ||
22 | QString X; | ||
23 | QTextStream TS(&F); | ||
24 | X = TS.readLine(); | ||
25 | // find interface | ||
26 | if( handlesInterface( X ) ) { | ||
27 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); | ||
28 | It.current(); | ||
29 | ++It ) { | ||
30 | Run = It.current(); | ||
31 | if( X == Run->Name ) { | ||
32 | Run->assignNode( netNode() ); | ||
33 | assignInterface( Run ); | ||
34 | NC->setCurrentState( IsUp ); | ||
35 | return; | ||
36 | } | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | |||
41 | if( ( Run = assignedInterface() ) ) { | ||
42 | // we already have an interface assigned -> still present ? | ||
43 | if( ! Run->IsUp ) { | ||
44 | // usb is still free -> keep assignment | ||
45 | NC->setCurrentState( Available ); | ||
46 | return; | ||
47 | } // else interface is up but NOT us -> some other profile | ||
48 | } | ||
49 | |||
50 | // nothing (valid) assigned to us | ||
51 | assignInterface( 0 ); | ||
52 | |||
53 | // find possible interface | ||
54 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); | ||
55 | It.current(); | ||
56 | ++It ) { | ||
57 | Run = It.current(); | ||
58 | if( handlesInterface( *Run ) && | ||
59 | ( Run->CardType == ARPHRD_ETHER | ||
60 | #ifdef ARPHRD_IEEE1394 | ||
61 | || Run->CardType == ARPHRD_IEEE1394 | ||
62 | #endif | ||
63 | ) && | ||
64 | ! Run->IsUp | ||
65 | ) { | ||
66 | // proper type, and Not UP -> free | ||
67 | NC->setCurrentState( Off ); | ||
68 | return; | ||
69 | } | ||
70 | } | ||
71 | // no free found | ||
72 | |||
73 | NC->setCurrentState( Unavailable ); | ||
74 | |||
75 | } | ||
76 | |||
77 | bool WLanRun::setState( NodeCollection * NC, Action_t A, bool ) { | ||
78 | |||
79 | // we only handle activate and deactivate | ||
80 | switch( A ) { | ||
81 | case Activate : | ||
82 | { | ||
83 | if( NC->currentState() != Off ) { | ||
84 | return 0; | ||
85 | } | ||
86 | InterfaceInfo * N = getInterface(); | ||
87 | if( ! N ) { | ||
88 | // no interface available | ||
89 | NC->setCurrentState( Unavailable ); | ||
90 | return 0; | ||
91 | } | ||
92 | // because we were OFF the interface | ||
93 | // we get back is NOT assigned | ||
94 | N->assignNode( netNode() ); | ||
95 | assignInterface( N ); | ||
96 | NC->setCurrentState( Available ); | ||
97 | return 1; | ||
98 | } | ||
99 | case Deactivate : | ||
100 | if( NC->currentState() == IsUp ) { | ||
101 | // bring down first | ||
102 | if( ! connection()->setState( Down ) ) | ||
103 | // could not ... | ||
104 | return 0; | ||
105 | } else if( NC->currentState() != Available ) { | ||
106 | return 1; | ||
107 | } | ||
108 | assignedInterface()->assignNode( 0 ); // release | ||
109 | assignInterface( 0 ); | ||
110 | NC->setCurrentState( Off ); | ||
111 | return 1; | ||
112 | default : | ||
113 | // FT | ||
114 | break; | ||
115 | } | ||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | bool WLanRun::canSetState( State_t Curr, Action_t A ) { | ||
120 | // we only handle up down activate and deactivate | ||
121 | switch( A ) { | ||
122 | case Activate : | ||
123 | { // at least available | ||
124 | if( Curr == Available ) { | ||
125 | return 1; | ||
126 | } | ||
127 | // or we can make one available | ||
128 | InterfaceInfo * N = getInterface(); | ||
129 | if( ! N || N->assignedNode() != 0 ) { | ||
130 | // non available or assigned | ||
131 | return 0; | ||
132 | } | ||
133 | return 1; | ||
134 | } | ||
135 | case Deactivate : | ||
136 | return ( Curr >= Available ); | ||
137 | default : | ||
138 | // FT | ||
139 | break; | ||
140 | } | ||
141 | return 0; | ||
142 | } | ||
143 | |||
144 | // get interface that is free or assigned to us | ||
145 | InterfaceInfo * WLanRun::getInterface( void ) { | ||
146 | |||
147 | System & S = NSResources->system(); | ||
148 | InterfaceInfo * best = 0, * Run; | ||
149 | |||
150 | for( QDictIterator<InterfaceInfo> It(S.interfaces()); | ||
151 | It.current(); | ||
152 | ++It ) { | ||
153 | Run = It.current(); | ||
154 | if( handlesInterface( *Run ) && | ||
155 | ( Run->CardType == ARPHRD_ETHER | ||
156 | #ifdef ARPHRD_IEEE1394 | ||
157 | || Run->CardType == ARPHRD_IEEE1394 | ||
158 | #endif | ||
159 | ) | ||
160 | ) { | ||
161 | // this is a LAN card | ||
162 | if( Run->assignedNode() == netNode() ) { | ||
163 | // assigned to us | ||
164 | return Run; | ||
165 | } else if( Run->assignedNode() == 0 ) { | ||
166 | // free | ||
167 | best = Run; | ||
168 | } | ||
169 | } | ||
170 | } | ||
171 | return best; // can be 0 | ||
172 | } | ||
173 | |||
3 | bool WLanRun::handlesInterface( const QString & S ) { | 174 | bool WLanRun::handlesInterface( const QString & S ) { |
175 | InterfaceInfo * II; | ||
176 | II = NSResources->system().interface( S ); | ||
177 | if( ( II = NSResources->system().interface( S ) ) ) { | ||
178 | return handlesInterface( *II ); | ||
179 | } | ||
4 | return Pat.match( S ) >= 0; | 180 | return Pat.match( S ) >= 0; |
5 | } | 181 | } |
182 | |||
183 | bool WLanRun::handlesInterface( const InterfaceInfo & II ) { | ||
184 | return ( Pat.match( II.Name ) < 0 ); | ||
185 | } | ||