|
ndgui/NetworkDiscovery
|
00001 00016 #ifndef NetworkDiscovery_H 00017 #define NetworkDiscovery_H 00018 00019 #include <QtNetwork> 00020 #include <QtCore> 00021 00022 #include <arpa/inet.h> 00023 #include <stdio.h> 00024 #include <unistd.h> 00025 #include <string.h> 00026 #include <stdlib.h> 00027 #include <syslog.h> 00028 #include <sysfs/libsysfs.h> 00029 00030 #include "loggerengine.h" 00031 #include "interfaceconfiguration.h" 00032 #include "networkmanager.h" 00033 00034 00035 #include "dhcp.h" 00036 00037 #include "../common/fbgui.h" 00038 00039 00040 00041 #define DEFAULT_PATHTODHCPCDEXE "/bin/cdhcpcd" 00042 00043 class NetworkDiscovery: public QObject { 00044 Q_OBJECT 00045 00046 public: 00047 NetworkDiscovery(QObject *parent=0); 00048 ~NetworkDiscovery(); 00049 00050 void initAndRun(QString serverIp, bool userChoice, 00051 bool autoUp, 00052 QString pathToLogFile, 00053 QString serverPath = DEFAULT_QTSOCKETADDRESS, 00054 QString pathToExe = DEFAULT_PATHTODHCPCDEXE, 00055 QStringList* args = NULL); 00056 int ip4_replaceDefaultRoute(QString ifName, QString gateway, int mss); 00057 QString getGatewayForInterface(QString ifName); 00058 00059 int ip4_setManualConfiguration(QVariantMap result); 00060 QString readLogFile(); 00061 void tryAgain(); 00062 void prepareTryAgain(); 00063 bool checkConnectivity(QString ifName); 00064 bool checkConnectivityViaTcp(); 00065 QVariantMap getInterfaceConfig(QString ifName); 00066 QString GetErrorStr(); 00067 00068 public slots: 00069 void handleNewConnection(); 00070 void handleNewInput(); 00071 void handleNewInputLine(QLocalSocket * client, QString data); 00072 void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); 00073 void handleProcessStarted(); 00074 void handleClientDisconnect(); 00075 00076 void slotReadyForRun(); 00077 00078 void checkForIsRunning(); 00079 00080 00081 signals: 00082 void addInterface(const QString &ifName); 00083 void changeProgressBarValue(const QString & ifName, const int $newValue); 00084 void connectionEstablished(QString ifName); 00085 void abortBoot(QString msg); 00086 void updateIfStatus(QString ifName, QString status); 00087 void updateStatus(QString status); 00088 void allProcessesFinished(); 00089 void continueBoot(QString ifName); 00090 void continueBootWithoutCheck(QString ifName); 00091 void setManualConfInterfaces(QString jsonArr); 00092 00093 void readyForRun(); 00094 00095 private: 00096 QString _tag; 00097 QLocalServer *_server; 00098 QMap<QLocalSocket*,QLocalSocket*> _clients; 00099 QLocalSocket *_client; 00100 QMap<QString,QLocalSocket*> _ifNameToClient; 00101 QMap<QProcess*,QString> _clientProcessToIfNameMap; 00102 QString _serverPath; 00103 QString _pathToDhcpcdExe; 00104 QStringList _dhcpcdArguments; 00105 int _numberOfProcesses; 00106 NetworkManager* _networkManager; 00107 bool _userChoice; 00108 bool _blocked; 00109 bool _autoUp; 00110 QString _serverIp; 00111 QString _pathToLogFile; 00112 QList<QString> _ifUpList; 00113 QList<QString> _ifDownList; 00114 int _ifUpCountdown; 00115 QTimer*_timer; 00116 QList<Q_PID> _pidsList; 00117 QString _errorStr; 00118 QMap<QString,interfaceconfiguration*> _ifcMap; 00119 void mainWork(); 00120 00121 void killDHCPCD(); 00122 00123 void handleNewInput(QLocalSocket * client); 00124 00125 void runDHCPCD(QList<QString> &interfaces); 00126 void runDHCPCD(QString interface); 00127 00128 bool checkCarrierState(QString interface); 00129 bool checkConnectivityViaTcp(QString server); 00130 00131 bool checkBlackList(QString i); 00132 00133 void getListOfNetworkInterfaces(); 00134 void getListOfNetworkInterfacesWithAutoUp(); 00135 00136 00137 }; 00138 00139 #endif // NetworkDiscovery_H