platform-mc: Support multi-handlers for polled events
platform-mc only supports one event handler for the polled events.
Update the code to allow multiple event handlers.
Change-Id: Icfb531ce89a49bb417ca94bd608442f9323810b4
Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
diff --git a/platform-mc/event_manager.cpp b/platform-mc/event_manager.cpp
index 139438b..80ee6fc 100644
--- a/platform-mc/event_manager.cpp
+++ b/platform-mc/event_manager.cpp
@@ -518,6 +518,33 @@
return PLDM_SUCCESS;
}
+void EventManager::callPolledEventHandlers(pldm_tid_t tid, uint8_t eventClass,
+ uint16_t eventId,
+ std::vector<uint8_t>& eventMessage)
+{
+ try
+ {
+ const auto& handlers = eventHandlers.at(eventClass);
+ for (const auto& handler : handlers)
+ {
+ auto rc =
+ handler(tid, eventId, eventMessage.data(), eventMessage.size());
+ if (rc != PLDM_SUCCESS)
+ {
+ lg2::error(
+ "Failed to handle platform event msg for terminus {TID}, event {EVENTID} return {RET}",
+ "TID", tid, "EVENTID", eventId, "RET", rc);
+ }
+ }
+ }
+ catch (const std::out_of_range& e)
+ {
+ lg2::error(
+ "Failed to handle platform event msg for terminus {TID}, event {EVENTID} error - {ERROR}",
+ "TID", tid, "EVENTID", eventId, "ERROR", e);
+ }
+}
+
exec::task<int> EventManager::pollForPlatformEventTask(
pldm_tid_t tid, uint32_t pollDataTransferHandle)
{
@@ -582,9 +609,8 @@
/* Handle the polled event after finish ACK it */
if (eventHandlers.contains(polledEventClass))
{
- eventHandlers.at(
- polledEventClass)(polledEventTid, polledEventId,
- eventMessage.data(), eventMessage.size());
+ callPolledEventHandlers(polledEventTid, polledEventClass,
+ polledEventId, eventMessage);
}
eventMessage.clear();