summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRatan Gupta <ratagupt@in.ibm.com>2018-03-23 23:05:17 +0530
committerRatan Gupta <ratagupt@in.ibm.com>2018-03-27 16:51:43 +0530
commit166c71a13c5cb48a29bdc0b6e8f4fc30c4375e5e (patch)
treeb51b563d1a99286a3ca5e92867058941a090aa71
parent04edb9b0d1c7f9be22a5334c87d8d2a5284fa9e9 (diff)
downloadphosphor-net-ipmid-166c71a13c5cb48a29bdc0b6e8f4fc30c4375e5e.tar.gz
phosphor-net-ipmid-166c71a13c5cb48a29bdc0b6e8f4fc30c4375e5e.zip
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>
-rw-r--r--main.cpp14
-rw-r--r--sd_event_loop.cpp10
-rw-r--r--sd_event_loop.hpp3
3 files changed, 16 insertions, 11 deletions
diff --git a/main.cpp b/main.cpp
index 611a6af..d79572c 100644
--- a/main.cpp
+++ b/main.cpp
@@ -32,6 +32,7 @@ std::tuple<session::Manager&, command::Table&, eventloop::EventLoop&,
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_bus* ipmid_get_sd_bus_connection()
*/
sd_event* ipmid_get_sd_event_connection()
{
- return loop.event;
+ return events;
}
/*
@@ -79,6 +80,14 @@ int main(int i_argc, char* i_argv[])
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 @@ int main(int i_argc, char* i_argv[])
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;
}
diff --git a/sd_event_loop.cpp b/sd_event_loop.cpp
index 16a5403..3351da7 100644
--- a/sd_event_loop.cpp
+++ b/sd_event_loop.cpp
@@ -171,7 +171,7 @@ static int retryTimerHandler(sd_event_source* s, uint64_t usec,
return 0;
}
-int EventLoop::startEventLoop()
+int EventLoop::startEventLoop(sd_event* events)
{
int fd = -1;
int r = 0;
@@ -180,12 +180,7 @@ int EventLoop::startEventLoop()
sd_event_source* source = nullptr;
auto bus = ipmid_get_sd_bus_connection();
- r = sd_event_default(&event);
- if (r < 0)
- {
- goto finish;
- }
-
+ event = events;
// Attach the bus to sd_event to service user requests
r = sd_bus_attach_event(bus, event, SD_EVENT_PRIORITY_NORMAL);
if (r < 0)
@@ -266,7 +261,6 @@ int EventLoop::startEventLoop()
r = sd_event_loop(event);
finish:
- event = sd_event_unref(event);
if (fd >= 0)
{
diff --git a/sd_event_loop.hpp b/sd_event_loop.hpp
index 87a12ff..2bb44d7 100644
--- a/sd_event_loop.hpp
+++ b/sd_event_loop.hpp
@@ -66,10 +66,11 @@ class EventLoop
/** @brief Initialise the event loop and add the handler for incoming
* IPMI packets.
+ * @param[in] events- sd bus event;
*
* @return EXIT_SUCCESS on success and EXIT_FAILURE on failure.
*/
- int startEventLoop();
+ int startEventLoop(sd_event* events);
/** @brief Add host console I/O event source to the event loop.
*
OpenPOWER on IntegriCloud