Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
aria::adapters::http::HttpAdapter Class Referencefinal

HTTP/REST/SSE implementation of IViewAdapter. More...

#include <http_adapter.hpp>

Inheritance diagram for aria::adapters::http::HttpAdapter:
[legend]

Classes

struct  ViewInfo
 Snapshot of currently registered (id, kind) pairs. More...

Public Types

using CommandHandler
 Custom command handler signature.

Public Member Functions

 HttpAdapter (HttpAdapterConfig config={})
 ~HttpAdapter () override
 HttpAdapter (const HttpAdapter &)=delete
HttpAdapteroperator= (const HttpAdapter &)=delete
 HttpAdapter (HttpAdapter &&)=delete
HttpAdapteroperator= (HttpAdapter &&)=delete
bool start ()
 Start the HTTP server on a background thread.
void stop ()
 Stop the server; closes all SSE connections.
bool running () const noexcept
 True iff the server thread is alive and listening.
std::uint16_t actual_port () const noexcept
 Actual bound port — useful when config.port == 0 and the OS picked.
std::size_t client_count () const noexcept
 Number of currently connected SSE clients.
HttpViewregister_view (std::string id, std::string kind)
 Register a logical view with stable id and kind.
HttpViewfind_view (std::string_view id)
 Look up a previously-registered view by id, or nullptr.
void unregister_view (std::string_view id)
 Unregister a view (also fires its on_destroy signal so any BindingEngine subscriptions are released cleanly).
std::vector< ViewInfolist_views () const
std::string_view platform_name () const noexcept override
void set_text (binding::IView &v, std::string_view text) override
std::string get_text (binding::IView &v) override
::aria::Subscription on_text_changed (binding::IView &v, std::function< void(std::string_view)> cb) override
void set_bool (binding::IView &v, bool value) override
bool get_bool (binding::IView &v) override
::aria::Subscription on_bool_changed (binding::IView &v, std::function< void(bool)> cb) override
void set_int (binding::IView &v, int value) override
int get_int (binding::IView &v) override
::aria::Subscription on_int_changed (binding::IView &v, std::function< void(int)> cb) override
void set_int64 (binding::IView &v, std::int64_t value) override
std::int64_t get_int64 (binding::IView &v) override
::aria::Subscription on_int64_changed (binding::IView &v, std::function< void(std::int64_t)> cb) override
void set_uint64 (binding::IView &v, std::uint64_t value) override
std::uint64_t get_uint64 (binding::IView &v) override
::aria::Subscription on_uint64_changed (binding::IView &v, std::function< void(std::uint64_t)> cb) override
void set_float (binding::IView &v, float value) override
float get_float (binding::IView &v) override
::aria::Subscription on_float_changed (binding::IView &v, std::function< void(float)> cb) override
void set_double (binding::IView &v, double value) override
double get_double (binding::IView &v) override
::aria::Subscription on_double_changed (binding::IView &v, std::function< void(double)> cb) override
void set_visible (binding::IView &v, bool visible) override
void set_enabled (binding::IView &v, bool enabled) override
::aria::Subscription on_click (binding::IView &v, std::function< void()> cb) override
void register_command (std::string_view view_id, std::string_view command_name, CommandHandler handler)
 Register a custom command.
void unregister_command (std::string_view view_id, std::string_view command_name)
 Unregister a previously-registered command.
::httplib::Server & native_server () noexcept
 Direct access to the underlying cpp-httplib server, for consumers that want to register their own REST routes / static mounts / chunked responses on the same listening socket.
Public Member Functions inherited from aria::binding::IViewAdapter
virtual ~IViewAdapter ()

Detailed Description

HTTP/REST/SSE implementation of IViewAdapter.

Member Typedef Documentation

◆ CommandHandler

Initial value:
std::function<std::string(std::string_view args_json)>

Custom command handler signature.

Receives JSON args (raw string, callee may parse), returns a JSON response string (empty for void).

Constructor & Destructor Documentation

◆ HttpAdapter() [1/3]

aria::adapters::http::HttpAdapter::HttpAdapter ( HttpAdapterConfig config = {})
explicit

◆ ~HttpAdapter()

aria::adapters::http::HttpAdapter::~HttpAdapter ( )
override

◆ HttpAdapter() [2/3]

aria::adapters::http::HttpAdapter::HttpAdapter ( const HttpAdapter & )
delete

◆ HttpAdapter() [3/3]

aria::adapters::http::HttpAdapter::HttpAdapter ( HttpAdapter && )
delete

Member Function Documentation

◆ operator=() [1/2]

HttpAdapter & aria::adapters::http::HttpAdapter::operator= ( const HttpAdapter & )
delete

◆ operator=() [2/2]

HttpAdapter & aria::adapters::http::HttpAdapter::operator= ( HttpAdapter && )
delete

◆ start()

bool aria::adapters::http::HttpAdapter::start ( )

Start the HTTP server on a background thread.

Returns true after listening readiness; false if already running or startup failed.

◆ stop()

void aria::adapters::http::HttpAdapter::stop ( )

Stop the server; closes all SSE connections.

Idempotent. Safe to call from the destructor.

◆ running()

bool aria::adapters::http::HttpAdapter::running ( ) const
nodiscardnoexcept

True iff the server thread is alive and listening.

◆ actual_port()

std::uint16_t aria::adapters::http::HttpAdapter::actual_port ( ) const
nodiscardnoexcept

Actual bound port — useful when config.port == 0 and the OS picked.

Returns 0 when not running.

◆ client_count()

std::size_t aria::adapters::http::HttpAdapter::client_count ( ) const
nodiscardnoexcept

Number of currently connected SSE clients.

◆ register_view()

HttpView & aria::adapters::http::HttpAdapter::register_view ( std::string id,
std::string kind )

Register a logical view with stable id and kind.

kind ∈ {"text","bool","int","int64","uint64","float","double","click"}. Returns a reference to the owned HttpView (lifetime-bound to the adapter). Registering the same id twice replaces the previous view (after firing its on_destroy signal).

◆ find_view()

HttpView * aria::adapters::http::HttpAdapter::find_view ( std::string_view id)
nodiscard

Look up a previously-registered view by id, or nullptr.

◆ unregister_view()

void aria::adapters::http::HttpAdapter::unregister_view ( std::string_view id)

Unregister a view (also fires its on_destroy signal so any BindingEngine subscriptions are released cleanly).

◆ list_views()

std::vector< ViewInfo > aria::adapters::http::HttpAdapter::list_views ( ) const
nodiscard

◆ platform_name()

std::string_view aria::adapters::http::HttpAdapter::platform_name ( ) const
inlinenodiscardoverridevirtualnoexcept

◆ set_text()

void aria::adapters::http::HttpAdapter::set_text ( binding::IView & v,
std::string_view text )
overridevirtual

◆ get_text()

std::string aria::adapters::http::HttpAdapter::get_text ( binding::IView & v)
nodiscardoverridevirtual

◆ on_text_changed()

::aria::Subscription aria::adapters::http::HttpAdapter::on_text_changed ( binding::IView & v,
std::function< void(std::string_view)> cb )
overridevirtual

◆ set_bool()

void aria::adapters::http::HttpAdapter::set_bool ( binding::IView & v,
bool value )
overridevirtual

◆ get_bool()

bool aria::adapters::http::HttpAdapter::get_bool ( binding::IView & v)
nodiscardoverridevirtual

◆ on_bool_changed()

::aria::Subscription aria::adapters::http::HttpAdapter::on_bool_changed ( binding::IView & v,
std::function< void(bool)> cb )
overridevirtual

◆ set_int()

void aria::adapters::http::HttpAdapter::set_int ( binding::IView & v,
int value )
overridevirtual

◆ get_int()

int aria::adapters::http::HttpAdapter::get_int ( binding::IView & v)
nodiscardoverridevirtual

◆ on_int_changed()

::aria::Subscription aria::adapters::http::HttpAdapter::on_int_changed ( binding::IView & v,
std::function< void(int)> cb )
overridevirtual

◆ set_int64()

void aria::adapters::http::HttpAdapter::set_int64 ( binding::IView & v,
std::int64_t value )
overridevirtual

◆ get_int64()

std::int64_t aria::adapters::http::HttpAdapter::get_int64 ( binding::IView & v)
nodiscardoverridevirtual

◆ on_int64_changed()

::aria::Subscription aria::adapters::http::HttpAdapter::on_int64_changed ( binding::IView & v,
std::function< void(std::int64_t)> cb )
overridevirtual

◆ set_uint64()

void aria::adapters::http::HttpAdapter::set_uint64 ( binding::IView & v,
std::uint64_t value )
overridevirtual

◆ get_uint64()

std::uint64_t aria::adapters::http::HttpAdapter::get_uint64 ( binding::IView & v)
nodiscardoverridevirtual

◆ on_uint64_changed()

::aria::Subscription aria::adapters::http::HttpAdapter::on_uint64_changed ( binding::IView & v,
std::function< void(std::uint64_t)> cb )
overridevirtual

◆ set_float()

void aria::adapters::http::HttpAdapter::set_float ( binding::IView & v,
float value )
overridevirtual

◆ get_float()

float aria::adapters::http::HttpAdapter::get_float ( binding::IView & v)
nodiscardoverridevirtual

◆ on_float_changed()

::aria::Subscription aria::adapters::http::HttpAdapter::on_float_changed ( binding::IView & v,
std::function< void(float)> cb )
overridevirtual

◆ set_double()

void aria::adapters::http::HttpAdapter::set_double ( binding::IView & v,
double value )
overridevirtual

◆ get_double()

double aria::adapters::http::HttpAdapter::get_double ( binding::IView & v)
nodiscardoverridevirtual

◆ on_double_changed()

::aria::Subscription aria::adapters::http::HttpAdapter::on_double_changed ( binding::IView & v,
std::function< void(double)> cb )
overridevirtual

◆ set_visible()

void aria::adapters::http::HttpAdapter::set_visible ( binding::IView & v,
bool visible )
overridevirtual

◆ set_enabled()

void aria::adapters::http::HttpAdapter::set_enabled ( binding::IView & v,
bool enabled )
overridevirtual

◆ on_click()

::aria::Subscription aria::adapters::http::HttpAdapter::on_click ( binding::IView & v,
std::function< void()> cb )
overridevirtual

◆ register_command()

void aria::adapters::http::HttpAdapter::register_command ( std::string_view view_id,
std::string_view command_name,
CommandHandler handler )

Register a custom command.

Invoked when the browser sends POST /aria/command {"view":id,"command":name,"args":{...}}. Multiple commands per view are allowed; (view_id, command_name) is the unique key.

◆ unregister_command()

void aria::adapters::http::HttpAdapter::unregister_command ( std::string_view view_id,
std::string_view command_name )

Unregister a previously-registered command.

◆ native_server()

::httplib::Server & aria::adapters::http::HttpAdapter::native_server ( )
nodiscardnoexcept

Direct access to the underlying cpp-httplib server, for consumers that want to register their own REST routes / static mounts / chunked responses on the same listening socket.

Stability: This is an escape hatch, not a stable contract. The return type leaks the implementation detail that the adapter is built on cpp-httplib. If we ever swap the HTTP backend, this signature changes. Higher-level use cases should prefer register_command() (REST-style POST handlers) or register_view() + binding (state pushed via SSE).

Threading:

  • Must be called before start() to register routes — once the server thread is running, mutating the route table is racy.
  • Available after construction (the underlying server is constructed eagerly), unlike pre-1.0 versions where you had to start first and downcast a void*.

Build-time visibility: Include <httplib.h> to use the returned server. The installed aria::http target exports the matching header, compile definitions and optional TLS link dependencies. This API remains coupled to the bundled cpp-httplib version.


The documentation for this class was generated from the following file: