Create sd_event outside from EventLoop

Presently timer in the provider library needs the sd_event
and sd_event gets created in the startEventLoop.
RegisterCallbackHandlers gets called before the startEventLoop
hence not getting the event.

This commit creates the sd_event outside from the sd_event_loop
and pass the sd_event reference to the startEventLoop function.

Tested: run the fru print in net-ipmid context.

Change-Id: I2b227154ba60e56d7faa6c8000c20a5231c4417c
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/main.cpp b/main.cpp
index 611a6af..d79572c 100644
--- a/main.cpp
+++ b/main.cpp
@@ -32,6 +32,7 @@
         sol::Manager&> singletonPool(manager, table, loop, solManager);
 
 sd_bus* bus = nullptr;
+sd_event* events = nullptr;
 
 // Global timer for network changes
 std::unique_ptr<phosphor::ipmi::Timer> networkTimer = nullptr;
@@ -53,7 +54,7 @@
  */
 sd_event* ipmid_get_sd_event_connection()
 {
-    return loop.event;
+    return events;
 }
 
 /*
@@ -79,6 +80,14 @@
         goto finish;
     }
 
+    /* Get an sd event handler */
+    rc = sd_event_default(&events);
+    if (rc < 0)
+    {
+        std::cerr << "Failure to create sd_event" << strerror(-rc) <<"\n";
+        goto finish;
+    }
+
     // Register callback to update cache for a GUID change and cache the GUID
     command::registerGUIDChangeCallback();
     cache::guid = command::getSystemGUID();
@@ -94,10 +103,11 @@
     sol::command::registerCommands();
 
     // Start Event Loop
-    return std::get<eventloop::EventLoop&>(singletonPool).startEventLoop();
+    return std::get<eventloop::EventLoop&>(singletonPool).startEventLoop(events);
 
 finish:
     sd_bus_unref(bus);
+    sd_event_unref(events);
 
     return 0;
 }