v2.0.0
Loading...
Searching...
No Matches
rt_cmd_client.h
Go to the documentation of this file.
1//=============================================================================================================
35
36#ifndef RTCMDCLIENT_H
37#define RTCMDCLIENT_H
38
39//=============================================================================================================
40// INCLUDES
41//=============================================================================================================
42
43#include "../com_global.h"
46
47//=============================================================================================================
48// QT INCLUDES
49//=============================================================================================================
50
51#include <QDataStream>
52#include <QMutex>
53#include <QSharedPointer>
54#include <QString>
55#include <QTcpSocket>
56
57//=============================================================================================================
58// DEFINE NAMESPACE COMLIB
59//=============================================================================================================
60
61namespace COMLIB
62{
63
64//=============================================================================================================
75class COMSHARED_EXPORT RtCmdClient : public QTcpSocket
76{
77 Q_OBJECT
78
79public:
80 typedef QSharedPointer<RtCmdClient> SPtr;
81 typedef QSharedPointer<const RtCmdClient> ConstSPtr;
82
83 //=========================================================================================================
89 explicit RtCmdClient(QObject *parent = Q_NULLPTR);
90
91 //=========================================================================================================
99 inline bool hasCommand(const QString &p_sCommand) const;
100
101 //=========================================================================================================
109 QString sendCLICommand(const QString &p_sCommand);
110
111 //=========================================================================================================
119 void sendCommandJSON(const Command &p_command);
120
121 //=========================================================================================================
127 inline QString readAvailableData();
128
129 //=========================================================================================================
133 qint32 requestBufsize();
134
135 //=========================================================================================================
139 void requestCommands();
140
141 //=========================================================================================================
149 qint32 requestConnectors(QMap<qint32, QString> &p_qMapConnectors);
150
151 //=========================================================================================================
159 bool waitForDataAvailable(qint32 msecs = 30000) const;
160
161 //=========================================================================================================
169 Command& operator[] (const QString &key);
170
171 //=========================================================================================================
179 const Command operator[] (const QString &key) const;
180
181signals:
182 //=========================================================================================================
188 void response(QString p_sResponse);
189
190private:
191 CommandManager m_commandManager;
192 QMutex m_qMutex;
193 QString m_sAvailableData;
194};
195
196//=============================================================================================================
197// INLINE DEFINITIONS
198//=============================================================================================================
199
201{
202 m_qMutex.lock();
203 QString p_sResponse = m_sAvailableData;
204 m_sAvailableData.clear();
205 m_qMutex.unlock();
206
207 return p_sResponse;
208}
209
210//=============================================================================================================
211
212inline bool RtCmdClient::hasCommand(const QString &p_sCommand) const
213{
214 return m_commandManager.hasCommand(p_sCommand);
215}
216} // NAMESPACE
217
218#endif // RTCMDCLIENT_H
Export macros, build-info entry points and namespace anchor for the COMLIB communication library.
#define COMSHARED_EXPORT
Definition com_global.h:53
Per-component registry of COMLIB::Command schemas; receives COMLIB::RawCommand from the parser and di...
Typed, parameter-bearing command object that round-trips between mne-cpp clients and mne_rt_server.
Real-time client/server communication primitives for talking to mne_rt_server.
void sendCommandJSON(const Command &p_command)
qint32 requestConnectors(QMap< qint32, QString > &p_qMapConnectors)
RtCmdClient(QObject *parent=nullptr)
bool hasCommand(const QString &p_sCommand) const
void response(QString p_sResponse)
QSharedPointer< RtCmdClient > SPtr
QSharedPointer< const RtCmdClient > ConstSPtr
QString sendCLICommand(const QString &p_sCommand)
QString readAvailableData()
bool waitForDataAvailable(qint32 msecs=30000) const
Named, parameterised command exchanged with mne_rt_server; supports both JSON and CLI serialisation.
Definition command.h:87
Observer-side registry of Command schemas a subsystem accepts from the shared CommandParser.