pldmd: Migrate instance ID allocation to pldm::InstanceIdDb
This removes use of `pldm::dbus_api::Requester` from around the
code-base. This makes progress towards removing the DBus API entirely
once all its consumers are converted to the libpldm instance ID APIs.
There was never a good reason for the code using the class to have
knowledge that it was related to DBus anyway, so this is, in-effect, a
double clean up improving separation of concerns.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I2d9397cae1b3c8c251c32e36ca520aad9c9b8cf6
diff --git a/host-bmc/dbus_to_event_handler.cpp b/host-bmc/dbus_to_event_handler.cpp
index e8f84a6..2c9d92e 100644
--- a/host-bmc/dbus_to_event_handler.cpp
+++ b/host-bmc/dbus_to_event_handler.cpp
@@ -10,7 +10,6 @@
namespace pldm
{
-using namespace pldm::dbus_api;
using namespace pldm::responder;
using namespace pldm::responder::pdr;
using namespace pldm::responder::pdr_utils;
@@ -22,16 +21,16 @@
const std::vector<uint8_t> pdrTypes{PLDM_STATE_SENSOR_PDR};
DbusToPLDMEvent::DbusToPLDMEvent(
- int mctp_fd, uint8_t mctp_eid, Requester& requester,
+ int mctp_fd, uint8_t mctp_eid, pldm::InstanceIdDb& instanceIdDb,
pldm::requester::Handler<pldm::requester::Request>* handler) :
mctp_fd(mctp_fd),
- mctp_eid(mctp_eid), requester(requester), handler(handler)
+ mctp_eid(mctp_eid), instanceIdDb(instanceIdDb), handler(handler)
{}
void DbusToPLDMEvent::sendEventMsg(uint8_t eventType,
const std::vector<uint8_t>& eventDataVec)
{
- auto instanceId = requester.getInstanceId(mctp_eid);
+ auto instanceId = instanceIdDb.next(mctp_eid);
std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
eventDataVec.size());
@@ -43,7 +42,7 @@
eventDataVec.size() + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES);
if (rc != PLDM_SUCCESS)
{
- requester.markFree(mctp_eid, instanceId);
+ instanceIdDb.free(mctp_eid, instanceId);
error("Failed to encode_platform_event_message_req, rc = {RC}", "RC",
rc);
return;
diff --git a/host-bmc/dbus_to_event_handler.hpp b/host-bmc/dbus_to_event_handler.hpp
index 886d6b5..87668c2 100644
--- a/host-bmc/dbus_to_event_handler.hpp
+++ b/host-bmc/dbus_to_event_handler.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "libpldmresponder/pdr_utils.hpp"
-#include "pldmd/dbus_impl_requester.hpp"
+#include "pldmd/instance_id.hpp"
#include "requester/handler.hpp"
#include <libpldm/platform.h>
@@ -41,7 +41,7 @@
* @param[in] handler - PLDM request handler
*/
explicit DbusToPLDMEvent(
- int mctp_fd, uint8_t mctp_eid, pldm::dbus_api::Requester& requester,
+ int mctp_fd, uint8_t mctp_eid, pldm::InstanceIdDb& instanceIdDb,
pldm::requester::Handler<pldm::requester::Request>* handler);
public:
@@ -71,10 +71,10 @@
/** @brief MCTP EID of host firmware */
uint8_t mctp_eid;
- /** @brief reference to Requester object, primarily used to access API to
- * obtain PLDM instance id.
+ /** @brief reference to an Instance ID database object, used to obtain PLDM
+ * instance IDs
*/
- pldm::dbus_api::Requester& requester;
+ pldm::InstanceIdDb& instanceIdDb;
/** @brief D-Bus property changed signal match */
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> stateSensorMatchs;
diff --git a/host-bmc/dbus_to_host_effecters.cpp b/host-bmc/dbus_to_host_effecters.cpp
index 8f54ca2..884662e 100644
--- a/host-bmc/dbus_to_host_effecters.cpp
+++ b/host-bmc/dbus_to_host_effecters.cpp
@@ -255,7 +255,7 @@
{
uint8_t& mctpEid = hostEffecterInfo[effecterInfoIndex].mctpEid;
uint8_t& compEffCnt = hostEffecterInfo[effecterInfoIndex].compEffecterCnt;
- auto instanceId = requester->getInstanceId(mctpEid);
+ auto instanceId = instanceIdDb->next(mctpEid);
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) + sizeof(effecterId) + sizeof(compEffCnt) +
@@ -269,7 +269,7 @@
{
error("Message encode failure. PLDM error code = {RC}", "RC", lg2::hex,
rc);
- requester->markFree(mctpEid, instanceId);
+ instanceIdDb->free(mctpEid, instanceId);
return rc;
}
diff --git a/host-bmc/dbus_to_host_effecters.hpp b/host-bmc/dbus_to_host_effecters.hpp
index c5aef12..3690ad8 100644
--- a/host-bmc/dbus_to_host_effecters.hpp
+++ b/host-bmc/dbus_to_host_effecters.hpp
@@ -2,7 +2,7 @@
#include "common/types.hpp"
#include "common/utils.hpp"
-#include "pldmd/dbus_impl_requester.hpp"
+#include "pldmd/instance_id.hpp"
#include "requester/handler.hpp"
#include <phosphor-logging/lg2.hpp>
@@ -74,7 +74,7 @@
virtual ~HostEffecterParser() = default;
/** @brief Constructor to create a HostEffecterParser object.
- * @param[in] requester - PLDM Requester object pointer
+ * @param[in] instanceIdDb - PLDM InstanceIdDb object pointer
* @param[in] fd - socket fd to communicate to host
* @param[in] repo - PLDM PDR repository
* @param[in] dbusHandler - D-bus Handler
@@ -82,11 +82,11 @@
* @param[in] handler - PLDM request handler
*/
explicit HostEffecterParser(
- pldm::dbus_api::Requester* requester, int fd, const pldm_pdr* repo,
+ pldm::InstanceIdDb* instanceIdDb, int fd, const pldm_pdr* repo,
pldm::utils::DBusHandler* const dbusHandler,
const std::string& jsonPath,
pldm::requester::Handler<pldm::requester::Request>* handler) :
- requester(requester),
+ instanceIdDb(instanceIdDb),
sockFd(fd), pdrRepo(repo), dbusHandler(dbusHandler), handler(handler)
{
try
@@ -173,10 +173,10 @@
uint16_t effecterId);
protected:
- pldm::dbus_api::Requester*
- requester; //!< Reference to Requester to obtain instance id
- int sockFd; //!< Socket fd to send message to host
- const pldm_pdr* pdrRepo; //!< Reference to PDR repo
+ pldm::InstanceIdDb* instanceIdDb; //!< Reference to the InstanceIdDb object
+ //!< to obtain instance id
+ int sockFd; //!< Socket fd to send message to host
+ const pldm_pdr* pdrRepo; //!< Reference to PDR repo
std::vector<EffecterInfo> hostEffecterInfo; //!< Parsed effecter information
std::vector<std::unique_ptr<sdbusplus::bus::match_t>>
effecterInfoMatch; //!< vector to catch the D-Bus property change
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index a5ecced..1b0024c 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -18,7 +18,6 @@
namespace pldm
{
-using namespace pldm::dbus_api;
using namespace pldm::responder::events;
using namespace pldm::utils;
using namespace sdbusplus::bus::match::rules;
@@ -50,12 +49,13 @@
HostPDRHandler::HostPDRHandler(
int mctp_fd, uint8_t mctp_eid, sdeventplus::Event& event, pldm_pdr* repo,
const std::string& eventsJsonsDir, pldm_entity_association_tree* entityTree,
- pldm_entity_association_tree* bmcEntityTree, Requester& requester,
+ pldm_entity_association_tree* bmcEntityTree,
+ pldm::InstanceIdDb& instanceIdDb,
pldm::requester::Handler<pldm::requester::Request>* handler) :
mctp_fd(mctp_fd),
mctp_eid(mctp_eid), event(event), repo(repo),
stateSensorHandler(eventsJsonsDir), entityTree(entityTree),
- bmcEntityTree(bmcEntityTree), requester(requester), handler(handler)
+ bmcEntityTree(bmcEntityTree), instanceIdDb(instanceIdDb), handler(handler)
{
fs::path hostFruJson(fs::path(HOST_JSONS_DIR) / fruJson);
if (fs::exists(hostFruJson))
@@ -172,14 +172,14 @@
{
recordHandle = nextRecordHandle;
}
- auto instanceId = requester.getInstanceId(mctp_eid);
+ auto instanceId = instanceIdDb.next(mctp_eid);
auto rc = encode_get_pdr_req(instanceId, recordHandle, 0,
PLDM_GET_FIRSTPART, UINT16_MAX, 0, request,
PLDM_GET_PDR_REQ_BYTES);
if (rc != PLDM_SUCCESS)
{
- requester.markFree(mctp_eid, instanceId);
+ instanceIdDb.free(mctp_eid, instanceId);
error("Failed to encode_get_pdr_req, rc = {RC}", "RC", rc);
return;
}
@@ -313,7 +313,7 @@
"RC", rc);
return;
}
- auto instanceId = requester.getInstanceId(mctp_eid);
+ auto instanceId = instanceIdDb.next(mctp_eid);
std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
actualSize);
@@ -324,7 +324,7 @@
actualSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES);
if (rc != PLDM_SUCCESS)
{
- requester.markFree(mctp_eid, instanceId);
+ instanceIdDb.free(mctp_eid, instanceId);
error("Failed to encode_platform_event_message_req, rc = {RC}", "RC",
rc);
return;
@@ -600,7 +600,7 @@
void HostPDRHandler::setHostFirmwareCondition()
{
responseReceived = false;
- auto instanceId = requester.getInstanceId(mctp_eid);
+ auto instanceId = instanceIdDb.next(mctp_eid);
std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
PLDM_GET_VERSION_REQ_BYTES);
auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
@@ -610,7 +610,7 @@
{
error("GetPLDMVersion encode failure. PLDM error code = {RC}", "RC",
lg2::hex, rc);
- requester.markFree(mctp_eid, instanceId);
+ instanceIdDb.free(mctp_eid, instanceId);
return;
}
@@ -672,7 +672,7 @@
sensorRearm.byte = 0;
uint8_t tid = std::get<0>(terminusInfo);
- auto instanceId = requester.getInstanceId(mctp_eid);
+ auto instanceId = instanceIdDb.next(mctp_eid);
std::vector<uint8_t> requestMsg(
sizeof(pldm_msg_hdr) +
PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES);
@@ -682,7 +682,7 @@
if (rc != PLDM_SUCCESS)
{
- requester.markFree(mctp_eid, instanceId);
+ instanceIdDb.free(mctp_eid, instanceId);
error(
"Failed to encode_get_state_sensor_readings_req, rc = {RC}",
"RC", rc);
diff --git a/host-bmc/host_pdr_handler.hpp b/host-bmc/host_pdr_handler.hpp
index 64f2442..15ce1ac 100644
--- a/host-bmc/host_pdr_handler.hpp
+++ b/host-bmc/host_pdr_handler.hpp
@@ -4,7 +4,7 @@
#include "common/utils.hpp"
#include "libpldmresponder/event_parser.hpp"
#include "libpldmresponder/pdr_utils.hpp"
-#include "pldmd/dbus_impl_requester.hpp"
+#include "pldmd/instance_id.hpp"
#include "requester/handler.hpp"
#include <libpldm/base.h>
@@ -83,7 +83,7 @@
* @param[in] eventsJsonDir - directory path which has the config JSONs
* @param[in] entityTree - Pointer to BMC and Host entity association tree
* @param[in] bmcEntityTree - pointer to BMC's entity association tree
- * @param[in] requester - reference to Requester object
+ * @param[in] instanceIdDb - reference to an InstanceIdDb object
* @param[in] handler - PLDM request handler
*/
explicit HostPDRHandler(
@@ -91,7 +91,7 @@
pldm_pdr* repo, const std::string& eventsJsonsDir,
pldm_entity_association_tree* entityTree,
pldm_entity_association_tree* bmcEntityTree,
- pldm::dbus_api::Requester& requester,
+ pldm::InstanceIdDb& instanceIdDb,
pldm::requester::Handler<pldm::requester::Request>* handler);
/** @brief fetch PDRs from host firmware. See @class.
@@ -230,10 +230,10 @@
/** @brief Pointer to BMC's entity association tree */
pldm_entity_association_tree* bmcEntityTree;
- /** @brief reference to Requester object, primarily used to access API to
- * obtain PLDM instance id.
+ /** @brief reference to Instance ID database object, used to obtain PLDM
+ * instance IDs
*/
- pldm::dbus_api::Requester& requester;
+ pldm::InstanceIdDb& instanceIdDb;
/** @brief PLDM request handler */
pldm::requester::Handler<pldm::requester::Request>* handler;
diff --git a/host-bmc/test/dbus_to_host_effecter_test.cpp b/host-bmc/test/dbus_to_host_effecter_test.cpp
index bb9fc13..5c62e31 100644
--- a/host-bmc/test/dbus_to_host_effecter_test.cpp
+++ b/host-bmc/test/dbus_to_host_effecter_test.cpp
@@ -10,7 +10,6 @@
using namespace pldm::host_effecters;
using namespace pldm::utils;
-using namespace pldm::dbus_api;
class MockHostEffecterParser : public HostEffecterParser
{