summaryrefslogblamecommitdiffstats
path: root/src/fbgui/networkdiscovery.h
blob: 51dc8a7236b551c1dbf6239f458c84af08b3313e (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                                                                          













                           


                                   
                 
                    
                            
 

                                        

       



                                                                   
 

                                               

                                                           
 

                               





                                                                   
             
                           



                                      
 

                                                                     
 


                                                                                  
        

                                          
                                                 
                                                            

                                                                                 
 
                                    
                                                      
 
                                    

        

                        



                                                     


                                                   
                          
 
                                                   

                              
                              
                                                    

                                                           

                                 

                         
                      


                                   



                                        
                                                       

                          


                            
/**
 * Copyright (c) 2010,2011 - RZ Uni Freiburg
 * Copyright (c) 2010,2011 - OpenSLX Project
 *
 * This program/file is free software distributed under the GPL version 2.
 * See http://openslx.org/COPYING
 *
 * If you have any feedback please consult http://openslx.org/feedback and
 * send your feedback to feedback@openslx.org
 *
 * General information about OpenSLX can be found under http://openslx.org
 */

#ifndef NetworkDiscovery_H
#define NetworkDiscovery_H

#include <QtNetwork>
#include <QtCore>

#include <arpa/inet.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <syslog.h>
#include <sysfs/libsysfs.h>

#include "interfaceconfiguration.h"
#include "networkmanager.h"

#include "dhcp.h"
#include "globals.h"
#include "../common/fbgui.h"

class NetworkDiscovery: public QObject {
Q_OBJECT

public:
	NetworkDiscovery(QObject *parent = 0);
	~NetworkDiscovery();

	void initAndRun(bool userChoice, QStringList* args = NULL);

	bool checkConnectivity(QString ifName);
	bool checkConnectivityViaTcp();

	int ip4_setManualConfiguration(QVariantMap result);

	void tryAgain();
	void prepareTryAgain();

	// Public member access
	QList<QString> getIfUpList();
	InterfaceConfiguration* getInterfaceConfig(QString ifName);
	QString GetErrorStr();

public slots:
	void readyForRun();
	void checkForIsRunning();

	void handleNewConnection();
	void handleClientDisconnect();

	void handleNewInput();
	void handleNewInputLine(QLocalSocket * client, QString data);

	void handleProcessStarted();
	void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);

signals:
	void updateStatus(QString status);

	void addInterface(const QString &ifName);
	void updateIfStatus(QString ifName, QString status);
	void changeProgressBarValue(const QString & ifName, const int $newValue);
	void connectionEstablished(QString ifName);

	void allProcessesFinished();
	void continueBootWithoutCheck(QString ifName);

	void abortBoot(QString msg);

private:
	void mainWork();

	void getListOfNetworkInterfaces();
	void getListOfNetworkInterfacesWithAutoUp();
	bool checkBlackList(QString i);
	bool checkConnectivityViaTcp(QString server);

	void runDHCPCD(QList<QString> &interfaces);
	void runDHCPCD(QString interface);
	void killDHCPCD();

	void handleNewInput(QLocalSocket * client);

	QLocalServer *_server;
	QLocalSocket *_client;
	QMap<QLocalSocket*, QLocalSocket*> _clients;
	QMap<QString, QLocalSocket*> _ifNameToClient;
	QMap<QProcess*, QString> _clientProcessToIfNameMap;
	//QList<Q_PID> _pidsList;

	bool _userChoice;
	bool _blocked;
	QTimer*_timer;
	QList<QString> _ifUpList;
	QList<QString> _ifDownList;
	int _ifUpCountdown;
	int _numberOfProcesses;
	QStringList _dhcpcdArguments;

	NetworkManager* _networkManager;
	QMap<QString, InterfaceConfiguration*> _ifcMap;

	QString _errorStr;
};

#endif // NetworkDiscovery_H