Aria 3.2.6
C++23 MVVM framework — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
http_adapter.hpp
Go to the documentation of this file.
1#pragma once
58
59#include "aria/abi/export.hpp"
61#include "http_config.hpp"
62#include "http_view.hpp"
63
64#include <cstdint>
65#include <functional>
66#include <memory>
67#include <string>
68#include <string_view>
69#include <vector>
70
72
75public:
76 explicit HttpAdapter(HttpAdapterConfig config = {});
77 ~HttpAdapter() override;
78
79 HttpAdapter(const HttpAdapter&) = delete;
83
84 // ── Lifecycle ──────────────────────────────────────────────────────
85
88 bool start();
89
92 void stop();
93
95 [[nodiscard]] bool running() const noexcept;
96
99 [[nodiscard]] std::uint16_t actual_port() const noexcept;
100
102 [[nodiscard]] std::size_t client_count() const noexcept;
103
104 // ── View registry ──────────────────────────────────────────────────
105
111 HttpView& register_view(std::string id, std::string kind);
112
114 [[nodiscard]] HttpView* find_view(std::string_view id);
115
118 void unregister_view(std::string_view id);
119
122 struct ViewInfo {
123 std::string id;
124 std::string kind;
125 };
126 [[nodiscard]] std::vector<ViewInfo> list_views() const;
127
128 // ── IViewAdapter ───────────────────────────────────────────────────
129
130 [[nodiscard]] std::string_view platform_name() const noexcept override {
131 return "http";
132 }
133
134 void set_text(binding::IView& v, std::string_view text) override;
135 [[nodiscard]] std::string get_text(binding::IView& v) override;
137 binding::IView& v, std::function<void(std::string_view)> cb) override;
138
139 void set_bool(binding::IView& v, bool value) override;
140 [[nodiscard]] bool get_bool(binding::IView& v) override;
142 binding::IView& v, std::function<void(bool)> cb) override;
143
144 void set_int(binding::IView& v, int value) override;
145 [[nodiscard]] int get_int(binding::IView& v) override;
147 binding::IView& v, std::function<void(int)> cb) override;
148
149 void set_int64(binding::IView& v, std::int64_t value) override;
150 [[nodiscard]] std::int64_t get_int64(binding::IView& v) override;
152 binding::IView& v, std::function<void(std::int64_t)> cb) override;
153
154 void set_uint64(binding::IView& v, std::uint64_t value) override;
155 [[nodiscard]] std::uint64_t get_uint64(binding::IView& v) override;
157 binding::IView& v, std::function<void(std::uint64_t)> cb) override;
158
159 void set_float(binding::IView& v, float value) override;
160 [[nodiscard]] float get_float(binding::IView& v) override;
162 binding::IView& v, std::function<void(float)> cb) override;
163
164 void set_double(binding::IView& v, double value) override;
165 [[nodiscard]] double get_double(binding::IView& v) override;
167 binding::IView& v, std::function<void(double)> cb) override;
168
169 void set_visible(binding::IView& v, bool visible) override;
170 void set_enabled(binding::IView& v, bool enabled) override;
171
173 binding::IView& v, std::function<void()> cb) override;
174
175 // ── Custom command channel ─────────────────────────────────────────
176
180 std::function<std::string(std::string_view args_json)>;
181
186 void register_command(std::string_view view_id,
187 std::string_view command_name,
188 CommandHandler handler);
189
191 void unregister_command(std::string_view view_id,
192 std::string_view command_name);
193
194private:
195 struct Impl;
196 std::shared_ptr<Impl> p_;
197};
198
199} // namespace aria::adapters::http
RAII handle to a single subscription.
Definition subscription.hpp:44
bool start()
Start the HTTP server on a background thread.
bool get_bool(binding::IView &v) override
std::uint64_t get_uint64(binding::IView &v) override
HttpView * find_view(std::string_view id)
Look up a previously-registered view by id, or nullptr.
void set_float(binding::IView &v, float value) override
void set_double(binding::IView &v, double value) override
::aria::Subscription on_click(binding::IView &v, std::function< void()> cb) override
void unregister_command(std::string_view view_id, std::string_view command_name)
Unregister a previously-registered command.
double get_double(binding::IView &v) override
std::size_t client_count() const noexcept
Number of currently connected SSE clients.
HttpAdapter(const HttpAdapter &)=delete
HttpAdapter(HttpAdapterConfig config={})
HttpAdapter & operator=(const HttpAdapter &)=delete
std::uint16_t actual_port() const noexcept
Actual bound port — useful when config.port == 0 and the OS picked.
void set_uint64(binding::IView &v, std::uint64_t value) override
void set_text(binding::IView &v, std::string_view text) override
bool running() const noexcept
True iff the server thread is alive and listening.
::aria::Subscription on_text_changed(binding::IView &v, std::function< void(std::string_view)> cb) override
float get_float(binding::IView &v) override
::aria::Subscription on_bool_changed(binding::IView &v, std::function< void(bool)> cb) override
void register_command(std::string_view view_id, std::string_view command_name, CommandHandler handler)
Register a custom command.
void set_int(binding::IView &v, int value) override
HttpView & register_view(std::string id, std::string kind)
Register a logical view with stable id and kind.
HttpAdapter(HttpAdapter &&)=delete
void set_int64(binding::IView &v, std::int64_t value) override
::aria::Subscription on_int_changed(binding::IView &v, std::function< void(int)> cb) override
std::int64_t get_int64(binding::IView &v) override
void set_visible(binding::IView &v, bool visible) override
std::vector< ViewInfo > list_views() const
void set_enabled(binding::IView &v, bool enabled) override
std::function< std::string(std::string_view args_json)> CommandHandler
Custom command handler signature.
Definition http_adapter.hpp:179
void unregister_view(std::string_view id)
Unregister a view (also fires its on_destroy signal so any BindingEngine subscriptions are released c...
::aria::Subscription on_int64_changed(binding::IView &v, std::function< void(std::int64_t)> cb) override
::aria::Subscription on_float_changed(binding::IView &v, std::function< void(float)> cb) override
std::string_view platform_name() const noexcept override
Definition http_adapter.hpp:130
std::string get_text(binding::IView &v) override
void set_bool(binding::IView &v, bool value) override
void stop()
Stop the server; closes all SSE connections.
HttpAdapter & operator=(HttpAdapter &&)=delete
int get_int(binding::IView &v) override
::aria::Subscription on_uint64_changed(binding::IView &v, std::function< void(std::uint64_t)> cb) override
::aria::Subscription on_double_changed(binding::IView &v, std::function< void(double)> cb) override
Logical view exposed over HTTP.
Definition http_view.hpp:29
Abstract platform adapter — knows how to read/write/observe widgets.
Definition view_adapter.hpp:80
Abstract platform widget reference.
Definition view_adapter.hpp:28
#define ARIA_HTTP_API
Definition export.hpp:83
Configuration for the HTTP adapter.
Logical "view" exposed over HTTP/REST/SSE.
Definition http_adapter.hpp:71
Definition validation_key.hpp:110
Snapshot of currently registered (id, kind) pairs.
Definition http_adapter.hpp:122
std::string kind
Definition http_adapter.hpp:124
std::string id
Definition http_adapter.hpp:123
Configuration for HttpAdapter.
Definition http_config.hpp:15