diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/callback.hpp | 17 |
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 |