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
19#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,
81 emu::IEmulator* emulator = nullptr,
82 RomGetter rom_getter = nullptr,
83 RomLoader rom_loader = nullptr,
84 test::TestManager* test_manager = nullptr,
85 net::RomVersionManager* version_mgr = nullptr,
86 net::ProposalApprovalManager* approval_mgr = nullptr,
87 CanvasAutomationServiceImpl* canvas_service = nullptr);
88
89 absl::Status Start();
90 absl::Status StartAsync();
91 absl::Status AddService(std::unique_ptr<grpc::Service> service);
92 void Shutdown();
93 bool IsRunning() const;
94 int Port() const { return config_.port; }
95 void SetConfig(const Config& config) { config_ = config; }
96
97 private:
98 Config config_;
99 std::unique_ptr<grpc::Server> server_;
100
101 // Services
102 std::unique_ptr<test::ImGuiTestHarnessServiceImpl> test_harness_service_;
103 std::unique_ptr<net::RomServiceImpl> rom_service_;
104 std::unique_ptr<net::EmulatorServiceImpl> emulator_service_;
105 CanvasAutomationServiceImpl* canvas_service_ = nullptr;
106
107 // GRPC Wrappers
108 std::unique_ptr<grpc::Service> canvas_grpc_service_;
109 std::unique_ptr<grpc::Service> test_harness_grpc_wrapper_;
110 std::vector<std::unique_ptr<grpc::Service>> extra_services_;
111
112 bool is_running_;
113
114 absl::Status BuildServer();
115};
116
117} // namespace yaze
118
119#endif // YAZE_WITH_GRPC
120#endif // YAZE_APP_CORE_SERVICE_UNIFIED_GRPC_SERVER_H_