MDF Lib 2.2
Interface against MDF 3/4 files
Loading...
Searching...
No Matches
mdf::ISampleObserver Class Reference

Interface to a sample observer that handle incoming samples events.

#include <isampleobserver.h>

Inheritance diagram for mdf::ISampleObserver:
Collaboration diagram for mdf::ISampleObserver:

Public Member Functions

 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.
 

Public Attributes

std::function< bool(uint64_t sample, uint64_t record_id, const std::vector< uint8_t > &record)> DoOnSample
 Function object that is called if assigned.
 

Protected Attributes

std::set< uint64_t > record_id_list_
 List of subscribed channel groups.
 
const IDataGroupdata_group_
 Reference to the data group (DG) block.
 

Member Function Documentation

◆ 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
VType of value.
Parameters
channelReference to a channel.
sampleSample number (0..N).
recordRecord buffer.
valueReference to the returning value.
array_indexArray 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
VType of value to return.
Parameters
channelReference to the channel.
sampleSample index.
recordRecord data bytes excluding the record ID bytes
valueReturns the scaled value.
array_indexOptional 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_idThe 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
sampleSample number.
record_idRecord ID (channel group identity).
recordSample record (excluding the record ID.
Returns
If this function returns false it indicate that reading should be aborted.

Member Data Documentation

◆ 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: