00001 #ifndef __SYSTEM__H
00002 #define __SYSTEM__H
00003
00004 #include <qstring.h>
00005
00006 #include <opie2/oprocess.h>
00007
00008 using namespace Opie::Core;
00009
00010
00011 #include <net/if_arp.h>
00012 #include <qdict.h>
00013 #include <qobject.h>
00014 #include <stdio.h>
00015
00016 class NetworkSetup;
00017 class ANetNodeInstance;
00018 class QFile;
00019
00020 class MyProcess : public QObject {
00021
00022 Q_OBJECT
00023
00024 public :
00025
00026 MyProcess();
00027 ~MyProcess();
00028
00029 inline OProcess & process()
00030 { return *P; }
00031
00032 inline void setEchoMode( bool M ) {
00033 EchoMode = M;
00034 }
00035
00036 public slots :
00037
00038 void SLOT_Stdout( Opie::Core::OProcess * P, char *, int );
00039 void SLOT_Stderr( Opie::Core::OProcess * P, char *, int );
00040 void SLOT_ProcessExited( Opie::Core::OProcess * P);
00041
00042 signals :
00043
00044 void stdoutLine( const QString & );
00045 void stderrLine( const QString & );
00046 void processExited( MyProcess * );
00047
00048 private :
00049
00050 QString StdoutBuffer;
00051 QString StderrBuffer;
00052 OProcess * P;
00053
00054 bool EchoMode;
00055 };
00056
00057 class InterfaceInfo {
00058
00059 public :
00060
00061 InterfaceInfo() :
00062 Name(),
00063 MACAddress(),
00064 BCastAddress(),
00065 Netmask(),
00066 DstAddress() {
00067 }
00068
00069 NetworkSetup * assignedToNetworkSetup()
00070 { return Collection; }
00071
00072 void assignToNetworkSetup( NetworkSetup * NNI )
00073 { Collection = NNI; }
00074
00075 NetworkSetup * Collection;
00076 QString Name;
00077 int CardType;
00078 QString MACAddress;
00079 QString Address;
00080 QString BCastAddress;
00081 QString Netmask;
00082 QString DstAddress;
00083 bool IsUp;
00084 bool HasMulticast;
00085 bool IsPointToPoint;
00086
00087 QString RcvBytes;
00088 QString RcvErrors;
00089 QString RcvPackets;
00090 QString RcvDropped;
00091
00092 QString SndBytes;
00093 QString SndErrors;
00094 QString SndPackets;
00095 QString SndDropped;
00096 QString Collisions;
00097 };
00098
00099 class System : public QObject {
00100
00101 Q_OBJECT
00102
00103 public :
00104
00105 System( void );
00106 ~System( void );
00107
00108 QDict<InterfaceInfo> & interfaces( void );
00109 InterfaceInfo * interface( const QString& N )
00110 { return interfaces()[N]; }
00111
00112
00113 int runAsRoot( QStringList & S, MyProcess * Prc = 0 );
00114
00115
00116 int execAsUser( QStringList & Cmd, bool Synchronous = 0 );
00117
00118
00119 void refreshStatistics( InterfaceInfo & );
00120
00121
00122 void probeInterfaces( void );
00123
00124 InterfaceInfo * findInterface( const QString & DevName );
00125
00126 private slots :
00127
00128 void SLOT_ProcessExited( MyProcess * );
00129
00130 signals :
00131
00132 void stdoutLine( const QString & );
00133 void stderrLine( const QString & );
00134 void processEvent( const QString & );
00135
00136 private :
00137
00138 QDict<InterfaceInfo> ProbedInterfaces;
00139 FILE * OutputOfCmd;
00140 QFile * ProcDevNet;
00141 };
00142
00143 #endif