ADTF
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cSampleReader

The default Sample Reader will read the incomung Stream of a IInPin. More...

#include <samplereader.h>

Inheritance diagram for cSampleReader:
[legend]

Public Member Functions

 cSampleReader ()
 Default CTOR.
 
 cSampleReader (ISampleStreamAccess::tMode eAccessMode)
 Default CTOR which defines the access method.
 
virtual tResult AcceptType (const ucom::ant::iobject_ptr< const IStreamType > &pStreamType)
 Accept or reject a new stream type - see also AcceptType and IsCompatible implementations.
 
tResult BeginStreaming (ISampleStream &oSampleStream) override
 BeginStreaming will open the given Sample Stream for Reading while a connection is establishing.
 
tResult EndStreaming () override
 Sample Stream disconnected.
 
void SetAcceptTypeCallback (const std::function< tResult(const ucom::iobject_ptr< const IStreamType > &pStreamType)> &fnAcceptTypeCallback)
 Sets a callback function which is called while a Stream Type is received - see also AcceptType and IsCompatible implementations.
 
void SetStreamErrorCallback (const std::function< tResult(tResult oStreamError)> &fnStreamErrorCallback)
 A callback function to react on stream errors.
 
tResult SetStreamError (const tResult &oError)
 Forward an error to the corresponding stream.
 
void GetSampleInStream (ucom::ant::iobject_ptr< ISampleInStream > &pSampleInStream)
 Returns the connected ISampleInStream.
 
void GetLastType (ucom::ant::iobject_ptr< const IStreamType > &pType)
 Returns the connected ISampleInStream.
 
virtual tResult GetNextSample (ucom::ant::iobject_ptr< const ISample > &pSample)
 Gets the next Sample within internal queue which not has been read.
 
void Reset () override
 
virtual tResult Push (const IStreamItem &oStreamItem, tTimeStamp tmTime)=0
 Push a new value to the internal sample queue.
 
virtual void Clear ()=0
 clears the local queue of the reader either only EndStreaming or incoming event ISampleInStream::IQueueItem::RE_Flush
 
virtual tResult Pop (IStreamItem &oStreamItem)=0
 Returns the next sample from the queue.
 
- Public Member Functions inherited from sample_streamer< ISampleReader, cInPin >
 sample_streamer ()=default
 CTOR.
 
 sample_streamer (const char *strName, const ucom::ant::iobject_ptr< const IStreamType > &pStreamType)
 CTOR initializer.
 
virtual ~sample_streamer ()
 DTOR.
 
void SetName (const char *strName)
 Sets the name of the streamer.
 
void ResetPin (ucom::ant::object_ptr< cInPin > &pPin)
 Resets the pin reference This is only internaly used.
 
void ResetPin ()
 Resets the pin reference to nullptr.
 
tResult GetName (base::ant::IString &&strName) const
 Gets the name of the streamer.
 
tResult SetType (const ucom::ant::iobject_ptr< const IStreamType > &pStreamType)
 Sets the StreamType of the streamer.
 
tResult GetType (ucom::ant::iobject_ptr< const IStreamType > &pStreamType) const override
 
tResult EndStreaming () override
 
 sample_streamer ()=default
 CTOR.
 
 sample_streamer (const char *strName, const ucom::ant::iobject_ptr< const IStreamType > &pStreamType)
 CTOR initializer.
 
virtual ~sample_streamer ()
 DTOR.
 
void SetName (const char *strName)
 Sets the name of the streamer.
 
void ResetPin (ucom::ant::object_ptr< cInPin > &pPin)
 Resets the pin reference This is only internaly used.
 
void ResetPin ()
 Resets the pin reference to nullptr.
 
tResult GetName (base::ant::IString &&strName) const
 Gets the name of the streamer.
 
tResult SetType (const ucom::ant::iobject_ptr< const IStreamType > &pStreamType)
 Sets the StreamType of the streamer.
 
tResult GetType (ucom::ant::iobject_ptr< const IStreamType > &pStreamType) const override
 
tResult EndStreaming () override
 
- Public Member Functions inherited from runnable< base::ant::IRunnable::RUN_PUSH, ISampleStream::IPushReadEventSink >
 runnable ()
 CTOR.
 
 runnable (IRunnable::tRunFunction fcRunOnceFunc)
 Main CTOR with callable function.
 
virtual ~runnable ()=default
 DTOR.
 
tResult Run (tTimeStamp tmTimeofActivation, IRunnable::tActivationType ui32ActivationType, const void *, size_t) override
 IRunnable::Run implementation which will call m_fcRunOnceFunc if ui32ActivationType is TYPE_OF_ACTIVATION.
 
virtual IRunnable::tActivationType GetActivationType () const
 Returns the type of activation implemented.
 
 runnable ()
 CTOR.
 
 runnable (IRunnable::tRunFunction fcRunOnceFunc)
 Main CTOR with callable function.
 
virtual ~runnable ()=default
 DTOR.
 
tResult Run (tTimeStamp tmTimeofActivation, IRunnable::tActivationType ui32ActivationType, const void *, size_t) override
 IRunnable::Run implementation which will call m_fcRunOnceFunc if ui32ActivationType is TYPE_OF_ACTIVATION.
 
virtual IRunnable::tActivationType GetActivationType () const
 Returns the type of activation implemented.
 
- Public Member Functions inherited from object< Bases >
tResult GetInterface (const char *i_strIID, void *&o_pInterface) override
 Query interfaces on an object.
 
tResult GetInterface (const char *i_strIID, const void *&o_pInterface) const override
 Provides const correct interface querying.
 
void Destroy () const override
 Switch from non-virtual destructor to virtual destructor.
 
- Public Member Functions inherited from IObject
 ADTF_IID (IObject, "object.ant.ucom.adtf.iid")
 Marks the IObject to be castable with the ucom_cast()
 

Protected Member Functions

tResult Push (tTimeStamp tmTimeofActivation)
 internal Push operation to implement pushread mode
 
virtual tResult ReadNextSample (ucom::ant::iobject_ptr< const ISample > &pSample)
 This will read the stream items until a sample is reached and return it.
 
tResult ProcessStreamItem (const IStreamItem &oStreamItem)
 This will process the stream items.
 
tResult HandleStreamError (tResult nError)
 
- Protected Member Functions inherited from sample_streamer< ISampleReader, cInPin >
 sample_streamer (const sample_streamer &)=delete
 deleted copy CTOR
 
 sample_streamer (sample_streamer &&)=delete
 deleted move CTOR
 
sample_streameroperator= (const sample_streamer &)=delete
 deleted copy operator
 
sample_streameroperator= (sample_streamer &&)=delete
 deleted move operator
 
 sample_streamer (const sample_streamer &)=delete
 deleted copy CTOR
 
 sample_streamer (sample_streamer &&)=delete
 deleted move CTOR
 
sample_streameroperator= (const sample_streamer &)=delete
 deleted copy operator
 
sample_streameroperator= (sample_streamer &&)=delete
 deleted move operator
 
- Protected Member Functions inherited from ISampleReader
 ~ISampleReader ()=default
 not destructable
 
- Protected Member Functions inherited from ISampleStreamer
 ~ISampleStreamer ()=default
 not destructable
 
- Protected Member Functions inherited from IObject
 ~IObject ()=default
 Protected destructor --> Only the final implementation can be destroyed!
 

Private Types

typedef sample_streamer< ISampleReader, cInPinbase_type
 base type of cSampleReader
 
typedef base::ant::runnable< base::ant::IRunnable::RUN_PUSH, ISampleStream::IPushReadEventSinkrunnable_type
 internal base type.
 

Private Attributes

ucom::object_ptr< ISampleInStreamm_pInStream
 Reader where to read.
 
std::mutex m_oReadLock
 Read synchronization.
 
std::function< tResult(const ucom::iobject_ptr< const IStreamType > &pStreamType)> m_fnAcceptTypeCallback
 Callback to reject type changes.
 
std::function< tResult(tResult oStreamError)> m_fnStreamErrorCallback
 Callback to react on stream errors.
 
bool m_bValidType = true
 state wether the current type is a valid type or not this will be set to false in AcceptType fails.
 
ucom::object_ptr< const IStreamTypem_pLastReadStreamType
 Last accepted incoming type.
 
ISampleStreamAccess::tMode m_eAccessMode
 current access method
 

Additional Inherited Members

- Public Types inherited from sample_streamer< ISampleReader, cInPin >
typedef cInPin pin_type
 
- Protected Attributes inherited from sample_streamer< ISampleReader, cInPin >
adtf_util::cString m_strName
 name of the streamer (used i.e. to create the pins name)
 
ucom::object_ptr< const IStreamTypem_pStreamType
 stream type of the streamer
 
ucom::object_ptr< cInPinm_poPin
 pin reference reading/writing from
 
adtf_util::cString m_strName
 name of the streamer (used i.e. to create the pins name)
 
ucom::object_ptr< const IStreamTypem_pStreamType
 stream type of the streamer
 
ucom::object_ptr< cInPinm_poPin
 pin reference reading/writing from
 
- Protected Attributes inherited from runnable< base::ant::IRunnable::RUN_PUSH, ISampleStream::IPushReadEventSink >
IRunnable::tRunFunction m_fcRunOnceFunc
 given function to call on Run
 
IRunnable::tRunFunction m_fcRunOnceFunc
 given function to call on Run
 

Detailed Description

The default Sample Reader will read the incomung Stream of a IInPin.

This sample reader has no internal queue! Make sure if you use this sample reader with PushRead to register a external queue or to override the Push, ReadNextSample and Push methods (for more detail see sample_reader)

Definition at line 171 of file samplereader.h.

Member Typedef Documentation

◆ base_type

base type of cSampleReader

Definition at line 181 of file samplereader.h.

◆ runnable_type

Constructor & Destructor Documentation

◆ cSampleReader() [1/2]

cSampleReader ( )
inline

Default CTOR.

Definition at line 209 of file samplereader.h.

References ADTF_RUN_FUNCTION, m_eAccessMode, and Push().

◆ cSampleReader() [2/2]

Default CTOR which defines the access method.

Parameters
eAccessModethe access method.
Remarks
Only PushRead access methed is implemented at the moment.

Definition at line 220 of file samplereader.h.

References ADTF_RUN_FUNCTION, m_eAccessMode, and Push().

Member Function Documentation

◆ AcceptType()

virtual tResult AcceptType ( const ucom::ant::iobject_ptr< const IStreamType > & pStreamType)
virtual

Accept or reject a new stream type - see also AcceptType and IsCompatible implementations.

If the SetAcceptTypeCallback method was used to set a accept sample callback method the internal meta type comparison will be replaced. The internal meta type comparison uses the IsCompatible implementation, where the "old" type and its Stream Meta Type decides wether the incoming type is accepted or rejected.

Parameters
[in]pStreamTypeThe incoming Stream Type to accept or reject.
Return values
ERR_INVALID_TYPEthe incoming Stream Type is not valid
ERR_NOERRORthe incoming Stream Type is valid
See also
AcceptType and IsCompatible implementations

Referenced by ProcessStreamItem().

◆ BeginStreaming()

tResult BeginStreaming ( ISampleStream & pStream)
inlineoverridevirtual

BeginStreaming will open the given Sample Stream for Reading while a connection is establishing.

Parameters
pStream[in] Sample Stream to open
Returns
Result Code depends on the implementation

Implements ISampleReader.

Definition at line 244 of file samplereader.h.

References EndStreaming(), m_eAccessMode, m_oReadLock, m_pInStream, sample_streamer< ISampleReader, cInPin >::m_pStreamType, sample_streamer< ISampleReader, cInPin >::m_strName, ISampleStream::Open(), ISampleStreamAccess::PushRead, RETURN_ERROR_DESC, RETURN_IF_FAILED, and RETURN_NOERROR.

◆ Clear()

virtual void Clear ( )
virtual

clears the local queue of the reader either only EndStreaming or incoming event ISampleInStream::IQueueItem::RE_Flush

Implements ISampleReaderQueue.

Referenced by EndStreaming().

◆ EndStreaming()

tResult EndStreaming ( )
inlineoverridevirtual

Sample Stream disconnected.

Streaming ends.

Returns
Standard Result Code. Depends on implmentation.

Implements ISampleStreamer.

Definition at line 270 of file samplereader.h.

References Clear(), m_oReadLock, m_pInStream, and RETURN_NOERROR.

Referenced by BeginStreaming().

◆ GetLastType()

void GetLastType ( ucom::ant::iobject_ptr< const IStreamType > & pType)
inline

◆ GetNextSample()

virtual tResult GetNextSample ( ucom::ant::iobject_ptr< const ISample > & pSample)
inlinevirtual

Gets the next Sample within internal queue which not has been read.

param[out] pSample Sample found

Returns
Standard Result Code
Return values
ERR_EMPTYNo Sample found.

Definition at line 346 of file samplereader.h.

References ReadNextSample().

Referenced by adtf::streaming::ant::operator>>(), adtf::streaming::ant::operator>>(), and adtf::streaming::ant::operator>>().

◆ GetSampleInStream()

void GetSampleInStream ( ucom::ant::iobject_ptr< ISampleInStream > & pSampleInStream)
inline

Returns the connected ISampleInStream.

Definition at line 319 of file samplereader.h.

References m_pInStream, and iobject_ptr_base< T >::Reset().

◆ HandleStreamError()

tResult HandleStreamError ( tResult nError)
inlineprotected

Definition at line 480 of file samplereader.h.

◆ Pop()

virtual tResult Pop ( IStreamItem & oStreamItem)
virtual

Returns the next sample from the queue.

Parameters
[out]oStreamItemstream item reference to copy the references to

Implements ISampleReaderQueue.

Referenced by ReadNextSample().

◆ ProcessStreamItem()

tResult ProcessStreamItem ( const IStreamItem & oStreamItem)
inlineprotected

This will process the stream items.

This method will cal the user hook callbacks for accepting type (SetAcceptTypeCallback)

Parameters
oStreamItemRecently read stream item.
Returns
internal or user error code.
Return values
ERR_INVALID_TYPEreceived Stream Type and Stream Meta Type was not accepted.
ERR_NOT_CONNECTEDNo Sample Stream is connected and the BeginStreaming is not called yet.

Definition at line 434 of file samplereader.h.

References AcceptType(), ADTF_BASE_COMPOSED_RESULT, IStreamItem::GetStreamType(), IStreamItem::GetType(), IS_FAILED, m_bValidType, RETURN_ERROR, RETURN_IF_FAILED, RETURN_NOERROR, and IStreamItem::StreamType.

Referenced by ReadNextSample().

◆ Push() [1/2]

virtual tResult Push ( const IStreamItem & oStreamItem,
tTimeStamp tmTime )
virtual

Push a new value to the internal sample queue.

Parameters
[in]oStreamItemThe sample to store
[in]tmTimeTime of storage

Implements ISampleReaderQueue.

◆ Push() [2/2]

tResult Push ( tTimeStamp tmTimeofActivation)
inlineprotected

internal Push operation to implement pushread mode

Definition at line 353 of file samplereader.h.

References IS_FAILED, LOG_DUMP, m_oReadLock, m_pInStream, Push(), RETURN_ERROR, RETURN_IF_FAILED, and RETURN_NOERROR.

Referenced by cSampleReader(), cSampleReader(), and Push().

◆ ReadNextSample()

virtual tResult ReadNextSample ( ucom::ant::iobject_ptr< const ISample > & pSample)
inlineprotectedvirtual

This will read the stream items until a sample is reached and return it.

If another stream item type is reached than sample, ProcessStreamItem will handle it.

Parameters
pSamplesample reference set if valid.
Returns
error code
Return values
ERR_EMPTYstream is empty
ERR_INVALID_TYPEreceived Stream Type and Stream Meta Type was not accepted.
ERR_NOT_CONNECTEDNo Sample Stream is connected and the BeginStreaming is not called yet.

Reimplemented in cLastSampleReader.

Definition at line 394 of file samplereader.h.

References ISampleStreamAccess::AsyncQueue, cStreamItem::GetSample(), cStreamItem::GetType(), IS_OK, m_pInStream, Pop(), ProcessStreamItem(), RETURN_IF_FAILED, and IStreamItem::Sample.

Referenced by GetNextSample(), and cLastSampleReader::ReadNextSample().

◆ Reset()

void Reset ( )
inlineoverride

Definition at line 468 of file samplereader.h.

◆ SetAcceptTypeCallback()

void SetAcceptTypeCallback ( const std::function< tResult(const ucom::iobject_ptr< const IStreamType > &pStreamType)> & fnAcceptTypeCallback)
inline

Sets a callback function which is called while a Stream Type is received - see also AcceptType and IsCompatible implementations.

Parameters
[in]fnAcceptTypeCallbackThe callback function is called while AcceptType is executed. It must return ERR_NOERROR to accept the type or any error to reject the new type.

Definition at line 288 of file samplereader.h.

References m_fnAcceptTypeCallback.

◆ SetStreamError()

tResult SetStreamError ( const tResult & oError)
inline

Forward an error to the corresponding stream.

Parameters
oError[in] The error passed to the SampleStream.
Returns
Standard Result Code.

Definition at line 305 of file samplereader.h.

References m_oReadLock, m_pInStream, and RETURN_ERROR.

◆ SetStreamErrorCallback()

void SetStreamErrorCallback ( const std::function< tResult(tResult oStreamError)> & fnStreamErrorCallback)
inline

A callback function to react on stream errors.

Parameters
[in]fnStreamErrorCallbackThe callback function which will be called on stream errors

Definition at line 298 of file samplereader.h.

References m_fnStreamErrorCallback.

Member Data Documentation

◆ m_bValidType

bool m_bValidType = true
private

state wether the current type is a valid type or not this will be set to false in AcceptType fails.

Definition at line 196 of file samplereader.h.

Referenced by ProcessStreamItem().

◆ m_eAccessMode

ISampleStreamAccess::tMode m_eAccessMode
private

current access method

Definition at line 203 of file samplereader.h.

Referenced by cSampleReader(), cSampleReader(), and BeginStreaming().

◆ m_fnAcceptTypeCallback

std::function<tResult(const ucom::iobject_ptr<const IStreamType>& pStreamType)> m_fnAcceptTypeCallback
private

Callback to reject type changes.

Definition at line 183 of file samplereader.h.

Referenced by SetAcceptTypeCallback().

◆ m_fnStreamErrorCallback

std::function<tResult(tResult oStreamError)> m_fnStreamErrorCallback
private

Callback to react on stream errors.

Definition at line 185 of file samplereader.h.

Referenced by SetStreamErrorCallback().

◆ m_oReadLock

std::mutex m_oReadLock
private

Read synchronization.

Definition at line 179 of file samplereader.h.

Referenced by BeginStreaming(), EndStreaming(), Push(), and SetStreamError().

◆ m_pInStream

ucom::object_ptr<ISampleInStream> m_pInStream
private

Reader where to read.

Definition at line 177 of file samplereader.h.

Referenced by BeginStreaming(), EndStreaming(), GetSampleInStream(), Push(), ReadNextSample(), and SetStreamError().

◆ m_pLastReadStreamType

ucom::object_ptr<const IStreamType> m_pLastReadStreamType
private

Last accepted incoming type.

Definition at line 200 of file samplereader.h.

Referenced by GetLastType().