summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/network/networkrun.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/network/networkrun.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/network/networkrun.cpp89
1 files changed, 31 insertions, 58 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
5void NetworkRun::detectState( NodeCollection * NC ) { 6State_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
21bool NetworkRun::setState( NodeCollection * NC, Action_t A, bool Force ) { 21QString 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(),
33 connection()->number() );
34 NSResources->system().runAsRoot( S );
35 }
36 return 1;
37 } else if( A == Down ) {
38 QString S;
39 if( Force ) {
40 Log(("Force mode %d\n", Force ));
41 for( int i = 0;
42 i < RI->netNode()->nodeClass()->instanceCount();
43 i ++ ) {
44 S.sprintf( "ifdown %s",
45 RI->netNode()->nodeClass()->genNic( i ).latin1() );
46 NSResources->system().runAsRoot( S );
47 }
48 } else {
49 if( NC->currentState() == IsUp ) {
50 S.sprintf( "ifdown %s=%s-c%d-allowed",
51 II->Name.latin1(), II->Name.latin1(), 30 II->Name.latin1(), II->Name.latin1(),
52 connection()->number() ); 31 nodeCollection()->number() );
53 NSResources->system().runAsRoot( S ); 32 if( ! NSResources->system().runAsRoot( SL ) ) {
54 } 33 return QString("Cannot call %1").arg(SL.join(" "));
55 }
56 return 1;
57 } 34 }
58 // delegate 35 return QString();
59 return RI->setState( NC, A, Force );
60} 36}
61 37
62bool NetworkRun::canSetState( State_t Curr, Action_t A ) { 38 if( A == Down ) {
63 // we handle UP and DOWN 39 QStringList SL;
64 RuntimeInfo * RI = netNode()->nextNode()->runtime(); 40 if( II ) {
65 41 SL << "ifdown"
66 if( A == Up ) { 42 << II->Name.latin1();
67 return ( Curr == Available ); 43 if( ! NSResources->system().runAsRoot( SL ) ) {
68 } else if( A == Down ) { 44 return QString( "Cannot call %1" ).arg( SL.join( " " ));
69 return ( Curr == IsUp );
70 } 45 }
71 // delegate 46 } else {
72 return RI->canSetState( Curr, A ); 47 Log(( "no interface assigned." ));
73} 48}
74 49 }
75bool NetworkRun::handlesInterface( const QString & S ) { 50 return QString();
76 // donno -> pass deeper
77 return netNode()->nextNode()->runtime()->handlesInterface(S);
78} 51}