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.cpp b/timer.cpp
index bf1a470..c98dcb0 100644
--- a/timer.cpp
+++ b/timer.cpp
@@ -44,12 +44,16 @@
{
using namespace phosphor::logging;
+ log<level::INFO>("Timer Expired");
+
auto timer = static_cast<Timer*>(userData);
timer->expire = true;
- log<level::INFO>("Timer Expired");
-
- //TODO: Need to call user callback function.
+ // Call an optional callback function
+ if(timer->userCallBack)
+ {
+ timer->userCallBack();
+ }
return 0;
}