1#ifndef YAZE_APP_SERVICE_EDITOR_HTTP_SERVER_H_
2#define YAZE_APP_SERVICE_EDITOR_HTTP_SERVER_H_
4#if !defined(__EMSCRIPTEN__) && defined(YAZE_HTTP_API_ENABLED)
8#include "absl/status/status.h"
19inline std::unique_ptr<cli::api::HttpServer> SetupEditorHttpServer(
20 const AppConfig& config) {
22 if (!config.enable_api || !controller || !controller->IsActive()) {
26 auto server = std::make_unique<cli::api::HttpServer>();
27 server->SetSymbolProviderSource(
28 [controller]() -> emu::debug::SymbolProvider* {
29 auto* manager = controller->editor_manager();
30 return manager ? &manager->emulator().symbol_provider() : nullptr;
34 auto run_window_action = [controller](void (Controller::*action)()) -> bool {
35 absl::Status status = util::UiThreadQueue::
Get().RunOnUiThread(
36 [controller, action]() -> absl::Status {
37 (controller->*action)();
38 return absl::OkStatus();
41 LOG_WARN(
"App",
"HTTP window action failed: %s",
42 std::string(status.message()).c_str());
46 server->SetWindowActions(
47 [run_window_action]() {
48 return run_window_action(&Controller::ShowWindow);
50 [run_window_action]() {
51 return run_window_action(&Controller::HideWindow);
54 if (config.editor_control) {
55 server->SetEditorControl([controller](
const std::string& request) {
56 return controller->RequestEditorControl(request);
60 auto status = server->Start(config.api_port, config.editor_control);
62 LOG_ERROR(
"App",
"Failed to start API server: %s",
63 std::string(status.message()).c_str());
66 LOG_INFO(
"App",
"API Server started on port %d", config.api_port);
Controller * GetController()
static Application & Instance()
#define LOG_ERROR(category, format,...)
#define LOG_WARN(category, format,...)
#define LOG_INFO(category, format,...)
WindowContent * Get(const std::string &id)
Get a specific panel by its ID.