Invoke optional callback function on timer expiration
When the timer expires, it calls into it's own timeout
handler which matches with sd_event callback handler.
However, it is beneficial if the users of timer register
their own callback routine so that they can execute some
operations on timeout.
Change-Id: Ia88cb4e3c17f6dd8d4528fa193ec7927f083a92b
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/timer.hpp b/timer.hpp
index 49580d7..2ade017 100644
--- a/timer.hpp
+++ b/timer.hpp
@@ -43,10 +43,14 @@
/** @brief Constructs timer object
*
- * @param[in] event - sd_event unique pointer reference
+ * @param[in] event - sd_event unique pointer
+ * @param[in] userCallBack - Optional function callback
+ * for timer expiration
*/
- Timer(EventPtr& event)
- : event(event)
+ Timer(EventPtr& event,
+ std::function<void()> userCallBack = nullptr)
+ : event(event),
+ userCallBack(userCallBack)
{
// Initialize the timer
initialize();
@@ -100,6 +104,11 @@
/** @brief Set to true when the timeoutHandler is called into */
bool expire = false;
+ /** @brief Optional function to call on timer expiration
+ * This is called from timeout handler.
+ */
+ std::function<void()> userCallBack;
+
/** @brief Initializes the timer object with infinite
* expiration time and sets up the callback handler
*