From 49e661750ceed68ada3f3ae00d6d1620800c1f5f Mon Sep 17 00:00:00 2001 From: Brad Bishop Date: Tue, 23 May 2017 19:16:21 -0400 Subject: Add callback groups Allow named collections of callbacks to be defined and used anywhere callbacks are used. Change-Id: I3224aa06b2250e9a055bc70d20c186caecd033af Signed-off-by: Brad Bishop --- src/callback.hpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/callback.hpp') diff --git a/src/callback.hpp b/src/callback.hpp index d7a678c..7c6f69b 100644 --- a/src/callback.hpp +++ b/src/callback.hpp @@ -52,6 +52,44 @@ class IndexedCallback : public Callback const PropertyIndex& index; }; +/** @class GroupOfCallbacks + * @brief Invoke multiple callbacks. + * + * A group of callbacks is implemented as a vector of array indicies + * into an external array of callbacks. The group function call + * operator traverses the vector of indicies, invoking each + * callback. + * + * @tparam CallbackAccess - Access to the array of callbacks. + */ +template +class GroupOfCallbacks : public Callback +{ + public: + GroupOfCallbacks() = delete; + GroupOfCallbacks(const GroupOfCallbacks&) = delete; + GroupOfCallbacks(GroupOfCallbacks&&) = default; + GroupOfCallbacks& operator=(const GroupOfCallbacks&) = delete; + GroupOfCallbacks& operator=(GroupOfCallbacks&&) = default; + ~GroupOfCallbacks() = default; + explicit GroupOfCallbacks( + const std::vector& graphEntry) + : graph(graphEntry) {} + + /** @brief Run the callbacks. */ + void operator()() override + { + for (auto e : graph) + { + (*CallbackAccess::get()[e])(); + } + } + + private: + /** @brief The offsets of the callbacks in the group. */ + const std::vector& graph; +}; + } // namespace monitoring } // namespace dbus } // namespace phosphor -- cgit v1.2.1