summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/network/networkrun.cpp
blob: c17aa7f4cc32050842a99c20faf7e417fdb4e5a4 (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
#include <system.h>
#include <netnode.h>
#include <resources.h>
#include "networkrun.h"

State_t NetworkRun::detectState( void ) { 
    InterfaceInfo * II = nodeCollection()->assignedInterface();

    Log(( "Interface %p : %d\n", II, (II) ? II->IsUp : 0 ));
    if( II && II->IsUp ) {
      // device has assigned interface
      return IsUp;
    }

    // had no interface or interface is no longer up -> release
    nodeCollection()->assignInterface( 0 );

    return Unknown;
}

QString NetworkRun::setMyState( NodeCollection * NC, Action_t A, bool ) { 
    // we handle UP and DOWN
    InterfaceInfo * II = NC->assignedInterface();

    if( A == Up ) {
      // we can bring UP if lower level is available
      QStringList SL;
      SL << "ifup"
         << QString().sprintf( "%s=%s-c%d-allowed",
                        II->Name.latin1(), II->Name.latin1(),
                        nodeCollection()->number() );
      if( ! NSResources->system().runAsRoot( SL ) ) {
        return QString("Cannot call %1").arg(SL.join(" "));
      }
      return QString();
    } 

    if( A == Down ) {
      QStringList SL;
      if( II ) {
        SL << "ifdown"
           << II->Name.latin1();
        if( !  NSResources->system().runAsRoot( SL ) ) {
          return QString( "Cannot call %1" ).arg( SL.join( " " ));
        }
      } else {
        Log(( "no interface assigned." ));
      }
    } 
    return QString();
}