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/libpldmresponder/base.cpp b/libpldmresponder/base.cpp
index dd0e94a..e5bbf2f 100644
--- a/libpldmresponder/base.cpp
+++ b/libpldmresponder/base.cpp
@@ -184,7 +184,7 @@
std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
PLDM_SET_EVENT_RECEIVER_REQ_BYTES);
auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
- auto instanceId = requester.getInstanceId(eid);
+ auto instanceId = instanceIdDb.next(eid);
uint8_t eventMessageGlobalEnable =
PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
@@ -196,7 +196,7 @@
eventReceiverAddressInfo, heartbeatTimer, request);
if (rc != PLDM_SUCCESS)
{
- requester.markFree(eid, instanceId);
+ instanceIdDb.free(eid, instanceId);
error("Failed to encode_set_event_receiver_req, rc = {RC}", "RC",
lg2::hex, rc);
return;
diff --git a/libpldmresponder/base.hpp b/libpldmresponder/base.hpp
index 9a13f2d..2f7c714 100644
--- a/libpldmresponder/base.hpp
+++ b/libpldmresponder/base.hpp
@@ -13,7 +13,6 @@
#include <vector>
-using namespace pldm::dbus_api;
using namespace pldm::responder;
namespace pldm
@@ -25,11 +24,12 @@
class Handler : public CmdHandler
{
public:
- Handler(uint8_t eid, Requester& requester, sdeventplus::Event& event,
+ Handler(uint8_t eid, pldm::InstanceIdDb& instanceIdDb,
+ sdeventplus::Event& event,
pldm::responder::oem_platform::Handler* oemPlatformHandler,
pldm::requester::Handler<pldm::requester::Request>* handler) :
eid(eid),
- requester(requester), event(event),
+ instanceIdDb(instanceIdDb), event(event),
oemPlatformHandler(oemPlatformHandler), handler(handler)
{
handlers.emplace(PLDM_GET_PLDM_TYPES,
@@ -94,10 +94,8 @@
/** @brief MCTP EID of host firmware */
uint8_t eid;
- /** @brief reference to Requester object, primarily used to access API to
- * obtain PLDM instance id.
- */
- Requester& requester;
+ /** @brief An instance ID database for allocating instance IDs. */
+ InstanceIdDb& instanceIdDb;
/** @brief reference of main event loop of pldmd, primarily used to schedule
* work
diff --git a/libpldmresponder/bios.cpp b/libpldmresponder/bios.cpp
index e2e4e52..4c46b9a 100644
--- a/libpldmresponder/bios.cpp
+++ b/libpldmresponder/bios.cpp
@@ -69,10 +69,10 @@
DBusHandler dbusHandler;
-Handler::Handler(int fd, uint8_t eid, dbus_api::Requester* requester,
+Handler::Handler(int fd, uint8_t eid, pldm::InstanceIdDb* instanceIdDb,
pldm::requester::Handler<pldm::requester::Request>* handler) :
biosConfig(BIOS_JSONS_DIR, BIOS_TABLES_DIR, &dbusHandler, fd, eid,
- requester, handler)
+ instanceIdDb, handler)
{
biosConfig.removeTables();
biosConfig.buildTables();
diff --git a/libpldmresponder/bios.hpp b/libpldmresponder/bios.hpp
index d77e9c8..f72c9e8 100644
--- a/libpldmresponder/bios.hpp
+++ b/libpldmresponder/bios.hpp
@@ -4,8 +4,8 @@
#include "bios_config.hpp"
#include "bios_table.hpp"
-#include "pldmd/dbus_impl_requester.hpp"
#include "pldmd/handler.hpp"
+#include "pldmd/instance_id.hpp"
#include "requester/handler.hpp"
#include <libpldm/bios.h>
@@ -33,10 +33,10 @@
*
* @param[in] fd - socket descriptor to communicate to host
* @param[in] eid - MCTP EID of host firmware
- * @param[in] requester - pointer to Requester object
+ * @param[in] instanceIdDb - pointer to an InstanceIdDb object
* @param[in] handler - PLDM request handler
*/
- Handler(int fd, uint8_t eid, dbus_api::Requester* requester,
+ Handler(int fd, uint8_t eid, pldm::InstanceIdDb* instanceIdDb,
pldm::requester::Handler<pldm::requester::Request>* handler);
/** @brief Handler for GetDateTime
diff --git a/libpldmresponder/bios_config.cpp b/libpldmresponder/bios_config.cpp
index 716b0dc..69a98f4 100644
--- a/libpldmresponder/bios_config.cpp
+++ b/libpldmresponder/bios_config.cpp
@@ -18,7 +18,6 @@
PHOSPHOR_LOG2_USING;
-using namespace pldm::dbus_api;
using namespace pldm::utils;
namespace pldm
@@ -44,11 +43,11 @@
BIOSConfig::BIOSConfig(
const char* jsonDir, const char* tableDir, DBusHandler* const dbusHandler,
- int fd, uint8_t eid, dbus_api::Requester* requester,
+ int fd, uint8_t eid, pldm::InstanceIdDb* instanceIdDb,
pldm::requester::Handler<pldm::requester::Request>* handler) :
jsonDir(jsonDir),
tableDir(tableDir), dbusHandler(dbusHandler), fd(fd), eid(eid),
- requester(requester), handler(handler)
+ instanceIdDb(instanceIdDb), handler(handler)
{
fs::create_directories(tableDir);
@@ -1042,7 +1041,7 @@
{
#ifdef OEM_IBM
auto rc = pldm::responder::platform::sendBiosAttributeUpdateEvent(
- eid, requester, listOfHandles, handler);
+ eid, instanceIdDb, listOfHandles, handler);
if (rc != PLDM_SUCCESS)
{
return;
diff --git a/libpldmresponder/bios_config.hpp b/libpldmresponder/bios_config.hpp
index 2d07593..6e27642 100644
--- a/libpldmresponder/bios_config.hpp
+++ b/libpldmresponder/bios_config.hpp
@@ -2,7 +2,7 @@
#include "bios_attribute.hpp"
#include "bios_table.hpp"
-#include "pldmd/dbus_impl_requester.hpp"
+#include "pldmd/instance_id.hpp"
#include "requester/handler.hpp"
#include <libpldm/bios_table.h>
@@ -74,13 +74,13 @@
* @param[in] dbusHandler - Dbus Handler
* @param[in] fd - socket descriptor to communicate to host
* @param[in] eid - MCTP EID of host firmware
- * @param[in] requester - pointer to Requester object
+ * @param[in] instanceIdDb - pointer to an InstanceIdDb object
* @param[in] handler - PLDM request handler
*/
explicit BIOSConfig(
const char* jsonDir, const char* tableDir,
pldm::utils::DBusHandler* const dbusHandler, int fd, uint8_t eid,
- dbus_api::Requester* requester,
+ pldm::InstanceIdDb* instanceIdDb,
pldm::requester::Handler<pldm::requester::Request>* handler);
/** @brief Set attribute value on dbus and attribute value table
@@ -146,10 +146,10 @@
/** @brief MCTP EID of host firmware */
uint8_t eid;
- /** @brief pointer to Requester object, primarily used to access API to
- * obtain PLDM instance id.
+ /** @brief pointer to an Instance ID database object, used to obtain PLDM
+ * instance IDs.
*/
- dbus_api::Requester* requester;
+ pldm::InstanceIdDb* instanceIdDb;
/** @brief PLDM request handler */
pldm::requester::Handler<pldm::requester::Request>* handler;
diff --git a/libpldmresponder/test/libpldmresponder_base_test.cpp b/libpldmresponder/test/libpldmresponder_base_test.cpp
index f1ecfc3..8931f0c 100644
--- a/libpldmresponder/test/libpldmresponder_base_test.cpp
+++ b/libpldmresponder/test/libpldmresponder_base_test.cpp
@@ -18,14 +18,11 @@
{
protected:
TestBaseCommands() :
- instanceIdDb(), requester(pldm::utils::DBusHandler::getBus(),
- "/abc/def", this->instanceIdDb),
- event(sdeventplus::Event::get_default())
+ instanceIdDb(), event(sdeventplus::Event::get_default())
{}
uint8_t mctpEid = 0;
TestInstanceIdDb instanceIdDb;
- Requester requester;
sdeventplus::Event event;
};
@@ -35,7 +32,7 @@
auto request = reinterpret_cast<pldm_msg*>(requestPayload.data());
// payload length will be 0 in this case
size_t requestPayloadLength = 0;
- base::Handler handler(mctpEid, requester, event, nullptr, nullptr);
+ base::Handler handler(mctpEid, instanceIdDb, event, nullptr, nullptr);
auto response = handler.getPLDMTypes(request, requestPayloadLength);
// Need to support OEM type.
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
@@ -52,7 +49,7 @@
requestPayload{};
auto request = reinterpret_cast<pldm_msg*>(requestPayload.data());
size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr);
- base::Handler handler(mctpEid, requester, event, nullptr, nullptr);
+ base::Handler handler(mctpEid, instanceIdDb, event, nullptr, nullptr);
auto response = handler.getPLDMCommands(request, requestPayloadLength);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
uint8_t* payload_ptr = responsePtr->payload;
@@ -69,7 +66,7 @@
request->payload[0] = 0xFF;
size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr);
- base::Handler handler(mctpEid, requester, event, nullptr, nullptr);
+ base::Handler handler(mctpEid, instanceIdDb, event, nullptr, nullptr);
auto response = handler.getPLDMCommands(request, requestPayloadLength);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
uint8_t* payload_ptr = responsePtr->payload;
@@ -94,7 +91,7 @@
ASSERT_EQ(0, rc);
- base::Handler handler(mctpEid, requester, event, nullptr, nullptr);
+ base::Handler handler(mctpEid, instanceIdDb, event, nullptr, nullptr);
auto response = handler.getPLDMVersion(request, requestPayloadLength);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
@@ -125,7 +122,7 @@
ASSERT_EQ(0, rc);
- base::Handler handler(mctpEid, requester, event, nullptr, nullptr);
+ base::Handler handler(mctpEid, instanceIdDb, event, nullptr, nullptr);
auto response = handler.getPLDMVersion(request, requestPayloadLength - 1);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
@@ -150,7 +147,7 @@
auto request = reinterpret_cast<pldm_msg*>(requestPayload.data());
size_t requestPayloadLength = 0;
- base::Handler handler(mctpEid, requester, event, nullptr, nullptr);
+ base::Handler handler(mctpEid, instanceIdDb, event, nullptr, nullptr);
auto response = handler.getTID(request, requestPayloadLength);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());