Add sdbusplus::asio::connection pointer to ipmi::Context
This adds a std::shared_ptr<sdbusplus::asio::connection> to every
ipmi::Context in order to facilitate easy transition to
yield_method_call over other D-Bus interfaces. This means that a
getDbusObjects call could just pass in the ipmi::Context and it will get
a yielding call. ipmi::Context is a natural fit because one is created
for each of the boost::asio::coroutine contexts. And because a yielding
call needs both an async D-Bus connection and a yield_context, this
means that we now have one object to rule them all.
Tested: Created a handler that uses the new shared_ptr in the context
to see the API in action.
Change-Id: I429a324180a38bf17845f7fd0544df2226d0300a
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/include/ipmid/message.hpp b/include/ipmid/message.hpp
index 7841e9e..4864f4e 100644
--- a/include/ipmid/message.hpp
+++ b/include/ipmid/message.hpp
@@ -23,6 +23,7 @@
#include <ipmid/message/types.hpp>
#include <memory>
#include <phosphor-logging/log.hpp>
+#include <sdbusplus/asio/connection.hpp>
#include <tuple>
#include <utility>
#include <vector>
@@ -34,27 +35,32 @@
{
using ptr = std::shared_ptr<Context>;
- Context() = default;
+ Context() = delete;
+ Context(const Context&) = default;
+ Context& operator=(const Context&) = default;
+ Context(Context&&) = delete;
+ Context& operator=(Context&&) = delete;
- Context(NetFn netFn, Cmd cmd, int channel, int userId, Privilege priv,
- int rqSA = 0, boost::asio::yield_context* yield = nullptr) :
- netFn(netFn),
- cmd(cmd), channel(channel), userId(userId), priv(priv), rqSA(rqSA),
- yield(yield)
+ Context(std::shared_ptr<sdbusplus::asio::connection> bus, NetFn netFn,
+ Cmd cmd, int channel, int userId, Privilege priv, int rqSA,
+ boost::asio::yield_context* yield) :
+ bus(bus),
+ netFn(netFn), cmd(cmd), channel(channel), userId(userId), priv(priv),
+ rqSA(rqSA), yield(yield)
{
}
+ std::shared_ptr<sdbusplus::asio::connection> bus;
// normal IPMI context (what call is this, from whence it came...)
- NetFn netFn = 0;
- Cmd cmd = 0;
- int channel = 0;
- int userId = 0;
- Privilege priv = Privilege::None;
+ NetFn netFn;
+ Cmd cmd;
+ int channel;
+ int userId;
+ Privilege priv;
// srcAddr is only set on IPMB requests because
// Platform Event Message needs it to determine the incoming format
- int rqSA = 0;
- // if non-null, use this to do blocking asynchronous asio calls
- boost::asio::yield_context* yield = nullptr;
+ int rqSA;
+ boost::asio::yield_context* yield;
};
namespace message
diff --git a/ipmid-new.cpp b/ipmid-new.cpp
index 7e77b12..c32ba3f 100644
--- a/ipmid-new.cpp
+++ b/ipmid-new.cpp
@@ -536,8 +536,8 @@
entry("PRIVILEGE=%u", static_cast<uint8_t>(privilege)),
entry("RQSA=%x", rqSA));
- auto ctx = std::make_shared<ipmi::Context>(netFn, cmd, channel, userId,
- privilege, rqSA, &yield);
+ auto ctx = std::make_shared<ipmi::Context>(getSdBus(), netFn, cmd, channel,
+ userId, privilege, rqSA, &yield);
auto request = std::make_shared<ipmi::message::Request>(
ctx, std::forward<std::vector<uint8_t>>(data));
message::Response::ptr response = executeIpmiCommand(request);
@@ -748,8 +748,9 @@
std::vector<uint8_t> data;
m.read(seq, netFn, lun, cmd, data);
+ std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
auto ctx = std::make_shared<ipmi::Context>(
- netFn, cmd, 0, 0, ipmi::Privilege::Admin, 0, &yield);
+ bus, netFn, cmd, 0, 0, ipmi::Privilege::Admin, 0, &yield);
auto request = std::make_shared<ipmi::message::Request>(
ctx, std::forward<std::vector<uint8_t>>(data));
ipmi::message::Response::ptr response =
@@ -764,9 +765,9 @@
dest = m.get_sender();
path = m.get_path();
boost::system::error_code ec;
- getSdBus()->yield_method_call(yield, ec, dest, path, DBUS_INTF,
- "sendMessage", seq, netFn, lun, cmd,
- response->cc, response->payload.raw);
+ bus->yield_method_call(yield, ec, dest, path, DBUS_INTF, "sendMessage",
+ seq, netFn, lun, cmd, response->cc,
+ response->payload.raw);
if (ec)
{
log<level::ERR>("Failed to send response to requestor",