summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Soldatov <a.soldatov@yadro.com>2018-11-23 14:37:50 +0300
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2018-12-06 14:02:47 +0000
commit78a5df906f563c99c451ea2355917ce414685a30 (patch)
tree74b88e89e3ae4dbc17753e5dd268893b5bc7ffde /src
parent223c40931e4f413431ab2f84d92c5f404e2d9cf2 (diff)
downloadphosphor-dbus-monitor-78a5df906f563c99c451ea2355917ce414685a30.tar.gz
phosphor-dbus-monitor-78a5df906f563c99c451ea2355917ce414685a30.zip
Saving current context in DeferrableCallback added.
DeferrableCallback operator() saves the context in self instance. When the timer expires, it calls operator() for the ConditionalCallback with the context saved in DeferrableCallback instance. Resolves openbmc/phosphor-dbus-monitor#1 Change-Id: I8d235b0747005c403829f8262d0290548b0a9910 Signed-off-by: Alexander Soldatov <a.soldatov@yadro.com>
Diffstat (limited to 'src')
-rw-r--r--src/callback.hpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/callback.hpp b/src/callback.hpp
index 0be7dc0..b1c8d0b 100644
--- a/src/callback.hpp
+++ b/src/callback.hpp
@@ -227,6 +227,12 @@ class DeferrableCallback : public ConditionalCallback<CallbackAccess>
{
}
+ /** @brief Start internal timer if the condition is satisfied.
+ *
+ * When the timer expires, it calls operator() for the
+ * ConditionalCallback with the context saved in
+ * DeferrableCallback instance.
+ */
void operator()(Context ctx) override
{
if (!timer)
@@ -234,8 +240,10 @@ class DeferrableCallback : public ConditionalCallback<CallbackAccess>
timer = std::make_unique<TimerType>(
sdeventplus::Event::get_default(),
// **INDENT-OFF**
- [ctx, this](auto& source) {
- this->ConditionalCallback<CallbackAccess>::operator()(ctx);
+ [this](auto& source) {
+ // The timer uses the context saved on timer enable
+ this->ConditionalCallback<CallbackAccess>::operator()(
+ this->ctx);
});
// **INDENT-ON**
}
@@ -245,6 +253,8 @@ class DeferrableCallback : public ConditionalCallback<CallbackAccess>
if (!timer->isEnabled())
{
// This is the first time the condition evaluated.
+ // Save current context for timer use.
+ this->ctx = ctx;
// Start the countdown.
timer->restartOnce(delayInterval);
}
@@ -262,6 +272,9 @@ class DeferrableCallback : public ConditionalCallback<CallbackAccess>
/** @brief Delegated timer functions. */
std::unique_ptr<TimerType> timer;
+
+ /** @brief Current context for timer. */
+ Context ctx;
};
} // namespace monitoring
OpenPOWER on IntegriCloud