utility/timer: Make it possible to get the Event
Other event sources expose the ability to get th event used for
constructing the source. Since our timer is basically just a time
source, we should be able to trivially get the event object.
Tested:
Built and run through unit tests
Change-Id: I4b4192797652a903cba90d6e73771014df7702d6
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 dfe4ca7..979c0af 100644
--- a/src/sdeventplus/utility/timer.cpp
+++ b/src/sdeventplus/utility/timer.cpp
@@ -24,6 +24,12 @@
}
template <ClockId Id>
+const Event& Timer<Id>::get_event() const
+{
+ return timeSource.get_event();
+}
+
+template <ClockId Id>
bool Timer<Id>::hasExpired() const
{
return expired;
diff --git a/src/sdeventplus/utility/timer.hpp b/src/sdeventplus/utility/timer.hpp
index 301842b..f5d4766 100644
--- a/src/sdeventplus/utility/timer.hpp
+++ b/src/sdeventplus/utility/timer.hpp
@@ -61,6 +61,12 @@
typename source::Time<Id>::Accuracy accuracy =
std::chrono::milliseconds{1});
+ /** @brief Gets the associated Event object
+ *
+ * @return The Event
+ */
+ const Event& get_event() const;
+
/** @brief Has the timer expired since creation or reset of expiration
* state.
*
diff --git a/test/utility/timer.cpp b/test/utility/timer.cpp
index a329287..6d5dff0 100644
--- a/test/utility/timer.cpp
+++ b/test/utility/timer.cpp
@@ -136,6 +136,7 @@
SaveArg<5>(&handler), Return(0)));
expectSetEnabled(source::Enabled::On);
timer = std::make_unique<TestTimer>(*event, runCallback, interval);
+ EXPECT_EQ(expected_event, timer->get_event().get());
}
void TearDown()