Add callback contexts
Add the notion of a callback context. This enables callbacks
to have logic around the conditions they were invoked in.
There are two context on which call back can be invoked
1) Startup: during startup all the call backs will be called
2) Signal: As part of condition match on the watched properties.
Callback would behave differently based on the context.
eg: eventCallback
1) Startup: Don't take any action.
2) Signal: Create the Dbus Object for the event.
Change-Id: If455558798ac3e44bbd8a93de0ce1b09d2e308ae
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/src/callback.hpp b/src/callback.hpp
index 1d248bd..d476d97 100644
--- a/src/callback.hpp
+++ b/src/callback.hpp
@@ -25,8 +25,14 @@
Callback& operator=(Callback&&) = default;
virtual ~Callback() = default;
- /** @brief Run the callback. */
- virtual void operator()() = 0;
+ /** @brief Run the callback.
+ * @param[in] ctx - caller context
+ * Context could be Startup or Signal
+ * Startup: Callback is called as part of process startup.
+ * Signal: Callback is called as part of watch condition has been met.
+ *
+ */
+ virtual void operator()(Context ctx) = 0;
};
/** @class Conditional
@@ -89,7 +95,7 @@
: Callback(), index(callbackIndex) {}
/** @brief Run the callback. */
- virtual void operator()() override = 0;
+ virtual void operator()(Context ctx) override = 0;
protected:
@@ -122,11 +128,11 @@
: graph(graphEntry) {}
/** @brief Run the callbacks. */
- void operator()() override
+ void operator()(Context ctx) override
{
for (auto e : graph)
{
- (*CallbackAccess::get()[e])();
+ (*CallbackAccess::get()[e])(ctx);
}
}
@@ -154,11 +160,11 @@
: graph(graphEntry), condition(cond) {}
/** @brief Run the callback if the condition is satisfied. */
- virtual void operator()() override
+ virtual void operator()(Context ctx) override
{
if (condition())
{
- (*CallbackAccess::get()[graph[0]])();
+ (*CallbackAccess::get()[graph[0]])(ctx);
}
}
@@ -202,15 +208,15 @@
delayInterval(delay),
timer(nullptr) {}
- void operator()() override
+ void operator()(Context ctx) override
{
if (!timer)
{
timer = std::make_unique<TimerType>(
// **INDENT-OFF**
- [this](auto & source)
+ [ctx, this](auto & source)
{
- this->ConditionalCallback<CallbackAccess>::operator()();
+ this->ConditionalCallback<CallbackAccess>::operator()(ctx);
});
// **INDENT-ON**
timer->disable();