Ocean
|
This class implements the base class for all devices providing measurement samples. More...
#include <Measurement.h>
Data Structures | |
class | ObjectMapper |
This class implements a helper class to simplify the mapping between internal object ids (of the actual tracking implementation) and extern object ids (of the device system). More... | |
class | Sample |
Definition of a sample holding a measurement. More... | |
class | SampleEventSubscription |
This class manages the lifetime of an event subscription for sample events. More... | |
Public Types | |
enum | InterpolationStrategy { IS_INVALID , IS_TIMESTAMP_NEAREST , IS_TIMESTAMP_INTERPOLATE } |
Definition of individual interpolation strategies for samples. More... | |
typedef unsigned int | ObjectId |
Definition of an object id. | |
typedef std::vector< ObjectId > | ObjectIds |
Definition of a vector holding object ids. | |
typedef std::unordered_set< ObjectId > | ObjectIdSet |
Definition of an unordered set holding object ids. | |
typedef std::unordered_map< std::string, Value > | Metadata |
Definition of an unordered map mapping keys to values. | |
typedef ObjectRef< Sample > | SampleRef |
Definition of an object reference for samples. | |
typedef Callback< void, const Measurement *, const SampleRef & > | SampleCallback |
Definition of a callback function to subscribe for new measurement sample events. | |
![]() | |
enum | MajorType : uint32_t { DEVICE_INVALID = 0u , DEVICE_MEASUREMENT = (1u << 0u) , DEVICE_SENSOR = (1u << 1u) | DEVICE_MEASUREMENT , DEVICE_TRACKER = (1u << 2u) | DEVICE_MEASUREMENT } |
Definition of all major device types. More... | |
enum | MinorType : uint32_t { MINOR_INVALID = 0u } |
Base definition of a minor type. More... | |
Public Member Functions | |
size_t | sampleCapacity () const |
Returns the capacity of the internal sample container. | |
bool | setSampleCapacity (const size_t capacity) |
Sets the capacity of the internal sample container. | |
virtual SampleRef | sample () const |
Returns the most recent sample. | |
virtual SampleRef | sample (const Timestamp timestamp) const |
Returns the sample with a specific timestamp. | |
virtual SampleRef | sample (const Timestamp ×tamp, const InterpolationStrategy interpolationStrategy) const |
Returns the sample best matching with a specified timestamp. | |
SampleEventSubscription | subscribeSampleEvent (SampleCallback &&callback) |
Subscribes a callback event function for new measurement sample events. | |
ObjectId | objectId (const std::string &description) const |
Returns the object id for an object description. | |
Strings | objectDescriptions () const |
Returns descriptions of all objects currently available. | |
std::string | objectDescription (const ObjectId objectId) const |
Returns the description of one object of this measurement. | |
![]() | |
const std::string & | name () const |
Returns the name of this device. | |
virtual const std::string & | library () const =0 |
Returns the name of the owner library. | |
virtual bool | isStarted () const |
Returns whether this device is active. | |
bool | isValid () const |
Returns whether this device is valid. | |
bool | isExclusive () const |
Returns whether this device can be use exclusively. | |
virtual bool | start () |
Starts the device. | |
virtual bool | pause () |
Pauses the device. | |
virtual bool | stop () |
Stops the device. | |
virtual bool | setParameter (const std::string ¶meter, const Value &value) |
Sets an abstract parameter of this device. | |
virtual bool | parameter (const std::string ¶meter, Value &value) |
Returns an abstract parameter of this device. | |
DeviceType | type () const |
Returns the major and minor type of this device. | |
Static Public Member Functions | |
static constexpr ObjectId | invalidObjectId () |
Returns an invalid object id. | |
![]() | |
static std::string | translateMajorType (const MajorType majorType) |
Translates the major devices type to a readable string. | |
static MajorType | translateMajorType (const std::string &majorType) |
Translates the major devices type from a readable string to a value. | |
Protected Types | |
typedef std::map< Timestamp, SampleRef > | SampleMap |
Definition of a map holding the most recent samples. | |
typedef std::unordered_map< std::string, ObjectId > | ObjectDescriptionToIdMap |
Definition of an unordered map mapping descriptions to unique object ids. | |
typedef std::unordered_map< ObjectId, std::string > | ObjectIdToDescriptionMap |
Definition of an unordered map mapping unique object ids to descriptions. | |
typedef std::unordered_map< SubscriptionId, SampleCallback > | SampleSubscriptionMap |
Definition of a map mapping subscription ids to event sample callback functions. | |
![]() | |
typedef unsigned int | SubscriptionId |
Definition of a subscription id for event callbacks. | |
Protected Member Functions | |
Measurement (const std::string &name, const DeviceType type) | |
Creates a new measurement object. | |
~Measurement () override | |
Destructs a measurement object. | |
void | postNewSample (const SampleRef &newSample) |
Posts a new measurement sample. | |
ObjectId | addUniqueObjectId (const std::string &description) |
Creates a unique object id for a new object (e.g., a tracking object like an image, a marker, or a location). | |
void | unsubscribeSampleEvent (const SubscriptionId subscriptionId) |
Unsubscribes a sample event callback function. | |
![]() | |
Device (const Device &device)=delete | |
Disabled copy constructor. | |
Device (const std::string &name, const DeviceType type) | |
Creates a new device by is name. | |
virtual | ~Device () |
Destructs a device. | |
Device & | operator= (const Device &device)=delete |
Disabled copy operator. | |
Protected Attributes | |
Lock | samplesLock_ |
Sample lock. | |
Lock | subscriptionLock_ |
Subscription lock. | |
![]() | |
std::string | deviceName |
Name of this device. | |
DeviceType | deviceType |
Major and minor type of this device. | |
bool | deviceIsValid |
Flag determining whether this device is valid. | |
Lock | deviceLock |
Device lock. | |
Private Attributes | |
SampleMap | sampleMap_ |
The most recent measurement samples. | |
size_t | sampleCapacity_ |
The maximal number of samples this measurement object can hold. | |
SampleSubscriptionMap | sampleSubscriptionMap_ |
Map holding all sample event subscriptions. | |
SubscriptionId | nextSampleSubscriptionId_ = SubscriptionId(invalidSubscriptionId() + 1u) |
The subscription id of the next event subscription. | |
ObjectDescriptionToIdMap | objectDescriptionToIdMap_ |
The map mapping object descriptions to object ids. | |
ObjectIdToDescriptionMap | objectIdToDescriptionMap_ |
The map mapping object ids to descriptions. | |
Additional Inherited Members | |
![]() | |
static constexpr SubscriptionId | invalidSubscriptionId () |
Returns an invalid subscription id. | |
This class implements the base class for all devices providing measurement samples.
Each measurement holds a container holding several most recent samples provided by the device.
Thus, depending on the number of stored samples a specific sample can be requested.
typedef std::unordered_map<std::string, Value> Ocean::Devices::Measurement::Metadata |
Definition of an unordered map mapping keys to values.
|
protected |
Definition of an unordered map mapping descriptions to unique object ids.
typedef unsigned int Ocean::Devices::Measurement::ObjectId |
Definition of an object id.
typedef std::vector<ObjectId> Ocean::Devices::Measurement::ObjectIds |
Definition of a vector holding object ids.
typedef std::unordered_set<ObjectId> Ocean::Devices::Measurement::ObjectIdSet |
Definition of an unordered set holding object ids.
|
protected |
Definition of an unordered map mapping unique object ids to descriptions.
typedef Callback<void, const Measurement*, const SampleRef&> Ocean::Devices::Measurement::SampleCallback |
Definition of a callback function to subscribe for new measurement sample events.
The first parameter is the Measurement object sending the sample The second parameter is the sample
|
protected |
Definition of a map holding the most recent samples.
Definition of an object reference for samples.
|
protected |
Definition of a map mapping subscription ids to event sample callback functions.
|
protected |
Creates a new measurement object.
name | The name of the measurement device |
type | Major and minor device type of the device |
|
overrideprotected |
Destructs a measurement object.
|
protected |
Creates a unique object id for a new object (e.g., a tracking object like an image, a marker, or a location).
description | The description of the new object, must be valid |
|
staticconstexpr |
Returns an invalid object id.
std::string Ocean::Devices::Measurement::objectDescription | ( | const ObjectId | objectId | ) | const |
Returns the description of one object of this measurement.
objectId | The id of the object for which the description will be returned, must be valid |
Strings Ocean::Devices::Measurement::objectDescriptions | ( | ) | const |
Returns descriptions of all objects currently available.
ObjectId Ocean::Devices::Measurement::objectId | ( | const std::string & | description | ) | const |
Returns the object id for an object description.
description | The description for which the object id will be returned |
|
protected |
Posts a new measurement sample.
newSample | New sample to post |
|
virtual |
Returns the most recent sample.
|
virtual |
Returns the sample best matching with a specified timestamp.
In case, the given timestamp does not fit to an existing sample, the resulting sample will be based on the specified interpolation strategy.
timestamp | The timestamp for which a sample will be determined, must be valid |
interpolationStrategy | The interpolation strategy to be applied in case the timestamp does not fit with an existing sample |
Returns the sample with a specific timestamp.
If no sample exists with the given timestamp the most recent sample is returned.
timestamp | The timestamp of the sample to be returned |
|
inline |
Returns the capacity of the internal sample container.
bool Ocean::Devices::Measurement::setSampleCapacity | ( | const size_t | capacity | ) |
Sets the capacity of the internal sample container.
capacity | The number maximal number of samples to be stored, with range [2, infinity) |
SampleEventSubscription Ocean::Devices::Measurement::subscribeSampleEvent | ( | SampleCallback && | callback | ) |
Subscribes a callback event function for new measurement sample events.
Do not subscribe or unsubscribe from inside an event thread.
callback | The callback function receiving the event calls, must be valid |
|
protected |
Unsubscribes a sample event callback function.
subscriptionId | The id of the event subscription to unsubscribe |
|
private |
The subscription id of the next event subscription.
|
private |
The map mapping object descriptions to object ids.
|
private |
The map mapping object ids to descriptions.
|
private |
The maximal number of samples this measurement object can hold.
|
private |
The most recent measurement samples.
|
private |
Map holding all sample event subscriptions.
|
protected |
Subscription lock.