3#include <uwebsockets/App.h>
5#include <BS_thread_pool.hpp>
33class MonitoringManager;
34class ProcedureRegistry;
61 using GetLogFn = std::function<std::vector<std::string>()>;
69 using RefreshCertFn = std::function<std::expected<void, std::string>()>;
96 std::function<std::expected<mm::net::Response, std::string>(
const std::string& body)>;
124 using RunCaptureFn = std::function<std::expected<std::filesystem::path, std::string>(
125 const std::string&
adapter,
int seconds)>;
152 std::string
corsOrigin{
"https://motion-master.synapticon.com"};
205 std::vector<mm::api::RegisterRoutesFn> routeModules_;
206 std::atomic<bool> running_{
false};
208 std::atomic<uWS::Loop*> loop_{
nullptr};
209 std::atomic<uWS::SSLApp*> app_{
nullptr};
211 std::promise<bool> listenResult_;
215 std::atomic<bool> stopping_{
false};
217 std::atomic<bool> captureRunning_{
false};
254 BS::light_thread_pool pool_{32};
HTTPS REST API server.
Definition http_server.h:45
std::function< std::expected< void, std::string >(uint32_t periodUs)> SetGameLoopPeriodFn
Callback type for PUT /api/game-loop.
Definition http_server.h:87
std::function< mm::auto_tuning::Status()> AutoTuningStatusFn
Callback type for GET /api/auto-tuning.
Definition http_server.h:103
std::function< std::expected< void, std::string >(const FieldbusConfig &fieldbus)> InitDeviceManagerFn
Callback type for POST /api/init.
Definition http_server.h:55
std::function< std::expected< std::filesystem::path, std::string >(const std::string &adapter, int seconds)> RunCaptureFn
Callback type for POST /api/captures.
Definition http_server.h:125
~HttpServer()
Destructor. Calls stop() if the server is still running.
Definition http_server.cc:413
std::function< std::expected< mm::net::Response, std::string >(const std::string &body)> AutoTuningRunFn
Callback type for POST /api/auto-tuning/run and GET /api/auto-tuning/swagger.yml.
Definition http_server.h:96
void addRoutes(mm::api::RegisterRoutesFn module)
Registers a route plug-in to be wired in when the server starts.
Definition http_server.cc:421
std::function< mm::node::EniCollectorOptions()> EniOptionsFn
Supplies the three things an ENI needs that no device can answer for: the master's name,...
Definition http_server.h:118
std::function< std::vector< std::string >()> GetLogFn
Callback type for GET /api/log.
Definition http_server.h:61
std::function< std::expected< void, std::string >()> RefreshCertFn
Callback type for POST /api/cert/refresh.
Definition http_server.h:69
void stop()
Stops the server, closes the listen socket, and joins the thread.
Definition http_server.cc:440
std::function< GameLoopHealth()> GetGameLoopHealthFn
Callback type for GET /api/game-loop.
Definition http_server.h:77
std::function< std::expected< mm::net::Response, std::string >()> AutoTuningSpecFn
Callback type for GET /api/auto-tuning/swagger.yml.
Definition http_server.h:109
bool start()
Starts the server background thread and begins accepting connections.
Definition http_server.cc:429
A flat, user-writable file store rooted at Motion Master's per-user cache directory.
Definition user_cache.h:65
Owns the fieldbus driver and node collection, and drives PDO exchange.
Definition device_manager.h:339
Owns the active monitorings and turns each into a lossless stream of recorded rows.
Definition monitoring_manager.h:62
Every procedure the server knows, and the four operations a client performs against it.
Definition procedure_registry.h:84
adapter
Definition config.h:230
mailboxStatusFmmu useCompleteAccess userCache
Definition config.h:245
mailboxStatusFmmu useCompleteAccess fieldbus
Definition config.h:244
A blocking HTTP client for the calls Motion Master makes out.
std::function< void(Router &router, const RouteContext &ctx)> RegisterRoutesFn
A route plug-in: registers its routes on the HTTP app.
Definition web_api.h:77
Definition http_server.h:27
Definition bus_health_source.h:7
Routes whose handlers cannot block the event loop, because they do not run on it.
What Motion Master knows about its auto-tuning process, as a client can read it.
The whole config file. Top-level keys map to these members.
Definition config.h:214
"fieldbus" block — the driver to auto-init at startup. An empty driver means "do not auto-init"; the ...
Definition config.h:50
Snapshot of game-loop real-time health for the GET /api/game-loop diagnostic endpoint....
Definition game_loop.h:15
Server configuration.
Definition http_server.h:128
AutoTuningRunFn runAutoTuning
Handler for POST /api/auto-tuning/run; forwards a call.
Definition http_server.h:145
RunCaptureFn runCapture
Definition http_server.h:150
AutoTuningStatusFn autoTuningStatus
Handler for GET /api/auto-tuning; the startup snapshot.
Definition http_server.h:147
RefreshCertFn refreshCert
Handler for POST /api/cert/refresh; fetches+installs a cert.
Definition http_server.h:140
GetGameLoopHealthFn getGameLoopHealth
Handler for GET /api/game-loop; RT loop health snapshot.
Definition http_server.h:142
GetLogFn getLog
Handler for GET /api/log; returns buffered log entries.
Definition http_server.h:139
std::string startedConfig
Serialized JSON of the boot config; served at GET /api/config.
Definition http_server.h:136
std::string version
Application version string served at GET /api/version.
Definition http_server.h:134
AutoTuningSpecFn autoTuningSpec
Handler for GET /api/auto-tuning/swagger.yml.
Definition http_server.h:148
std::string bindAddress
Local address to bind. Loopback serves only this machine; "0.0.0.0" serves the network.
Definition http_server.h:130
InitDeviceManagerFn initDeviceManager
Handler for POST /api/init; required for API-driven init.
Definition http_server.h:138
uint16_t port
TCP port to listen on (TLS).
Definition http_server.h:131
std::string certFile
Path to the TLS certificate (PEM).
Definition http_server.h:132
EniOptionsFn eniOptions
Supplies the non-bus half of GET /api/eni; required for it.
Definition http_server.h:149
std::string keyFile
Path to the TLS private key (PEM).
Definition http_server.h:133
std::string corsOrigin
Value sent in Access-Control-Allow-Origin. Defaults to the production PWA origin.
Definition http_server.h:152
SetGameLoopPeriodFn setGameLoopPeriod
Handler for PUT /api/game-loop; retimes the RT loop.
Definition http_server.h:144
The state of the auto-tuning process, reported by GET /api/auto-tuning.
Definition status.h:22
What an ENI needs that no device can answer for.
Definition eni_collector.h:19