implement async handlers for all requester commands
this commit makes use of 74f27c730ef3925a0f2a3adfaa04f8790f931372 to
convert the existing blocking requester commands in pldm to async
ones.
this is tested with Host code and seems to work fine
Change-Id: I8d4762c3cd5bce49f854b30f8325bfcd1dcb4ff9
Signed-off-by: Sampa Misra <sampmisr@in.ibm.com>
diff --git a/host-bmc/dbus_to_event_handler.cpp b/host-bmc/dbus_to_event_handler.cpp
index ac8778f..bb38cb8 100644
--- a/host-bmc/dbus_to_event_handler.cpp
+++ b/host-bmc/dbus_to_event_handler.cpp
@@ -15,10 +15,11 @@
{
const std::vector<uint8_t> pdrTypes{PLDM_STATE_SENSOR_PDR};
-DbusToPLDMEvent::DbusToPLDMEvent(int mctp_fd, uint8_t mctp_eid,
- Requester& requester) :
+DbusToPLDMEvent::DbusToPLDMEvent(
+ int mctp_fd, uint8_t mctp_eid, Requester& requester,
+ pldm::requester::Handler<pldm::requester::Request>* handler) :
mctp_fd(mctp_fd),
- mctp_eid(mctp_eid), requester(requester)
+ mctp_eid(mctp_eid), requester(requester), handler(handler)
{}
void DbusToPLDMEvent::sendEventMsg(uint8_t eventType,
@@ -42,36 +43,34 @@
return;
}
- uint8_t* responseMsg = nullptr;
- size_t responseMsgSize{};
+ auto platformEventMessageResponseHandler = [](mctp_eid_t /*eid*/,
+ const pldm_msg* response,
+ size_t respMsgLen) {
+ if (response == nullptr || !respMsgLen)
+ {
+ std::cerr
+ << "Failed to receive response for platform event message \n";
+ return;
+ }
+ uint8_t completionCode{};
+ uint8_t status{};
+ auto rc = decode_platform_event_message_resp(response, respMsgLen,
+ &completionCode, &status);
+ if (rc || completionCode)
+ {
+ std::cerr << "Failed to decode_platform_event_message_resp: "
+ << "rc=" << rc
+ << ", cc=" << static_cast<unsigned>(completionCode)
+ << std::endl;
+ }
+ };
- auto requesterRc =
- pldm_send_recv(mctp_eid, mctp_fd, requestMsg.data(), requestMsg.size(),
- &responseMsg, &responseMsgSize);
- std::unique_ptr<uint8_t, decltype(std::free)*> responseMsgPtr{responseMsg,
- std::free};
-
- requester.markFree(mctp_eid, instanceId);
- if (requesterRc != PLDM_REQUESTER_SUCCESS)
+ rc = handler->registerRequest(
+ mctp_eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE,
+ std::move(requestMsg), std::move(platformEventMessageResponseHandler));
+ if (rc)
{
- std::cerr
- << "Failed to send msg to report state sensor event changes, rc = "
- << requesterRc << std::endl;
- return;
- }
- uint8_t completionCode{};
- uint8_t status{};
- auto responsePtr = reinterpret_cast<struct pldm_msg*>(responseMsgPtr.get());
- rc = decode_platform_event_message_resp(
- responsePtr, responseMsgSize - sizeof(pldm_msg_hdr), &completionCode,
- &status);
-
- if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
- {
- std::cerr << "Failed to decode_platform_event_message_resp: "
- << "rc=" << rc
- << ", cc=" << static_cast<unsigned>(completionCode)
- << std::endl;
+ std::cerr << "Failed to send the platform event message \n";
}
}