From cbbb480b0843b86bd37f4289563f389275138c0d Mon Sep 17 00:00:00 2001 From: scawful Date: Sat, 11 Oct 2025 14:47:31 -0400 Subject: [PATCH] refactor(agent): reorganize emulator command handling for gRPC support - Removed direct inclusion of `emulator_commands.h` in non-gRPC contexts to streamline dependencies. - Updated CMake configuration to conditionally include emulator command sources only when gRPC is enabled, enhancing modularity. - Ensured consistent handling of emulator commands across different components. Benefits: - Improved code organization and maintainability by clarifying the inclusion of gRPC-related features. - Enhanced flexibility in managing command handlers based on compilation flags. --- src/cli/agent.cmake | 2 +- src/cli/handlers/agent.cc | 1 - src/cli/handlers/command_handlers.cc | 4 ++++ src/cli/service/agent/tool_dispatcher.cc | 4 ++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cli/agent.cmake b/src/cli/agent.cmake index 60d18359..b501e4de 100644 --- a/src/cli/agent.cmake +++ b/src/cli/agent.cmake @@ -41,7 +41,6 @@ set(YAZE_AGENT_SOURCES cli/handlers/game/dialogue_commands.cc cli/handlers/game/music_commands.cc cli/handlers/graphics/palette_commands.cc - cli/handlers/tools/emulator_commands.cc cli/handlers/game/message_commands.cc cli/handlers/graphics/sprite_commands.cc # ROM commands @@ -56,6 +55,7 @@ if(YAZE_WITH_GRPC) list(APPEND YAZE_AGENT_SOURCES cli/service/agent/agent_control_server.cc cli/service/agent/emulator_service_impl.cc + cli/handlers/tools/emulator_commands.cc ) endif() diff --git a/src/cli/handlers/agent.cc b/src/cli/handlers/agent.cc index 0907952b..622e2177 100644 --- a/src/cli/handlers/agent.cc +++ b/src/cli/handlers/agent.cc @@ -14,7 +14,6 @@ #include "cli/handlers/game/dungeon_commands.h" #include "cli/handlers/game/overworld_commands.h" #include "cli/handlers/tools/gui_commands.h" -#include "cli/handlers/tools/emulator_commands.h" ABSL_DECLARE_FLAG(bool, quiet); diff --git a/src/cli/handlers/command_handlers.cc b/src/cli/handlers/command_handlers.cc index 253e2b26..1675e212 100644 --- a/src/cli/handlers/command_handlers.cc +++ b/src/cli/handlers/command_handlers.cc @@ -2,7 +2,9 @@ #include "cli/handlers/tools/resource_commands.h" #include "cli/handlers/tools/gui_commands.h" +#ifdef YAZE_WITH_GRPC #include "cli/handlers/tools/emulator_commands.h" +#endif #include "cli/handlers/game/dungeon_commands.h" #include "cli/handlers/game/overworld_commands.h" #include "cli/handlers/game/message_commands.h" @@ -95,6 +97,7 @@ std::vector> CreateAgentCommandHandle handlers.push_back(std::make_unique()); // Emulator & debugger commands +#ifdef YAZE_WITH_GRPC handlers.push_back(std::make_unique()); handlers.push_back(std::make_unique()); handlers.push_back(std::make_unique()); @@ -107,6 +110,7 @@ std::vector> CreateAgentCommandHandle handlers.push_back(std::make_unique()); handlers.push_back(std::make_unique()); handlers.push_back(std::make_unique()); +#endif return handlers; } diff --git a/src/cli/service/agent/tool_dispatcher.cc b/src/cli/service/agent/tool_dispatcher.cc index d67fbe40..0067baf3 100644 --- a/src/cli/service/agent/tool_dispatcher.cc +++ b/src/cli/service/agent/tool_dispatcher.cc @@ -13,7 +13,9 @@ #include "cli/handlers/game/music_commands.h" #include "cli/handlers/game/overworld_commands.h" #include "cli/handlers/graphics/sprite_commands.h" +#ifdef YAZE_WITH_GRPC #include "cli/handlers/tools/emulator_commands.h" +#endif #include "cli/handlers/tools/gui_commands.h" #include "cli/handlers/tools/resource_commands.h" #include "cli/service/resources/command_context.h" @@ -168,6 +170,7 @@ std::unique_ptr CreateHandler(ToolCallType type) { return std::make_unique(); // Emulator & Debugger commands +#ifdef YAZE_WITH_GRPC case ToolCallType::kEmulatorStep: return std::make_unique(); case ToolCallType::kEmulatorRun: @@ -192,6 +195,7 @@ std::unique_ptr CreateHandler(ToolCallType type) { return std::make_unique(); case ToolCallType::kEmulatorGetMetrics: return std::make_unique(); +#endif default: return nullptr;