CVB++ 15.0

Stream handler for synchronous streams. More...

#include <cvb/async/stream_handler_base.hpp>

Public Types

using StreamType = STREAMTYPE
 Shorthand notation of the stream type.
 
using StreamPtrType = std::shared_ptr<StreamType>
 Shorthand notation of the shared pointer of the specified stream.
 
using StreamVectorType = std::vector<StreamPtrType>
 Shorthand notation of the container of the stream shared pointer.
 
using DeliverableType = typename Internal::DeliverableTraits<STREAMTYPE>::type
 Shorthand notation of the stream deliverable type of the specified stream.
 
using DeliverablePtrType = std::shared_ptr<typename Internal::DeliverableTraits<STREAMTYPE>::type>
 Shorthand notation of the shared pointer of the stream deliverable.
 
using DeliverablePtrVectorType = std::vector<DeliverablePtrType>
 Shorthand notation of the container of the stream deliverable shared pointers.
 
using EventHandlerType = std::function<void(DeliverablePtrType, Cvb::WaitStatus)>
 Shorthand notation of the event handler, a callable, type.
 
using EventHandlerVectorType = std::vector<EventHandlerType>
 Shorthand notation of the container of the event handler.
 

Public Member Functions

void Run ()
 Start the handler.
 
bool TryFinish () noexcept
 Stop the handler.
 
void Finish ()
 Stop the handler.
 
bool IsActive () const noexcept
 Check if the acquisition thread is running.
 

Static Public Member Functions

static std::unique_ptr< StreamHandlerBaseCreate (const StreamVectorType &streamVector)
 Create a stream handler object.
 
static std::unique_ptr< StreamHandlerBaseCreate (const StreamPtrType &stream)
 Create a stream handler object.
 

Protected Member Functions

 StreamHandlerBase (const StreamVectorType &streamVector)
 Creates a stream handler object.
 
 StreamHandlerBase (const StreamPtrType &stream)
 Creates a stream handler object.
 
virtual void HandleAsyncStream (const StreamVectorType &streamVector)
 Asynchronously called for all registered streams.
 
virtual void HandleAsyncWaitResult (const std::vector< WaitResult< typename Internal::DeliverableTraits< STREAMTYPE >::type > > &waitResultVector)
 Asynchronously called for all acquired images.
 
virtual void HandleAsyncWaitResult (const std::vector< WaitResultTuple< typename Internal::DeliverableTraits< STREAMTYPE >::type > > &waitResultVector)
 Asynchronously called for all acquired images.
 
virtual void Setup (const StreamVectorType streamVector)
 Setup the streams for acquisition.
 
virtual void TearDown (const StreamVectorType streamVector) noexcept
 Tear down the streams after acquisition.
 
virtual void HandleError (const std::exception &error) noexcept
 Handles standard exceptions in the acquisition thread.
 
virtual void Begin () noexcept
 Performs custom operations at the beginning of the acquisition thread.
 
virtual void End () noexcept
 Performs custom operations just before the end of the acquisition thread.
 
std::vector< StreamPtrTypeStreamVector () const noexcept
 Get the streams associated with this handler.
 

Detailed Description

template<class STREAMTYPE>
class Cvb::StreamHandlerBase< STREAMTYPE >

Stream handler for synchronous streams.

Template Parameters
STREAMTYPEType of stream to be taken care of.

Constructor & Destructor Documentation

◆ StreamHandlerBase() [1/2]

template<class STREAMTYPE>
StreamHandlerBase ( const StreamVectorType & streamVector)
inlineexplicitprotected

Creates a stream handler object.

Parameters
[in]streamVectorList with synchronous streams.
Exceptions
Anyexception derived from std::exception including CvbException.

Call this in a customized subclass to setup the handler.

◆ StreamHandlerBase() [2/2]

template<class STREAMTYPE>
StreamHandlerBase ( const StreamPtrType & stream)
inlineexplicitprotected

Creates a stream handler object.

Parameters
[in]streamSynchronous stream.
Exceptions
Anyexception derived from std::exception including CvbException.

Call this in a customized subclass to setup the handler.

Member Function Documentation

◆ Begin()

template<class STREAMTYPE>
virtual void Begin ( )
inlineprotectedvirtualnoexcept

Performs custom operations at the beginning of the acquisition thread.

Exceptions
Doesnot throw any exception.

The default implementation does nothing. Be aware, that this method is called from the acquisition thread. Reimplemented it to setup resources that require the acquisition thread up and running. This is useful for interaction with Qt. E.g. you may create QObject derived classes here to archive correct thread affinity.

◆ Create() [1/2]

template<class STREAMTYPE>
static std::unique_ptr< StreamHandlerBase > Create ( const StreamPtrType & stream)
inlinestatic

Create a stream handler object.

Parameters
[in]streamSynchronous stream.
Returns
A stream handler object.
Exceptions
Anyexception derived from std::exception including CvbException.

This overload can be helpful if it is obvious that the number of streams is limited to one.

Note
You must not destroy a stream handler that is currently running. In order to prevent that you may use a StreamHandlerGuard.

◆ Create() [2/2]

template<class STREAMTYPE>
static std::unique_ptr< StreamHandlerBase > Create ( const StreamVectorType & streamVector)
inlinestatic

Create a stream handler object.

Parameters
[in]streamVectorList with synchronous streams.
Returns
A stream handler object.
Exceptions
Anyexception derived from std::exception including CvbException.
Note
You must not destroy a stream handler that is currently running. In order to prevent that you may use a StreamHandlerGuard.

◆ End()

template<class STREAMTYPE>
virtual void End ( )
inlineprotectedvirtualnoexcept

Performs custom operations just before the end of the acquisition thread.

Exceptions
Doesnot throw any exception.

The default implementation does nothing. Be aware, that this method is called from the acquisition thread. Reimplemented it to free resources that have been allocated in Begin().

◆ Finish()

template<class STREAMTYPE>
void Finish ( )
inline

Stop the handler.

Exceptions
Anyexception derived from std::exception including CvbException this also includes the last error on the acquisition thread.

This will stop the acquisition thread and call TearDown() on the calling thread. This blocks until the acquisition thread has finished, so blocking in a customized HandleAsyncStream() method can lead to deadlocks.

Note
If the acquisition handler is destroyed it automatically finishes.

◆ HandleAsyncStream()

template<class STREAMTYPE>
void HandleAsyncStream ( const StreamVectorType & streamVector)
inlineprotectedvirtual

Asynchronously called for all registered streams.

Parameters
[in]streamVectorList with synchronous streams (provided at creation).
Exceptions
Anyexception derived from std::exception including CvbException.

The default implementation just waits for the next image on each stream.

Attention
This method is called on a dedicated thread!

◆ HandleAsyncWaitResult() [1/2]

template<class STREAMTYPE>
void HandleAsyncWaitResult ( const std::vector< WaitResult< typename Internal::DeliverableTraits< STREAMTYPE >::type > > & waitResultVector)
inlineprotectedvirtual

Asynchronously called for all acquired images.

Parameters
[in]waitResultVectorList with synchronous acquired WaitResults.
Exceptions
Anyexception derived from std::exception including CvbException.

The default implementation does nothing.

Attention
This method is called on a dedicated thread!

◆ HandleAsyncWaitResult() [2/2]

template<class STREAMTYPE>
void HandleAsyncWaitResult ( const std::vector< WaitResultTuple< typename Internal::DeliverableTraits< STREAMTYPE >::type > > & waitResultVector)
inlineprotectedvirtual

Asynchronously called for all acquired images.

Parameters
[in]waitResultVectorList with synchronous acquired WaitResults.
Exceptions
Anyexception derived from std::exception including CvbException.

The default implementation does nothing.

Attention
This method is called on a dedicated thread!

◆ HandleError()

template<class STREAMTYPE>
void HandleError ( const std::exception & error)
inlineprotectedvirtualnoexcept

Handles standard exceptions in the acquisition thread.

Parameters
[in]&errorThe exception thrown.
Exceptions
Doesnot throw any exception.

This handler is called for all not explicitly handled standard exception in the acquisition thread. After the handler returned the acquisition thread may finish, but remain in the active state. Be aware that this handler is by default called from the acquisition thread.

Note
After this handler there will be no automatic call to TearDown(). So you have to call Finish() explicitly. If you reimplemented this handler you should call the default implementation so Finish() will deliver the error into the controlling thread, otherwise the error will be swallowed within the acquisition thread.

◆ IsActive()

template<class STREAMTYPE>
bool IsActive ( ) const
inlinenoexcept

Check if the acquisition thread is running.

Returns
True if running otherwise false.
Exceptions
Doesnot throw any exception.

◆ Run()

template<class STREAMTYPE>
void Run ( )
inline

Start the handler.

Exceptions
Anyexception derived from std::exception including CvbException.

This will call Setup() on the calling thread, before creating a dedicated acquisition thread. The acquisition thread will repeatedly call HandleAsyncStream().

◆ Setup()

template<class STREAMTYPE>
void Setup ( const StreamVectorType streamVector)
inlineprotectedvirtual

Setup the streams for acquisition.

Parameters
[in]streamVectorList with synchronous streams (provided at creation).
Exceptions
Anyexception derived from std::exception including CvbException.

The default implementation just calls Stream::Start() for each stream.

◆ StreamVector()

template<class STREAMTYPE>
std::vector< StreamPtrType > StreamVector ( ) const
inlineprotectednoexcept

Get the streams associated with this handler.

Returns
Stream vector.
Exceptions
Doesnot throw any exception.

◆ TearDown()

template<class STREAMTYPE>
void TearDown ( const StreamVectorType streamVector)
inlineprotectedvirtualnoexcept

Tear down the streams after acquisition.

Parameters
[in]streamVectorList with synchronous streams (provided at creation).
Exceptions
Doesnot throw any exception.

The default implementation just calls Stream::TryAbort() for each stream.

◆ TryFinish()

template<class STREAMTYPE>
bool TryFinish ( )
inlinenoexcept

Stop the handler.

Returns
True if no error occurred in the acquisition thread, otherwise.
Exceptions
Doesnot throw any exception.

This will stop the acquisition thread and call TearDown() on the calling thread. This blocks until the acquisition thread has finished, so blocking in a customized HandleAsyncStream() method can lead to deadlocks.

Note
If the acquisition handler is destroyed it automatically finishes.