siplasplas
A library for C++ reflection and introspection
cpp::AsyncSink Class Reference

Implements an asynchronous signal sink suited for communication between different threads. More...

#include <siplasplas/signals/asyncsink.hpp>

Inheritance diagram for cpp::AsyncSink:
cpp::SignalSink

Public Member Functions

template<typename Caller , typename Function >
 AsyncSink (Caller &caller, Function function)
 Creates an asynchronous sink given a caller and a destination function. More...
 
template<typename Caller , typename Callee , typename Function >
 AsyncSink (Caller &caller, Callee &callee, Function function)
 Creates an asynchronous sink given a caller, a callee, and a destination function. More...
 
bool pull () override
 Checks whether there are queued signal emissions waiting to be handled and invokes the destination function for each of them. More...
 
- Public Member Functions inherited from cpp::SignalSink
template<typename Caller , typename Callee >
 SignalSink (Caller &caller, Callee &callee)
 Constructs a sink given the connection caller and the callee. More...
 
template<typename Caller >
 SignalSink (Caller &caller)
 Constructs a sink given the connection caller object. More...
 
template<typename... Args>
void operator() (Args &&...args)
 Invokes the sink with the given arguments. More...
 
SignalEmittercallee () const
 Gives the callee of the connection. More...
 
SignalEmittercaller () const
 Gives the caller of the connection. More...
 

Protected Member Functions

void invoke (std::vector< cpp::SimpleAny32 > &&args) override
 
bool invokeWithoutCallee () const override
 

Detailed Description

Implements an asynchronous signal sink suited for communication between different threads.

The AsyncSink class implements a sink that by default enqueues signal emissions in a thread safe queue. The destination function is invoked only when the user asks for incomming signals by pulling the sink. See AsyncSInk::pull().

Constructor & Destructor Documentation

template<typename Caller , typename Function >
cpp::AsyncSink::AsyncSink ( Caller &  caller,
Function  function 
)
inline

Creates an asynchronous sink given a caller and a destination function.

See SignalEmitter::connect_async()

Parameters
callerCaller object.
functionFunction to be invoked when the signal is handled.
template<typename Caller , typename Callee , typename Function >
cpp::AsyncSink::AsyncSink ( Caller &  caller,
Callee &  callee,
Function  function 
)
inline

Creates an asynchronous sink given a caller, a callee, and a destination function.

See SignalEmitter::connect_async()

Parameters
callerCaller object.
calleeCallee object.
functionFunction to be invoked when the signal is handled.

Member Function Documentation

bool cpp::AsyncSink::pull ( )
overridevirtual

Checks whether there are queued signal emissions waiting to be handled and invokes the destination function for each of them.

The AsyncSink::pull() method fetches pending signals emissions (That is, argument sets from previous signal emissions from the caller object) and invokes the destination function using that arguments, once for each arguments set in the queue. This function continues invoking the destination function until the queue is empty. The destination function is executed from the same thread pull() was invoked.

Returns
true if at lest one pending signal emission was processed, false if the queue was empty.

Implements cpp::SignalSink.


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