MNE-CPP  beta 1.0
commandmanager.h
1 #ifndef COMMUNICATIONMANAGER_H
2 #define COMMUNICATIONMANAGER_H
3 
4 //*************************************************************************************************************
5 //=============================================================================================================
6 // Includes
7 //=============================================================================================================
8 
9 #include "rtcommand_global.h"
10 #include "command.h"
11 #include "commandparser.h"
12 
14 
15 
16 //*************************************************************************************************************
17 //=============================================================================================================
18 // Qt Includes
19 //=============================================================================================================
20 
21 #include <QObject>
22 #include <QJsonDocument>
23 
24 
25 //*************************************************************************************************************
26 //=============================================================================================================
27 // DEFINE NAMESPACE RTCOMMANDLIB
28 //=============================================================================================================
29 
30 namespace RTCOMMANDLIB
31 {
32 
33 
34 //*************************************************************************************************************
35 //=============================================================================================================
36 // USED NAMESPACES
37 //=============================================================================================================
38 
39 
40 //*************************************************************************************************************
41 //=============================================================================================================
42 // FORWARD DECLARATIONS
43 //=============================================================================================================
44 
45 
46 //=============================================================================================================
50 class RTCOMMANDSHARED_EXPORT CommandManager : public QObject, public IObserver
51 {
52  Q_OBJECT
53 public:
54  explicit CommandManager(bool p_bIsActive = true, QObject *parent = 0);
55 
56  explicit CommandManager(const QByteArray &p_qByteArrayJsonDoc, bool p_bIsActive = true, QObject *parent = 0);
57 
58  explicit CommandManager(const QJsonDocument &p_jsonDoc, bool p_bIsActive = true, QObject *parent = 0);
59 
60  virtual ~CommandManager();
61 
62  //=========================================================================================================
66  void clear();
67 
68  //=========================================================================================================
74  inline QMap<QString, Command>& commandMap();
75 
76  //=========================================================================================================
84  inline bool hasCommand(const QString &p_sCommand) const;
85 
86  //=========================================================================================================
93  void insert(const QJsonDocument &p_jsonDocument);
94 
95  //=========================================================================================================
102  void insert(const QString &p_sKey, const QString &p_sDescription);
103 
104  //=========================================================================================================
111  void insert(const QString &p_sKey, const Command &p_command);
112 
113  //=========================================================================================================
119  inline bool isActive() const;
120 
121  //=========================================================================================================
127  inline void setStatus(bool status);
128 
129  //=========================================================================================================
135  virtual void update(Subject* p_pSubject);
136 
137  //=========================================================================================================
145  Command& operator[] (const QString &key);
146 
147  //=========================================================================================================
155  const Command operator[] (const QString &key) const;
156 
157 private:
158  //=========================================================================================================
162  void init();
163 
164  bool m_bIsActive;
165 
166  QJsonDocument m_jsonDocumentOrigin;
167 
168  QMetaObject::Connection m_conReplyChannel;
170  QMap<QString, Command> m_qMapCommands;
172 signals:
173  void commandMapChanged();//(QStringList)
174 
175  //=========================================================================================================
181  void triggered(Command p_command);
182 
183  //=========================================================================================================
190  void response(QString p_sReply, Command p_command);
191 };
192 
193 //*************************************************************************************************************
194 //=============================================================================================================
195 // INLINE DEFINITIONS
196 //=============================================================================================================
197 
198 inline QMap<QString, Command>& CommandManager::commandMap()
199 {
200  return m_qMapCommands;
201 }
202 
203 
204 //*************************************************************************************************************
205 
206 inline bool CommandManager::hasCommand(const QString &p_sCommand) const
207 {
208  return m_qMapCommands.contains(p_sCommand);
209 }
210 
211 
212 //*************************************************************************************************************
213 
214 inline bool CommandManager::isActive() const
215 {
216  return m_bIsActive;
217 }
218 
219 
220 //*************************************************************************************************************
221 
222 inline void CommandManager::setStatus(bool status)
223 {
224  m_bIsActive = status;
225 }
226 
227 } // NAMESPACE
228 
229 #endif // COMMUNICATIONMANAGER_H
Declaration of the Command Class.
#define RTCOMMANDSHARED_EXPORT
Declaration of the CommandParser Class.
The IObserver interface provides the base class of every observer of the observer design pattern...
Contains declarations of the observer design pattern: Subject class and IObserver interface...
The Subject class provides the base class of every subject of the observer design pattern...
RtCommand library export/import macros.
QMap< QString, Command > & commandMap()
bool hasCommand(const QString &p_sCommand) const