utility/timer: Callback should pass in the timer
This makes the timer better resemble the other source types, and makes
it easier to access timer properties from the callback.
Since we do not yet have any committed users of this API it is safe to
change it.
Tested:
Unit tests were run and builds work fine.
Change-Id: I9ecb24a20bc822b2ab55900e47a7cae834ba873d
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/sdeventplus/utility/timer.cpp b/src/sdeventplus/utility/timer.cpp
index 6ad684c..7c75e07 100644
--- a/src/sdeventplus/utility/timer.cpp
+++ b/src/sdeventplus/utility/timer.cpp
@@ -102,7 +102,7 @@
expired = true;
if (callback)
{
- callback();
+ callback(*this);
}
resetRemaining();
}
diff --git a/src/sdeventplus/utility/timer.hpp b/src/sdeventplus/utility/timer.hpp
index a9d4fbc..8865ba1 100644
--- a/src/sdeventplus/utility/timer.hpp
+++ b/src/sdeventplus/utility/timer.hpp
@@ -31,7 +31,7 @@
/** @brief Type of the user provided callback function when the
* timer elapses.
*/
- using Callback = std::function<void()>;
+ using Callback = std::function<void(Timer<Id>&)>;
Timer(const Timer& other) = delete;
Timer(Timer&& other) = default;
diff --git a/test/utility/timer.cpp b/test/utility/timer.cpp
index c919f7e..414ad82 100644
--- a/test/utility/timer.cpp
+++ b/test/utility/timer.cpp
@@ -91,7 +91,7 @@
.WillRepeatedly(DoAll(EventUnref(), Return(nullptr)));
Event event(expected_event, &mock);
- auto runCallback = [&]() {
+ auto runCallback = [&](TestTimer&) {
if (callback)
{
callback();