event: Allow extracting the event and sdevent impl
diff --git a/src/sdeventplus/event.cpp b/src/sdeventplus/event.cpp
index 1d31f91..f65750e 100644
--- a/src/sdeventplus/event.cpp
+++ b/src/sdeventplus/event.cpp
@@ -44,6 +44,16 @@
return Event(event, std::false_type(), sdevent);
}
+sd_event* Event::get() const
+{
+ return event.get();
+}
+
+const internal::SdEvent* Event::getSdEvent() const
+{
+ return sdevent;
+}
+
int Event::loop() const
{
int r = sdevent->sd_event_loop(event.get());
diff --git a/src/sdeventplus/event.hpp b/src/sdeventplus/event.hpp
index a583dfb..b979cfc 100644
--- a/src/sdeventplus/event.hpp
+++ b/src/sdeventplus/event.hpp
@@ -20,6 +20,9 @@
static Event
get_default(const internal::SdEvent* sdevent = &internal::sdevent_impl);
+ sd_event* get() const;
+ const internal::SdEvent* getSdEvent() const;
+
int loop() const;
int get_watchdog() const;
int set_watchdog(int b) const;
diff --git a/test/event.cpp b/test/event.cpp
index ef762b8..7149ac4 100644
--- a/test/event.cpp
+++ b/test/event.cpp
@@ -27,6 +27,8 @@
EXPECT_CALL(mock, sd_event_ref(expected_event))
.WillOnce(Return(expected_event));
Event event(expected_event, &mock);
+ EXPECT_EQ(&mock, event.getSdEvent());
+ EXPECT_EQ(expected_event, event.get());
EXPECT_CALL(mock, sd_event_unref(expected_event)).WillOnce(Return(nullptr));
}
@@ -34,6 +36,8 @@
TEST_F(EventTest, NewEventNoRef)
{
Event event(expected_event, std::false_type(), &mock);
+ EXPECT_EQ(&mock, event.getSdEvent());
+ EXPECT_EQ(expected_event, event.get());
EXPECT_CALL(mock, sd_event_unref(expected_event)).WillOnce(Return(nullptr));
}
@@ -43,6 +47,8 @@
EXPECT_CALL(mock, sd_event_new(testing::_))
.WillOnce(DoAll(SetArgPointee<0>(expected_event), Return(0)));
Event event = Event::get_new(&mock);
+ EXPECT_EQ(&mock, event.getSdEvent());
+ EXPECT_EQ(expected_event, event.get());
EXPECT_CALL(mock, sd_event_unref(expected_event)).WillOnce(Return(nullptr));
}
@@ -58,6 +64,8 @@
EXPECT_CALL(mock, sd_event_default(testing::_))
.WillOnce(DoAll(SetArgPointee<0>(expected_event), Return(0)));
Event event = Event::get_default(&mock);
+ EXPECT_EQ(&mock, event.getSdEvent());
+ EXPECT_EQ(expected_event, event.get());
EXPECT_CALL(mock, sd_event_unref(expected_event)).WillOnce(Return(nullptr));
}