summaryrefslogtreecommitdiffstats
path: root/src/callback.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/callback.hpp')
-rw-r--r--src/callback.hpp38
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
OpenPOWER on IntegriCloud