MNE-CPP  beta 1.0
rtcmdclient.h
Go to the documentation of this file.
1 //=============================================================================================================
38 #ifndef RTCMDCLIENT_H
39 #define RTCMDCLIENT_H
40 
41 
42 //*************************************************************************************************************
43 //=============================================================================================================
44 // MNE INCLUDES
45 //=============================================================================================================
46 
47 #include "rtclient_global.h"
48 #include <rtCommand/commandmanager.h>
49 #include <rtCommand/command.h>
50 
51 
52 //*************************************************************************************************************
53 //=============================================================================================================
54 // QT INCLUDES
55 //=============================================================================================================
56 
57 #include <QDataStream>
58 #include <QMutex>
59 #include <QSharedPointer>
60 #include <QString>
61 #include <QTcpSocket>
62 
63 
64 //*************************************************************************************************************
65 //=============================================================================================================
66 // DEFINE NAMESPACE RTCLIENTLIB
67 //=============================================================================================================
68 
69 namespace RTCLIENTLIB
70 {
71 
72 
73 //*************************************************************************************************************
74 //=============================================================================================================
75 // USED NAMESPACES
76 //=============================================================================================================
77 
78 using namespace RTCOMMANDLIB;
79 
80 //=============================================================================================================
86 class RTCLIENTSHARED_EXPORT RtCmdClient : public QTcpSocket
87 {
88  Q_OBJECT
89 public:
90  typedef QSharedPointer<RtCmdClient> SPtr;
91  typedef QSharedPointer<const RtCmdClient> ConstSPtr;
93  //=========================================================================================================
99  explicit RtCmdClient(QObject *parent = 0);
100 
101  //=========================================================================================================
107  void connectToHost(QString &p_sRtServerHostName);
108 
109  //=========================================================================================================
117  inline bool hasCommand(const QString &p_sCommand) const;
118 
119  //=========================================================================================================
127  QString sendCLICommand(const QString &p_sCommand);
128 
129  //=========================================================================================================
137  void sendCommandJSON(const Command &p_command);
138 
139  //=========================================================================================================
145  inline QString readAvailableData();
146 
147  //=========================================================================================================
151  qint32 requestBufsize();
152 
153  //=========================================================================================================
157  void requestCommands();
158 
159  //=========================================================================================================
167  qint32 requestConnectors(QMap<qint32, QString> &p_qMapConnectors);
168 
169  //=========================================================================================================
177  bool waitForDataAvailable(qint32 msecs = 30000) const;
178 
179  //=========================================================================================================
187  Command& operator[] (const QString &key);
188 
189  //=========================================================================================================
197  const Command operator[] (const QString &key) const;
198 
199 signals:
200  //=========================================================================================================
206  void response(QString p_sResponse);
207 
208 private:
209  CommandManager m_commandManager;
210  QMutex m_qMutex;
211  QString m_sAvailableData;
212 };
213 
214 //*************************************************************************************************************
215 //=============================================================================================================
216 // INLINE DEFINITIONS
217 //=============================================================================================================
218 
220 {
221  m_qMutex.lock();
222  QString p_sResponse = m_sAvailableData;
223  m_sAvailableData.clear();
224  m_qMutex.unlock();
225 
226  return p_sResponse;
227 }
228 
229 
230 //*************************************************************************************************************
231 
232 inline bool RtCmdClient::hasCommand(const QString &p_sCommand) const
233 {
234  return m_commandManager.hasCommand(p_sCommand);
235 }
236 
237 } // NAMESPACE
238 
239 #endif // RTCMDCLIENT_H
Declaration of the Command Class.
Real-time command client.
Definition: rtcmdclient.h:86
#define RTCLIENTSHARED_EXPORT
rtclient library export/import macros.
QSharedPointer< RtCmdClient > SPtr
Definition: rtcmdclient.h:90
bool hasCommand(const QString &p_sCommand) const
Definition: rtcmdclient.h:232
QSharedPointer< const RtCmdClient > ConstSPtr
Definition: rtcmdclient.h:91