summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/network/networkrun.cpp
blob: 41e1c5333c7d381d2443158256d5054abdc653b7 (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
#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;
    }

    // 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 ) {
      if( NC->currentState() == IsUp || Force ) {
        QString S;
        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 );
}

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);
}