Diffstat (limited to 'noncore/settings/networksettings2/network/networkrun.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/network/networkrun.cpp | 91 |
1 files changed, 32 insertions, 59 deletions
diff --git a/noncore/settings/networksettings2/network/networkrun.cpp b/noncore/settings/networksettings2/network/networkrun.cpp index 3e24c5f..c17aa7f 100644 --- a/noncore/settings/networksettings2/network/networkrun.cpp +++ b/noncore/settings/networksettings2/network/networkrun.cpp | |||
@@ -1,78 +1,51 @@ | |||
1 | #include <system.h> | 1 | #include <system.h> |
2 | #include <asdevice.h> | 2 | #include <netnode.h> |
3 | #include <resources.h> | ||
3 | #include "networkrun.h" | 4 | #include "networkrun.h" |
4 | 5 | ||
5 | void NetworkRun::detectState( NodeCollection * NC ) { | 6 | State_t NetworkRun::detectState( void ) { |
6 | RuntimeInfo * RI = netNode()->nextNode()->runtime(); | 7 | InterfaceInfo * II = nodeCollection()->assignedInterface(); |
7 | AsDevice * Next = RI->asDevice(); | ||
8 | InterfaceInfo * II = Next->assignedInterface(); | ||
9 | 8 | ||
10 | if( II ) { | 9 | Log(( "Interface %p : %d\n", II, (II) ? II->IsUp : 0 )); |
10 | if( II && II->IsUp ) { | ||
11 | // device has assigned interface | 11 | // device has assigned interface |
12 | NC->setCurrentState( (( II->IsUp ) ? IsUp : Available) ); | 12 | return IsUp; |
13 | return; | ||
14 | } | 13 | } |
15 | 14 | ||
16 | Log(( "%s not ! UP or ava\n", NC->name().latin1() )); | 15 | // had no interface or interface is no longer up -> release |
17 | // has no interface -> delegate | 16 | nodeCollection()->assignInterface( 0 ); |
18 | RI->detectState( NC ); | 17 | |
18 | return Unknown; | ||
19 | } | 19 | } |
20 | 20 | ||
21 | bool NetworkRun::setState( NodeCollection * NC, Action_t A, bool Force ) { | 21 | QString NetworkRun::setMyState( NodeCollection * NC, Action_t A, bool ) { |
22 | // we handle UP and DOWN | 22 | // we handle UP and DOWN |
23 | RuntimeInfo * RI = netNode()->nextNode()->runtime(); | 23 | InterfaceInfo * II = NC->assignedInterface(); |
24 | AsDevice * Next = RI->asDevice(); | ||
25 | InterfaceInfo * II = Next->assignedInterface(); | ||
26 | 24 | ||
27 | if( A == Up ) { | 25 | if( A == Up ) { |
28 | // we can bring UP if lower level is available | 26 | // we can bring UP if lower level is available |
29 | if( NC->currentState() == Available || Force ) { | 27 | QStringList SL; |
30 | QString S; | 28 | SL << "ifup" |
31 | S.sprintf( "ifup %s=%s-c%d-allowed", | 29 | << QString().sprintf( "%s=%s-c%d-allowed", |
32 | II->Name.latin1(), II->Name.latin1(), | 30 | II->Name.latin1(), II->Name.latin1(), |
33 | connection()->number() ); | 31 | nodeCollection()->number() ); |
34 | NSResources->system().runAsRoot( S ); | 32 | if( ! NSResources->system().runAsRoot( SL ) ) { |
33 | return QString("Cannot call %1").arg(SL.join(" ")); | ||
35 | } | 34 | } |
36 | return 1; | 35 | return QString(); |
37 | } else if( A == Down ) { | 36 | } |
38 | QString S; | 37 | |
39 | if( Force ) { | 38 | if( A == Down ) { |
40 | Log(("Force mode %d\n", Force )); | 39 | QStringList SL; |
41 | for( int i = 0; | 40 | if( II ) { |
42 | i < RI->netNode()->nodeClass()->instanceCount(); | 41 | SL << "ifdown" |
43 | i ++ ) { | 42 | << II->Name.latin1(); |
44 | S.sprintf( "ifdown %s", | 43 | if( ! NSResources->system().runAsRoot( SL ) ) { |
45 | RI->netNode()->nodeClass()->genNic( i ).latin1() ); | 44 | return QString( "Cannot call %1" ).arg( SL.join( " " )); |
46 | NSResources->system().runAsRoot( S ); | ||
47 | } | 45 | } |
48 | } else { | 46 | } else { |
49 | if( NC->currentState() == IsUp ) { | 47 | Log(( "no interface assigned." )); |
50 | S.sprintf( "ifdown %s=%s-c%d-allowed", | ||
51 | II->Name.latin1(), II->Name.latin1(), | ||
52 | connection()->number() ); | ||
53 | NSResources->system().runAsRoot( S ); | ||
54 | } | ||
55 | } | 48 | } |
56 | return 1; | ||
57 | } | ||
58 | // delegate | ||
59 | return RI->setState( NC, A, Force ); | ||
60 | } | ||
61 | |||
62 | bool NetworkRun::canSetState( State_t Curr, Action_t A ) { | ||
63 | // we handle UP and DOWN | ||
64 | RuntimeInfo * RI = netNode()->nextNode()->runtime(); | ||
65 | |||
66 | if( A == Up ) { | ||
67 | return ( Curr == Available ); | ||
68 | } else if( A == Down ) { | ||
69 | return ( Curr == IsUp ); | ||
70 | } | 49 | } |
71 | // delegate | 50 | return QString(); |
72 | return RI->canSetState( Curr, A ); | ||
73 | } | ||
74 | |||
75 | bool NetworkRun::handlesInterface( const QString & S ) { | ||
76 | // donno -> pass deeper | ||
77 | return netNode()->nextNode()->runtime()->handlesInterface(S); | ||
78 | } | 51 | } |