PicoScenes API Docs
 
Loading...
Searching...
No Matches
AsyncPipeline< ObjectType > Class Template Reference

Template class implementing an asynchronous processing pipeline. More...

#include <AsyncPipeline.hxx>

Public Member Functions

AsyncPipelinestartService ()
 Starts the pipeline service.
 
void stopService ()
 Stops the pipeline service.
 
template<typename T >
uint64_t send (T &&object)
 Sends an object to the pipeline for asynchronous processing.
 
template<typename T >
uint64_t sendSync (T &&object)
 Sends an object to the pipeline and waits for processing completion.
 
int pause ()
 Pauses the pipeline processing.
 
int resume ()
 Resumes the pipeline processing.
 
AsyncPipeline< ObjectType > & registerAsyncHandler (std::string handlerName, std::function< void(const ObjectType &object)> handler)
 Registers an asynchronous handler for processing objects.
 
std::optional< ObjectType > selectDataByCondition (const std::function< bool(const ObjectType &)> &condition, const std::chrono::milliseconds &maxWait_ms, std::optional< std::string > conditionName)
 Selects data from the pipeline based on a condition.
 
AsyncPipeline< ObjectType > & unregisterHandler (const std::string &handlerName)
 Unregisters a handler from the pipeline.
 
bool hasHandler (const std::string &handlerName)
 Checks if a handler exists in the pipeline.
 
bool isPipelineRunning () const
 Checks if the pipeline is currently running.
 
bool isPipelinePaused () const
 Checks if the pipeline is currently paused.
 

Detailed Description

template<typename ObjectType>
class AsyncPipeline< ObjectType >

Template class implementing an asynchronous processing pipeline.

AsyncPipeline provides a thread-safe mechanism for processing objects asynchronously through a series of registered handlers. It supports operations like starting, stopping, pausing, and resuming the pipeline, as well as synchronous and asynchronous object processing.

Template Parameters
ObjectTypeThe type of objects to be processed in the pipeline

Definition at line 24 of file AsyncPipeline.hxx.

Member Function Documentation

◆ hasHandler()

template<typename ObjectType >
bool AsyncPipeline< ObjectType >::hasHandler ( const std::string &  handlerName)
inline

Checks if a handler exists in the pipeline.

Parameters
handlerNameName of the handler to check
Returns
true if handler exists, false otherwise

Definition at line 194 of file AsyncPipeline.hxx.

◆ isPipelinePaused()

template<typename ObjectType >
bool AsyncPipeline< ObjectType >::isPipelinePaused ( ) const
inline

Checks if the pipeline is currently paused.

Returns
true if pipeline is paused, false otherwise

Definition at line 212 of file AsyncPipeline.hxx.

◆ isPipelineRunning()

template<typename ObjectType >
bool AsyncPipeline< ObjectType >::isPipelineRunning ( ) const
inline

Checks if the pipeline is currently running.

Returns
true if pipeline is running, false otherwise

Definition at line 203 of file AsyncPipeline.hxx.

◆ pause()

template<typename ObjectType >
int AsyncPipeline< ObjectType >::pause ( )
inline

Pauses the pipeline processing.

Returns
0 on success

Definition at line 109 of file AsyncPipeline.hxx.

◆ registerAsyncHandler()

template<typename ObjectType >
AsyncPipeline< ObjectType > & AsyncPipeline< ObjectType >::registerAsyncHandler ( std::string  handlerName,
std::function< void(const ObjectType &object)>  handler 
)
inline

Registers an asynchronous handler for processing objects.

Parameters
handlerNameUnique name for the handler
handlerFunction to process objects of ObjectType
Returns
Reference to this AsyncPipeline instance

Definition at line 133 of file AsyncPipeline.hxx.

Referenced by AsyncPipeline< ObjectType >::selectDataByCondition().

◆ resume()

template<typename ObjectType >
int AsyncPipeline< ObjectType >::resume ( )
inline

Resumes the pipeline processing.

Returns
0 on success

Definition at line 120 of file AsyncPipeline.hxx.

◆ selectDataByCondition()

template<typename ObjectType >
std::optional< ObjectType > AsyncPipeline< ObjectType >::selectDataByCondition ( const std::function< bool(const ObjectType &)> &  condition,
const std::chrono::milliseconds &  maxWait_ms,
std::optional< std::string >  conditionName 
)
inline

Selects data from the pipeline based on a condition.

Parameters
conditionFunction that evaluates whether an object meets the selection criteria
maxWait_msMaximum time to wait for matching data
conditionNameOptional name for the condition handler
Returns
Optional containing the selected object if found

Definition at line 148 of file AsyncPipeline.hxx.

References AsyncPipeline< ObjectType >::registerAsyncHandler(), and AsyncPipeline< ObjectType >::unregisterHandler().

◆ send()

template<typename ObjectType >
template<typename T >
uint64_t AsyncPipeline< ObjectType >::send ( T &&  object)
inline

Sends an object to the pipeline for asynchronous processing.

Template Parameters
TType of the object being sent (enables perfect forwarding)
Parameters
objectObject to be processed
Returns
Tracking ID for the sent object

Definition at line 73 of file AsyncPipeline.hxx.

Referenced by AsyncPipeline< ObjectType >::sendSync().

◆ sendSync()

template<typename ObjectType >
template<typename T >
uint64_t AsyncPipeline< ObjectType >::sendSync ( T &&  object)
inline

Sends an object to the pipeline and waits for processing completion.

Template Parameters
TType of the object being sent (enables perfect forwarding)
Parameters
objectObject to be processed
Returns
Tracking ID for the sent object

Definition at line 90 of file AsyncPipeline.hxx.

References AsyncPipeline< ObjectType >::send().

◆ startService()

template<typename ObjectType >
AsyncPipeline & AsyncPipeline< ObjectType >::startService ( )
inline

Starts the pipeline service.

Initializes the pipeline state and starts the service loop in a separate thread.

Returns
Reference to this AsyncPipeline instance

Definition at line 33 of file AsyncPipeline.hxx.

References Singleton< T >::getInstance().

◆ stopService()

template<typename ObjectType >
void AsyncPipeline< ObjectType >::stopService ( )
inline

Stops the pipeline service.

Stops the pipeline, clears all handlers and buffered objects, and waits for completion.

Definition at line 49 of file AsyncPipeline.hxx.

◆ unregisterHandler()

template<typename ObjectType >
AsyncPipeline< ObjectType > & AsyncPipeline< ObjectType >::unregisterHandler ( const std::string &  handlerName)
inline

Unregisters a handler from the pipeline.

Parameters
handlerNameName of the handler to remove
Returns
Reference to this AsyncPipeline instance

Definition at line 179 of file AsyncPipeline.hxx.

Referenced by AsyncPipeline< ObjectType >::selectDataByCondition().


The documentation for this class was generated from the following file: