![]() |
ImFusion C++ SDK 4.4.0
|
#include <ImFusion/Stream/StreamGroup.h>
Templated stream group class for bundling multiple streams using the CRTP pattern. More...
Templated stream group class for bundling multiple streams using the CRTP pattern.
StreamGroup enables a proxy stream to manage an arbitrary number of substreams, coordinating their lifecycle and data emission. The proxy stream (template parameter Proxy) can be any class deriving from Stream (e.g., ImageStream, TrackingStream) or Stream itself, and serves as the representative and controller for all substreams.
Key features:
The proxy stream appears as a normal Stream in the data model, while substreams appear as child data objects through the CompoundData interface.
Example implementation for a tracking device with two camera streams:
| Proxy | The proxy stream class, which must derive from Stream and typically uses CRTP (e.g., class MyGroup : public Stream, public StreamGroup<MyGroup>). |
Public Member Functions | |
| StreamGroup (StreamGroup &&) noexcept | |
| StreamGroup & | operator= (StreamGroup &&other) noexcept |
| Stream * | proxyStream () override |
| Returns the non-owning pointer to the proxy stream, valid for the lifetime of the stream group. | |
| DataList | children () const override |
| Returns substreams as a non-owning list for the CompoundData interface. | |
| std::vector< Stream * > | substreams () const override |
| Returns all substreams in this stream group. | |
| Public Member Functions inherited from ImFusion::SignalReceiver | |
| SignalReceiver ()=default | |
| Default constructor. | |
| SignalReceiver (const SignalReceiver &other) | |
| Copy constructor, does not copy any existing signal connections from other. | |
| SignalReceiver & | operator= (SignalReceiver rhs) |
| Assignment operator, disconnects all existing connections, does not copy any existing signal connections from rhs. | |
| virtual | ~SignalReceiver () |
| Virtual destructor disconnects from all connected signals. | |
Protected Member Functions | |
| bool | addSubstream (std::unique_ptr< SubstreamBase > substream) override |
| Adds a substream to the stream group. | |
| bool | removeSubstream (Stream *substream) override |
| Removes a substream from the stream group. | |
| void | emitMainAndSubSignals (std::shared_ptr< const CompoundStreamData > tuple, bool emitSubstreamSignals=true) |
| Emits stream data via both compound and individual signals. | |
| Protected Member Functions inherited from ImFusion::StreamGroupBase | |
| void | reassignSubstream (SubstreamBase *substream) |
| Reassigns a substream to this stream group. | |
| Protected Member Functions inherited from ImFusion::Utils::NotCopyable | |
| NotCopyable (NotCopyable &&) noexcept=default | |
| NotCopyable & | operator= (NotCopyable &&) noexcept=default |
| NotCopyable (const NotCopyable &)=delete | |
| NotCopyable & | operator= (const NotCopyable &)=delete |
| Protected Member Functions inherited from ImFusion::SignalReceiver | |
| void | disconnectAll () |
| Disconnects all existing connections. | |
Additional Inherited Members | |
| Public Attributes inherited from ImFusion::StreamGroupBase | |
| ProtectedSignal< std::shared_ptr< const CompoundStreamData > > | signalNewStreamGroupData |
| Signal emitted when new stream data is available from the stream group. | |
| Public Attributes inherited from ImFusion::CompoundData | |
| Signal< Data * > | signalChildAdded |
| Signal emitted when a new Data instance has been added to children(). | |
| Signal< Data * > | signalChildMoved |
| Signal emitted when a Data instance has changed its position in children(). | |
| Signal< Data * > | signalChildAboutToBeRemoved |
| Signal emitted when a Data instance is about to be removed or taken from children(). | |
|
overridevirtual |
Returns the non-owning pointer to the proxy stream, valid for the lifetime of the stream group.
Convenience method that casts the stream group to its proxy stream.
Implements ImFusion::StreamGroupBase.
|
overridevirtualthreadsafe |
Returns substreams as a non-owning list for the CompoundData interface.
This method provides the child data objects for the CompoundData interface, enabling the stream group to appear as a hierarchical data structure in the data model. See substreams() for details on thread safety and livetime guarantees.
Can be called concurrently from any thread.
Implements ImFusion::CompoundData.
|
overridevirtualthreadsafe |
Returns all substreams in this stream group.
This method is thread-safe and returns a snapshot of the current substreams. The returned pointers remain valid even if substreams are removed concurrently, provided the removal happens during a doWork() execution and emitMainAndSubSignals() is called before the method returns.
Thread-safety guarantee: Substreams are guaranteed not to be deleted within a doWork() execution until emitMainAndSubSignals() completes. This allows safe iteration over substreams even if they are removed from another thread during the iteration.
Safe usage pattern in doWork():
Can be called concurrently from any thread.
Implements ImFusion::StreamGroupBase.
|
overrideprotectedvirtualthreadsafe |
Adds a substream to the stream group.
The substream must have been constructed with this stream group as its parent. Ownership is transferred to the stream group. The substream will be added to the data model as a child of this stream group.
Returns true if the substream was added successfully, false if the substream's parent does not match this group.
Can be called concurrently from any thread.
Implements ImFusion::StreamGroupBase.
|
overrideprotectedvirtualthreadsafe |
Removes a substream from the stream group.
The removal is always executed on the main thread to ensure data model consistency. If called from a worker thread, the actual removal is invoked on the main thread. The substream is not immediately deleted but moved to a garbage collection vector, with actual deletion occurring at the end of the next emitMainAndSubSignals() call.
Returns true if the substream was removed successfully, false if not found.
Can be called concurrently from any thread.
Implements ImFusion::StreamGroupBase.
|
protected |
Emits stream data via both compound and individual signals.
This method handles the coordinated emission of StreamData from all streams in the group:
This dual emission strategy allows receivers to either:
Thread safety: This method must be called after all operations working on a local copy of substreams() in the doWork() method. Actual deletion of removed substreams occurs at the end of this call, ensuring safe iteration in doWork().
Use this method instead of directly emitting signals to ensure consistency and thread safety.
| tuple | Shared pointer to the CompoundStreamData containing all stream data to emit. |
| emitSubstreamSignals | If false, skips emitting individual substream signals. Useful when substreams emit their own StreamData independently to avoid double emission. |