mirror of
https://github.com/tnodir/fort
synced 2024-11-14 16:33:45 +00:00
UI: ControlManager: Simplify processCommand()
This commit is contained in:
parent
8e64d26859
commit
c8f6986edf
@ -257,29 +257,27 @@ bool processCommandZone(const ProcessCommandArgs &p)
|
||||
return processCommandZoneAction(zoneAction);
|
||||
}
|
||||
|
||||
bool processCommandRpc(const ProcessCommandArgs &p)
|
||||
{
|
||||
return IoC<RpcManager>()->processCommandRpc(p);
|
||||
}
|
||||
|
||||
using processCommand_func = bool (*)(const ProcessCommandArgs &p);
|
||||
|
||||
static const processCommand_func processCommand_funcList[] = {
|
||||
&processCommandHome, // Control::CommandHome,
|
||||
&processCommandBlock, // Control::CommandBlock,
|
||||
&processCommandProg, // Control::CommandProg,
|
||||
&processCommandBackup, // Control::CommandBackup,
|
||||
&processCommandZone, // Control::CommandZone,
|
||||
};
|
||||
|
||||
bool processCommand(const ProcessCommandArgs &p)
|
||||
{
|
||||
bool ok;
|
||||
const processCommand_func func = RpcManager::getProcessFunc(p.command, processCommand_funcList,
|
||||
Control::CommandHome, Control::CommandZone, &processCommandRpc);
|
||||
|
||||
switch (p.command) {
|
||||
case Control::CommandHome: {
|
||||
ok = processCommandHome(p);
|
||||
} break;
|
||||
case Control::CommandBlock: {
|
||||
ok = processCommandBlock(p);
|
||||
} break;
|
||||
case Control::CommandProg: {
|
||||
ok = processCommandProg(p);
|
||||
} break;
|
||||
case Control::CommandBackup: {
|
||||
ok = processCommandBackup(p);
|
||||
} break;
|
||||
case Control::CommandZone: {
|
||||
ok = processCommandZone(p);
|
||||
} break;
|
||||
default:
|
||||
ok = IoC<RpcManager>()->processCommandRpc(p);
|
||||
}
|
||||
const bool ok = func(p);
|
||||
|
||||
if (!ok && p.errorMessage.isEmpty()) {
|
||||
p.errorMessage = "Invalid command";
|
||||
|
@ -40,11 +40,11 @@ public:
|
||||
bool processCommandRpc(const ProcessCommandArgs &p);
|
||||
|
||||
template<typename F>
|
||||
constexpr static F *getProcessFunc(
|
||||
Control::Command command, F *const funcList[], int minIndex, int maxIndex)
|
||||
constexpr static F *getProcessFunc(Control::Command command, F *const funcList[], int minIndex,
|
||||
int maxIndex, F *defaultFunc = nullptr)
|
||||
{
|
||||
if (command < minIndex || command > maxIndex)
|
||||
return nullptr;
|
||||
return defaultFunc;
|
||||
|
||||
const int funcIndex = command - minIndex;
|
||||
return funcList[funcIndex];
|
||||
|
Loading…
Reference in New Issue
Block a user