diff options
author | William A. Kennington III <wak@google.com> | 2018-10-18 15:24:49 -0700 |
---|---|---|
committer | William A. Kennington III <wak@google.com> | 2018-11-07 20:27:55 +0000 |
commit | 4f67cc37b40baa61be47556166a0f6b8af4a9f63 (patch) | |
tree | 286d2270122de54b7ec4285fc0fbb5cc4c9bffc8 /softoff | |
parent | 438fb7957f4b763ba28b13ef36732b40e77bb226 (diff) | |
download | phosphor-host-ipmid-4f67cc37b40baa61be47556166a0f6b8af4a9f63.tar.gz phosphor-host-ipmid-4f67cc37b40baa61be47556166a0f6b8af4a9f63.zip |
softoff: Convert to sdeventplus loop
Tested:
Builds and passes unit tests
Change-Id: I6c37fa7088b7bcfbfc9f8b93185b826782a72c6a
Signed-off-by: William A. Kennington III <wak@google.com>
Diffstat (limited to 'softoff')
-rw-r--r-- | softoff/Makefile.am | 2 | ||||
-rw-r--r-- | softoff/mainapp.cpp | 37 |
2 files changed, 15 insertions, 24 deletions
diff --git a/softoff/Makefile.am b/softoff/Makefile.am index ed0c226..ecd8f86 100644 --- a/softoff/Makefile.am +++ b/softoff/Makefile.am @@ -19,10 +19,12 @@ CLEANFILES = xyz/openbmc_project/Ipmi/Internal/SoftPowerOff/server.cpp \ phosphor_softpoweroff_LDFLAGS = $(SYSTEMD_LIBS) \ $(SDBUSPLUS_LIBS) \ + $(SDEVENTPLUS_LIBS) \ $(PHOSPHOR_LOGGING_LIBS) \ $(PHOSPHOR_DBUS_INTERFACES_LIBS) phosphor_softpoweroff_CXXFLAGS = $(SYSTEMD_CFLAGS) \ $(SDBUSPLUS_CFLAGS) \ + $(SDEVENTPLUS_CFLAGS) \ $(PHOSPHOR_LOGGING_CFLAGS) \ $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) diff --git a/softoff/mainapp.cpp b/softoff/mainapp.cpp index f6a52ac..70defb7 100644 --- a/softoff/mainapp.cpp +++ b/softoff/mainapp.cpp @@ -17,11 +17,10 @@ #include "softoff.hpp" -#include <systemd/sd-event.h> - #include <phosphor-logging/elog-errors.hpp> #include <phosphor-logging/elog.hpp> -#include <sdbusplus/timer.hpp> +#include <sdeventplus/event.hpp> +#include <sdeventplus/exception.hpp> #include <xyz/openbmc_project/State/Host/error.hpp> // Return -1 on any errors to ensure we follow the calling targets OnFailure= @@ -30,26 +29,17 @@ int main(int argc, char** argv) { using namespace phosphor::logging; - // systemd event handler - sd_event* events = nullptr; - // Get a handle to system dbus. auto bus = sdbusplus::bus::new_default(); // Add systemd object manager. sdbusplus::server::manager::manager(bus, SOFTOFF_OBJPATH); - // sd_event object - auto r = sd_event_default(&events); - if (r < 0) - { - log<level::ERR>("Failure to create sd_event handler", - entry("ERRNO=0x%X", -r)); - return -1; - } + // Get default event loop + auto event = sdeventplus::Event::get_default(); // Attach the bus to sd_event to service user requests - bus.attach_event(events, SD_EVENT_PRIORITY_NORMAL); + bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); // Claim the bus. Delaying it until sending SMS_ATN may result // in a race condition between this available and IPMI trying to send @@ -57,19 +47,21 @@ int main(int argc, char** argv) bus.request_name(SOFTOFF_BUSNAME); // Create the SoftPowerOff object. - phosphor::ipmi::SoftPowerOff powerObj(bus, events, SOFTOFF_OBJPATH); + phosphor::ipmi::SoftPowerOff powerObj(bus, event.get(), SOFTOFF_OBJPATH); // Wait for client requests until this application has processed // at least one successful SoftPowerOff or we timed out while (!powerObj.isCompleted() && !powerObj.isTimerExpired()) { - // -1 denotes wait for ever - r = sd_event_run(events, (uint64_t)-1); - if (r < 0) + try + { + event.run(std::nullopt); + } + catch (const sdeventplus::SdEventError& e) { log<level::ERR>("Failure in processing request", - entry("ERRNO=0x%X", -r)); - return -1; + entry("ERROR=%s", e.what())); + return 1; } } @@ -86,8 +78,5 @@ int main(int argc, char** argv) return -1; } - // Cleanup the event handler - events = sd_event_unref(events); - return 0; } |