summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2/system.h
blob: f7a727417beba8e64188c9f569f6160b14611927 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef __SYSTEM__H
#define __SYSTEM__H

#include <qstring.h>

#include <opie2/oprocess.h>

using namespace Opie::Core;

// for hardware types
#include <net/if_arp.h>
#include <qdict.h>
#include <qobject.h>
#include <stdio.h>

class NodeCollection;
class ANetNodeInstance;
class QFile;

class MyProcess : public QObject {

      Q_OBJECT

public :

      MyProcess();
      ~MyProcess();

      inline OProcess & process()
        { return *P; }

public slots :

      void SLOT_Stdout( Opie::Core::OProcess * P, char *, int );
      void SLOT_Stderr( Opie::Core::OProcess * P, char *, int );
      void SLOT_ProcessExited( Opie::Core::OProcess * P);

signals :

      void stdoutLine( const QString & );
      void stderrLine( const QString & );
      void processExited( MyProcess * );

private :

      QString StdoutBuffer;
      QString StderrBuffer;
      OProcess * P;
};

class InterfaceInfo {

public :

        InterfaceInfo() :
            Name(),
            MACAddress(),
            BCastAddress(),
            Netmask(),
            DstAddress() {
        }

        NodeCollection * assignedConnection()
          { return Collection; }

        void assignConnection( NodeCollection * NNI )
          { Collection = NNI; }

        NodeCollection * Collection;    // connection taking care of me
        QString Name;                   // name of interface
        int     CardType;               // type of card
        QString MACAddress;             // MAC address
        QString Address;                // IP Address
        QString BCastAddress;           // Broadcast Address
        QString Netmask;                // Netmask
        QString DstAddress;             // Peer address (if P-t-P)
        bool    IsUp;                   // interface is UP
        bool    HasMulticast;           // Supports Multicast
        bool    IsPointToPoint;         // IsPointToPoint card

        QString RcvBytes;
        QString SndBytes;
        QString RcvErrors;
        QString SndErrors;
        QString RcvDropped;
        QString SndDropped;
        QString Collisions;
};

class System : public QObject {

      Q_OBJECT

public :

      System( void );
      ~System( void );

      QDict<InterfaceInfo> & interfaces( void );
      InterfaceInfo * interface( const QString& N ) 
        { return interfaces()[N]; }

      // exec command as root
      int runAsRoot( QStringList & S, MyProcess * Prc = 0 );

      // exec command as user
      int execAsUser( QStringList & Cmd );

      // refresh stats for this interface
      void refreshStatistics( InterfaceInfo & );

      // reloads interfaces
      void probeInterfaces( void );

      InterfaceInfo * findInterface( const QString & DevName );

private slots :

      void SLOT_ProcessExited( MyProcess * );

signals :

      void stdoutLine( const QString & );
      void stderrLine( const QString & );
      void processEvent( const QString & );

private  :

      QDict<InterfaceInfo>  ProbedInterfaces;
      FILE *                OutputOfCmd;
      QFile *               ProcDevNet;
};

#endif