diff options
author | Ratan Gupta <ratagupt@in.ibm.com> | 2018-02-21 19:03:13 +0530 |
---|---|---|
committer | Ratan Gupta <ratagupt@in.ibm.com> | 2018-02-22 21:05:19 +0530 |
commit | a45e086dc57f51efb882bf864e78fe678238deea (patch) | |
tree | 47099446e3b5f83528435a46af0efc90dd395d2a /src/callback.hpp | |
parent | 882d741c2392e2c37c2fbdaf1207e64ea6dc91a7 (diff) | |
download | phosphor-dbus-monitor-a45e086dc57f51efb882bf864e78fe678238deea.tar.gz phosphor-dbus-monitor-a45e086dc57f51efb882bf864e78fe678238deea.zip |
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>
Diffstat (limited to 'src/callback.hpp')
-rw-r--r-- | src/callback.hpp | 26 |
1 files changed, 16 insertions, 10 deletions
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 @@ class Callback 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 @@ class IndexedCallback : public Callback : Callback(), index(callbackIndex) {} /** @brief Run the callback. */ - virtual void operator()() override = 0; + virtual void operator()(Context ctx) override = 0; protected: @@ -122,11 +128,11 @@ class GroupOfCallbacks : public Callback : 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 @@ class ConditionalCallback: public Callback : 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 @@ class DeferrableCallback : public ConditionalCallback<CallbackAccess> 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(); |