-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommanddispatcher.cpp
More file actions
46 lines (31 loc) · 943 Bytes
/
commanddispatcher.cpp
File metadata and controls
46 lines (31 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "commanddispatcher.h"
QHash<QString, ICommand*> CommandDispatcher::commands;
CommandDispatcher::CommandDispatcher(QObject* parent) : QObject(parent)
{
}
void CommandDispatcher::RegisterCommand(ICommand* command)
{
QString commandId;
/* Check for valid command */
if (command == nullptr)
{
return;
}
commandId = command->GetCommandId();
commands.insert(commandId,command);
return;
}
void CommandDispatcher::DispatchCommand(QJsonObject* command)
{
QString commandId = (*command)["commandId"].toString();
/* Try to find the command ID in registered commands */
QHash<QString, ICommand*>::const_iterator commandIterator = commands.find(commandId);
if (commandIterator == commands.end())
{
/* Command ID not in the list */
return;
}
ICommand* foundCommand = commandIterator.value();
foundCommand->ProcessCommand(command);
return;
}