Motion Master 6.0.0-alpha.52
Next-generation motion control software
Loading...
Searching...
No Matches
mm::example Namespace Reference

Example application namespace — the starting point for a C++ HTTP-endpoint plug-in. More...

Classes

struct  DeviceSummary
 A trimmed, presentation-shaped view of one device — the kind of derived data an application-specific endpoint typically returns (vs. the full Device JSON the built-in /api/devices route serves). More...
 

Functions

void to_json (nlohmann::json &j, const DeviceSummary &summary)
 Serialises a DeviceSummary to JSON. Lives next to the type (ADL-found by nlohmann) so a nlohmann::json(summary) or nlohmann::json(vector<DeviceSummary>) just works.
 
std::vector< DeviceSummarysummarizeDevices (const mm::node::DeviceManager &deviceManager)
 Builds a summary row for every device currently known to deviceManager.
 
void registerRoutes (uWS::SSLApp &app, const mm::api::RouteContext &ctx)
 Registers the example application's HTTP routes (/api/example/...) on app.
 

Detailed Description

Example application namespace — the starting point for a C++ HTTP-endpoint plug-in.

Everything here is meant to be copied and renamed: copy libs/example, rename the directory, the mm::example namespace, and the route prefix, then replace this domain code and these routes with your own. The split mirrors the rest of the codebase: real work lives in plain, HTTP-agnostic functions here (testable without a server), and example_routes.cc is the thin layer that parses requests, calls these functions, and formats responses.

Function Documentation

◆ registerRoutes()

void mm::example::registerRoutes ( uWS::SSLApp &  app,
const mm::api::RouteContext ctx 
)

Registers the example application's HTTP routes (/api/example/...) on app.

This is a mm::api::RegisterRoutesFn — wire it into the server in the composition root with HttpServer::addRoutes(mm::example::registerRoutes) before start(). It is the C++ analogue of the web/apps/example PWA: a minimal, copy-me starting point for adding your own endpoints.

Called once, on the HTTP event-loop thread, with ctx bound to the live device and monitoring managers. Handlers registered here run on that same loop thread for every request.

◆ summarizeDevices()

std::vector< DeviceSummary > mm::example::summarizeDevices ( const mm::node::DeviceManager deviceManager)

Builds a summary row for every device currently known to deviceManager.

Pure read-only domain logic — no HTTP, no I/O — so it is unit-testable against a DeviceManager with no live bus (returns an empty vector when nothing has been scanned).

◆ to_json()

void mm::example::to_json ( nlohmann::json &  j,
const DeviceSummary summary 
)

Serialises a DeviceSummary to JSON. Lives next to the type (ADL-found by nlohmann) so a nlohmann::json(summary) or nlohmann::json(vector<DeviceSummary>) just works.