sdevent: Support source destroy callbacks
Will be needed to support heap allocated userdata and floating sources.
Change-Id: I927acb3e03fb6c724e762b3ac47cd0d4d297ef87
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/meson.build b/src/meson.build
index 7cd2e92..cb076f5 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,5 +1,5 @@
sdeventplus_deps = [
- dependency('libsystemd'),
+ dependency('libsystemd', version: '>=239'),
dependency('stdplus'),
]
diff --git a/src/sdeventplus/internal/sdevent.cpp b/src/sdeventplus/internal/sdevent.cpp
index ece6b50..26b2f80 100644
--- a/src/sdeventplus/internal/sdevent.cpp
+++ b/src/sdeventplus/internal/sdevent.cpp
@@ -249,6 +249,18 @@
return ::sd_event_source_get_child_pid(source, pid);
}
+int SdEventImpl::sd_event_source_set_destroy_callback(
+ sd_event_source* source, sd_event_destroy_t callback) const
+{
+ return ::sd_event_source_set_destroy_callback(source, callback);
+}
+
+int SdEventImpl::sd_event_source_get_destroy_callback(
+ sd_event_source* source, sd_event_destroy_t* callback) const
+{
+ return ::sd_event_source_get_destroy_callback(source, callback);
+}
+
SdEventImpl sdevent_impl;
} // namespace internal
diff --git a/src/sdeventplus/internal/sdevent.hpp b/src/sdeventplus/internal/sdevent.hpp
index e69b2fd..46486f7 100644
--- a/src/sdeventplus/internal/sdevent.hpp
+++ b/src/sdeventplus/internal/sdevent.hpp
@@ -107,6 +107,10 @@
virtual int sd_event_source_get_signal(sd_event_source* source) const = 0;
virtual int sd_event_source_get_child_pid(sd_event_source* source,
pid_t* pid) const = 0;
+ virtual int sd_event_source_set_destroy_callback(
+ sd_event_source* source, sd_event_destroy_t callback) const = 0;
+ virtual int sd_event_source_get_destroy_callback(
+ sd_event_source* source, sd_event_destroy_t* callback) const = 0;
};
/** @class SdEventImpl
@@ -212,6 +216,10 @@
int sd_event_source_get_signal(sd_event_source* source) const override;
int sd_event_source_get_child_pid(sd_event_source* source,
pid_t* pid) const override;
+ int sd_event_source_set_destroy_callback(
+ sd_event_source* source, sd_event_destroy_t callback) const override;
+ int sd_event_source_get_destroy_callback(
+ sd_event_source* source, sd_event_destroy_t* callback) const override;
};
/** @brief Default instantiation of sd_event
diff --git a/src/sdeventplus/test/sdevent.hpp b/src/sdeventplus/test/sdevent.hpp
index 6e78169..818c85d 100644
--- a/src/sdeventplus/test/sdevent.hpp
+++ b/src/sdeventplus/test/sdevent.hpp
@@ -94,6 +94,10 @@
MOCK_CONST_METHOD1(sd_event_source_get_signal, int(sd_event_source*));
MOCK_CONST_METHOD2(sd_event_source_get_child_pid,
int(sd_event_source*, pid_t*));
+ MOCK_CONST_METHOD2(sd_event_source_set_destroy_callback,
+ int(sd_event_source*, sd_event_destroy_t));
+ MOCK_CONST_METHOD2(sd_event_source_get_destroy_callback,
+ int(sd_event_source*, sd_event_destroy_t*));
};
} // namespace test