template class utils::DelegatedNotifier — HIRO 0.7.0 documentation

# template class utils::DelegatedNotifier

## Overview

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

    #include <Notifier.h>

    template <typename... Args>
    class DelegatedNotifier: public utils::Notifier {
    public:
        // methods

        virtual void Notify(Args... args);
        virtual void SendAllNotifications();
        virtual void WaitUntilAllSent();

    protected:
        // fields

        std::vector<std::tuple<Args...>> tuples_;
        std::condition_variable notifier_condition_;
    };

### Inherited Members

    public:
        // typedefs

        typedef std::function<void(Args...)> CallbackType;

        // methods

        void AddCallback(CallbackType callback);
        virtual void Notify(Args... args);
        bool HasCallback() const;

    protected:
        // fields

        std::vector<CallbackType> callbacks_;
        std::mutex notifier_access_;

## Detailed Documentation

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

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.

### Fields

    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.

### Methods

    virtual void Notify(Args... args)

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.