summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/wlan/wlanrun.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/wlan/wlanrun.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/wlan/wlanrun.cpp91
1 files changed, 13 insertions, 78 deletions
diff --git a/noncore/settings/networksettings2/wlan/wlanrun.cpp b/noncore/settings/networksettings2/wlan/wlanrun.cpp
index 3f1d4a9..fe49c4e 100644
--- a/noncore/settings/networksettings2/wlan/wlanrun.cpp
+++ b/noncore/settings/networksettings2/wlan/wlanrun.cpp
@@ -2,18 +2,19 @@
2#include <qfile.h> 2#include <qfile.h>
3#include <qtextstream.h> 3#include <qtextstream.h>
4#include <qstringlist.h> 4#include <qstringlist.h>
5#include <resources.h> 5#include <resources.h>
6#include "wlanrun.h" 6#include "wlanrun.h"
7 7
8void WLanRun::detectState( NodeCollection * NC ) { 8State_t WLanRun::detectState( void ) {
9 9
10 // unavailable : no card found 10 // unavailable : no card found
11 // available : card found and assigned to us or free 11 // available : card found and assigned to us or free
12 // up : card found and assigned to us and up 12 // up : card found and assigned to us and up
13 13
14 NodeCollection * NC = nodeCollection();
14 QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); 15 QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number());
15 System & Sys = NSResources->system(); 16 System & Sys = NSResources->system();
16 InterfaceInfo * Run; 17 InterfaceInfo * Run;
17 18
18 QFile F( S ); 19 QFile F( S );
19 20
@@ -26,32 +27,29 @@ void WLanRun::detectState( NodeCollection * NC ) {
26 if( handlesInterface( X ) ) { 27 if( handlesInterface( X ) ) {
27 for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); 28 for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
28 It.current(); 29 It.current();
29 ++It ) { 30 ++It ) {
30 Run = It.current(); 31 Run = It.current();
31 if( X == Run->Name ) { 32 if( X == Run->Name ) {
32 Run->assignNode( netNode() ); 33 NC->assignInterface( Run );
33 assignInterface( Run ); 34 return IsUp;
34 NC->setCurrentState( IsUp );
35 return;
36 } 35 }
37 } 36 }
38 } 37 }
39 } 38 }
40 39
41 if( ( Run = assignedInterface() ) ) { 40 if( ( Run = NC->assignedInterface() ) ) {
42 // we already have an interface assigned -> still present ? 41 // we already have an interface assigned -> still present ?
43 if( ! Run->IsUp ) { 42 if( ! Run->IsUp ) {
44 // usb is still free -> keep assignment 43 // usb is still free -> keep assignment
45 NC->setCurrentState( Available ); 44 return Available;
46 return;
47 } // else interface is up but NOT us -> some other profile 45 } // else interface is up but NOT us -> some other profile
48 } 46 }
49 47
50 // nothing (valid) assigned to us 48 // nothing (valid) assigned to us
51 assignInterface( 0 ); 49 NC->assignInterface( 0 );
52 50
53 // find possible interface 51 // find possible interface
54 for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); 52 for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
55 It.current(); 53 It.current();
56 ++It ) { 54 ++It ) {
57 Run = It.current(); 55 Run = It.current();
@@ -61,87 +59,24 @@ void WLanRun::detectState( NodeCollection * NC ) {
61 || Run->CardType == ARPHRD_IEEE1394 59 || Run->CardType == ARPHRD_IEEE1394
62#endif 60#endif
63 ) && 61 ) &&
64 ! Run->IsUp 62 ! Run->IsUp
65 ) { 63 ) {
66 // proper type, and Not UP -> free 64 // proper type, and Not UP -> free
67 NC->setCurrentState( Off ); 65 return Off;
68 return;
69 } 66 }
70 } 67 }
71 // no free found
72 68
73 NC->setCurrentState( Unavailable ); 69 return Unavailable;
74 70
75} 71}
76 72
77bool WLanRun::setState( NodeCollection * NC, Action_t A, bool ) { 73QString WLanRun::setMyState( NodeCollection * , Action_t , bool ) {
78 74
79 // we only handle activate and deactivate 75 // we only handle activate and deactivate
80 switch( A ) { 76 return QString();
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
119bool 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} 77}
143 78
144// get interface that is free or assigned to us 79// get interface that is free or assigned to us
145InterfaceInfo * WLanRun::getInterface( void ) { 80InterfaceInfo * WLanRun::getInterface( void ) {
146 81
147 System & S = NSResources->system(); 82 System & S = NSResources->system();
@@ -156,16 +91,16 @@ InterfaceInfo * WLanRun::getInterface( void ) {
156#ifdef ARPHRD_IEEE1394 91#ifdef ARPHRD_IEEE1394
157 || Run->CardType == ARPHRD_IEEE1394 92 || Run->CardType == ARPHRD_IEEE1394
158#endif 93#endif
159 ) 94 )
160 ) { 95 ) {
161 // this is a LAN card 96 // this is a LAN card
162 if( Run->assignedNode() == netNode() ) { 97 if( Run->assignedConnection() == netNode()->connection() ) {
163 // assigned to us 98 // assigned to us
164 return Run; 99 return Run;
165 } else if( Run->assignedNode() == 0 ) { 100 } else if( Run->assignedConnection() == 0 ) {
166 // free 101 // free
167 best = Run; 102 best = Run;
168 } 103 }
169 } 104 }
170 } 105 }
171 return best; // can be 0 106 return best; // can be 0