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

    // has no interface -> delegate
    RI->detectState( NC );
}

bool NetworkRun::setState( NodeCollection * NC, Action_t A ) { 
    // 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 ) {
        QString S;
        S.sprintf( "ifup %s=manual", II->Name.latin1() );
        NSResources->system().execute( S );
        NC->setCurrentState( IsUp );
      }
      return 1;
    } else if( A == Down ) {
      if( NC->currentState() == IsUp ) {
        QString S;
        S.sprintf( "ifdown %s", II->Name.latin1() );
        NSResources->system().execute( S );
        NC->setCurrentState( Available );
      }
      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);
}