Reorganize the setEventReceiver code

This commit is to re-organise the code to make the
setEventReceiver optional when GetTID gets called.

Currently, it is being called on every GetTID command.
This is and OEM behaviour, which was implemented at -
https://gerrit.openbmc.org/c/openbmc/pldm/+/41779/36

Also, setEventReceiver is a command defined in the platform
Spec, so rightfully placing it under the platform handler.

Signed-off-by: Sagar Srinivas <sagar.srinivas@ibm.com>
Change-Id: Ib60e9d46a8eaf4806c5ec2e9575f4e219bc80eab
diff --git a/libpldmresponder/base.cpp b/libpldmresponder/base.cpp
index e1d86ec..076d894 100644
--- a/libpldmresponder/base.cpp
+++ b/libpldmresponder/base.cpp
@@ -174,65 +174,11 @@
     return response;
 }
 
-void Handler::processSetEventReceiver(
-    sdeventplus::source::EventBase& /*source */)
+void Handler::_processSetEventReceiver(sdeventplus::source::EventBase&
+                                       /*source */)
 {
     survEvent.reset();
-    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 = instanceIdDb.next(eid);
-    uint8_t eventMessageGlobalEnable =
-        PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
-    uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
-    uint8_t eventReceiverAddressInfo = pldm::responder::pdr::BmcMctpEid;
-    uint16_t heartbeatTimer = HEARTBEAT_TIMEOUT;
-
-    auto rc = encode_set_event_receiver_req(
-        instanceId, eventMessageGlobalEnable, transportProtocolType,
-        eventReceiverAddressInfo, heartbeatTimer, request);
-    if (rc != PLDM_SUCCESS)
-    {
-        instanceIdDb.free(eid, instanceId);
-        error("Failed to encode_set_event_receiver_req, rc = {RC}", "RC",
-              lg2::hex, rc);
-        return;
-    }
-
-    auto processSetEventReceiverResponse =
-        [](mctp_eid_t /*eid*/, const pldm_msg* response, size_t respMsgLen) {
-        if (response == nullptr || !respMsgLen)
-        {
-            error("Failed to receive response for setEventReceiver command");
-            return;
-        }
-
-        uint8_t completionCode{};
-        auto rc = decode_set_event_receiver_resp(response, respMsgLen,
-                                                 &completionCode);
-        if (rc || completionCode)
-        {
-            error(
-                "Failed to decode setEventReceiver command response, rc = {RC}, cc = {CC}",
-                "RC", rc, "CC", (unsigned)completionCode);
-            pldm::utils::reportError(
-                "xyz.openbmc_project.bmc.pldm.InternalFailure");
-        }
-    };
-    rc = handler->registerRequest(
-        eid, instanceId, PLDM_PLATFORM, PLDM_SET_EVENT_RECEIVER,
-        std::move(requestMsg), std::move(processSetEventReceiverResponse));
-
-    if (rc != PLDM_SUCCESS)
-    {
-        error("Failed to send the setEventReceiver request");
-    }
-
-    if (oemPlatformHandler)
-    {
-        oemPlatformHandler->countSetEventReceiver();
-        oemPlatformHandler->checkAndDisableWatchDog();
-    }
+    oemPlatformHandler->processSetEventReceiver();
 }
 
 Response Handler::getTID(const pldm_msg* request, size_t /*payloadLength*/)
@@ -246,8 +192,11 @@
         return ccOnlyResponse(request, rc);
     }
 
-    survEvent = std::make_unique<sdeventplus::source::Defer>(
-        event, std::bind_front(&Handler::processSetEventReceiver, this));
+    if (oemPlatformHandler)
+    {
+        survEvent = std::make_unique<sdeventplus::source::Defer>(
+            event, std::bind_front(&Handler::_processSetEventReceiver, this));
+    }
 
     return response;
 }