sdevent: Remove in favor of sdeventplus
The sdevent utility was replaced with use of sdeventplus and is no
longer used within any of the fan applications.
sdevent was replaced by sdeventplus over a year ago by commit
1cfc2f11b13412a15f8478cebc35e50e6feb13a2
Tested:
Built all fan applications
Change-Id: If3adb9ec0f56ed1c7b300ddc0f23546cd327f6b3
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/sdevent.hpp b/sdevent.hpp
deleted file mode 100644
index ba40435..0000000
--- a/sdevent.hpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#pragma once
-
-#include "sdevent/event.hpp"
-
-namespace phosphor
-{
-namespace fan
-{
-namespace util
-{
-/** @class SDEvent
- * @brief DBus access delegate implementation for sdevent.
- */
-class SDEvent
-{
- public:
- /** @brief Get the event loop. */
- static auto& getEvent()
- {
- static auto event = sdevent::event::newDefault();
- return event;
- }
-};
-
-} // namespace util
-} // namespace fan
-} // namespace phosphor
diff --git a/sdevent/event.hpp b/sdevent/event.hpp
deleted file mode 100644
index 2058462..0000000
--- a/sdevent/event.hpp
+++ /dev/null
@@ -1,195 +0,0 @@
-#pragma once
-
-#include <chrono>
-#include <memory>
-#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include <sdbusplus/bus.hpp>
-#include <systemd/sd-event.h>
-#include <xyz/openbmc_project/Common/error.hpp>
-
-namespace sdevent
-{
-namespace event
-{
-namespace io
-{
-class IO;
-} // namespace io
-
-using EventPtr = sd_event*;
-class Event;
-
-/** @brief Get an instance of the 'default' event. */
-Event newDefault();
-
-namespace details
-{
-
-/** @brief unique_ptr functor to release an event reference. */
-struct EventDeleter
-{
- void operator()(sd_event* ptr) const
- {
- deleter(ptr);
- }
-
- decltype(&sd_event_unref) deleter = sd_event_unref;
-};
-
-/* @brief Alias 'event' to a unique_ptr type for auto-release. */
-using Event = std::unique_ptr<sd_event, EventDeleter>;
-
-} // namespace details
-
-using namespace phosphor::logging;
-
-/** @class Event
- * @brief Provides C++ bindings to the sd_event_* class functions.
- */
-class Event
-{
- private:
- using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
- Error::InternalFailure;
-
- public:
- /* Define all of the basic class operations:
- * Not allowed:
- * - Default constructor to avoid nullptrs.
- * - Copy operations due to internal unique_ptr.
- * Allowed:
- * - Move operations.
- * - Destructor.
- */
- Event() = delete;
- Event(const Event&) = delete;
- Event& operator=(const Event&) = delete;
- Event(Event&&) = default;
- Event& operator=(Event&&) = default;
- ~Event() = default;
-
- /** @brief Conversion constructor from 'EventPtr'.
- *
- * Increments ref-count of the event-pointer and releases it when
- * done.
- */
- explicit Event(EventPtr e);
-
- /** @brief Constructor for 'Event'.
- *
- * Takes ownership of the event-pointer and releases it when done.
- */
- Event(EventPtr e, std::false_type);
-
- /** @brief Release ownership of the stored event-pointer. */
- EventPtr release()
- {
- return evt.release();
- }
-
- /** @brief Wait indefinitely for new event sources. */
- void loop()
- {
- auto rc = sd_event_loop(evt.get());
- if (rc < 0)
- {
- log<level::ERR>("Error in call to sd_event_loop",
- entry("RC=%d", rc));
- elog<InternalFailure>();
- }
- }
-
- /** @brief Stop the loop. */
- void exit(int status = 0)
- {
- auto rc = sd_event_exit(evt.get(), status);
- if (rc < 0)
- {
- log<level::ERR>("Error in call to sd_event_exit",
- entry("RC=%d", rc),
- entry("STATUS=%d", status));
- elog<InternalFailure>();
- }
- }
-
- /** @brief Get the loop exit code. */
- auto getExitStatus()
- {
- int status;
- auto rc = sd_event_get_exit_code(evt.get(), &status);
- if (rc < 0)
- {
- log<level::ERR>("Error in call to sd_event_get_exit_code",
- entry("RC=%d", rc));
- elog<InternalFailure>();
- }
-
- return status;
- }
-
- /** @brief Attach to a DBus loop. */
- void attach(sdbusplus::bus::bus& bus)
- {
- bus.attach_event(evt.get(), SD_EVENT_PRIORITY_NORMAL);
- }
-
- /** @brief C++ wrapper for sd_event_now. */
- auto now()
- {
- using namespace std::chrono;
-
- uint64_t usec;
- auto rc = sd_event_now(evt.get(), CLOCK_MONOTONIC, &usec);
- if (rc < 0)
- {
- log<level::ERR>("Error in call to sd_event_now",
- entry("RC=%d", rc));
- elog<InternalFailure>();
- }
-
- microseconds d(usec);
- return steady_clock::time_point(d);
- }
-
- friend class io::IO;
-
- private:
-
- EventPtr get()
- {
- return evt.get();
- }
-
- details::Event evt;
-};
-
-inline Event::Event(EventPtr l) : evt(sd_event_ref(l))
-{
-
-}
-
-inline Event::Event(EventPtr l, std::false_type) : evt(l)
-{
-
-}
-
-inline Event newDefault()
-{
- using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
- Error::InternalFailure;
-
- sd_event* e = nullptr;
- auto rc = sd_event_default(&e);
- if (rc < 0)
- {
- log<level::ERR>("Error in call to sd_event_default",
- entry("RC=%d", rc));
- elog<InternalFailure>();
- }
-
- return Event(e, std::false_type());
-}
-
-} // namespace event
-} // namespace sdevent
diff --git a/sdevent/io.hpp b/sdevent/io.hpp
deleted file mode 100644
index f511cf0..0000000
--- a/sdevent/io.hpp
+++ /dev/null
@@ -1,108 +0,0 @@
-#pragma once
-
-#include <functional>
-#include <memory>
-#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include <systemd/sd-event.h>
-#include <xyz/openbmc_project/Common/error.hpp>
-
-#include "sdevent/source.hpp"
-#include "sdevent/event.hpp"
-
-namespace sdevent
-{
-namespace event
-{
-namespace io
-{
-
-using namespace phosphor::logging;
-/** @class IO
- * @brief Provides C++ bindings to the sd_event_source* io functions.
- */
-class IO
-{
- private:
- using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
- Error::InternalFailure;
-
- public:
- /* Define all of the basic class operations:
- * Not allowed:
- * - Default constructor to avoid nullptrs.
- * - Copy operations due to internal unique_ptr.
- * Allowed:
- * - Move operations.
- * - Destructor.
- */
- IO() = delete;
- IO(const IO&) = delete;
- IO& operator=(const IO&) = delete;
- IO(IO&&) = default;
- IO& operator=(IO&&) = default;
- ~IO() = default;
-
- using Callback = std::function<void(source::Source&)>;
-
- /** @brief Register an io callback.
- *
- * @param[in] event - The event to register on.
- * @param[in] fd - The file descriptor to poll.
- * @param[in] callback - The callback method.
- */
- IO(
- sdevent::event::Event& event,
- int fd,
- Callback callback)
- : src(nullptr),
- cb(std::make_unique<Callback>(std::move(callback)))
- {
- sd_event_source* source = nullptr;
- auto rc = sd_event_add_io(
- event.get(),
- &source,
- fd,
- EPOLLIN,
- callCallback,
- cb.get());
- if (rc < 0)
- {
- log<level::ERR>("Error in call to sd_event_add_io",
- entry("RC=%d", rc),
- entry("FD=%d", fd));
- elog<InternalFailure>();
- }
-
- src = decltype(src){source, std::false_type()};
- }
-
- /** @brief Set the IO source enable state. */
- void enable(int enable)
- {
- src.enable(enable);
- }
-
- /** @brief Query the IO enable state. */
- auto enabled()
- {
- return src.enabled();
- }
-
- private:
- source::Source src;
- std::unique_ptr<Callback> cb = nullptr;
-
- static int callCallback(sd_event_source* s, int fd, uint32_t events,
- void* context)
- {
- source::Source source(s);
- auto c = static_cast<Callback*>(context);
- (*c)(source);
-
- return 0;
- }
-};
-} // namespace io
-} // namespace event
-} // namespace sdevent
diff --git a/sdevent/source.hpp b/sdevent/source.hpp
deleted file mode 100644
index e90efd4..0000000
--- a/sdevent/source.hpp
+++ /dev/null
@@ -1,113 +0,0 @@
-#pragma once
-
-#include <memory>
-#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include <systemd/sd-event.h>
-#include <xyz/openbmc_project/Common/error.hpp>
-
-namespace sdevent
-{
-namespace source
-{
-
-using SourcePtr = sd_event_source*;
-
-namespace details
-{
-
-/** @brief unique_ptr functor to release a source reference. */
-struct SourceDeleter
-{
- void operator()(sd_event_source* ptr) const
- {
- deleter(ptr);
- }
-
- decltype(&sd_event_source_unref) deleter = sd_event_source_unref;
-};
-
-/* @brief Alias 'source' to a unique_ptr type for auto-release. */
-using source = std::unique_ptr<sd_event_source, SourceDeleter>;
-
-} // namespace details
-
-using namespace phosphor::logging;
-
-/** @class Source
- * @brief Provides C++ bindings to the sd_event_source* functions.
- */
-class Source
-{
- private:
- using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
- Error::InternalFailure;
-
- public:
- /* Define all of the basic class operations:
- * Not allowed:
- * - Default constructor to avoid nullptrs.
- * - Copy operations due to internal unique_ptr.
- * Allowed:
- * - Move operations.
- * - Destructor.
- */
- Source() = delete;
- Source(const Source&) = delete;
- Source& operator=(const Source&) = delete;
- Source(Source&&) = default;
- Source& operator=(Source&&) = default;
- ~Source() = default;
-
- /** @brief Conversion constructor from 'SourcePtr'.
- *
- * Increments ref-count of the source-pointer and releases it
- * when done.
- */
- explicit Source(SourcePtr s) : src(sd_event_source_ref(s)) {}
-
- /** @brief Constructor for 'source'.
- *
- * Takes ownership of the source-pointer and releases it when done.
- */
- Source(SourcePtr s, std::false_type) : src(s) {}
-
- /** @brief Check if source contains a real pointer. (non-nullptr). */
- explicit operator bool() const
- {
- return bool(src);
- }
-
- /** @brief Test whether or not the source can generate events. */
- auto enabled()
- {
- int enabled;
- auto rc = sd_event_source_get_enabled(src.get(), &enabled);
- if (rc < 0)
- {
- log<level::ERR>("Error in call to sd_event_source_get_enabled",
- entry("RC=%d", rc));
- elog<InternalFailure>();
- }
-
- return enabled;
- }
-
- /** @brief Allow the source to generate events. */
- void enable(int enable)
- {
- auto rc = sd_event_source_set_enabled(src.get(), enable);
- if (rc < 0)
- {
- log<level::ERR>("Error in call to sd_event_source_set_enabled",
- entry("RC=%d", rc),
- entry("ENABLE=%d", enable));
- elog<InternalFailure>();
- }
- }
-
- private:
- details::source src;
-};
-} // namespace source
-} // namespace sdevent
diff --git a/sdevent/test/.gitignore b/sdevent/test/.gitignore
deleted file mode 100644
index 014ec3f..0000000
--- a/sdevent/test/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-iotest
diff --git a/sdevent/test/Makefile.am b/sdevent/test/Makefile.am
deleted file mode 100644
index 39790de..0000000
--- a/sdevent/test/Makefile.am
+++ /dev/null
@@ -1,25 +0,0 @@
-AM_CPPFLAGS = -iquote$(top_srcdir)
-gtest_cflags = $(PTHREAD_CFLAGS)
-gtest_ldadd = -lgtest -lgtest_main -lgmock $(PTHREAD_LIBS)
-
-check_PROGRAMS =
-
-TESTS = $(check_PROGRAMS)
-
-check_PROGRAMS += iotest
-iotest_SOURCES = \
- iotest.cpp
-iotest_CXXFLAGS = \
- $(gtest_cflags) \
- $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \
- $(PHOSPHOR_LOGGING_CFLAGS) \
- $(SDBUSPLUS_CFLAGS) \
- $(SYSTEMD_CFLAGS)
-iotest_LDFLAGS = \
- $(OESDK_TESTCASE_FLAGS)
-iotest_LDADD = \
- $(gtest_ldadd) \
- $(PHOSPHOR_DBUS_INTERFACES_LIBS) \
- $(PHOSPHOR_LOGGING_LIBS) \
- $(SDBUSPLUS_LIBS) \
- $(SYSTEMD_LIBS)
diff --git a/sdevent/test/iotest.cpp b/sdevent/test/iotest.cpp
deleted file mode 100644
index 015f87b..0000000
--- a/sdevent/test/iotest.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-#include <gtest/gtest.h>
-#include <thread>
-#include <unistd.h>
-#include "sdevent/event.hpp"
-#include "sdevent/io.hpp"
-
-TEST(IoTest, TestIo)
-{
- // Validate an sd event io callback can be
- // constructed, added to an event loop, and
- // that the callback is invoked.
-
- auto loop = sdevent::event::newDefault();
- auto expected = 100;
- volatile auto actual = 0;
-
- std::array<int, 2> fds;
- auto rc = pipe(fds.data());
- ASSERT_EQ(rc, 0);
-
- auto t = std::thread([&loop](){loop.loop();});
-
- sdevent::event::io::IO io(
- loop,
- fds.data()[0],
- [&fds, &actual, &loop](auto& s)
- {
- auto tmp = 0;
- auto rc = read(fds.data()[0], &tmp, sizeof(tmp));
- ASSERT_GT(rc, 0);
- actual = tmp;
- loop.exit();
- });
-
- rc = write(fds.data()[1], &expected, sizeof(expected));
- ASSERT_GT(rc, 0);
- t.join();
- close(fds.data()[0]);
- close(fds.data()[1]);
-
- ASSERT_EQ(expected, actual);
-}