remove legacy ipmid_get_sd_bus_connection calls
The new way is to use the shared_ptr to the sdbusplus::asio::
connection. A shared pointer is cheaper to instantiate than
a dbus object. This also paves the way to eventually replace
many of the blocking dbus calls with yielding or async dbus
calls.
Change-Id: Iea326782266d769457851aabf98e2e582d1bf81e
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/src/smbiosmdrv2handler.cpp b/src/smbiosmdrv2handler.cpp
index f3c4275..193b2f5 100644
--- a/src/smbiosmdrv2handler.cpp
+++ b/src/smbiosmdrv2handler.cpp
@@ -27,7 +27,6 @@
#include <ipmid/api.hpp>
#include <ipmid/utils.hpp>
#include <phosphor-logging/log.hpp>
-#include <sdbusplus/bus.hpp>
#include <sdbusplus/message/types.hpp>
#include <smbiosmdrv2handler.hpp>
#include <string>
@@ -37,7 +36,6 @@
std::unique_ptr<MDRV2> mdrv2 = nullptr;
static void register_netfn_smbiosmdrv2_functions() __attribute__((constructor));
-static sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
int MDRV2::agentLookup(const uint16_t &agentId)
{
@@ -60,15 +58,16 @@
sdbusplus::message::variant<uint8_t> &value,
const std::string &service)
{
+ std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
sdbusplus::message::message method =
- bus.new_method_call(service.c_str(), mdrv2Path, dbusProperties, "Get");
+ bus->new_method_call(service.c_str(), mdrv2Path, dbusProperties, "Get");
method.append(mdrv2Interface, name);
- sdbusplus::message::message reply = bus.call(method);
+ sdbusplus::message::message reply = bus->call(method);
try
{
- sdbusplus::message::message reply = bus.call(method);
+ sdbusplus::message::message reply = bus->call(method);
reply.read(value);
}
catch (sdbusplus::exception_t &e)
@@ -86,14 +85,15 @@
const std::string &service)
{
std::vector<uint32_t> commonData;
+ std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
sdbusplus::message::message method =
- bus.new_method_call(service.c_str(), mdrv2Path, mdrv2Interface,
- "SynchronizeDirectoryCommonData");
+ bus->new_method_call(service.c_str(), mdrv2Path, mdrv2Interface,
+ "SynchronizeDirectoryCommonData");
method.append(idIndex, size);
try
{
- sdbusplus::message::message reply = bus.call(method);
+ sdbusplus::message::message reply = bus->call(method);
reply.read(commonData);
}
catch (sdbusplus::exception_t &e)
@@ -129,7 +129,8 @@
return -1;
}
- sdbusplus::message::message method = bus.new_method_call(
+ std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
+ sdbusplus::message::message method = bus->new_method_call(
service.c_str(), mdrv2Path, mdrv2Interface, "FindIdIndex");
std::vector<uint8_t> info;
info.resize(len);
@@ -138,7 +139,7 @@
try
{
- sdbusplus::message::message reply = bus.call(method);
+ sdbusplus::message::message reply = bus->call(method);
reply.read(idIndex);
}
catch (sdbusplus::exception_t &e)
@@ -282,7 +283,8 @@
*data_len = 0;
- std::string service = ipmi::getService(bus, mdrv2Interface, mdrv2Path);
+ std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
+ std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
if (mdrv2 == nullptr)
{
@@ -310,14 +312,14 @@
return IPMI_CC_PARM_OUT_OF_RANGE;
}
- sdbusplus::message::message method = bus.new_method_call(
+ sdbusplus::message::message method = bus->new_method_call(
service.c_str(), mdrv2Path, mdrv2Interface, "GetDirectoryInformation");
method.append(requestData->dirIndex);
try
{
- sdbusplus::message::message reply = bus.call(method);
+ sdbusplus::message::message reply = bus->call(method);
reply.read(dirInfo);
}
catch (sdbusplus::exception_t &e)
@@ -370,7 +372,8 @@
*data_len = 0;
- std::string service = ipmi::getService(bus, mdrv2Interface, mdrv2Path);
+ std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
+ std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
if (mdrv2 == nullptr)
{
@@ -393,7 +396,7 @@
return IPMI_CC_STORGE_LEAK;
}
- sdbusplus::message::message method = bus.new_method_call(
+ sdbusplus::message::message method = bus->new_method_call(
service.c_str(), mdrv2Path, mdrv2Interface, "SendDirectoryInformation");
method.append(requestData->dirVersion, requestData->dirIndex,
requestData->returnedEntries, requestData->remainingEntries);
@@ -407,7 +410,7 @@
try
{
- sdbusplus::message::message reply = bus.call(method);
+ sdbusplus::message::message reply = bus->call(method);
reply.read(teminate);
}
catch (sdbusplus::exception_t &e)
@@ -446,7 +449,8 @@
*data_len = 0;
- std::string service = ipmi::getService(bus, mdrv2Interface, mdrv2Path);
+ std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
+ std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
if (mdrv2 == nullptr)
{
@@ -473,14 +477,14 @@
return IPMI_CC_PARM_OUT_OF_RANGE;
}
- sdbusplus::message::message method = bus.new_method_call(
+ sdbusplus::message::message method = bus->new_method_call(
service.c_str(), mdrv2Path, mdrv2Interface, "GetDataInformation");
method.append(idIndex);
try
{
- sdbusplus::message::message reply = bus.call(method);
+ sdbusplus::message::message reply = bus->call(method);
reply.read(res);
}
catch (sdbusplus::exception_t &e)
@@ -513,7 +517,8 @@
*/
ipmi::RspType<std::vector<uint8_t>> mdr2DataInfoOffer(uint16_t agentId)
{
- std::string service = ipmi::getService(bus, mdrv2Interface, mdrv2Path);
+ std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
+ std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
if (mdrv2 == nullptr)
{
@@ -528,13 +533,13 @@
return ipmi::responseParmOutOfRange();
}
- sdbusplus::message::message method = bus.new_method_call(
+ sdbusplus::message::message method = bus->new_method_call(
service.c_str(), mdrv2Path, mdrv2Interface, "GetDataOffer");
std::vector<uint8_t> dataInfo;
try
{
- sdbusplus::message::message reply = bus.call(method);
+ sdbusplus::message::message reply = bus->call(method);
reply.read(dataInfo);
}
catch (sdbusplus::exception_t &e)
@@ -582,7 +587,8 @@
return IPMI_CC_PARM_OUT_OF_RANGE;
}
- std::string service = ipmi::getService(bus, mdrv2Interface, mdrv2Path);
+ std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
+ std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
if (mdrv2 == nullptr)
{
@@ -609,7 +615,7 @@
return IPMI_CC_PARM_OUT_OF_RANGE;
}
- sdbusplus::message::message method = bus.new_method_call(
+ sdbusplus::message::message method = bus->new_method_call(
service.c_str(), mdrv2Path, mdrv2Interface, "SendDataInformation");
method.append((uint8_t)idIndex, requestData->validFlag,
@@ -618,7 +624,7 @@
try
{
- sdbusplus::message::message reply = bus.call(method);
+ sdbusplus::message::message reply = bus->call(method);
reply.read(entryChanged);
}
catch (sdbusplus::exception_t &e)
@@ -666,8 +672,6 @@
*data_len = 0;
- std::string service = ipmi::getService(bus, mdrv2Interface, mdrv2Path);
-
if (mdrv2 == nullptr)
{
mdrv2 = std::make_unique<MDRV2>();
@@ -781,8 +785,6 @@
*data_len = 0;
- std::string service = ipmi::getService(bus, mdrv2Interface, mdrv2Path);
-
if (mdrv2 == nullptr)
{
mdrv2 = std::make_unique<MDRV2>();
@@ -1064,7 +1066,8 @@
return IPMI_CC_PARM_OUT_OF_RANGE;
}
- std::string service = ipmi::getService(bus, mdrv2Interface, mdrv2Path);
+ std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
+ std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
int idIndex =
mdrv2->findDataId(requestData->dataSetInfo.dataInfo,
@@ -1113,8 +1116,6 @@
*data_len = 0;
- std::string service = ipmi::getService(bus, mdrv2Interface, mdrv2Path);
-
if (mdrv2 == nullptr)
{
mdrv2 = std::make_unique<MDRV2>();
@@ -1175,7 +1176,8 @@
return ipmi::responseParmOutOfRange();
}
- std::string service = ipmi::getService(bus, mdrv2Interface, mdrv2Path);
+ std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
+ std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
if (mdrv2 == nullptr)
{
@@ -1300,13 +1302,14 @@
return ipmi::responseDestinationUnavailable();
}
bool status = false;
- std::string service = ipmi::getService(bus, mdrv2Interface, mdrv2Path);
- sdbusplus::message::message method = bus.new_method_call(
+ std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
+ std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
+ sdbusplus::message::message method = bus->new_method_call(
service.c_str(), mdrv2Path, mdrv2Interface, "AgentSynchronizeData");
try
{
- sdbusplus::message::message reply = bus.call(method);
+ sdbusplus::message::message reply = bus->call(method);
reply.read(status);
}
catch (sdbusplus::exception_t &e)