summaryrefslogtreecommitdiff
authorwimpie <wimpie>2005-01-10 16:38:47 (UTC)
committer wimpie <wimpie>2005-01-10 16:38:47 (UTC)
commitdd649f98d0010711ed3d0fac433bd9fafa4002db (patch) (unidiff)
tree7a1f19cf6cf3e64bed58100f19d8427909fc44f2
parentf7b2f19ecbe3ae9151c1f9dc238bcfd019b3fdbe (diff)
downloadopie-dd649f98d0010711ed3d0fac433bd9fafa4002db.zip
opie-dd649f98d0010711ed3d0fac433bd9fafa4002db.tar.gz
opie-dd649f98d0010711ed3d0fac433bd9fafa4002db.tar.bz2
Do not assume device is Up based on existance of profile-xx file only
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/lancard/lancardrun.cpp2
-rw-r--r--noncore/settings/networksettings2/usb/usbrun.cpp2
-rw-r--r--noncore/settings/networksettings2/wlan/wlanrun.cpp2
3 files changed, 3 insertions, 3 deletions
diff --git a/noncore/settings/networksettings2/lancard/lancardrun.cpp b/noncore/settings/networksettings2/lancard/lancardrun.cpp
index 470b797..8157dce 100644
--- a/noncore/settings/networksettings2/lancard/lancardrun.cpp
+++ b/noncore/settings/networksettings2/lancard/lancardrun.cpp
@@ -1,148 +1,148 @@
1#include <qfile.h> 1#include <qfile.h>
2#include <qtextstream.h> 2#include <qtextstream.h>
3#include <qstringlist.h> 3#include <qstringlist.h>
4#include <resources.h> 4#include <resources.h>
5#include "lancardrun.h" 5#include "lancardrun.h"
6 6
7State_t LanCardRun::detectState( void ) { 7State_t LanCardRun::detectState( void ) {
8 8
9 // unavailable : no card found 9 // unavailable : no card found
10 // available : card found and assigned to us or free 10 // available : card found and assigned to us or free
11 // up : card found and assigned to us and up 11 // up : card found and assigned to us and up
12 12
13 NodeCollection * NC = nodeCollection(); 13 NodeCollection * NC = nodeCollection();
14 QString S = QString( "/tmp/profile-%1.up" ). 14 QString S = QString( "/tmp/profile-%1.up" ).
15 arg( NC->number()); 15 arg( NC->number());
16 System & Sys = NSResources->system(); 16 System & Sys = NSResources->system();
17 InterfaceInfo * Run; 17 InterfaceInfo * Run;
18 18
19 QFile F( S ); 19 QFile F( S );
20 20
21 if( F.open( IO_ReadOnly ) ) { 21 if( F.open( IO_ReadOnly ) ) {
22 // could open file -> read interface and assign 22 // could open file -> read interface and assign
23 QString X; 23 QString X;
24 QTextStream TS(&F); 24 QTextStream TS(&F);
25 X = TS.readLine(); 25 X = TS.readLine();
26 // find interface 26 // find interface
27 if( handlesInterface( X ) ) { 27 if( handlesInterface( X ) ) {
28 for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); 28 for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
29 It.current(); 29 It.current();
30 ++It ) { 30 ++It ) {
31 Run = It.current(); 31 Run = It.current();
32 if( X == Run->Name ) { 32 if( X == Run->Name ) {
33 NC->assignInterface( Run ); 33 NC->assignInterface( Run );
34 return IsUp; 34 return (Run->IsUp) ? IsUp : Available;
35 } 35 }
36 } 36 }
37 } 37 }
38 } 38 }
39 39
40 if( ( Run = NC->assignedInterface() ) ) { 40 if( ( Run = NC->assignedInterface() ) ) {
41 // we already have an interface assigned -> still present ? 41 // we already have an interface assigned -> still present ?
42 if( ! Run->IsUp ) { 42 if( ! Run->IsUp ) {
43 // usb is still free -> keep assignment 43 // usb is still free -> keep assignment
44 return Available; 44 return Available;
45 } // else interface is up but NOT us -> some other profile 45 } // else interface is up but NOT us -> some other profile
46 } 46 }
47 47
48 // nothing (valid) assigned to us 48 // nothing (valid) assigned to us
49 NC->assignInterface( 0 ); 49 NC->assignInterface( 0 );
50 50
51 // find possible interface 51 // find possible interface
52 for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); 52 for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
53 It.current(); 53 It.current();
54 ++It ) { 54 ++It ) {
55 Run = It.current(); 55 Run = It.current();
56 if( handlesInterface( *Run ) && 56 if( handlesInterface( *Run ) &&
57 ( Run->CardType == ARPHRD_ETHER 57 ( Run->CardType == ARPHRD_ETHER
58#ifdef ARPHRD_IEEE1394 58#ifdef ARPHRD_IEEE1394
59 || Run->CardType == ARPHRD_IEEE1394 59 || Run->CardType == ARPHRD_IEEE1394
60#endif 60#endif
61 ) && 61 ) &&
62 ! Run->IsUp 62 ! Run->IsUp
63 ) { 63 ) {
64 // proper type, and Not UP -> free 64 // proper type, and Not UP -> free
65 return Off; 65 return Off;
66 } 66 }
67 } 67 }
68 // no free found 68 // no free found
69 69
70 return Unavailable; 70 return Unavailable;
71} 71}
72 72
73QString LanCardRun::setMyState( NodeCollection * NC, Action_t A, bool ) { 73QString LanCardRun::setMyState( NodeCollection * NC, Action_t A, bool ) {
74 74
75 if( A == Activate ) { 75 if( A == Activate ) {
76 InterfaceInfo * N = getInterface(); 76 InterfaceInfo * N = getInterface();
77 77
78 if( ! N ) { 78 if( ! N ) {
79 // no interface available 79 // no interface available
80 NC->setCurrentState( Unavailable ); 80 NC->setCurrentState( Unavailable );
81 return tr("No interface found"); 81 return tr("No interface found");
82 } 82 }
83 83
84 // because we were OFF the interface 84 // because we were OFF the interface
85 // we get back is NOT assigned 85 // we get back is NOT assigned
86 NC->assignInterface( N ); 86 NC->assignInterface( N );
87 NC->setCurrentState( Available ); 87 NC->setCurrentState( Available );
88 return QString(); 88 return QString();
89 } 89 }
90 90
91 if( A == Deactivate ) { 91 if( A == Deactivate ) {
92 NC->assignInterface( 0 ); 92 NC->assignInterface( 0 );
93 NC->setCurrentState( Off ); 93 NC->setCurrentState( Off );
94 } 94 }
95 95
96 return QString(); 96 return QString();
97} 97}
98 98
99// get interface that is free or assigned to us 99// get interface that is free or assigned to us
100InterfaceInfo * LanCardRun::getInterface( void ) { 100InterfaceInfo * LanCardRun::getInterface( void ) {
101 101
102 System & S = NSResources->system(); 102 System & S = NSResources->system();
103 InterfaceInfo * best = 0, * Run; 103 InterfaceInfo * best = 0, * Run;
104 104
105 for( QDictIterator<InterfaceInfo> It(S.interfaces()); 105 for( QDictIterator<InterfaceInfo> It(S.interfaces());
106 It.current(); 106 It.current();
107 ++It ) { 107 ++It ) {
108 Run = It.current(); 108 Run = It.current();
109 if( handlesInterface( *Run ) && 109 if( handlesInterface( *Run ) &&
110 ( Run->CardType == ARPHRD_ETHER 110 ( Run->CardType == ARPHRD_ETHER
111#ifdef ARPHRD_IEEE1394 111#ifdef ARPHRD_IEEE1394
112 || Run->CardType == ARPHRD_IEEE1394 112 || Run->CardType == ARPHRD_IEEE1394
113#endif 113#endif
114 ) 114 )
115 ) { 115 ) {
116 // this is a LAN card 116 // this is a LAN card
117 if( Run->assignedConnection() == netNode()->connection() ) { 117 if( Run->assignedConnection() == netNode()->connection() ) {
118 // assigned to us 118 // assigned to us
119 return Run; 119 return Run;
120 } else if( Run->assignedConnection() == 0 ) { 120 } else if( Run->assignedConnection() == 0 ) {
121 // free 121 // free
122 best = Run; 122 best = Run;
123 } 123 }
124 } 124 }
125 } 125 }
126 return best; // can be 0 126 return best; // can be 0
127} 127}
128 128
129bool LanCardRun::handlesInterface( const QString & S ) { 129bool LanCardRun::handlesInterface( const QString & S ) {
130 InterfaceInfo * II; 130 InterfaceInfo * II;
131 II = NSResources->system().interface( S ); 131 II = NSResources->system().interface( S );
132 if( ( II = NSResources->system().interface( S ) ) ) { 132 if( ( II = NSResources->system().interface( S ) ) ) {
133 return handlesInterface( *II ); 133 return handlesInterface( *II );
134 } 134 }
135 return Pat.match( S ) >= 0; 135 return Pat.match( S ) >= 0;
136} 136}
137 137
138bool LanCardRun::handlesInterface( const InterfaceInfo & II ) { 138bool LanCardRun::handlesInterface( const InterfaceInfo & II ) {
139 if( Pat.match( II.Name ) < 0 ) 139 if( Pat.match( II.Name ) < 0 )
140 return 0; 140 return 0;
141 141
142 if( Data->AnyLanCard ) { 142 if( Data->AnyLanCard ) {
143 return 1; 143 return 1;
144 } 144 }
145 145
146 // must also match hardware address 146 // must also match hardware address
147 return ( Data->HWAddresses.findIndex( II.MACAddress ) >= 0 ); 147 return ( Data->HWAddresses.findIndex( II.MACAddress ) >= 0 );
148} 148}
diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp
index de8c8a2..763644e 100644
--- a/noncore/settings/networksettings2/usb/usbrun.cpp
+++ b/noncore/settings/networksettings2/usb/usbrun.cpp
@@ -1,120 +1,120 @@
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
7State_t USBRun::detectState( void ) { 7State_t USBRun::detectState( void ) {
8 8
9 // unavailable : no card found 9 // unavailable : no card found
10 // available : card found and assigned to us or free 10 // available : card found and assigned to us or free
11 // up : card found and assigned to us and up 11 // up : card found and assigned to us and up
12 12
13 NodeCollection * NC = nodeCollection(); 13 NodeCollection * NC = nodeCollection();
14 QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); 14 QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number());
15 System & Sys = NSResources->system(); 15 System & Sys = NSResources->system();
16 InterfaceInfo * Run; 16 InterfaceInfo * Run;
17 QFile F( S ); 17 QFile F( S );
18 Log(("Detecting for %s\n", NC->name().latin1() )); 18 Log(("Detecting for %s\n", NC->name().latin1() ));
19 19
20 if( F.open( IO_ReadOnly ) ) { 20 if( F.open( IO_ReadOnly ) ) {
21 // could open file -> read interface and assign 21 // could open file -> read interface and assign
22 QString X; 22 QString X;
23 QTextStream TS(&F); 23 QTextStream TS(&F);
24 X = TS.readLine(); 24 X = TS.readLine();
25 Log(("%s exists\n", S.latin1() )); 25 Log(("%s exists\n", S.latin1() ));
26 // find interface 26 // find interface
27 if( handlesInterface( X ) ) { 27 if( handlesInterface( X ) ) {
28 for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); 28 for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
29 It.current(); 29 It.current();
30 ++It ) { 30 ++It ) {
31 Run = It.current(); 31 Run = It.current();
32 if( X == Run->Name ) { 32 if( X == Run->Name ) {
33 NC->assignInterface( Run ); 33 NC->assignInterface( Run );
34 return IsUp; 34 return (Run->IsUp) ? IsUp : Available;
35 } 35 }
36 } 36 }
37 } 37 }
38 } 38 }
39 39
40 Log(("Assigned %p\n", NC->assignedInterface() )); 40 Log(("Assigned %p\n", NC->assignedInterface() ));
41 41
42 if( ( Run = NC->assignedInterface() ) ) { 42 if( ( Run = NC->assignedInterface() ) ) {
43 // we already have an interface assigned -> still present ? 43 // we already have an interface assigned -> still present ?
44 if( ! Run->IsUp ) { 44 if( ! Run->IsUp ) {
45 // usb is still free -> keep assignment 45 // usb is still free -> keep assignment
46 return Available; 46 return Available;
47 } // else interface is up but NOT us -> some other profile 47 } // else interface is up but NOT us -> some other profile
48 } 48 }
49 49
50 // nothing (valid) assigned to us 50 // nothing (valid) assigned to us
51 NC->assignInterface( 0 ); 51 NC->assignInterface( 0 );
52 52
53 // find possible interface 53 // find possible interface
54 if( getInterface() ) { 54 if( getInterface() ) {
55 // proper type, and Not UP -> free 55 // proper type, and Not UP -> free
56 // usb cables are currently always available when requested 56 // usb cables are currently always available when requested
57 // until we can detect if we are plugged in 57 // until we can detect if we are plugged in
58 return Available; 58 return Available;
59 } 59 }
60 60
61 return Unavailable; 61 return Unavailable;
62} 62}
63 63
64QString USBRun::setMyState( NodeCollection * NC, Action_t A, bool ) { 64QString USBRun::setMyState( NodeCollection * NC, Action_t A, bool ) {
65 65
66 InterfaceInfo * I = getInterface(); 66 InterfaceInfo * I = getInterface();
67 67
68 if( ! I ) { 68 if( ! I ) {
69 return QString("No usb device available"); 69 return QString("No usb device available");
70 } 70 }
71 71
72 Log(( "Grabbed USB interface %s\n", I->Name.latin1() )); 72 Log(( "Grabbed USB interface %s\n", I->Name.latin1() ));
73 // grab this interface 73 // grab this interface
74 NC->assignInterface( I ); 74 NC->assignInterface( I );
75 75
76 return QString(); 76 return QString();
77} 77}
78 78
79// get interface that is free or assigned to us 79// get interface that is free or assigned to us
80InterfaceInfo * USBRun::getInterface( void ) { 80InterfaceInfo * USBRun::getInterface( void ) {
81 81
82 System & S = NSResources->system(); 82 System & S = NSResources->system();
83 InterfaceInfo * best = 0, * Run; 83 InterfaceInfo * best = 0, * Run;
84 84
85 for( QDictIterator<InterfaceInfo> It(S.interfaces()); 85 for( QDictIterator<InterfaceInfo> It(S.interfaces());
86 It.current(); 86 It.current();
87 ++It ) { 87 ++It ) {
88 Run = It.current(); 88 Run = It.current();
89 89
90 Log(("%s %d %d=%d %d\n", 90 Log(("%s %d %d=%d %d\n",
91 Run->Name.latin1(), 91 Run->Name.latin1(),
92 handlesInterface( Run->Name ), 92 handlesInterface( Run->Name ),
93 Run->CardType, ARPHRD_ETHER, 93 Run->CardType, ARPHRD_ETHER,
94 ! Run->IsUp )); 94 ! Run->IsUp ));
95 95
96 if( handlesInterface( Run->Name ) && 96 if( handlesInterface( Run->Name ) &&
97 Run->CardType == ARPHRD_ETHER 97 Run->CardType == ARPHRD_ETHER
98 ) { 98 ) {
99 // this is a USB card 99 // this is a USB card
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->IsUp && 103 } else if( ! Run->IsUp &&
104 Run->assignedConnection() == 0 ) { 104 Run->assignedConnection() == 0 ) {
105 // free 105 // free
106 best = Run; 106 best = Run;
107 } // UP or not assigned to us 107 } // UP or not assigned to us
108 } 108 }
109 } 109 }
110 return best; // can be 0 110 return best; // can be 0
111} 111}
112 112
113bool USBRun::handlesInterface( const QString & S ) { 113bool USBRun::handlesInterface( const QString & S ) {
114 return Pat.match( S ) >= 0; 114 return Pat.match( S ) >= 0;
115} 115}
116 116
117bool USBRun::handlesInterface( InterfaceInfo * I ) { 117bool USBRun::handlesInterface( InterfaceInfo * I ) {
118 return handlesInterface( I->Name ); 118 return handlesInterface( I->Name );
119} 119}
120 120
diff --git a/noncore/settings/networksettings2/wlan/wlanrun.cpp b/noncore/settings/networksettings2/wlan/wlanrun.cpp
index fe49c4e..b15a560 100644
--- a/noncore/settings/networksettings2/wlan/wlanrun.cpp
+++ b/noncore/settings/networksettings2/wlan/wlanrun.cpp
@@ -1,120 +1,120 @@
1 1
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
8State_t WLanRun::detectState( void ) { 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 NodeCollection * NC = nodeCollection();
15 QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); 15 QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number());
16 System & Sys = NSResources->system(); 16 System & Sys = NSResources->system();
17 InterfaceInfo * Run; 17 InterfaceInfo * Run;
18 18
19 QFile F( S ); 19 QFile F( S );
20 20
21 if( F.open( IO_ReadOnly ) ) { 21 if( F.open( IO_ReadOnly ) ) {
22 // could open file -> read interface and assign 22 // could open file -> read interface and assign
23 QString X; 23 QString X;
24 QTextStream TS(&F); 24 QTextStream TS(&F);
25 X = TS.readLine(); 25 X = TS.readLine();
26 // find interface 26 // find interface
27 if( handlesInterface( X ) ) { 27 if( handlesInterface( X ) ) {
28 for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); 28 for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
29 It.current(); 29 It.current();
30 ++It ) { 30 ++It ) {
31 Run = It.current(); 31 Run = It.current();
32 if( X == Run->Name ) { 32 if( X == Run->Name ) {
33 NC->assignInterface( Run ); 33 NC->assignInterface( Run );
34 return IsUp; 34 return (Run->IsUp) ? IsUp : Available;
35 } 35 }
36 } 36 }
37 } 37 }
38 } 38 }
39 39
40 if( ( Run = NC->assignedInterface() ) ) { 40 if( ( Run = NC->assignedInterface() ) ) {
41 // we already have an interface assigned -> still present ? 41 // we already have an interface assigned -> still present ?
42 if( ! Run->IsUp ) { 42 if( ! Run->IsUp ) {
43 // usb is still free -> keep assignment 43 // usb is still free -> keep assignment
44 return Available; 44 return Available;
45 } // else interface is up but NOT us -> some other profile 45 } // else interface is up but NOT us -> some other profile
46 } 46 }
47 47
48 // nothing (valid) assigned to us 48 // nothing (valid) assigned to us
49 NC->assignInterface( 0 ); 49 NC->assignInterface( 0 );
50 50
51 // find possible interface 51 // find possible interface
52 for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); 52 for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
53 It.current(); 53 It.current();
54 ++It ) { 54 ++It ) {
55 Run = It.current(); 55 Run = It.current();
56 if( handlesInterface( *Run ) && 56 if( handlesInterface( *Run ) &&
57 ( Run->CardType == ARPHRD_ETHER 57 ( Run->CardType == ARPHRD_ETHER
58#ifdef ARPHRD_IEEE1394 58#ifdef ARPHRD_IEEE1394
59 || Run->CardType == ARPHRD_IEEE1394 59 || Run->CardType == ARPHRD_IEEE1394
60#endif 60#endif
61 ) && 61 ) &&
62 ! Run->IsUp 62 ! Run->IsUp
63 ) { 63 ) {
64 // proper type, and Not UP -> free 64 // proper type, and Not UP -> free
65 return Off; 65 return Off;
66 } 66 }
67 } 67 }
68 68
69 return Unavailable; 69 return Unavailable;
70 70
71} 71}
72 72
73QString WLanRun::setMyState( NodeCollection * , Action_t , bool ) { 73QString WLanRun::setMyState( NodeCollection * , Action_t , bool ) {
74 74
75 // we only handle activate and deactivate 75 // we only handle activate and deactivate
76 return QString(); 76 return QString();
77} 77}
78 78
79// get interface that is free or assigned to us 79// get interface that is free or assigned to us
80InterfaceInfo * WLanRun::getInterface( void ) { 80InterfaceInfo * WLanRun::getInterface( void ) {
81 81
82 System & S = NSResources->system(); 82 System & S = NSResources->system();
83 InterfaceInfo * best = 0, * Run; 83 InterfaceInfo * best = 0, * Run;
84 84
85 for( QDictIterator<InterfaceInfo> It(S.interfaces()); 85 for( QDictIterator<InterfaceInfo> It(S.interfaces());
86 It.current(); 86 It.current();
87 ++It ) { 87 ++It ) {
88 Run = It.current(); 88 Run = It.current();
89 if( handlesInterface( *Run ) && 89 if( handlesInterface( *Run ) &&
90 ( Run->CardType == ARPHRD_ETHER 90 ( Run->CardType == ARPHRD_ETHER
91#ifdef ARPHRD_IEEE1394 91#ifdef ARPHRD_IEEE1394
92 || Run->CardType == ARPHRD_IEEE1394 92 || Run->CardType == ARPHRD_IEEE1394
93#endif 93#endif
94 ) 94 )
95 ) { 95 ) {
96 // this is a LAN card 96 // this is a LAN card
97 if( Run->assignedConnection() == netNode()->connection() ) { 97 if( Run->assignedConnection() == netNode()->connection() ) {
98 // assigned to us 98 // assigned to us
99 return Run; 99 return Run;
100 } else if( Run->assignedConnection() == 0 ) { 100 } else if( Run->assignedConnection() == 0 ) {
101 // free 101 // free
102 best = Run; 102 best = Run;
103 } 103 }
104 } 104 }
105 } 105 }
106 return best; // can be 0 106 return best; // can be 0
107} 107}
108 108
109bool WLanRun::handlesInterface( const QString & S ) { 109bool WLanRun::handlesInterface( const QString & S ) {
110 InterfaceInfo * II; 110 InterfaceInfo * II;
111 II = NSResources->system().interface( S ); 111 II = NSResources->system().interface( S );
112 if( ( II = NSResources->system().interface( S ) ) ) { 112 if( ( II = NSResources->system().interface( S ) ) ) {
113 return handlesInterface( *II ); 113 return handlesInterface( *II );
114 } 114 }
115 return Pat.match( S ) >= 0; 115 return Pat.match( S ) >= 0;
116} 116}
117 117
118bool WLanRun::handlesInterface( const InterfaceInfo & II ) { 118bool WLanRun::handlesInterface( const InterfaceInfo & II ) {
119 return ( Pat.match( II.Name ) < 0 ); 119 return ( Pat.match( II.Name ) < 0 );
120} 120}