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 //=========================================================================================================
138 void insert(const QString &p_sKey, const QString &p_sDescription);
139
140 //=========================================================================================================
147 void insert(const QString &p_sKey, const Command &p_command);
148
149 //=========================================================================================================
155 inline bool isActive() const;
156
157 //=========================================================================================================
163 inline void setStatus(bool status);
164
165 //=========================================================================================================
171 virtual void update(UTILSLIB::Subject* p_pSubject);
172
173 //=========================================================================================================
181 Command& operator[] (const QString &key);
182
183 //=========================================================================================================
191 const Command operator[] (const QString &key) const;
192
193private:
194 //=========================================================================================================
198 void init();
199
200 bool m_bIsActive;
201
202 QJsonDocument m_jsonDocumentOrigin;
203
204 QMetaObject::Connection m_conReplyChannel;
205
206 QMap<QString, Command> m_qMapCommands;
207
208signals:
209 void commandMapChanged();//(QStringList)
210
211 //=========================================================================================================
217 void triggered(Command p_command);
218
219 //=========================================================================================================
226 void response(QString p_sReply, Command p_command);
227};
228
229//=============================================================================================================
230// INLINE DEFINITIONS
231//=============================================================================================================
232
233inline QMap<QString, Command>& CommandManager::commandMap()
234{
235 return m_qMapCommands;
236}
237
238//=============================================================================================================
239
240inline bool CommandManager::hasCommand(const QString &p_sCommand) const
241{
242 return m_qMapCommands.contains(p_sCommand);
243}
244
245//=============================================================================================================
246
247inline bool CommandManager::isActive() const
248{
249 return m_bIsActive;
250}
251
252//=============================================================================================================
253
254inline void CommandManager::setStatus(bool status)
255{
256 m_bIsActive = status;
257}
258} // NAMESPACE
259
260#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)
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.