Ocean
|
This class implements a handler for scoped subscriptions to callback functions. More...
Public Types | |
using | CallbackFunctionType = TCallbackFunction |
Definition of the data type of the callback function. More... | |
Public Types inherited from Ocean::ScopedSubscriptionHandler | |
using | ScopedSubscriptionType = ScopedSubscriptionT< unsigned int, ScopedSubscriptionHandler > |
Definition of a scoped subscription object. More... | |
Public Member Functions | |
ScopedSubscriptionType | addCallback (TCallbackFunction callbackFunction) |
Adds a new callback function to this handler. More... | |
size_t | subscriptions () const |
Returns the number of subscriptions. More... | |
bool | isEmpty () const |
Returns whether no subscription exists. More... | |
Static Public Attributes | |
static constexpr bool | isThreadSafe_ = tThreadSafe |
True, if this handler is thread-safe. More... | |
Protected Types | |
using | CallbackMap = std::unordered_map< unsigned int, TCallbackFunction > |
Definition of an unordered map mapping subscription ids to callback functions. More... | |
Protected Member Functions | |
template<class... TArgs> | |
TCallbackFunction::result_type | callCallbacks (TArgs &&... args) |
Calls all callback functions of this handler. More... | |
void | removeCallback (const unsigned int &subscriptionId) |
Removes a callback function from the handler. More... | |
Protected Member Functions inherited from Ocean::ScopedSubscriptionHandler | |
ScopedSubscriptionType | scopedSubscription (const unsigned int &subscriptionId, ScopedSubscriptionType::ReleaseCallbackFunction releaseCallbackFunction) |
Returns the subscription object for a given subscription id. More... | |
Protected Attributes | |
CallbackMap | callbackMap_ |
The map mapping subscription ids to callback functions. More... | |
unsigned int | subscriptionIdCounter_ = 0u |
The counter for subscription ids. More... | |
TemplatedLock< tThreadSafe > | lock_ |
The optional lock object. More... | |
Private Attributes | |
friend | TOwner |
This class implements a handler for scoped subscriptions to callback functions.
The class mainly wraps a counter for subscription ids and a map holding the callback functions.
TCallbackFunction | The data type of the callback function |
TOwner | The owner of this handler (the class in which the handler will be located) |
tThreadSafe | True, to make the handler thread-safe |
using Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::CallbackFunctionType = TCallbackFunction |
Definition of the data type of the callback function.
|
protected |
Definition of an unordered map mapping subscription ids to callback functions.
ScopedSubscriptionHandler::ScopedSubscriptionType Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::addCallback | ( | TCallbackFunction | callbackFunction | ) |
Adds a new callback function to this handler.
callbackFunction | The callback function to add, must be valid |
|
protected |
Calls all callback functions of this handler.
args | The arguments of the callback function |
TArgs | The data types of the callback functions |
bool Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::isEmpty |
Returns whether no subscription exists.
|
protected |
Removes a callback function from the handler.
subscriptionId | The id of the subscription to be removed |
size_t Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::subscriptions |
Returns the number of subscriptions.
|
protected |
The map mapping subscription ids to callback functions.
|
staticconstexpr |
True, if this handler is thread-safe.
|
mutableprotected |
The optional lock object.
|
protected |
The counter for subscription ids.
|
private |