00001 #ifndef __NETWORKMANAGER_H__
00002 #define __NETWORKMANAGER_H__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <QObject>
00029 #include <QList>
00030 #include <QTimer>
00031
00032 #include "Types/MachineData.h"
00033
00034 class NServer;
00035 class NClient;
00036
00037 class Logger;
00038
00039 class NetworkManager : public QObject
00040 {
00041 Q_OBJECT
00042
00043 public:
00044 enum MessageType
00045 {
00046 MT_PatientInfo,
00047 MT_ChatMessage,
00048 MT_Connection,
00049 MT_Disconnection
00050 };
00051
00052 private:
00053
00054 static const char* IP_TABLE_FILENAME;
00055 static const quint16 CONNECTION_PORT = 5555;
00056 static const unsigned int CHECK_CONNECTION_DELAY = 1000;
00057
00058 Logger* m_pLogger;
00060 QList<MachineData> m_machinesList;
00061
00062 NServer* m_pServer;
00063 QList<NClient*> m_clients;
00064 QList<QString> m_clientsIpAddress;
00065 bool m_isSSLEnabled;
00067 QList<QByteArray> m_dataReceived;
00069 QTimer* m_pConnectionTimer;
00071 Q_SLOT void connectToMachines();
00072 Q_SLOT void errorOnClient(NClient* pClient);
00073 Q_SLOT void clientConnected(NClient* pClient);
00074
00075 public:
00076 NetworkManager(Logger* pLogger, QObject* parent=0);
00077 ~NetworkManager();
00078
00079 void write(MessageType type, const QByteArray& data);
00080 void write(NClient* pClient, MessageType type, const QByteArray& data);
00081 Q_SLOT void appendData(QByteArray data);
00082 QList<QByteArray>& dataReceived();
00083 void clearData();
00084
00085 const QList<MachineData>& getMachinesList()const { return m_machinesList; }
00086
00087 Q_SIGNAL void newClientConnected(NClient* pClient);
00088
00089 Q_SLOT void addMachine(QString machineIP, QString machineName);
00090 Q_SLOT void deleteMachine(QString machineIP);
00091 Q_SIGNAL void machineListUpdated();
00092 };
00093
00152 #endif