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 <string>
9#include <vector>
10
11#include "absl/status/status.h"
12#include "absl/status/statusor.h"
15
16// gRPC types used by the server interface.
17#include <grpcpp/impl/service_type.h>
18#include <grpcpp/server.h>
19
20#include "app/emu/i_emulator.h"
22
23namespace yaze {
24
25// Forward declarations
26class CanvasAutomationServiceImpl;
27class Rom;
28
29namespace emu {
30// class Emulator; // Forward decl handled by i_emulator.h if needed, or unnecessary now
31}
32
33namespace editor {
34class EditorManager;
35}
36
37namespace net {
38class ProposalApprovalManager;
39class RomServiceImpl;
40class EmulatorServiceImpl;
41} // namespace net
42
43namespace test {
44class TestManager;
45class ImGuiTestHarnessServiceImpl;
46struct ScreenshotArtifact;
47} // namespace test
48
53class YazeGRPCServer {
54 public:
55 using RomGetter = std::function<Rom*()>;
56 using RomLoader = std::function<bool(const std::string& path)>;
57
58 struct Config {
59 int port = 50052; // Unified server port
60 bool enable_test_harness = true;
61 bool enable_rom_service = true;
62 bool enable_emulator_service = true;
63 bool enable_canvas_automation = true;
64 bool require_approval_for_rom_writes = true;
65 // "0.0.0.0" listens on every interface (the historical default, used by
66 // the iPad remote). Settings > Test mode binds "127.0.0.1" instead.
67 std::string bind_address = "0.0.0.0";
68 };
69
70 void SetBindAddress(const std::string& address) {
71 config_.bind_address = address;
72 }
73
74 YazeGRPCServer();
75 ~YazeGRPCServer();
76
89 absl::Status Initialize(
90 int port, emu::IEmulator* emulator = nullptr,
91 RomGetter rom_getter = nullptr, RomLoader rom_loader = nullptr,
92 test::TestManager* test_manager = nullptr,
93 net::RomVersionManager* version_mgr = nullptr,
94 net::ProposalApprovalManager* approval_mgr = nullptr,
95 CanvasAutomationServiceImpl* canvas_service = nullptr);
96
97 // Forwards to EmulatorServiceImpl::SetScreenshotCapturer (after Initialize).
98 void SetEmulatorScreenshotCapturer(
99 std::function<absl::StatusOr<test::ScreenshotArtifact>()> capturer);
100
101 absl::Status Start();
102 absl::Status StartAsync();
103 absl::Status AddService(std::unique_ptr<grpc::Service> service);
104 void Shutdown();
105 bool IsRunning() const;
106 int Port() const { return config_.port; }
107 void SetConfig(const Config& config) { config_ = config; }
108
109 private:
110 Config config_;
111 std::unique_ptr<grpc::Server> server_;
112
113 // Services
114 std::unique_ptr<test::ImGuiTestHarnessServiceImpl> test_harness_service_;
115 std::unique_ptr<net::RomServiceImpl> rom_service_;
116 std::unique_ptr<net::EmulatorServiceImpl> emulator_service_;
117 CanvasAutomationServiceImpl* canvas_service_ = nullptr;
118
119 // GRPC Wrappers
120 std::unique_ptr<grpc::Service> canvas_grpc_service_;
121 std::unique_ptr<grpc::Service> test_harness_grpc_wrapper_;
122 std::vector<std::unique_ptr<grpc::Service>> extra_services_;
123
124 bool is_running_;
125
126 absl::Status BuildServer();
127 void ReleaseRegisteredServices();
128};
129
130} // namespace yaze
131
132#endif // YAZE_WITH_GRPC
133#endif // YAZE_APP_CORE_SERVICE_UNIFIED_GRPC_SERVER_H_