roo_transceivers
API Documentation for roo_transceivers
Loading...
Searching...
No Matches
universe.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include "roo_collections/flat_small_hash_map.h"
6#include "roo_collections/flat_small_hash_set.h"
7#include "roo_logging.h"
8#include "roo_transceivers.h"
10#include "roo_transceivers/id.h"
12
13namespace roo_transceivers {
14
15/// An abstract collection of transceiver devices.
16///
17/// Each transceiver can have up to 16 sensors and up to 16 actuators, as
18/// defined in its descriptor.
19class Universe {
20 public:
21 virtual ~Universe() = default;
22
23 /// Returns the total number of transceiver devices in this universe.
24 virtual size_t deviceCount() const = 0;
25
26 /// Iterates over all transceiver devices in this universe, calling
27 /// `callback` for each device.
28 ///
29 /// Callback return value controls iteration:
30 /// - `true` => continue iterating,
31 /// - `false` => interrupt iteration.
32 ///
33 /// Returns `true` if iteration completed (callback returned `true` for all
34 /// devices), and `false` if interrupted by callback.
35 virtual bool forEachDevice(
36 std::function<bool(const DeviceLocator&)> callback) const = 0;
37
38 /// Retrieves the descriptor for the transceiver identified by `locator`.
39 ///
40 /// Returns `true` on success; `false` when the device is not found.
41 virtual bool getDeviceDescriptor(
42 const DeviceLocator& locator,
43 roo_transceivers_Descriptor& descriptor) const = 0;
44
45 /// Returns the latest known reading of the sensor identified by `locator`.
46 ///
47 /// If device/sensor is not found, returned measurement is initial
48 /// (`isInitial() == true`).
49 virtual Measurement read(const SensorLocator& locator) const = 0;
50
51 /// Writes to the actuator identified by `locator`.
52 ///
53 /// Returns `true` on success; `false` if locator is invalid or not found, or
54 /// if write fails.
55 virtual bool write(const ActuatorLocator& locator, float value) = 0;
56
57 /// Requests sensor reading update from underlying devices.
58 virtual void requestUpdate() = 0;
59
60 /// Registers a listener for device-set and reading update events.
61 virtual void addEventListener(EventListener* listener) {}
62
63 /// Removes a previously registered event listener.
64 virtual void removeEventListener(EventListener* listener) {}
65};
66
67} // namespace roo_transceivers
Identifies actuator within a transceiver device.
Definition id.h:104
Identifies a transceiver device by schema and device id.
Definition id.h:21
Listener for universe-level change notifications.
Definition notification.h:9
Measurement of a quantity at a specific time.
Definition measurement.h:11
Identifies sensor within a transceiver device.
Definition id.h:57
An abstract collection of transceiver devices.
Definition universe.h:19
virtual bool write(const ActuatorLocator &locator, float value)=0
Writes to the actuator identified by locator.
virtual Measurement read(const SensorLocator &locator) const =0
Returns the latest known reading of the sensor identified by locator.
virtual void removeEventListener(EventListener *listener)
Removes a previously registered event listener.
Definition universe.h:64
virtual size_t deviceCount() const =0
Returns the total number of transceiver devices in this universe.
virtual bool getDeviceDescriptor(const DeviceLocator &locator, roo_transceivers_Descriptor &descriptor) const =0
Retrieves the descriptor for the transceiver identified by locator.
virtual ~Universe()=default
virtual void requestUpdate()=0
Requests sensor reading update from underlying devices.
virtual bool forEachDevice(std::function< bool(const DeviceLocator &)> callback) const =0
Iterates over all transceiver devices in this universe, calling callback for each device.
virtual void addEventListener(EventListener *listener)
Registers a listener for device-set and reading update events.
Definition universe.h:61