CVB++ 15.0
MultiStreamHandler Class Reference

Handler object for multiple synchronous streams. More...

#include <cvb/async/multi_stream_handler.hpp>

Inherits StreamHandlerBase< Stream >.

Inherited by SingleStreamHandler.

Static Public Member Functions

static std::unique_ptr< MultiStreamHandlerCreate (const std::vector< Driver::StreamPtr > &streamVector)
 Create a stream handler object. More...
 
- Static Public Member Functions inherited from StreamHandlerBase< Stream >
static std::unique_ptr< StreamHandlerBaseCreate (const StreamVectorType &streamVector)
 Create a stream handler object. More...
 
static std::unique_ptr< StreamHandlerBaseCreate (const StreamPtrType &stream)
 Create a stream handler object. More...
 

Protected Member Functions

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

Additional Inherited Members

- Public Types inherited from StreamHandlerBase< Stream >
using StreamType = Stream
 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< Stream >::type
 Shorthand notation of the stream deliverable type of the specified stream.
 
using DeliverablePtrType = std::shared_ptr< typename Internal::DeliverableTraits< Stream >::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 inherited from StreamHandlerBase< Stream >
void Run ()
 Start the handler. More...
 
bool TryFinish () noexcept
 Stop the handler. More...
 
void Finish ()
 Stop the handler. More...
 
bool IsActive () const noexcept
 Check if the acquisition thread is running. More...
 

Detailed Description

Handler object for multiple synchronous streams.

This handler provides a convenient way to acquire images from multiple synchronous streams within a dedicated thread. All streams for this handler must be synchronously (exactly the same frame rate). If this is not the case you will loose images. Please be aware, that there is no way for the application to verify, that the streams are synchronized. For multiple devices usually an external electrical synchronizations mechanism is provided.

For a single stream see SingleStreamHandler.

Example:
class MyMultiStreamHandler
{
public:
MyMultiStreamHandler(const std::vector<Cvb::StreamPtr> & streamVector)
:MultiStreamHandler(streamVector)
{
}
private:
void HandleAsyncStream(const std::vector<Cvb::StreamPtr> &streamVector) override
{
auto readData = 0;
for (auto & stream : streamVector)
{
auto result = stream->WaitFor<Cvb::RingBufferImage>(std::chrono::milliseconds(500));
// Do something.
}
}
};
Handler object for multiple synchronous streams.
Definition: decl_multi_stream_handler.hpp:58
virtual void HandleAsyncStream(const StreamVectorType &streamVector)
Asynchronously called for all registered streams.
Definition: detail_stream_handler_base.hpp:131
Stream image that is returned, when the ring buffer interface is available on a device.
Definition: decl_ring_buffer_image.hpp:29

Constructor & Destructor Documentation

◆ MultiStreamHandler()

MultiStreamHandler ( const std::vector< Driver::StreamPtr > &  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.

Member Function Documentation

◆ Create()

static std::unique_ptr< MultiStreamHandler > Create ( const std::vector< Driver::StreamPtr > &  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.