MNE-CPP  beta 1.0
IServer.h
Go to the documentation of this file.
1 //=============================================================================================================
36 #ifndef ISERVER_H
37 #define ISERVER_H
38 
39 
40 //*************************************************************************************************************
41 //=============================================================================================================
42 // QT INCLUDES
43 //=============================================================================================================
44 
45 #include <QTcpServer>
46 #include <QThread>
47 #include <QList>
48 
49 
50 //*************************************************************************************************************
51 //=============================================================================================================
52 // DEFINE NAMESPACE RTSERVER
53 //=============================================================================================================
54 
55 namespace RTSERVER
56 {
57 
58 
59 //*************************************************************************************************************
60 //=============================================================================================================
61 // ENUMERATIONS
62 //=============================================================================================================
63 
64 
65 //=========================================================================================================
71 class IServer : public QTcpServer
72 {
73  Q_OBJECT
74 
75 public:
76 
77  //=========================================================================================================
81  virtual ~IServer()
82  {
83  clearClients();
84  };
85 
86  //=========================================================================================================
90  inline QThread* getClient(quint8 id);
91 
92  //=========================================================================================================
96  inline quint8 addClient(QThread* p_pThreadClient);
97 
98  //=========================================================================================================
102  inline void clearClients();
103 
104 private:
105  QMap<quint8, QThread*> m_qClientList;
106  quint8 m_iNextClientId;
107 
108 };
109 
110 //*************************************************************************************************************
111 //=============================================================================================================
112 // INLINE DEFINITIONS
113 //=============================================================================================================
114 
115 QThread* IServer::getClient(quint8 id)
116 {
117  return m_qClientList[id];
118 }
119 
120 
121 //*************************************************************************************************************
122 
123 quint8 IServer::addClient(QThread* p_pThreadClient)
124 {
125  qint8 id = m_iNextClientId;
126  m_qClientList.insert(id, p_pThreadClient);
127  ++m_iNextClientId;
128  return id;
129 }
130 
131 
132 //*************************************************************************************************************
133 
135 {
136  QMap<quint8, QThread*>::const_iterator i = m_qClientList.constBegin();
137  while (i != map.constEnd()) {
138  if(i.value())
139  delete i.value();
140  ++i;
141  }
142  m_qClientList.clear();
143 }
144 
145 
146 
147 } //Namespace
148 
149 
150 #endif //ISERVER_H
quint8 addClient(QThread *p_pThreadClient)
Definition: IServer.h:123
The IConnector class is the interface class of all modules.
Definition: IServer.h:71
virtual ~IServer()
Definition: IServer.h:81
void clearClients()
Definition: IServer.h:134
QThread * getClient(quint8 id)
Definition: IServer.h:115