yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
unified_grpc_server.h
Go to the documentation of this file.
1#ifndef YAZE_APP_CORE_SERVICE_UNIFIED_GRPC_SERVER_H_
2#define YAZE_APP_CORE_SERVICE_UNIFIED_GRPC_SERVER_H_
3
4#ifdef YAZE_WITH_GRPC
5
6#include <functional>
7#include <memory>
8#include <vector>
9
10#include "absl/status/status.h"
13
14// gRPC types used by the server interface.
15#include <grpcpp/impl/service_type.h>
16#include <grpcpp/server.h>
17
18#include "app/emu/i_emulator.h"
20
21namespace yaze {
22
23// Forward declarations
24class CanvasAutomationServiceImpl;
25class Rom;
26
27namespace emu {
28// class Emulator; // Forward decl handled by i_emulator.h if needed, or unnecessary now
29}
30
31namespace editor {
32class EditorManager;
33}
34
35namespace net {
36class ProposalApprovalManager;
37class RomServiceImpl;
38class EmulatorServiceImpl;
39} // namespace net
40
41namespace test {
42class TestManager;
43class ImGuiTestHarnessServiceImpl;
44} // namespace test
45
50class YazeGRPCServer {
51 public:
52 using RomGetter = std::function<Rom*()>;
53 using RomLoader = std::function<bool(const std::string& path)>;
54
55 struct Config {
56 int port = 50052; // Unified server port
57 bool enable_test_harness = true;
58 bool enable_rom_service = true;
59 bool enable_emulator_service = true;
60 bool enable_canvas_automation = true;
61 bool require_approval_for_rom_writes = true;
62 };
63
64 YazeGRPCServer();
65 ~YazeGRPCServer();
66
79 absl::Status Initialize(
80 int port, emu::IEmulator* emulator = nullptr,
81 RomGetter rom_getter = nullptr, RomLoader rom_loader = nullptr,
82 test::TestManager* test_manager = nullptr,
83 net::RomVersionManager* version_mgr = nullptr,
84 net::ProposalApprovalManager* approval_mgr = nullptr,
85 CanvasAutomationServiceImpl* canvas_service = nullptr);
86
87 absl::Status Start();
88 absl::Status StartAsync();
89 absl::Status AddService(std::unique_ptr<grpc::Service> service);
90 void Shutdown();
91 bool IsRunning() const;
92 int Port() const { return config_.port; }
93 void SetConfig(const Config& config) { config_ = config; }
94
95 private:
96 Config config_;
97 std::unique_ptr<grpc::Server> server_;
98
99 // Services
100 std::unique_ptr<test::ImGuiTestHarnessServiceImpl> test_harness_service_;
101 std::unique_ptr<net::RomServiceImpl> rom_service_;
102 std::unique_ptr<net::EmulatorServiceImpl> emulator_service_;
103 CanvasAutomationServiceImpl* canvas_service_ = nullptr;
104
105 // GRPC Wrappers
106 std::unique_ptr<grpc::Service> canvas_grpc_service_;
107 std::unique_ptr<grpc::Service> test_harness_grpc_wrapper_;
108 std::vector<std::unique_ptr<grpc::Service>> extra_services_;
109
110 bool is_running_;
111
112 absl::Status BuildServer();
113 void ReleaseRegisteredServices();
114};
115
116} // namespace yaze
117
118#endif // YAZE_WITH_GRPC
119#endif // YAZE_APP_CORE_SERVICE_UNIFIED_GRPC_SERVER_H_