yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
http_server.h
Go to the documentation of this file.
1#ifndef YAZE_SRC_CLI_SERVICE_API_HTTP_SERVER_H_
2#define YAZE_SRC_CLI_SERVICE_API_HTTP_SERVER_H_
3
4#include <atomic>
5#include <functional>
6#include <memory>
7#include <string>
8#include <thread>
9
10#include "absl/status/status.h"
11#include "absl/status/statusor.h"
13
14namespace httplib {
15class Server;
16}
17
18namespace yaze {
19namespace emu {
20namespace debug {
21class SymbolProvider;
22}
23} // namespace emu
24
25namespace app {
26namespace service {
27class RenderService;
28}
29} // namespace app
30
31class Rom;
32} // namespace yaze
33
34namespace yaze {
35namespace cli {
36namespace api {
37
39 public:
42 using RomSource = std::function<Rom*()>;
43 using ProjectPathSource = std::function<std::string()>;
44 using WindowAction = std::function<bool()>;
46 std::function<absl::StatusOr<std::string>(const std::string&)>;
48 editor_control_ = std::move(control);
49 }
50
51 HttpServer();
53
54 // Start the server on the specified port in a background thread.
55 // `loopback_only` binds 127.0.0.1 and overrides the bind address.
56 absl::Status Start(int port, bool loopback_only = false);
57
58 // Address to bind when not loopback-only. Call before Start().
59 void SetBindAddress(std::string address) {
60 bind_address_ = std::move(address);
61 }
62
63 // When disabled, POST /api/v1/command/execute responds 403. Call before
64 // Start().
65 void SetCommandExecutionEnabled(bool enabled) {
67 }
68
69 // Stop the server.
70 void Stop();
71
72 // Check if server is running
73 bool IsRunning() const;
74
75 // Set the source for symbols
77 symbol_source_ = std::move(source);
78 }
79
80 // Set the source for the render service (headless dungeon rendering).
82 render_source_ = std::move(source);
83 }
84
85 // Set the source for ROM context (used by command execution).
86 void SetRomSource(RomSource source) { rom_source_ = std::move(source); }
87
88 // Set the source for project path (used by annotation endpoints).
90 project_path_source_ = std::move(source);
91 }
92
93 // Get current port.
94 int port() const { return port_; }
95
96 // Optional window control hooks (GUI builds only)
98 window_show_ = std::move(show);
99 window_hide_ = std::move(hide);
100 }
101
102 // Get current symbol source
104
105 // Access the Bonjour publisher (e.g. to update ROM title).
107
108 private:
109 void RunServer(int port);
110 void RegisterRoutes();
111
112 std::unique_ptr<httplib::Server> server_;
113 std::unique_ptr<std::thread> server_thread_;
114 std::atomic<bool> is_running_{false};
115 int port_ = 0;
117 std::string bind_address_ = "0.0.0.0";
127};
128
129} // namespace api
130} // namespace cli
131} // namespace yaze
132
133#endif // YAZE_SRC_CLI_SERVICE_API_HTTP_SERVER_H_
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:52
void SetProjectPathSource(ProjectPathSource source)
Definition http_server.h:89
std::unique_ptr< httplib::Server > server_
std::function< std::string()> ProjectPathSource
Definition http_server.h:43
BonjourPublisher bonjour_
RenderServiceSource render_source_
SymbolProviderSource symbol_source_
BonjourPublisher & GetBonjourPublisher()
absl::Status Start(int port, bool loopback_only=false)
std::function< absl::StatusOr< std::string >(const std::string &)> EditorControl
Definition http_server.h:45
std::function< Rom *()> RomSource
Definition http_server.h:42
SymbolProviderSource GetSymbolSource() const
void SetRomSource(RomSource source)
Definition http_server.h:86
std::function< app::service::RenderService *()> RenderServiceSource
Definition http_server.h:41
void SetBindAddress(std::string address)
Definition http_server.h:59
void SetRenderServiceSource(RenderServiceSource source)
Definition http_server.h:81
ProjectPathSource project_path_source_
void SetEditorControl(EditorControl control)
Definition http_server.h:47
std::function< bool()> WindowAction
Definition http_server.h:44
void SetWindowActions(WindowAction show, WindowAction hide)
Definition http_server.h:97
std::function< emu::debug::SymbolProvider *()> SymbolProviderSource
Definition http_server.h:40
void SetSymbolProviderSource(SymbolProviderSource source)
Definition http_server.h:76
void SetCommandExecutionEnabled(bool enabled)
Definition http_server.h:65
std::unique_ptr< std::thread > server_thread_
std::atomic< bool > is_running_
EditorControl editor_control_
Provider for symbol (label) resolution in disassembly.