mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-27 06:01:14 +01:00
b message parser
move from [id] json lookup to .at(id) this gives better exception output
This commit is contained in:
+15
-15
@@ -27,14 +27,14 @@ json command_parser(json command)
|
|||||||
json j;
|
json j;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::string type = command["type"];
|
std::string type = command.at("type");
|
||||||
Command cmd = magic_enum::enum_cast<Command>(type).value_or(Command::end);
|
Command cmd = magic_enum::enum_cast<Command>(type).value_or(Command::end);
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case Command::get_UI_element:
|
case Command::get_UI_element:
|
||||||
spdlog::info("Command {}: {}", type, std::string(command["id"]));
|
spdlog::info("Command {}: {}", type, std::string(command.at("id")));
|
||||||
j["response"]["type"] = type;
|
j["response"]["type"] = type;
|
||||||
j["response"]["UI_item"] = g_simulators->invoke_active_simulator()->get_UI_item(command["id"])->to_json();
|
j["response"]["UI_item"] = g_simulators->invoke_active_simulator()->get_UI_item(command.at("id"))->to_json();
|
||||||
break;
|
break;
|
||||||
case Command::get_UI_elements:
|
case Command::get_UI_elements:
|
||||||
spdlog::info("Command {}", type);
|
spdlog::info("Command {}", type);
|
||||||
@@ -42,8 +42,8 @@ json command_parser(json command)
|
|||||||
j["response"]["UI_items"] = g_simulators->invoke_active_simulator()->get_UI_items()["UI_items"];
|
j["response"]["UI_items"] = g_simulators->invoke_active_simulator()->get_UI_items()["UI_items"];
|
||||||
break;
|
break;
|
||||||
case Command::switch_simulator:
|
case Command::switch_simulator:
|
||||||
spdlog::info("Command {} to {}", type, std::string(command["name"]));
|
spdlog::info("Command {} to {}", type, std::string(command.at("name")));
|
||||||
g_simulators->switch_simulator(command["name"]);
|
g_simulators->switch_simulator(command.at("name"));
|
||||||
j["response"]["type"] = type;
|
j["response"]["type"] = type;
|
||||||
break;
|
break;
|
||||||
case Command::get_active_simulator_name:
|
case Command::get_active_simulator_name:
|
||||||
@@ -64,7 +64,7 @@ json command_parser(json command)
|
|||||||
{
|
{
|
||||||
spdlog::error(e.what());
|
spdlog::error(e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ void event_handler(json event)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::string type = event["type"];
|
std::string type = event.at("type");
|
||||||
Event e = magic_enum::enum_cast<Event>(type).value_or(Event::end);
|
Event e = magic_enum::enum_cast<Event>(type).value_or(Event::end);
|
||||||
if (g_simulators->invoke_active_simulator() == nullptr)
|
if (g_simulators->invoke_active_simulator() == nullptr)
|
||||||
{
|
{
|
||||||
@@ -84,26 +84,26 @@ void event_handler(json event)
|
|||||||
{
|
{
|
||||||
case Event::clicked:
|
case Event::clicked:
|
||||||
{
|
{
|
||||||
spdlog::debug("Event {}: {}", type, std::string(event["id"]));
|
spdlog::debug("Event {}: {}", type, std::string(event.at("id")));
|
||||||
g_simulators->invoke_active_simulator()->get_UI_item(std::string(event["id"]))->click();
|
g_simulators->invoke_active_simulator()->get_UI_item(std::string(event.at("id")))->click();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Event::value_changed:
|
case Event::value_changed:
|
||||||
{
|
{
|
||||||
spdlog::debug("Event {}: {} {}", type, std::string(event["id"]), (double)(event["value"]));
|
spdlog::debug("Event {}: {} {}", type, std::string(event.at("id")), (double)(event["value"]));
|
||||||
g_simulators->invoke_active_simulator()->get_UI_item(std::string(event["id"]))->set_value((double)event["value"]);
|
g_simulators->invoke_active_simulator()->get_UI_item(std::string(event.at("id")))->set_value((double)event.at("value"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Event::text_changed:
|
case Event::text_changed:
|
||||||
{
|
{
|
||||||
spdlog::debug("Event {}: {} {}", type, std::string(event["id"]), std::string(event["text"]));
|
spdlog::debug("Event {}: {} {}", type, std::string(event.at("id")), std::string(event.at("text")));
|
||||||
g_simulators->invoke_active_simulator()->get_UI_item(std::string(event["id"]))->set_text(std::string(event["text"]));
|
g_simulators->invoke_active_simulator()->get_UI_item(std::string(event.at("id")))->set_text(std::string(event.at("text")));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Event::selected:
|
case Event::selected:
|
||||||
{
|
{
|
||||||
spdlog::debug("Event {}: {} {}", type, std::string(event["id"]), std::string(event["selected"]));
|
spdlog::debug("Event {}: {} {}", type, std::string(event.at("id")), std::string(event.at("selected")));
|
||||||
g_simulators->invoke_active_simulator()->get_UI_item(std::string(event["id"]))->set_selected(std::string(event["selected"]));
|
g_simulators->invoke_active_simulator()->get_UI_item(std::string(event.at("id")))->set_selected(std::string(event.at("selected")));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user