Motion Master 6.0.0-alpha.86
Next-generation motion control software
Loading...
Searching...
No Matches
mm::api::RouteContext Struct Reference

The live collaborators a route plug-in needs, handed to it at registration time. More...

#include <web_api.h>

Collaboration diagram for mm::api::RouteContext:
[legend]

Public Attributes

mm::node::DeviceManagerdeviceManager
 Device list + SDO/PDO/state/bus access.
 
mm::node::MonitoringManagermonitoringManager
 Monitoring registry (for monitoring-aware plug-ins).
 
std::string_view corsOrigin
 

Detailed Description

The live collaborators a route plug-in needs, handed to it at registration time.

A plug-in's RegisterRoutesFn receives this by const reference. The referenced objects (DeviceManager / MonitoringManager) and the storage backing corsOrigin all outlive the running server, so a handler may safely capture the individual fields it needs — but it must **never capture the RouteContext itself**, which is a temporary that dies once registration returns. Capture the fields instead:

void registerRoutes(mm::api::Router& router, const mm::api::RouteContext& ctx) {
router.get("/api/example/devices", [&dm = ctx.deviceManager](const mm::api::Request&) {
return mm::api::json(summarize(dm));
});
}
A request, snapshotted on the loop thread so a handler can outlive it.
Definition router.h:61
Registers routes whose handlers run off the event loop.
Definition router.h:274
void get(const std::string &pattern, Handler handler)
Registers handler for GET pattern. Path parameters are :name as in uWS.
Definition router.h:287
The live collaborators a route plug-in needs, handed to it at registration time.
Definition web_api.h:51
mm::node::DeviceManager & deviceManager
Device list + SDO/PDO/state/bus access.
Definition web_api.h:53

Member Data Documentation

◆ corsOrigin

std::string_view mm::api::RouteContext::corsOrigin

Value to send in Access-Control-Allow-Origin; outlives run().

Rarely needed now: a Router handler returns a Response and the framework writes the header. It remains for a plug-in that hand-rolls a response on the loop thread.

◆ deviceManager

mm::node::DeviceManager& mm::api::RouteContext::deviceManager

Device list + SDO/PDO/state/bus access.

◆ monitoringManager

mm::node::MonitoringManager& mm::api::RouteContext::monitoringManager

Monitoring registry (for monitoring-aware plug-ins).


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