Handler object for multiple synchronous streams.
More...
#include <cvb/async/multi_stream_handler.hpp>
Inherited by SingleStreamHandler.
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:
{
}
private:
{
auto readData = 0;
for (auto & stream : streamVector)
{
}
}
};
Handler object for multiple synchronous streams.
Definition: decl_multi_stream_handler.hpp:64
virtual void HandleAsyncStream(const std::vector< Driver::StreamPtr > &streamVector)
Asynchronously called for all registered streams.
Definition: detail_multi_stream_handler.hpp:84
Stream image that is returned, when the ring buffer interface is available on a device.
Definition: decl_ring_buffer_image.hpp:29
◆ MultiStreamHandler()
Creates a stream handler object.
- Parameters
-
[in] | streamVector | List with synchronous streams. |
- Exceptions
-
Call this in a customized subclass to setup the handler.
◆ Begin()
|
inlineprotectedvirtualnoexcept |
Performs custom operations at the beginning of the acquisition thread.
- Exceptions
-
Does | not 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()
Create a stream handler object.
- Parameters
-
[in] | streamVector | List with synchronous streams. |
- Returns
- A stream handler object.
- Exceptions
-
- Note
- You must not destroy a stream handler that is currently running. In order to prevent that you may use a StreamHandlerGuard.
◆ End()
|
inlineprotectedvirtualnoexcept |
Performs custom operations just before the end of the acquisition thread.
- Exceptions
-
Does | not 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()
Stop the handler.
- Exceptions
-
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()
Asynchronously called for all registered streams.
- Parameters
-
[in] | streamVector | List with synchronous streams (provided at creation). |
- Exceptions
-
The default implementation just waits for the next image on each stream.
- Attention
- This method is called on a dedicated thread!
◆ HandleAsyncWaitResult()
Asynchronously called for all acquired images.
- Parameters
-
[in] | waitResultVector | List with synchronous acquired WaitResults. |
- Exceptions
-
The default implementation does nothing.
- Attention
- This method is called on a dedicated thread!
◆ HandleError()
|
inlineprotectedvirtualnoexcept |
Handles standard exceptions in the acquisition thread.
- Parameters
-
[in] | &error | The exception thrown. |
- Exceptions
-
Does | not 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()
Check if the acquisition thread is running.
- Returns
- True if running otherwise false.
- Exceptions
-
Does | not throw any exception. |
◆ Run()
Start the handler.
- Exceptions
-
This will call Setup() on the calling thread, before createing a dedicated acquisition thread. The acquisition thread will repeatedly call HandleAsyncStream().
◆ Setup()
Setup the streams for acquisition.
- Parameters
-
[in] | streamVector | List with synchronous streams (provided at creation). |
- Exceptions
-
The default implementation just calls Stream::Start() for each stream.
◆ StreamVector()
Get the streams associated with this handler.
- Returns
- Stream vector.
- Exceptions
-
Does | not throw any exception. |
◆ TearDown()
|
inlineprotectedvirtualnoexcept |
Tear down the streams after acquisition.
- Parameters
-
[in] | streamVector | List with synchronous streams (provided at creation). |
- Exceptions
-
Does | not throw any exception. |
The default implemntation just calls Stream::TryAbort() for each stream.
◆ TryFinish()
Stop the handler.
- Returns
- True if no error occurred in the acquisition thread, otherwise.
- Exceptions
-
Does | not 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.