Interface to a sample observer that handle incoming samples events.
#include <isampleobserver.h>
|
| ISampleObserver (const IDataGroup &data_group) |
| Sample observer constructor.
|
|
virtual | ~ISampleObserver () |
| Destructor.
|
|
virtual void | AttachObserver () |
| Attach the observer to an observer list (publisher).
|
|
virtual void | DetachObserver () |
| Detach the observer from an observer list.
|
|
virtual bool | OnSample (uint64_t sample, uint64_t record_id, const std::vector< uint8_t > &record) |
| Observer function that receives the sample record and parse out a channel value.
|
|
bool | IsRecordIdNeeded (uint64_t record_id) const |
| Function that test if this observer needs to read a specific record.
|
|
template<typename V > |
bool | GetChannelValue (const IChannel &channel, uint64_t sample, const std::vector< uint8_t > &record, V &value, uint64_t array_index=0) const |
| The function returns a channel value.
|
|
template<typename V > |
bool | GetEngValue (const IChannel &channel, uint64_t sample, const std::vector< uint8_t > &record, V &value, uint64_t array_index=0) const |
| Returns the scaled sample value for the channel with the record bytes as input. This function is mainly for internal use but is used together with sample observers.
|
|
|
std::function< bool(uint64_t sample, uint64_t record_id, const std::vector< uint8_t > &record)> | DoOnSample |
| Function object that is called if assigned.
|
|
|
std::set< uint64_t > | record_id_list_ |
| List of subscribed channel groups.
|
|
const IDataGroup & | data_group_ |
| Reference to the data group (DG) block.
|
|
◆ AttachObserver()
virtual void mdf::ISampleObserver::AttachObserver |
( |
| ) |
|
|
virtual |
This function is normally called in the constructor of an observer, so there is normally no need to call it.
◆ DetachObserver()
virtual void mdf::ISampleObserver::DetachObserver |
( |
| ) |
|
|
virtual |
This function detach the observer from the observer list. This function shall be called when OnSample() function is not needed anymore. This function is needed to handle dangling pointers. For example it is called after the ReadData() function in a reader.
◆ GetChannelValue()
template<typename V >
bool mdf::ISampleObserver::GetChannelValue |
( |
const IChannel & | channel, |
|
|
uint64_t | sample, |
|
|
const std::vector< uint8_t > & | record, |
|
|
V & | value, |
|
|
uint64_t | array_index = 0 ) const |
|
inline |
Use this function to get a channel value from a sample record buffer. Note that the array index should only be used if the channel is a so-called channel array (CA block).
- Template Parameters
-
- Parameters
-
channel | Reference to a channel. |
sample | Sample number (0..N). |
record | Record buffer. |
value | Reference to the returning value. |
array_index | Array index in case of an array channel object. |
- Returns
- True if the value is valid.
◆ GetEngValue()
template<typename V >
bool mdf::ISampleObserver::GetEngValue |
( |
const IChannel & | channel, |
|
|
uint64_t | sample, |
|
|
const std::vector< uint8_t > & | record, |
|
|
V & | value, |
|
|
uint64_t | array_index = 0 ) const |
|
inline |
The engineering value is the scaled value of the channel value. The attached conversion block defines the type of scaling to apply. Note that the channel value and the scaled value may have different type and unit.
- Template Parameters
-
V | Type of value to return. |
- Parameters
-
channel | Reference to the channel. |
sample | Sample index. |
record | Record data bytes excluding the record ID bytes |
value | Returns the scaled value. |
array_index | Optional array index in case of channel array. |
- Returns
- Return true if the value is valid.
◆ IsRecordIdNeeded()
bool mdf::ISampleObserver::IsRecordIdNeeded |
( |
uint64_t | record_id | ) |
const |
|
inlinenodiscard |
- Parameters
-
record_id | The channel groups record ID |
- Returns
- True if this channel subscribe on this record (channel group).
◆ OnSample()
virtual bool mdf::ISampleObserver::OnSample |
( |
uint64_t | sample, |
|
|
uint64_t | record_id, |
|
|
const std::vector< uint8_t > & | record ) |
|
virtual |
The function may be override by an inheritance for more complex implementations but in simpler use cases the DoOnSample function should be used instead.
The function normally returns true indicating that more reading is expected. If any observer want to stop further parsing, the function should return false.
- Parameters
-
sample | Sample number. |
record_id | Record ID (channel group identity). |
record | Sample record (excluding the record ID. |
- Returns
- If this function returns false it indicate that reading should be aborted.
◆ DoOnSample
std::function<bool(uint64_t sample, uint64_t record_id, const std::vector<uint8_t>& record)> mdf::ISampleObserver::DoOnSample |
The function object is typically assigned to a lambda function. See also OnSample() function.
The documentation for this class was generated from the following file: