pldmd: implement PLDM.Requester D-Bus API

Implement D-Bus API defined at
https://gerrit.openbmc-project.xyz/#/c/openbmc/phosphor-dbus-interfaces/+/27077/.

This commit provides an implementation of the PLDM instance id as per
DSP0240 v1.0.0. Ids are tracked per MCTP EID.

Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Change-Id: I8a1ef213646529b71d9bf33edda67537f7c0f32a
diff --git a/pldmd.cpp b/pldmd.cpp
index dce5625..39bee54 100644
--- a/pldmd.cpp
+++ b/pldmd.cpp
@@ -1,3 +1,4 @@
+#include "dbus_impl_requester.hpp"
 #include "libpldmresponder/base.hpp"
 #include "libpldmresponder/bios.hpp"
 #include "libpldmresponder/platform.hpp"
@@ -40,7 +41,8 @@
 using namespace sdeventplus;
 using namespace sdeventplus::source;
 
-static Response processRxMsg(const std::vector<uint8_t>& requestMsg)
+static Response processRxMsg(const std::vector<uint8_t>& requestMsg,
+                             dbus_api::Requester& requester)
 {
 
     Response response;
@@ -78,6 +80,10 @@
             response.insert(response.end(), completion_code);
         }
     }
+    else
+    {
+        requester.markFree(eid, hdr->instance_id);
+    }
     return response;
 }
 
@@ -180,7 +186,10 @@
         exit(EXIT_FAILURE);
     }
 
-    auto callback = [verbose](IO& /*io*/, int fd, uint32_t revents) {
+    auto bus = sdbusplus::bus::new_default();
+    dbus_api::Requester dbusImplReq(bus, "/xyz/openbmc_project/pldm");
+    auto callback = [verbose, &dbusImplReq](IO& /*io*/, int fd,
+                                            uint32_t revents) {
         if (!(revents & EPOLLIN))
         {
             return;
@@ -231,7 +240,7 @@
                 else
                 {
                     // process message and send response
-                    auto response = processRxMsg(requestMsg);
+                    auto response = processRxMsg(requestMsg, dbusImplReq);
                     if (!response.empty())
                     {
                         if (verbose)
@@ -269,6 +278,8 @@
     };
 
     auto event = Event::get_default();
+    bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
+    bus.request_name("xyz.openbmc_project.PLDM");
     IO io(event, socketFd(), EPOLLIN, std::move(callback));
     event.loop();