Shift to boost asio library
This commit shifts vpd manager from sdbusplus event loop to
boost io_context event loop.
The shift was done to have a more flexible way to perform
async Dbus calls.
For example read/write of vpd data can be performed
asynchronously.
It also removes dependency of Manager class on the interface
class created as a part of Phosphor-Dbus-Interface repo.
Test:
- Introspect com.ibm.VPD.Manager /com/ibm/VPD/Manager to ensure
that all the methods exposed under com.ibm.VPD.Manager interface
matches to the ones documented under PDI repo.
- Make DBus call to each of the exposed api to ensure that the
funcation calls are working fine.
-To ensure bios handler call back is working.
Stop vpd-manager service.
Stop pldm service.
Start vpd-manager service
Start pldm service.
Should recieve callback.
-To ensure gpio call back
std::cout were added to callback function being trigerred on
timer expiration and the same were verified in journal.
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
Change-Id: I00640f64de487d5244e8be2e7a3f3d63a013644e
diff --git a/vpd-manager/gpioMonitor.cpp b/vpd-manager/gpioMonitor.cpp
index 69d5e60..1affa62 100644
--- a/vpd-manager/gpioMonitor.cpp
+++ b/vpd-manager/gpioMonitor.cpp
@@ -3,19 +3,12 @@
#include "common_utility.hpp"
#include "ibm_vpd_utils.hpp"
-#include <systemd/sd-event.h>
-
-#include <chrono>
+#include <boost/asio.hpp>
+#include <boost/bind/bind.hpp>
#include <gpiod.hpp>
-#include <sdeventplus/clock.hpp>
-#include <sdeventplus/utility/timer.hpp>
using namespace std;
using namespace openpower::vpd::constants;
-using sdeventplus::ClockId;
-using sdeventplus::Event;
-using Timer = sdeventplus::utility::Timer<ClockId::Monotonic>;
-using namespace std::chrono_literals;
namespace openpower
{
@@ -44,7 +37,8 @@
return gpioData;
}
-void GpioMonitor::initGpioInfos(Event& event)
+void GpioMonitor::initGpioInfos(
+ std::shared_ptr<boost::asio::io_context>& ioContext)
{
Byte outputValue = 0;
Byte presenceValue = 0;
@@ -105,7 +99,7 @@
make_shared<GpioEventHandler>(
presencePinName, presenceValue, outputPinName,
outputValue, devNameAddr, driverType, busType,
- objectPath, event);
+ objectPath, ioContext);
gpioObjects.push_back(gpioObj);
}
@@ -161,20 +155,43 @@
executeCmd(cmnd);
}
-void GpioEventHandler::doEventAndTimerSetup(sdeventplus::Event& event)
+void GpioEventHandler::handleTimerExpiry(
+ const boost::system::error_code& ec,
+ std::shared_ptr<boost::asio::steady_timer>& timer)
+{
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return;
+ }
+
+ if (ec)
+ {
+ std::cerr << "Timer wait failed for gpio pin" << ec.message();
+ return;
+ }
+
+ if (hasEventOccurred())
+ {
+ toggleGpio();
+ }
+ timer->expires_at(std::chrono::steady_clock::now() +
+ std::chrono::seconds(5));
+ timer->async_wait(boost::bind(&GpioEventHandler::handleTimerExpiry, this,
+ boost::asio::placeholders::error, timer));
+}
+
+void GpioEventHandler::doEventAndTimerSetup(
+ std::shared_ptr<boost::asio::io_context>& ioContext)
{
prevPresPinValue = getPresencePinValue();
- static vector<shared_ptr<Timer>> timers;
- shared_ptr<Timer> timer = make_shared<Timer>(
- event,
- [this](Timer&) {
- if (hasEventOccurred())
- {
- toggleGpio();
- }
- },
- std::chrono::seconds{5s});
+ static vector<std::shared_ptr<boost::asio::steady_timer>> timers;
+
+ auto timer = make_shared<boost::asio::steady_timer>(
+ *ioContext, std::chrono::seconds(5));
+
+ timer->async_wait(boost::bind(&GpioEventHandler::handleTimerExpiry, this,
+ boost::asio::placeholders::error, timer));
timers.push_back(timer);
}