v2.0.0
Loading...
Searching...
No Matches
command_manager.h
Go to the documentation of this file.
1//=============================================================================================================
41
42#ifndef COMMUNICATIONMANAGER_H
43#define COMMUNICATIONMANAGER_H
44
45//=============================================================================================================
46// Includes
47//=============================================================================================================
48
49#include "../com_global.h"
50#include "command.h"
51#include "command_parser.h"
52
54
55//=============================================================================================================
56// Qt Includes
57//=============================================================================================================
58
59#include <QObject>
60#include <QJsonDocument>
61
62//=============================================================================================================
63// DEFINE NAMESPACE COMLIB
64//=============================================================================================================
65
66namespace COMLIB
67{
68
69//=============================================================================================================
70// FORWARD DECLARATIONS
71//=============================================================================================================
72
73//=============================================================================================================
86{
87 Q_OBJECT
88
89public:
90 explicit CommandManager(bool p_bIsActive = true, QObject* parent = 0);
91
92 explicit CommandManager(const QByteArray& p_qByteArrayJsonDoc, bool p_bIsActive = true, QObject* parent = 0);
93
94 explicit CommandManager(const QJsonDocument& p_jsonDoc, bool p_bIsActive = true, QObject* parent = 0);
95
96 virtual ~CommandManager();
97
98 //=========================================================================================================
102 void clear();
103
104 //=========================================================================================================
110 inline QMap<QString, Command>& commandMap();
111
112 //=========================================================================================================
120 inline bool hasCommand(const QString& p_sCommand) const;
121
122 //=========================================================================================================
129 void insert(const QJsonDocument& p_jsonDocument);
130
131 //=========================================================================================================
140 void insert(const QString& p_sKey, const QString& p_sDescription);
141
142 //=========================================================================================================
149 void insert(const QString& p_sKey, const Command& p_command);
150
151 //=========================================================================================================
157 inline bool isActive() const;
158
159 //=========================================================================================================
165 inline void setStatus(bool status);
166
167 //=========================================================================================================
173 virtual void update(UTILSLIB::Subject* p_pSubject);
174
175 //=========================================================================================================
183 Command& operator[](const QString& key);
184
185 //=========================================================================================================
193 const Command operator[](const QString& key) const;
194
195private:
196 //=========================================================================================================
200 void init();
201
202 bool m_bIsActive;
203
204 QJsonDocument m_jsonDocumentOrigin;
205
206 QMetaObject::Connection m_conReplyChannel;
207
208 QMap<QString, Command> m_qMapCommands;
209
210signals:
211 void commandMapChanged(); //(QStringList)
212
213 //=========================================================================================================
219 void triggered(Command p_command);
220
221 //=========================================================================================================
228 void response(QString p_sReply, Command p_command);
229};
230
231//=============================================================================================================
232// INLINE DEFINITIONS
233//=============================================================================================================
234
235inline QMap<QString, Command>& CommandManager::commandMap()
236{
237 return m_qMapCommands;
238}
239
240//=============================================================================================================
241
242inline bool CommandManager::hasCommand(const QString& p_sCommand) const
243{
244 return m_qMapCommands.contains(p_sCommand);
245}
246
247//=============================================================================================================
248
249inline bool CommandManager::isActive() const
250{
251 return m_bIsActive;
252}
253
254//=============================================================================================================
255
256inline void CommandManager::setStatus(bool status)
257{
258 m_bIsActive = status;
259}
260} // NAMESPACE
261
262#endif // COMMUNICATIONMANAGER_H
Export macros, build-info entry points and namespace anchor for the COMLIB communication library.
#define COMSHARED_EXPORT
Definition com_global.h:53
Front-end tokeniser that turns incoming JSON or CLI payloads into COMLIB::RawCommand objects and noti...
Typed, parameter-bearing command object that round-trips between mne-cpp clients and mne_rt_server.
Classical GoF observer pattern (Subject + IObserver) used by MNE-CPP's non-QObject model classes.
Real-time client/server communication primitives for talking to mne_rt_server.
Named, parameterised command exchanged with mne_rt_server; supports both JSON and CLI serialisation.
Definition command.h:87
void response(QString p_sReply, Command p_command)
void setStatus(bool status)
virtual void update(UTILSLIB::Subject *p_pSubject)
QMap< QString, Command > & commandMap()
void triggered(Command p_command)
bool hasCommand(const QString &p_sCommand) const
CommandManager(bool p_bIsActive=true, QObject *parent=0)
Command & operator[](const QString &key)
void insert(const QJsonDocument &p_jsonDocument)
The IObserver interface provides the base class of every observer of the observer design pattern.
The Subject class provides the base class of every subject of the observer design pattern.