source: Add class
diff --git a/src/Makefile.am b/src/Makefile.am
index f1516ba..8c48eeb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,6 +14,9 @@
nobase_include_HEADERS += sdeventplus/exception.hpp
libsdeventplus_la_SOURCES += sdeventplus/exception.cpp
+nobase_include_HEADERS += sdeventplus/source.hpp
+libsdeventplus_la_SOURCES += sdeventplus/source.cpp
+
nobase_include_HEADERS += sdeventplus/internal/sdevent.hpp
libsdeventplus_la_SOURCES += sdeventplus/internal/sdevent.cpp
diff --git a/src/sdeventplus/internal/sdevent.hpp b/src/sdeventplus/internal/sdevent.hpp
index 129e67f..fd4bd77 100644
--- a/src/sdeventplus/internal/sdevent.hpp
+++ b/src/sdeventplus/internal/sdevent.hpp
@@ -16,6 +16,11 @@
virtual sd_event *sd_event_unref(sd_event *event) const = 0;
virtual int sd_event_loop(sd_event *event) const = 0;
+
+ virtual sd_event_source *
+ sd_event_source_ref(sd_event_source *source) const = 0;
+ virtual sd_event_source *
+ sd_event_source_unref(sd_event_source *source) const = 0;
};
class SdEventImpl : public SdEventInterface
@@ -45,6 +50,16 @@
{
return ::sd_event_loop(event);
}
+
+ sd_event_source *sd_event_source_ref(sd_event_source *source) const override
+ {
+ return ::sd_event_source_ref(source);
+ }
+ sd_event_source *
+ sd_event_source_unref(sd_event_source *source) const override
+ {
+ return ::sd_event_source_unref(source);
+ }
};
extern SdEventImpl sdevent_impl;
diff --git a/src/sdeventplus/source.cpp b/src/sdeventplus/source.cpp
new file mode 100644
index 0000000..eb3c903
--- /dev/null
+++ b/src/sdeventplus/source.cpp
@@ -0,0 +1,21 @@
+#include <sdeventplus/source.hpp>
+#include <type_traits>
+
+namespace sdeventplus
+{
+
+Source::Source(sd_event_source* source, SdEventInterface* intf) :
+ intf(intf), source(source, &SdEventInterface::sd_event_source_ref,
+ &SdEventInterface::sd_event_source_unref, intf)
+{
+}
+
+Source::Source(sd_event_source* source, std::false_type,
+ SdEventInterface* intf) :
+ intf(intf),
+ source(source, &SdEventInterface::sd_event_source_ref,
+ &SdEventInterface::sd_event_source_unref, std::false_type(), intf)
+{
+}
+
+} // namespace sdeventplus
diff --git a/src/sdeventplus/source.hpp b/src/sdeventplus/source.hpp
new file mode 100644
index 0000000..9921a88
--- /dev/null
+++ b/src/sdeventplus/source.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <sdeventplus/internal/sdevent.hpp>
+#include <sdeventplus/internal/sdref.hpp>
+#include <type_traits>
+
+namespace sdeventplus
+{
+
+class Source
+{
+ public:
+ Source(sd_event_source* source, SdEventInterface* intf = &sdevent_impl);
+ Source(sd_event_source* source, std::false_type,
+ SdEventInterface* intf = &sdevent_impl);
+
+ private:
+ SdEventInterface* intf;
+ SdRef<sd_event_source> source;
+};
+
+} // namespace sdeventplus
diff --git a/src/sdeventplus/test/sdevent.hpp b/src/sdeventplus/test/sdevent.hpp
index 7cea28d..c43b983 100644
--- a/src/sdeventplus/test/sdevent.hpp
+++ b/src/sdeventplus/test/sdevent.hpp
@@ -16,6 +16,11 @@
MOCK_CONST_METHOD1(sd_event_unref, sd_event *(sd_event *));
MOCK_CONST_METHOD1(sd_event_loop, int(sd_event *));
+
+ MOCK_CONST_METHOD1(sd_event_source_ref,
+ sd_event_source *(sd_event_source *));
+ MOCK_CONST_METHOD1(sd_event_source_unref,
+ sd_event_source *(sd_event_source *));
};
} // namespace sdeventplus