|
Motion Master 6.0.0-alpha.50
Next-generation motion control software
|
Owns the active monitorings and turns each into a lossless stream of recorded rows. More...
#include <monitoring_manager.h>
Public Types | |
| using | PublishFn = std::function< void(std::string topic, std::string json)> |
Publishes one batch: json (a {"type":"monitoring","topic",...} envelope) under topic. Wired in the composition root to the WebSocket server's topic publish. | |
Public Member Functions | |
| MonitoringManager (DeviceManager &deviceManager) | |
Constructs the manager over deviceManager. Does not start sampling — call start(). | |
| ~MonitoringManager () | |
| Stops the owned refresher (and, once added, the sampler thread). | |
| MonitoringManager (const MonitoringManager &)=delete | |
| MonitoringManager & | operator= (const MonitoringManager &)=delete |
| void | setPublish (PublishFn publish) |
Sets the batch publish callback. Call before start(). | |
| std::expected< Monitoring, std::string > | create (Monitoring config) |
Validates config, classifies its parameters, registers SDO ones with the refresher, and registers the monitoring. | |
| bool | remove (const std::string &topic) |
| Removes a monitoring, releasing its SDO parameters from the refresher. | |
| std::optional< nlohmann::json > | get (const std::string &topic) const |
Returns the monitoring resource as JSON (config + per-parameter source + buffer fill), or nullopt if topic is unknown. | |
| nlohmann::json | list () const |
| Returns all monitoring resources as a JSON array, in topic order. | |
| void | start () |
| Starts the owned refresher (and, once added, the sampler thread). Idempotent. | |
| void | stop () |
| Stops the owned refresher (and, once added, the sampler thread). Idempotent. | |
| void | sampleAll () |
| Flushes every monitoring once: delivers each one's recorded cycles since its last flush. The deterministic core the scheduler thread drives; exposed for tests. | |
| std::size_t | monitoringCount () const |
| Number of registered monitorings. For tests / status. | |
| std::size_t | polledSdoCount () const |
| Number of distinct SDO objects currently polled by the refresher. For tests / status. | |
Owns the active monitorings and turns each into a lossless stream of recorded rows.
A client creates a Monitoring (topic, interval, parameters); the manager validates it, classifies every parameter by how its value is sourced, and on each flush ships every process-data cycle recorded since the last flush. The stream is lossless: each monitoring holds a read cursor into the recorder ring and, each time it is due, decodes and publishes every cycle-row in [cursor, recorderHead()) as one batch, then advances the cursor. interval is the flush cadence, not a sample rate — a longer interval means a bigger batch, never dropped cycles. A cursor that falls more than a whole ring behind (a stalled client) is logged and resynced to the oldest available cycle; the gap is never silent.
Sourcing (decided once at create, against the published process image):
ParameterRefresher which polls it in the background, and the sampler reads the cached value.Monitoring is live-only: a parameter whose owning device is not exchanging (SAFE-OP/OP) samples null. Topics are unique.
Thread-safe. Owns a private ParameterRefresher (the sampler is its sole client). The App wires only this manager (with a DeviceManager& and a publish callback).
| using mm::node::MonitoringManager::PublishFn = std::function<void(std::string topic, std::string json)> |
Publishes one batch: json (a {"type":"monitoring","topic",...} envelope) under topic. Wired in the composition root to the WebSocket server's topic publish.
|
explicit |
Constructs the manager over deviceManager. Does not start sampling — call start().
| mm::node::MonitoringManager::~MonitoringManager | ( | ) |
Stops the owned refresher (and, once added, the sampler thread).
|
delete |
| std::expected< Monitoring, std::string > mm::node::MonitoringManager::create | ( | Monitoring | config | ) |
Validates config, classifies its parameters, registers SDO ones with the refresher, and registers the monitoring.
Validation: topic URL-safe; not already registered; interval between 5 ms and 2000 ms (the flush cadence); parameters non-empty; and every parameter is either PDO-mapped or present in its device's object dictionary (otherwise it cannot be sourced).
| std::optional< nlohmann::json > mm::node::MonitoringManager::get | ( | const std::string & | topic | ) | const |
Returns the monitoring resource as JSON (config + per-parameter source + buffer fill), or nullopt if topic is unknown.
| nlohmann::json mm::node::MonitoringManager::list | ( | ) | const |
Returns all monitoring resources as a JSON array, in topic order.
| std::size_t mm::node::MonitoringManager::monitoringCount | ( | ) | const |
Number of registered monitorings. For tests / status.
|
delete |
| std::size_t mm::node::MonitoringManager::polledSdoCount | ( | ) | const |
Number of distinct SDO objects currently polled by the refresher. For tests / status.
| bool mm::node::MonitoringManager::remove | ( | const std::string & | topic | ) |
Removes a monitoring, releasing its SDO parameters from the refresher.
true if a monitoring with topic existed, false otherwise. | void mm::node::MonitoringManager::sampleAll | ( | ) |
Flushes every monitoring once: delivers each one's recorded cycles since its last flush. The deterministic core the scheduler thread drives; exposed for tests.
| void mm::node::MonitoringManager::setPublish | ( | PublishFn | publish | ) |
Sets the batch publish callback. Call before start().
| void mm::node::MonitoringManager::start | ( | ) |
Starts the owned refresher (and, once added, the sampler thread). Idempotent.
| void mm::node::MonitoringManager::stop | ( | ) |
Stops the owned refresher (and, once added, the sampler thread). Idempotent.