diff options
author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-05-23 19:16:21 -0400 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-06-19 16:26:47 -0400 |
commit | 49e661750ceed68ada3f3ae00d6d1620800c1f5f (patch) | |
tree | 4dd9ae109b41aa488b360d36e52f7deb2ee02782 /src/callback.hpp | |
parent | 3ce5c484aa9d25927b106f9bd3f819ec861176ad (diff) | |
download | phosphor-dbus-monitor-49e661750ceed68ada3f3ae00d6d1620800c1f5f.tar.gz phosphor-dbus-monitor-49e661750ceed68ada3f3ae00d6d1620800c1f5f.zip |
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 <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'src/callback.hpp')
-rw-r--r-- | src/callback.hpp | 38 |
1 files changed, 38 insertions, 0 deletions
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 <typename CallbackAccess> +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<size_t>& 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<size_t>& graph; +}; + } // namespace monitoring } // namespace dbus } // namespace phosphor |