Utilities
Utilities header only library
utils::DelegatedNotifier< Args > Class Template Reference

An extension to Notifier - does not notify by itself. Instead it collects notifications and allows external code to call them when it pleases. More...

Inheritance diagram for utils::DelegatedNotifier< Args >:
[legend]

Public Member Functions

virtual void Notify (Args... args) override
 Notify does not execute all notifications - it merely collects the arguments and allows the Owner to execute them when it pleases.
 
virtual void SendAllNotifications ()
 Send all collected notifications at this moment.
 
virtual void WaitUntilAllSent ()
 Wait until all notifications are sent.
 
- Public Member Functions inherited from utils::Notifier< Args... >
void AddCallback (CallbackType callback)
 Add a single callback function.
 
bool HasCallback () const
 Returns whether it has any callback registered.
 

Protected Attributes

std::vector< std::tuple< Args... > > tuples_
 The collected arguments to be executed on the next execution loop call.
 
std::condition_variable notifier_condition_
 Condition variable to trigger rechecking conditions.
 
- Protected Attributes inherited from utils::Notifier< Args... >
std::vector< CallbackType > callbacks_
 The callbacks.
 
std::mutex notifier_access_
 mutex to ensure thread safety.
 

Additional Inherited Members

- Public Types inherited from utils::Notifier< Args... >
using CallbackType = std::function< void(Args...)>
 The callback is a void function taking the variadic templated arguments of the Notifier class.
 

Detailed Description

template<typename... Args>
class utils::DelegatedNotifier< Args >

An extension to Notifier - does not notify by itself. Instead it collects notifications and allows external code to call them when it pleases.

Note
The motivation is thread safety. The usage is that the owner (to whom the notification functionality is delegated), must call the SendAllNotifications function at the appropriate moment.