diff options
| author | William A. Kennington III <wak@google.com> | 2018-07-17 14:40:14 -0700 |
|---|---|---|
| committer | William A. Kennington III <wak@google.com> | 2018-07-17 14:40:14 -0700 |
| commit | dcc08b6cde29e434a3e7dfd95a6c42fb4bd8484b (patch) | |
| tree | 04cecc3bb4c67fc8dc9d3d6f7953fb84c459e24d /src | |
| parent | 1967df4967e671d4c14410f5b74e89b3f46b23a3 (diff) | |
| download | sdeventplus-dcc08b6cde29e434a3e7dfd95a6c42fb4bd8484b.tar.gz sdeventplus-dcc08b6cde29e434a3e7dfd95a6c42fb4bd8484b.zip | |
source: Add class
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.am | 3 | ||||
| -rw-r--r-- | src/sdeventplus/internal/sdevent.hpp | 15 | ||||
| -rw-r--r-- | src/sdeventplus/source.cpp | 21 | ||||
| -rw-r--r-- | src/sdeventplus/source.hpp | 22 | ||||
| -rw-r--r-- | src/sdeventplus/test/sdevent.hpp | 5 |
5 files changed, 66 insertions, 0 deletions
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 @@ libsdeventplus_la_SOURCES += sdeventplus/event.cpp 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 @@ class SdEventInterface 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 @@ class SdEventImpl : public SdEventInterface { 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 @@ class SdEventMock : public SdEventInterface 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 |

