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/oem/ibm/libpldmresponder/file_io.hpp b/oem/ibm/libpldmresponder/file_io.hpp
index 4e2af4f..aa3b9a9 100644
--- a/oem/ibm/libpldmresponder/file_io.hpp
+++ b/oem/ibm/libpldmresponder/file_io.hpp
@@ -170,11 +170,11 @@
 {
   public:
     Handler(oem_platform::Handler* oemPlatformHandler, int hostSockFd,
-            uint8_t hostEid, dbus_api::Requester* dbusImplReqester,
+            uint8_t hostEid, pldm::InstanceIdDb* instanceIdDb,
             pldm::requester::Handler<pldm::requester::Request>* handler) :
         oemPlatformHandler(oemPlatformHandler),
-        hostSockFd(hostSockFd), hostEid(hostEid),
-        dbusImplReqester(dbusImplReqester), handler(handler)
+        hostSockFd(hostSockFd), hostEid(hostEid), instanceIdDb(instanceIdDb),
+        handler(handler)
     {
         handlers.emplace(PLDM_READ_FILE_INTO_MEMORY,
                          [this](const pldm_msg* request, size_t payloadLength) {
@@ -229,7 +229,7 @@
             pldm::utils::DBusHandler::getBus(),
             sdbusplus::bus::match::rules::interfacesAdded() +
                 sdbusplus::bus::match::rules::argNpath(0, dumpObjPath),
-            [this, hostSockFd, hostEid, dbusImplReqester,
+            [this, hostSockFd, hostEid, instanceIdDb,
              handler](sdbusplus::message_t& msg) {
             std::map<std::string,
                      std::map<std::string, std::variant<std::string, uint32_t>>>
@@ -258,7 +258,7 @@
                         .emplace_back(
                             std::make_unique<
                                 pldm::requester::oem_ibm::DbusToFileHandler>(
-                                hostSockFd, hostEid, dbusImplReqester, path,
+                                hostSockFd, hostEid, instanceIdDb, path,
                                 handler))
                         ->processNewResourceDump(vspstring, password);
                     break;
@@ -269,7 +269,7 @@
             pldm::utils::DBusHandler::getBus(),
             sdbusplus::bus::match::rules::interfacesAdded() +
                 sdbusplus::bus::match::rules::argNpath(0, certObjPath),
-            [this, hostSockFd, hostEid, dbusImplReqester,
+            [this, hostSockFd, hostEid, instanceIdDb,
              handler](sdbusplus::message_t& msg) {
             std::map<std::string,
                      std::map<std::string, std::variant<std::string, uint32_t>>>
@@ -295,8 +295,8 @@
                                 .emplace_back(
                                     std::make_unique<pldm::requester::oem_ibm::
                                                          DbusToFileHandler>(
-                                        hostSockFd, hostEid, dbusImplReqester,
-                                        path, handler))
+                                        hostSockFd, hostEid, instanceIdDb, path,
+                                        handler))
                                 ->newCsrFileAvailable(csr, fileHandle);
                             break;
                         }
@@ -408,7 +408,7 @@
     oem_platform::Handler* oemPlatformHandler;
     int hostSockFd;
     uint8_t hostEid;
-    dbus_api::Requester* dbusImplReqester;
+    pldm::InstanceIdDb* instanceIdDb;
     using DBusInterfaceAdded = std::vector<std::pair<
         std::string,
         std::vector<std::pair<std::string, std::variant<std::string>>>>>;
diff --git a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
index fd1b0c4..c4befbb 100644
--- a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
+++ b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
@@ -368,7 +368,7 @@
     eventClass->sensor_offset = sensorOffset;
     eventClass->event_state = eventState;
     eventClass->previous_event_state = prevEventState;
-    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 +
                                     sensorEventDataVec.size());
@@ -377,7 +377,7 @@
     if (rc != PLDM_SUCCESS)
     {
         error("Failed to encode state sensor event, rc = {RC}", "RC", rc);
-        requester.markFree(mctp_eid, instanceId);
+        instanceIdDb.free(mctp_eid, instanceId);
         return;
     }
     rc = sendEventToHost(requestMsg, instanceId);
diff --git a/oem/ibm/libpldmresponder/oem_ibm_handler.hpp b/oem/ibm/libpldmresponder/oem_ibm_handler.hpp
index 4de6835..520d060 100644
--- a/oem/ibm/libpldmresponder/oem_ibm_handler.hpp
+++ b/oem/ibm/libpldmresponder/oem_ibm_handler.hpp
@@ -31,12 +31,13 @@
   public:
     Handler(const pldm::utils::DBusHandler* dBusIntf,
             pldm::responder::CodeUpdate* codeUpdate, int mctp_fd,
-            uint8_t mctp_eid, pldm::dbus_api::Requester& requester,
+            uint8_t mctp_eid, pldm::InstanceIdDb& instanceIdDb,
             sdeventplus::Event& event,
             pldm::requester::Handler<pldm::requester::Request>* handler) :
         oem_platform::Handler(dBusIntf),
         codeUpdate(codeUpdate), platformHandler(nullptr), mctp_fd(mctp_fd),
-        mctp_eid(mctp_eid), requester(requester), event(event), handler(handler)
+        mctp_eid(mctp_eid), instanceIdDb(instanceIdDb), event(event),
+        handler(handler)
     {
         codeUpdate->setVersions();
         setEventReceiverCnt = 0;
@@ -192,10 +193,9 @@
     /** @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.
-     */
-    pldm::dbus_api::Requester& requester;
+    /** @brief reference to an InstanceIdDb object, used to obtain a PLDM
+     * instance id. */
+    pldm::InstanceIdDb& instanceIdDb;
     /** @brief sdeventplus event source */
     std::unique_ptr<sdeventplus::source::Defer> assembleImageEvent;
     std::unique_ptr<sdeventplus::source::Defer> startUpdateEvent;
diff --git a/oem/ibm/libpldmresponder/platform_oem_ibm.cpp b/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
index e7966a2..022404c 100644
--- a/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
+++ b/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
@@ -20,7 +20,7 @@
 namespace platform
 {
 int sendBiosAttributeUpdateEvent(
-    uint8_t eid, dbus_api::Requester* requester,
+    uint8_t eid, pldm::InstanceIdDb* instanceIdDb,
     const std::vector<uint16_t>& handles,
     pldm::requester::Handler<pldm::requester::Request>* handler)
 {
@@ -61,7 +61,7 @@
             "EXCEP_NAME", e.name());
     }
 
-    auto instanceId = requester->getInstanceId(eid);
+    auto instanceId = instanceIdDb->next(eid);
 
     std::vector<uint8_t> requestMsg(
         sizeof(pldm_msg_hdr) + sizeof(pldm_bios_attribute_update_event_req) -
@@ -79,7 +79,7 @@
         error(
             "BIOS Attribute update event message encode failure. PLDM error code = {RC}",
             "RC", lg2::hex, rc);
-        requester->markFree(eid, instanceId);
+        instanceIdDb->free(eid, instanceId);
         return rc;
     }
 
diff --git a/oem/ibm/libpldmresponder/platform_oem_ibm.hpp b/oem/ibm/libpldmresponder/platform_oem_ibm.hpp
index 94dc2dd..13ec2d5 100644
--- a/oem/ibm/libpldmresponder/platform_oem_ibm.hpp
+++ b/oem/ibm/libpldmresponder/platform_oem_ibm.hpp
@@ -1,6 +1,6 @@
 #pragma once
 
-#include "pldmd/dbus_impl_requester.hpp"
+#include "pldmd/instance_id.hpp"
 #include "requester/handler.hpp"
 
 #include <vector>
@@ -20,12 +20,12 @@
  *  list of BIOS attribute handles.
  *
  *  @param[in] eid - MCTP EID of host firmware
- *  @param[in] requester - pointer to Requester object
+ *  @param[in] instanceIdDb - pointer to InstanceIdDb object
  *  @param[in] handles - List of BIOS attribute handles
  *  @param[in] handler - PLDM request handler
  */
 int sendBiosAttributeUpdateEvent(
-    uint8_t eid, dbus_api::Requester* requester,
+    uint8_t eid, pldm::InstanceIdDb* instanceIdDb,
     const std::vector<uint16_t>& handles,
     pldm::requester::Handler<pldm::requester::Request>* handler);
 
diff --git a/oem/ibm/requester/dbus_to_file_handler.cpp b/oem/ibm/requester/dbus_to_file_handler.cpp
index e71116a..9c2b80a 100644
--- a/oem/ibm/requester/dbus_to_file_handler.cpp
+++ b/oem/ibm/requester/dbus_to_file_handler.cpp
@@ -27,25 +27,25 @@
     "xyz.openbmc_project.Common.Progress.OperationStatus.Failed";
 
 DbusToFileHandler::DbusToFileHandler(
-    int mctp_fd, uint8_t mctp_eid, dbus_api::Requester* requester,
+    int mctp_fd, uint8_t mctp_eid, pldm::InstanceIdDb* instanceIdDb,
     sdbusplus::message::object_path resDumpCurrentObjPath,
     pldm::requester::Handler<pldm::requester::Request>* handler) :
     mctp_fd(mctp_fd),
-    mctp_eid(mctp_eid), requester(requester),
+    mctp_eid(mctp_eid), instanceIdDb(instanceIdDb),
     resDumpCurrentObjPath(resDumpCurrentObjPath), handler(handler)
 {}
 
 void DbusToFileHandler::sendNewFileAvailableCmd(uint64_t fileSize)
 {
-    if (requester == NULL)
+    if (instanceIdDb == NULL)
     {
         error(
-            "Failed to send resource dump parameters as requester is not set");
+            "Failed to send resource dump parameters as instance ID DB is not set");
         pldm::utils::reportError(
             "xyz.openbmc_project.bmc.pldm.InternalFailure");
         return;
     }
-    auto instanceId = requester->getInstanceId(mctp_eid);
+    auto instanceId = instanceIdDb->next(mctp_eid);
     std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
                                     PLDM_NEW_FILE_REQ_BYTES);
     auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
@@ -57,7 +57,7 @@
                                   fileHandle, fileSize, request);
     if (rc != PLDM_SUCCESS)
     {
-        requester->markFree(mctp_eid, instanceId);
+        instanceIdDb->free(mctp_eid, instanceId);
         error("Failed to encode_new_file_req, rc = {RC}", "RC", rc);
         return;
     }
@@ -247,14 +247,14 @@
                                                    const uint32_t fileHandle,
                                                    const uint16_t type)
 {
-    if (requester == NULL)
+    if (instanceIdDb == NULL)
     {
         error("Failed to send csr to host.");
         pldm::utils::reportError(
             "xyz.openbmc_project.bmc.pldm.InternalFailure");
         return;
     }
-    auto instanceId = requester->getInstanceId(mctp_eid);
+    auto instanceId = instanceIdDb->next(mctp_eid);
     std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
                                     PLDM_NEW_FILE_REQ_BYTES);
     auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
@@ -263,7 +263,7 @@
                                   request);
     if (rc != PLDM_SUCCESS)
     {
-        requester->markFree(mctp_eid, instanceId);
+        instanceIdDb->free(mctp_eid, instanceId);
         error("Failed to encode_new_file_req, rc = {RC}", "RC", rc);
         return;
     }
diff --git a/oem/ibm/requester/dbus_to_file_handler.hpp b/oem/ibm/requester/dbus_to_file_handler.hpp
index 60f1b70..a2ba166 100644
--- a/oem/ibm/requester/dbus_to_file_handler.hpp
+++ b/oem/ibm/requester/dbus_to_file_handler.hpp
@@ -1,6 +1,6 @@
 #pragma once
 
-#include "pldmd/dbus_impl_requester.hpp"
+#include "pldmd/instance_id.hpp"
 #include "requester/handler.hpp"
 
 #include <libpldm/platform.h>
@@ -34,12 +34,12 @@
     /** @brief Constructor
      *  @param[in] mctp_fd - fd of MCTP communications socket
      *  @param[in] mctp_eid - MCTP EID of host firmware
-     *  @param[in] requester - pointer to a Requester object
+     *  @param[in] instanceIdDb - pointer to a InstanceIdDb object
      *  @param[in] resDumpCurrentObjPath - resource dump current object path
      *  @param[in] handler - PLDM request handler
      */
     DbusToFileHandler(
-        int mctp_fd, uint8_t mctp_eid, dbus_api::Requester* requester,
+        int mctp_fd, uint8_t mctp_eid, pldm::InstanceIdDb* instanceIdDb,
         sdbusplus::message::object_path resDumpCurrentObjPath,
         pldm::requester::Handler<pldm::requester::Request>* handler);
 
@@ -85,10 +85,8 @@
     /** @brief MCTP EID of host firmware */
     uint8_t mctp_eid;
 
-    /** @brief Pointer to a Requester object, primarily used to access API to
-     *  obtain PLDM instance id.
-     */
-    dbus_api::Requester* requester;
+    /** @brief Pointer to an InstanceIdDb used to obtain PLDM instance id. */
+    pldm::InstanceIdDb* instanceIdDb;
 
     /** @brief Hold the current resource dump object path */
     sdbusplus::message::object_path resDumpCurrentObjPath;
diff --git a/oem/ibm/test/libpldmresponder_oem_platform_test.cpp b/oem/ibm/test/libpldmresponder_oem_platform_test.cpp
index ca9dd66..bb157f2 100644
--- a/oem/ibm/test/libpldmresponder_oem_platform_test.cpp
+++ b/oem/ibm/test/libpldmresponder_oem_platform_test.cpp
@@ -15,7 +15,6 @@
 
 #include <iostream>
 
-using namespace pldm::dbus_api;
 using namespace pldm::utils;
 using namespace pldm::responder;
 using namespace pldm::responder::pdr;
@@ -37,10 +36,10 @@
   public:
     MockOemPlatformHandler(const pldm::utils::DBusHandler* dBusIntf,
                            pldm::responder::CodeUpdate* codeUpdate, int mctp_fd,
-                           uint8_t mctp_eid, Requester& requester,
+                           uint8_t mctp_eid, pldm::InstanceIdDb& instanceIdDb,
                            sdeventplus::Event& event) :
         oem_ibm_platform::Handler(dBusIntf, codeUpdate, mctp_fd, mctp_eid,
-                                  requester, event, nullptr)
+                                  instanceIdDb, event, nullptr)
     {}
     MOCK_METHOD(uint16_t, getNextEffecterId, ());
     MOCK_METHOD(uint16_t, getNextSensorId, ());
@@ -56,7 +55,6 @@
     TestInstanceIdDb instanceIdDb;
 
     sdbusplus::bus_t bus(sdbusplus::bus::new_default());
-    Requester requester(bus, "/abc/def", instanceIdDb);
     auto event = sdeventplus::Event::get_default();
     std::vector<get_sensor_state_field> stateField;
 
@@ -66,8 +64,8 @@
     std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
 
     oemPlatformHandler = std::make_unique<oem_ibm_platform::Handler>(
-        mockDbusHandler.get(), mockCodeUpdate.get(), 0x1, 0x9, requester, event,
-        nullptr);
+        mockDbusHandler.get(), mockCodeUpdate.get(), 0x1, 0x9, instanceIdDb,
+        event, nullptr);
 
     auto rc = oemPlatformHandler->getOemStateSensorReadingsHandler(
         entityID_, entityInstance_, stateSetId_, compSensorCnt_, stateField);
@@ -191,7 +189,6 @@
     sdbusplus::bus_t bus(sdbusplus::bus::new_default());
     std::filesystem::path dbPath;
     TestInstanceIdDb instanceIdDb;
-    Requester requester(bus, "/abc/def", instanceIdDb);
     auto mockDbusHandler = std::make_unique<MockdBusHandler>();
     auto event = sdeventplus::Event::get_default();
     std::unique_ptr<CodeUpdate> mockCodeUpdate =
@@ -199,7 +196,7 @@
     std::unique_ptr<oem_ibm_platform::Handler> mockoemPlatformHandler =
         std::make_unique<MockOemPlatformHandler>(mockDbusHandler.get(),
                                                  mockCodeUpdate.get(), 0x1, 0x9,
-                                                 requester, event);
+                                                 instanceIdDb, event);
     Repo inRepo(inPDRRepo);
 
     mockoemPlatformHandler->buildOEMPDR(inRepo);
@@ -298,7 +295,6 @@
     sdbusplus::bus_t bus(sdbusplus::bus::new_default());
     std::filesystem::path dbPath;
     TestInstanceIdDb instanceIdDb;
-    Requester requester(bus, "/abc/def", instanceIdDb);
 
     auto mockDbusHandler = std::make_unique<MockdBusHandler>();
     auto event = sdeventplus::Event::get_default();
@@ -307,7 +303,7 @@
     std::unique_ptr<oem_ibm_platform::Handler> mockoemPlatformHandler =
         std::make_unique<MockOemPlatformHandler>(mockDbusHandler.get(),
                                                  mockCodeUpdate.get(), 0x1, 0x9,
-                                                 requester, event);
+                                                 instanceIdDb, event);
     Repo inRepo(inPDRRepo);
     mockoemPlatformHandler->buildOEMPDR(inRepo);
     ASSERT_EQ(inRepo.empty(), false);