Diffstat (limited to 'noncore/settings/networksettings2/lancard/lancardrun.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/lancard/lancardrun.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/noncore/settings/networksettings2/lancard/lancardrun.cpp b/noncore/settings/networksettings2/lancard/lancardrun.cpp index b3b592b..951756d 100644 --- a/noncore/settings/networksettings2/lancard/lancardrun.cpp +++ b/noncore/settings/networksettings2/lancard/lancardrun.cpp | |||
@@ -15,49 +15,58 @@ void LanCardRun::detectState( NodeCollection * NC ) { | |||
15 | 15 | ||
16 | QFile F( S ); | 16 | QFile F( S ); |
17 | 17 | ||
18 | if( F.open( IO_ReadOnly ) ) { | 18 | if( F.open( IO_ReadOnly ) ) { |
19 | // could open file -> read interface and assign | 19 | // could open file -> read interface and assign |
20 | QString X; | 20 | QString X; |
21 | QTextStream TS(&F); | 21 | QTextStream TS(&F); |
22 | X = TS.readLine(); | 22 | X = TS.readLine(); |
23 | // find interface | 23 | // find interface |
24 | if( handlesInterface( X ) ) { | 24 | if( handlesInterface( X ) ) { |
25 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); | 25 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); |
26 | It.current(); | 26 | It.current(); |
27 | ++It ) { | 27 | ++It ) { |
28 | Run = It.current(); | 28 | Run = It.current(); |
29 | if( X == Run->Name ) { | 29 | if( X == Run->Name ) { |
30 | Run->assignNode( netNode() ); | 30 | Run->assignNode( netNode() ); |
31 | assignInterface( Run ); | 31 | assignInterface( Run ); |
32 | NC->setCurrentState( IsUp ); | 32 | NC->setCurrentState( IsUp ); |
33 | return; | 33 | return; |
34 | } | 34 | } |
35 | } | 35 | } |
36 | } | 36 | } |
37 | } | 37 | } |
38 | 38 | ||
39 | // we are certainly not UP | 39 | if( ( Run = assignedInterface() ) ) { |
40 | // we already have an interface assigned -> still present ? | ||
41 | if( ! Run->IsUp ) { | ||
42 | // usb is still free -> keep assignment | ||
43 | NC->setCurrentState( Available ); | ||
44 | return; | ||
45 | } // else interface is up but NOT us -> some other profile | ||
46 | } | ||
47 | |||
48 | // nothing (valid) assigned to us | ||
40 | assignInterface( 0 ); | 49 | assignInterface( 0 ); |
41 | 50 | ||
42 | // find possible interface | 51 | // find possible interface |
43 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); | 52 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); |
44 | It.current(); | 53 | It.current(); |
45 | ++It ) { | 54 | ++It ) { |
46 | Run = It.current(); | 55 | Run = It.current(); |
47 | if( handlesInterface( Run->Name ) && | 56 | if( handlesInterface( Run->Name ) && |
48 | Run->CardType == ARPHRD_ETHER && | 57 | Run->CardType == ARPHRD_ETHER && |
49 | ! Run->IsUp | 58 | ! Run->IsUp |
50 | ) { | 59 | ) { |
51 | // proper type, and Not UP -> free | 60 | // proper type, and Not UP -> free |
52 | NC->setCurrentState( Off ); | 61 | NC->setCurrentState( Off ); |
53 | return; | 62 | return; |
54 | } | 63 | } |
55 | } | 64 | } |
56 | // no free found | 65 | // no free found |
57 | 66 | ||
58 | NC->setCurrentState( Unavailable ); | 67 | NC->setCurrentState( Unavailable ); |
59 | 68 | ||
60 | } | 69 | } |
61 | 70 | ||
62 | bool LanCardRun::setState( NodeCollection * NC, Action_t A ) { | 71 | bool LanCardRun::setState( NodeCollection * NC, Action_t A ) { |
63 | 72 | ||
@@ -66,50 +75,49 @@ bool LanCardRun::setState( NodeCollection * NC, Action_t A ) { | |||
66 | case Activate : | 75 | case Activate : |
67 | { | 76 | { |
68 | if( NC->currentState() != Off ) { | 77 | if( NC->currentState() != Off ) { |
69 | return 0; | 78 | return 0; |
70 | } | 79 | } |
71 | InterfaceInfo * N = getInterface(); | 80 | InterfaceInfo * N = getInterface(); |
72 | if( ! N ) { | 81 | if( ! N ) { |
73 | // no interface available | 82 | // no interface available |
74 | NC->setCurrentState( Unavailable ); | 83 | NC->setCurrentState( Unavailable ); |
75 | return 0; | 84 | return 0; |
76 | } | 85 | } |
77 | // because we were OFF the interface | 86 | // because we were OFF the interface |
78 | // we get back is NOT assigned | 87 | // we get back is NOT assigned |
79 | N->assignNode( netNode() ); | 88 | N->assignNode( netNode() ); |
80 | assignInterface( N ); | 89 | assignInterface( N ); |
81 | NC->setCurrentState( Available ); | 90 | NC->setCurrentState( Available ); |
82 | return 1; | 91 | return 1; |
83 | } | 92 | } |
84 | case Deactivate : | 93 | case Deactivate : |
85 | if( NC->currentState() == IsUp ) { | 94 | if( NC->currentState() == IsUp ) { |
86 | // bring down first | 95 | // bring down first |
87 | if( ! connection()->setState( Down ) ) | 96 | if( ! connection()->setState( Down ) ) |
88 | // could not ... | 97 | // could not ... |
89 | return 0; | 98 | return 0; |
90 | } | 99 | } else if( NC->currentState() != Available ) { |
91 | if( NC->currentState() != Available ) { | ||
92 | return 1; | 100 | return 1; |
93 | } | 101 | } |
94 | assignedInterface()->assignNode( 0 ); // release | 102 | assignedInterface()->assignNode( 0 ); // release |
95 | assignInterface( 0 ); | 103 | assignInterface( 0 ); |
96 | NC->setCurrentState( Off ); | 104 | NC->setCurrentState( Off ); |
97 | return 1; | 105 | return 1; |
98 | default : | 106 | default : |
99 | // FT | 107 | // FT |
100 | break; | 108 | break; |
101 | } | 109 | } |
102 | return 0; | 110 | return 0; |
103 | } | 111 | } |
104 | 112 | ||
105 | bool LanCardRun::canSetState( State_t Curr, Action_t A ) { | 113 | bool LanCardRun::canSetState( State_t Curr, Action_t A ) { |
106 | // we only handle up down activate and deactivate | 114 | // we only handle up down activate and deactivate |
107 | switch( A ) { | 115 | switch( A ) { |
108 | case Activate : | 116 | case Activate : |
109 | { // at least available | 117 | { // at least available |
110 | if( Curr == Available ) { | 118 | if( Curr == Available ) { |
111 | return 1; | 119 | return 1; |
112 | } | 120 | } |
113 | // or we can make one available | 121 | // or we can make one available |
114 | InterfaceInfo * N = getInterface(); | 122 | InterfaceInfo * N = getInterface(); |
115 | if( ! N || N->assignedNode() != 0 ) { | 123 | if( ! N || N->assignedNode() != 0 ) { |