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{
88 Q_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 //=========================================================================================================
151 explicit Command(const QString& p_sCommand, const QString& p_sDescription,
152 const QStringList& p_qListParamNames, const QList<QVariant>& p_qListParamValues, const QStringList& p_vecParameterDescriptions, bool p_bIsJson = true, QObject* parent = 0);
153
154 //=========================================================================================================
160 Command(const Command& p_Command);
161
162 //=========================================================================================================
166 virtual ~Command();
167
168 //=========================================================================================================
174 inline QString command() const;
175
176 //=========================================================================================================
182 inline quint32 count() const;
183
184 //=========================================================================================================
190 inline QString description() const;
191
192 //=========================================================================================================
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 //=========================================================================================================
276 Command& operator=(const Command& rhs);
277
278 //=========================================================================================================
286 QVariant& operator[](const QString& key);
287
288 //=========================================================================================================
296 QVariant& operator[](qint32 idx);
297
298 //=========================================================================================================
306 const QVariant operator[](const QString& key) const;
307
308signals:
309 //=========================================================================================================
315 void executed(Command p_command);
316
317public:
318 QString m_sCommand;
320 QStringList m_qListParamNames;
321 QList<QVariant> m_qListParamValues;
324};
325
326//=============================================================================================================
327// INLINE DEFINITIONS
328//=============================================================================================================
329
330inline QString Command::command() const
331{
332 return m_sCommand;
333}
334
335//=============================================================================================================
336
337inline quint32 Command::count() const
338{
339 return m_qListParamValues.size();
340}
341
342//=============================================================================================================
343
344inline QString Command::description() const
345{
346 return m_sDescription;
347}
348
349//=============================================================================================================
350
351inline bool& Command::isJson()
352{
353 return m_bIsJson;
354}
355
356//=============================================================================================================
357
358inline QList<QString> Command::pDescriptions() const
359{
361}
362
363//=============================================================================================================
364
365inline QList<QString> Command::pNames() const
366{
367 return m_qListParamNames;
368}
369
370//=============================================================================================================
371
372inline QList<QVariant>& Command::pValues()
373{
374 return m_qListParamValues;
375}
376} // NAMESPACE
377
378#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:194
QJsonObject toJsonObject() const
Definition command.cpp:175
QList< QString > pDescriptions() const
Definition command.h:358
QString m_sDescription
Definition command.h:319
void reply(const QString &p_sReply)
Definition command.cpp:153
quint32 count() const
Definition command.h:337
QStringList m_qListParamDescriptions
Definition command.h:322
QStringList m_qListParamNames
Definition command.h:320
Command & operator=(const Command &rhs)
Definition command.cpp:235
Command(bool p_bIsJson=true, QObject *parent=0)
Definition command.cpp:47
QString m_sCommand
Definition command.h:318
QList< QVariant > m_qListParamValues
Definition command.h:321
bool & isJson()
Definition command.h:351
QString description() const
Definition command.h:344
void executed(Command p_command)
QList< QVariant > & pValues()
Definition command.h:372
virtual void execute()
Definition command.cpp:146
QSharedPointer< Command > SPtr
Definition command.h:91
QString toStringReadySend() const
Definition command.cpp:215
QVariant & operator[](const QString &key)
Definition command.cpp:251
QString command() const
Definition command.h:330
QList< QString > pNames() const
Definition command.h:365
QSharedPointer< const Command > ConstSPtr
Definition command.h:92
The ICommand interface provides the base class of every command of the command design pattern.