6 #include "commandmanager.h"
15 #include <QJsonObject>
16 #include <QStringList>
22 using namespace COMMUNICATIONLIB;
28 CommandManager::CommandManager(
bool p_bIsActive, QObject *parent)
30 , m_bIsActive(p_bIsActive)
37 CommandManager::CommandManager(
const QByteArray &p_qByteArrayJsonDoc,
bool p_bIsActive, QObject *parent)
39 , m_bIsActive(p_bIsActive)
43 m_jsonDocumentOrigin = QJsonDocument::fromJson(p_qByteArrayJsonDoc);
45 insert(m_jsonDocumentOrigin);
50 CommandManager::CommandManager(
const QJsonDocument &p_jsonDoc,
bool p_bIsActive, QObject *parent)
52 , m_bIsActive(p_bIsActive)
53 , m_jsonDocumentOrigin(p_jsonDoc)
57 insert(m_jsonDocumentOrigin);
62 CommandManager::~CommandManager()
74 m_qMapCommands.clear();
79 void CommandManager::init()
87 QJsonObject t_jsonObjectCommand;
90 if(p_jsonDocument.isObject() && p_jsonDocument.object().value(QString(
"commands")) != QJsonValue::Undefined)
91 t_jsonObjectCommand = p_jsonDocument.object().value(QString(
"commands")).toObject();
95 QJsonObject::Iterator it;
96 for(it = t_jsonObjectCommand.begin(); it != t_jsonObjectCommand.end(); ++it)
98 if(!m_qMapCommands.contains(it.key()))
99 m_qMapCommands.insert(it.key(),
Command(it.key(), it.value().toObject(),
true,
this));
101 qWarning(
"Warning: CommandMap contains command %s already. Insertion skipped.\n", it.key().toUtf8().constData());
104 emit commandMapChanged();
111 Command t_command(p_sKey, p_sDescription,
false,
this);
112 insert(p_sKey, t_command);
120 t_command.setParent(
this);
121 m_qMapCommands.insert(p_sKey, t_command);
122 emit commandMapChanged();
136 QString t_sCommandName = t_rawCommand.
command();
142 if(t_rawCommand.
count() >= m_qMapCommands[t_sCommandName].count())
144 m_qMapCommands[t_sCommandName].isJson() = t_rawCommand.
isJson();
147 for(quint32 i = 0; i < m_qMapCommands[t_sCommandName].count(); ++i)
149 QVariant::Type t_type = m_qMapCommands[t_sCommandName][i].type();
151 QVariant t_qVariantParam(t_rawCommand.
pValues()[i]);
153 if(t_qVariantParam.canConvert(t_type) && t_qVariantParam.convert(t_type))
154 m_qMapCommands[t_sCommandName][i] = t_qVariantParam;
159 m_qMapCommands[t_sCommandName].execute();
167 return m_qMapCommands[key];
174 return m_qMapCommands[key];