softoff: Convert to sdeventplus loop

Tested:
    Builds and passes unit tests

Change-Id: I6c37fa7088b7bcfbfc9f8b93185b826782a72c6a
Signed-off-by: William A. Kennington III <wak@google.com>
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 @@
 {
     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 @@
     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 @@
         return -1;
     }
 
-    // Cleanup the event handler
-    events = sd_event_unref(events);
-
     return 0;
 }