6 #ifndef UTILS_NOTIFIER_H 7 #define UTILS_NOTIFIER_H 12 #include <condition_variable> 20 template <
typename... Args>
38 inline virtual void Notify(Args... args)
68 template <
typename... Args>
74 inline virtual void Notify(Args... args)
override 79 tuples_.emplace_back(std::tuple<Args...>(args...));
81 notifier_condition_.notify_all();
88 for (
const auto &tuple : tuples_)
92 callback(std::get<Args>(tuple) ...);
96 notifier_condition_.notify_all();
103 notifier_condition_.wait(lock, [
this]() {
return tuples_.empty(); });
std::condition_variable notifier_condition_
Condition variable to trigger rechecking conditions.
Definition: Notifier.h:110
std::vector< CallbackType > callbacks_
The callbacks.
Definition: Notifier.h:55
An extension to Notifier - does not notify by itself. Instead it collects notifications and allows ex...
Definition: Notifier.h:69
bool HasCallback() const
Returns whether it has any callback registered.
Definition: Notifier.h:48
std::function< void(Args...)> CallbackType
The callback is a void function taking the variadic templated arguments of the Notifier class...
Definition: Notifier.h:25
virtual void Notify(Args... args)
Send all notifications at this moment.
Definition: Notifier.h:38
std::mutex notifier_access_
mutex to ensure thread safety.
Definition: Notifier.h:57
A notifier is a mechanism to allow inter-object notifications.
Definition: Notifier.h:21
virtual void SendAllNotifications()
Send all collected notifications at this moment.
Definition: Notifier.h:85
void AddCallback(CallbackType callback)
Add a single callback function.
Definition: Notifier.h:28
std::vector< std::tuple< Args... > > tuples_
The collected arguments to be executed on the next execution loop call.
Definition: Notifier.h:108
virtual void Notify(Args... args) override
Notify does not execute all notifications - it merely collects the arguments and allows the Owner to ...
Definition: Notifier.h:74
virtual void WaitUntilAllSent()
Wait until all notifications are sent.
Definition: Notifier.h:100
General namespace for utilities.
Definition: BulletConversions.h:9