v2.0.0
Loading...
Searching...
No Matches
command_manager.h
Go to the documentation of this file.
1//=============================================================================================================
36
37#ifndef COMMUNICATIONMANAGER_H
38#define COMMUNICATIONMANAGER_H
39
40//=============================================================================================================
41// Includes
42//=============================================================================================================
43
44#include "../com_global.h"
45#include "command.h"
46#include "command_parser.h"
47
49
50//=============================================================================================================
51// Qt Includes
52//=============================================================================================================
53
54#include <QObject>
55#include <QJsonDocument>
56
57//=============================================================================================================
58// DEFINE NAMESPACE COMLIB
59//=============================================================================================================
60
61namespace COMLIB
62{
63
64//=============================================================================================================
65// FORWARD DECLARATIONS
66//=============================================================================================================
67
68//=============================================================================================================
73{
74 Q_OBJECT
75
76public:
77 explicit CommandManager(bool p_bIsActive = true, QObject *parent = 0);
78
79 explicit CommandManager(const QByteArray &p_qByteArrayJsonDoc, bool p_bIsActive = true, QObject *parent = 0);
80
81 explicit CommandManager(const QJsonDocument &p_jsonDoc, bool p_bIsActive = true, QObject *parent = 0);
82
83 virtual ~CommandManager();
84
85 //=========================================================================================================
89 void clear();
90
91 //=========================================================================================================
97 inline QMap<QString, Command>& commandMap();
98
99 //=========================================================================================================
107 inline bool hasCommand(const QString &p_sCommand) const;
108
109 //=========================================================================================================
116 void insert(const QJsonDocument &p_jsonDocument);
117
118 //=========================================================================================================
125 void insert(const QString &p_sKey, const QString &p_sDescription);
126
127 //=========================================================================================================
134 void insert(const QString &p_sKey, const Command &p_command);
135
136 //=========================================================================================================
142 inline bool isActive() const;
143
144 //=========================================================================================================
150 inline void setStatus(bool status);
151
152 //=========================================================================================================
158 virtual void update(UTILSLIB::Subject* p_pSubject);
159
160 //=========================================================================================================
168 Command& operator[] (const QString &key);
169
170 //=========================================================================================================
178 const Command operator[] (const QString &key) const;
179
180private:
181 //=========================================================================================================
185 void init();
186
187 bool m_bIsActive;
188
189 QJsonDocument m_jsonDocumentOrigin;
190
191 QMetaObject::Connection m_conReplyChannel;
192
193 QMap<QString, Command> m_qMapCommands;
194
195signals:
196 void commandMapChanged();//(QStringList)
197
198 //=========================================================================================================
204 void triggered(Command p_command);
205
206 //=========================================================================================================
213 void response(QString p_sReply, Command p_command);
214};
215
216//=============================================================================================================
217// INLINE DEFINITIONS
218//=============================================================================================================
219
220inline QMap<QString, Command>& CommandManager::commandMap()
221{
222 return m_qMapCommands;
223}
224
225//=============================================================================================================
226
227inline bool CommandManager::hasCommand(const QString &p_sCommand) const
228{
229 return m_qMapCommands.contains(p_sCommand);
230}
231
232//=============================================================================================================
233
234inline bool CommandManager::isActive() const
235{
236 return m_bIsActive;
237}
238
239//=============================================================================================================
240
241inline void CommandManager::setStatus(bool status)
242{
243 m_bIsActive = status;
244}
245} // NAMESPACE
246
247#endif // COMMUNICATIONMANAGER_H
#define COMSHARED_EXPORT
Definition com_global.h:52
Declaration of the Command Class.
Contains declarations of the observer design pattern: Subject class and IObserver interface.
Real-time client/server communication (commands, raw data streaming).
Named command with typed parameters for real-time server control.
Definition command.h:78
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.