main: use sdeventplus

Make use of the RAII that comes with the sdeventplus c++ bindings for
the sd_event library.

Change-Id: Ie655766fdc625e1150c956b2eb16e0352e7c3859
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/Makefile.am b/Makefile.am
index 8488bac..37adaf1 100755
--- a/Makefile.am
+++ b/Makefile.am
@@ -52,12 +52,14 @@
 	$(SYSTEMD_CFLAGS) \
 	$(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \
 	$(SDBUSPLUS_CFLAGS) \
+	$(SDEVENTPLUS_CFLAGS) \
 	$(PHOSPHOR_LOGGING_CFLAGS) \
 	-flto
 generic_ldflags = \
 	$(SYSTEMD_LIBS) \
 	$(PHOSPHOR_DBUS_INTERFACES_LIBS) \
 	$(SDBUSPLUS_LIBS) \
+	$(SDEVENTPLUS_LIBS) \
 	$(PHOSPHOR_LOGGING_LIBS) \
 	-lssl \
 	-lcrypto
diff --git a/configure.ac b/configure.ac
index 2c1969d..cd2a88f 100755
--- a/configure.ac
+++ b/configure.ac
@@ -15,6 +15,7 @@
 # Check for libraries
 PKG_CHECK_MODULES([PHOSPHOR_DBUS_INTERFACES], [phosphor-dbus-interfaces])
 PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus])
+PKG_CHECK_MODULES([SDEVENTPLUS], [sdeventplus])
 PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging])
 
 # Checks for library functions
diff --git a/item_updater_main.cpp b/item_updater_main.cpp
index 69ee015..0e4a35b 100644
--- a/item_updater_main.cpp
+++ b/item_updater_main.cpp
@@ -12,6 +12,7 @@
 #include <phosphor-logging/log.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/server/manager.hpp>
+#include <sdeventplus/event.hpp>
 
 #include <system_error>
 
@@ -20,15 +21,7 @@
     using namespace openpower::software::updater;
     using namespace phosphor::logging;
     auto bus = sdbusplus::bus::new_default();
-
-    sd_event* loop = nullptr;
-    auto rc = sd_event_default(&loop);
-    if (rc < 0)
-    {
-        log<level::ERR>("Error occurred during the sd_event_default",
-                        entry("RC=%d", rc));
-        return -1;
-    }
+    auto loop = sdeventplus::Event::get_default();
 
     // Add sdbusplus ObjectManager.
     sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
@@ -46,12 +39,12 @@
     {
 #ifdef UBIFS_LAYOUT
         openpower::software::updater::Watch watch(
-            loop,
+            loop.get(),
             std::bind(std::mem_fn(&ItemUpdater::updateFunctionalAssociation),
                       &updater, std::placeholders::_1));
 #endif
-        bus.attach_event(loop, SD_EVENT_PRIORITY_NORMAL);
-        rc = sd_event_loop(loop);
+        bus.attach_event(loop.get(), SD_EVENT_PRIORITY_NORMAL);
+        auto rc = loop.loop();
         if (rc < 0)
         {
             log<level::ERR>("Error occurred during the sd_event_loop",
@@ -65,7 +58,5 @@
         return -1;
     }
 
-    sd_event_unref(loop);
-
     return 0;
 }
diff --git a/meson.build b/meson.build
index af82637..1fb5d35 100644
--- a/meson.build
+++ b/meson.build
@@ -167,6 +167,7 @@
         dependency('phosphor-dbus-interfaces'),
         dependency('phosphor-logging'),
         dependency('sdbusplus'),
+        dependency('sdeventplus'),
     ],
     install: true
 )