summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/network/networkrun.cpp
blob: 3e24c5f0c2185d49be1af586d4f450984f76b9bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <system.h>
#include <asdevice.h>
#include "networkrun.h"

void NetworkRun::detectState( NodeCollection * NC ) { 
    RuntimeInfo * RI = netNode()->nextNode()->runtime();
    AsDevice * Next = RI->asDevice();
    InterfaceInfo * II = Next->assignedInterface();

    if( II ) {
      // device has assigned interface
      NC->setCurrentState( (( II->IsUp ) ? IsUp : Available) );
      return;
    }

    Log(( "%s not ! UP or ava\n", NC->name().latin1() ));
    // has no interface -> delegate
    RI->detectState( NC );
}

bool NetworkRun::setState( NodeCollection * NC, Action_t A, bool Force ) { 
    // we handle UP and DOWN
    RuntimeInfo * RI = netNode()->nextNode()->runtime();
    AsDevice * Next = RI->asDevice();
    InterfaceInfo * II = Next->assignedInterface();

    if( A == Up ) {
      // we can bring UP if lower level is available
      if( NC->currentState() == Available || Force ) {
        QString S;
        S.sprintf( "ifup %s=%s-c%d-allowed", 
            II->Name.latin1(), II->Name.latin1(),
            connection()->number() );
        NSResources->system().runAsRoot( S );
      }
      return 1;
    } else if( A == Down ) {
      QString S;
      if( Force ) {
        Log(("Force mode %d\n", Force ));
        for( int i = 0; 
             i < RI->netNode()->nodeClass()->instanceCount(); 
             i ++ ) {
          S.sprintf( "ifdown %s", 
                      RI->netNode()->nodeClass()->genNic( i ).latin1() );
          NSResources->system().runAsRoot( S );
        }
      } else {
        if( NC->currentState() == IsUp ) {
          S.sprintf( "ifdown %s=%s-c%d-allowed", 
              II->Name.latin1(), II->Name.latin1(),
              connection()->number() );
          NSResources->system().runAsRoot( S );
        }
      }
      return 1;
    } 
    // delegate
    return RI->setState( NC, A, Force );
}

bool NetworkRun::canSetState( State_t Curr, Action_t A ) {
    // we handle UP and DOWN
    RuntimeInfo * RI = netNode()->nextNode()->runtime();

    if( A == Up ) {
      return ( Curr == Available );
    } else if( A == Down ) {
      return ( Curr == IsUp );
    } 
    // delegate
    return RI->canSetState( Curr, A );
}

bool NetworkRun::handlesInterface( const QString & S ) {
    // donno -> pass deeper
    return netNode()->nextNode()->runtime()->handlesInterface(S);
}