mirror of
https://github.com/tnodir/fort
synced 2024-11-15 03:36:07 +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);
|
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 processCommand(const ProcessCommandArgs &p)
|
||||||
{
|
{
|
||||||
bool ok;
|
const processCommand_func func = RpcManager::getProcessFunc(p.command, processCommand_funcList,
|
||||||
|
Control::CommandHome, Control::CommandZone, &processCommandRpc);
|
||||||
|
|
||||||
switch (p.command) {
|
const bool ok = func(p);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ok && p.errorMessage.isEmpty()) {
|
if (!ok && p.errorMessage.isEmpty()) {
|
||||||
p.errorMessage = "Invalid command";
|
p.errorMessage = "Invalid command";
|
||||||
|
@ -40,11 +40,11 @@ public:
|
|||||||
bool processCommandRpc(const ProcessCommandArgs &p);
|
bool processCommandRpc(const ProcessCommandArgs &p);
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
constexpr static F *getProcessFunc(
|
constexpr static F *getProcessFunc(Control::Command command, F *const funcList[], int minIndex,
|
||||||
Control::Command command, F *const funcList[], int minIndex, int maxIndex)
|
int maxIndex, F *defaultFunc = nullptr)
|
||||||
{
|
{
|
||||||
if (command < minIndex || command > maxIndex)
|
if (command < minIndex || command > maxIndex)
|
||||||
return nullptr;
|
return defaultFunc;
|
||||||
|
|
||||||
const int funcIndex = command - minIndex;
|
const int funcIndex = command - minIndex;
|
||||||
return funcList[funcIndex];
|
return funcList[funcIndex];
|
||||||
|
Loading…
Reference in New Issue
Block a user