v2.0.0
Loading...
Searching...
No Matches
command.h
Go to the documentation of this file.
1//=============================================================================================================
38
39#ifndef COMMAND_H
40#define COMMAND_H
41
42//=============================================================================================================
43// INCLUDES
44//=============================================================================================================
45
46#include "../com_global.h"
47
49
50//=============================================================================================================
51// QT INCLUDES
52//=============================================================================================================
53
54#include <QObject>
55#include <QList>
56#include <QString>
57#include <QVariant>
58#include <QJsonObject>
59#include <QSharedPointer>
60#include <QDebug>
61#include <QPair>
62#include <QStringList>
63
64//=============================================================================================================
65// DEFINE NAMESPACE COMLIB
66//=============================================================================================================
67
68namespace COMLIB
69{
70
71static QVariant defaultVariant;
72
73//=============================================================================================================
86class COMSHARED_EXPORT Command: public QObject, public UTILSLIB::ICommand
87{
88Q_OBJECT
89
90public:
91 typedef QSharedPointer<Command> SPtr;
92 typedef QSharedPointer<const Command> ConstSPtr;
93
94 //=========================================================================================================
101 explicit Command(bool p_bIsJson = true, QObject *parent = 0);
102
103 //=========================================================================================================
112 explicit Command(const QString &p_sCommand, const QJsonObject &p_qCommandContent, bool p_bIsJson = true, QObject *parent = 0);
113
114 //=========================================================================================================
123 explicit Command(const QString &p_sCommand, const QString &p_sDescription, bool p_bIsJson = true, QObject *parent = 0);
124
125 //=========================================================================================================
136 explicit Command(const QString &p_sCommand, const QString &p_sDescription,
137 const QStringList &p_qListParamNames, const QList<QVariant> &p_qListParamValues, bool p_bIsJson = true, QObject *parent = 0);
138
139 //=========================================================================================================
149 explicit Command(const QString &p_sCommand, const QString &p_sDescription,
150 const QStringList &p_qListParamNames, const QList<QVariant> &p_qListParamValues, const QStringList &p_vecParameterDescriptions, bool p_bIsJson = true, QObject *parent = 0);
151
152 //=========================================================================================================
158 Command(const Command &p_Command);
159
160 //=========================================================================================================
164 virtual ~Command();
165
166 //=========================================================================================================
172 inline QString command() const;
173
174 //=========================================================================================================
180 inline quint32 count() const;
181
182 //=========================================================================================================
188 inline QString description() const;
189
190 //=========================================================================================================
196 virtual void execute();
197
198 //=========================================================================================================
204 inline bool& isJson();
205
206 //=========================================================================================================
212 inline QList<QString> pDescriptions() const;
213
214 //=========================================================================================================
220 inline QList<QString> pNames() const;
221
222 //=========================================================================================================
228 inline QList<QVariant>& pValues();
229
230 //=========================================================================================================
236 void reply(const QString &p_sReply);
237
238 //=========================================================================================================
242 void send();
243
244 //=========================================================================================================
250 QJsonObject toJsonObject() const;
251
252 //=========================================================================================================
258 QStringList toStringList() const;
259
260 //=========================================================================================================
266 QString toStringReadySend() const;
267
268 //=========================================================================================================
274 Command& operator= (const Command &rhs);
275
276 //=========================================================================================================
284 QVariant& operator[] (const QString &key);
285
286 //=========================================================================================================
294 QVariant& operator[] (qint32 idx);
295
296 //=========================================================================================================
304 const QVariant operator[] (const QString &key) const;
305
306signals:
307 //=========================================================================================================
313 void executed(Command p_command);
314
315public:
316 QString m_sCommand;
318 QStringList m_qListParamNames;
319 QList<QVariant> m_qListParamValues;
322};
323
324//=============================================================================================================
325// INLINE DEFINITIONS
326//=============================================================================================================
327
328inline QString Command::command() const
329{
330 return m_sCommand;
331}
332
333//=============================================================================================================
334
335inline quint32 Command::count() const
336{
337 return m_qListParamValues.size();
338}
339
340//=============================================================================================================
341
342inline QString Command::description() const
343{
344 return m_sDescription;
345}
346
347//=============================================================================================================
348
349inline bool& Command::isJson()
350{
351 return m_bIsJson;
352}
353
354//=============================================================================================================
355
356inline QList<QString> Command::pDescriptions() const
357{
359}
360
361//=============================================================================================================
362
363inline QList<QString> Command::pNames() const
364{
365 return m_qListParamNames;
366}
367
368//=============================================================================================================
369
370inline QList<QVariant>& Command::pValues()
371{
372 return m_qListParamValues;
373}
374} // NAMESPACE
375
376#endif // COMMAND_H
Export macros, build-info entry points and namespace anchor for the COMLIB communication library.
#define COMSHARED_EXPORT
Definition com_global.h:53
Minimal ICommand interface for the GoF command pattern, used by the MNE Scan plugin runtime.
Real-time client/server communication primitives for talking to mne_rt_server.
QStringList toStringList() const
Definition command.cpp:200
QJsonObject toJsonObject() const
Definition command.cpp:180
QList< QString > pDescriptions() const
Definition command.h:356
QString m_sDescription
Definition command.h:317
void reply(const QString &p_sReply)
Definition command.cpp:158
quint32 count() const
Definition command.h:335
QStringList m_qListParamDescriptions
Definition command.h:320
QStringList m_qListParamNames
Definition command.h:318
Command(bool p_bIsJson=true, QObject *parent=0)
Definition command.cpp:47
QString m_sCommand
Definition command.h:316
QList< QVariant > m_qListParamValues
Definition command.h:319
bool & isJson()
Definition command.h:349
QString description() const
Definition command.h:342
void executed(Command p_command)
QList< QVariant > & pValues()
Definition command.h:370
virtual void execute()
Definition command.cpp:151
QSharedPointer< Command > SPtr
Definition command.h:91
QString toStringReadySend() const
Definition command.cpp:222
QString command() const
Definition command.h:328
QList< QString > pNames() const
Definition command.h:363
QSharedPointer< const Command > ConstSPtr
Definition command.h:92
The ICommand interface provides the base class of every command of the command design pattern.