Fix: create a deferred event for tasks after GetPDR
There are certain tasks that need to be performed when a GetPDR is
received. That should be done after sending response to GetPDR
before fix:
Received Msg
09 01 86 02 51 00 00 00 00 00 00 00 00 01 ff 7f 00 00
Sending Msg
06 02 51 05
after fix:
Received Msg
09 01 9e 02 51 34 00 00 00 00 00 00 00 01 ff 7f 00 00
Sending Msg
1e 02 51 00 35 00 00 00 00 00 00 00 05 1d 00 34 00 00
00 01 0b 00 00 13 00 02 00 03 00 43 00 04 00 01 00 00 00 00 00 01 c0 00 01 0c
Change-Id: I9590a8365177d5f0e31bad3b67be7e6fbd302822
Signed-off-by: Sampa Misra <sampmisr@in.ibm.com>
diff --git a/libpldmresponder/platform.cpp b/libpldmresponder/platform.cpp
index eebad87..893cc83 100644
--- a/libpldmresponder/platform.cpp
+++ b/libpldmresponder/platform.cpp
@@ -159,8 +159,11 @@
if (dbusToPLDMEventHandler)
{
- dbusToPLDMEventHandler->listenSensorEvent(pdrRepo,
- sensorDbusObjMaps);
+ deferredGetPDREvent = std::make_unique<sdeventplus::source::Defer>(
+ event,
+ std::bind(std::mem_fn(&pldm::responder::platform::Handler::
+ _processPostGetPDRActions),
+ this, std::placeholders::_1));
}
}
@@ -656,6 +659,13 @@
return response;
}
+void Handler::_processPostGetPDRActions(
+ sdeventplus::source::EventBase& /*source */)
+{
+ deferredGetPDREvent.reset();
+ dbusToPLDMEventHandler->listenSensorEvent(pdrRepo, sensorDbusObjMaps);
+}
+
bool isOemStateSensor(Handler& handler, uint16_t sensorId,
uint8_t sensorRearmCount, uint8_t& compSensorCnt,
uint16_t& entityType, uint16_t& entityInstance,
diff --git a/libpldmresponder/platform.hpp b/libpldmresponder/platform.hpp
index 09418cd..de81898 100644
--- a/libpldmresponder/platform.hpp
+++ b/libpldmresponder/platform.hpp
@@ -57,13 +57,13 @@
HostPDRHandler* hostPDRHandler,
DbusToPLDMEvent* dbusToPLDMEventHandler, fru::Handler* fruHandler,
pldm::responder::oem_platform::Handler* oemPlatformHandler,
- bool buildPDRLazily = false,
+ sdeventplus::Event& event, bool buildPDRLazily = false,
const std::optional<EventMap>& addOnHandlersMap = std::nullopt) :
pdrRepo(repo),
hostPDRHandler(hostPDRHandler),
dbusToPLDMEventHandler(dbusToPLDMEventHandler), fruHandler(fruHandler),
dBusIntf(dBusIntf), oemPlatformHandler(oemPlatformHandler),
- pdrJsonsDir(pdrJsonsDir), pdrCreated(false)
+ event(event), pdrJsonsDir(pdrJsonsDir), pdrCreated(false)
{
if (!buildPDRLazily)
{
@@ -434,6 +434,12 @@
return fruHandler->getAssociateEntityMap();
}
+ /** @brief process the actions that needs to be performed after a GetPDR
+ * call is received
+ * @param[in] source - sdeventplus event source
+ */
+ void _processPostGetPDRActions(sdeventplus::source::EventBase& source);
+
private:
pdr_utils::Repo pdrRepo;
uint16_t nextEffecterId{};
@@ -445,8 +451,10 @@
fru::Handler* fruHandler;
const pldm::utils::DBusHandler* dBusIntf;
pldm::responder::oem_platform::Handler* oemPlatformHandler;
+ sdeventplus::Event& event;
std::string pdrJsonsDir;
bool pdrCreated;
+ std::unique_ptr<sdeventplus::source::Defer> deferredGetPDREvent;
};
/** @brief Function to check if a sensor falls in OEM range
diff --git a/pldmd/pldmd.cpp b/pldmd/pldmd.cpp
index 3fedbd2..ceeff08 100644
--- a/pldmd/pldmd.cpp
+++ b/pldmd/pldmd.cpp
@@ -205,7 +205,7 @@
auto platformHandler = std::make_unique<platform::Handler>(
dbusHandler.get(), PDR_JSONS_DIR, pdrRepo.get(), hostPDRHandler.get(),
dbusToPLDMEventHandler.get(), fruHandler.get(),
- oemPlatformHandler.get(), true);
+ oemPlatformHandler.get(), event, true);
#ifdef OEM_IBM
pldm::responder::oem_ibm_platform::Handler* oemIbmPlatformHandler =
dynamic_cast<pldm::responder::oem_ibm_platform::Handler*>(
diff --git a/test/libpldmresponder_pdr_effecter_test.cpp b/test/libpldmresponder_pdr_effecter_test.cpp
index 0b91ee8..107972c 100644
--- a/test/libpldmresponder_pdr_effecter_test.cpp
+++ b/test/libpldmresponder_pdr_effecter_test.cpp
@@ -5,6 +5,7 @@
#include "mocked_utils.hpp"
#include <sdbusplus/test/sdbus_mock.hpp>
+#include <sdeventplus/event.hpp>
#include <gtest/gtest.h>
@@ -27,8 +28,9 @@
auto inPDRRepo = pldm_pdr_init();
auto outPDRRepo = pldm_pdr_init();
Repo outRepo(outPDRRepo);
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", inPDRRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_STATE_EFFECTER_PDR);
@@ -126,8 +128,9 @@
auto inPDRRepo = pldm_pdr_init();
auto outPDRRepo = pldm_pdr_init();
Repo outRepo(outPDRRepo);
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", inPDRRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_NUMERIC_EFFECTER_PDR);
@@ -172,8 +175,9 @@
auto inPDRRepo = pldm_pdr_init();
auto outPDRRepo = pldm_pdr_init();
Repo outRepo(outPDRRepo);
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", inPDRRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_STATE_EFFECTER_PDR);
@@ -193,8 +197,9 @@
.WillRepeatedly(Return("foo.bar"));
auto inPDRRepo = pldm_pdr_init();
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", inPDRRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
uint16_t entityType = 33;
uint16_t entityInstance = 0;
uint16_t containerId = 0;
diff --git a/test/libpldmresponder_pdr_sensor_test.cpp b/test/libpldmresponder_pdr_sensor_test.cpp
index ad844c1..700af67 100644
--- a/test/libpldmresponder_pdr_sensor_test.cpp
+++ b/test/libpldmresponder_pdr_sensor_test.cpp
@@ -5,6 +5,7 @@
#include "mocked_utils.hpp"
#include <sdbusplus/test/sdbus_mock.hpp>
+#include <sdeventplus/event.hpp>
#include <gtest/gtest.h>
@@ -32,8 +33,9 @@
auto inPDRRepo = pldm_pdr_init();
auto outPDRRepo = pldm_pdr_init();
Repo outRepo(outPDRRepo);
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_sensor/good", inPDRRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
handler.getPDR(req, requestPayloadLength);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_STATE_SENSOR_PDR);
@@ -82,8 +84,9 @@
auto inPDRRepo = pldm_pdr_init();
auto outPDRRepo = pldm_pdr_init();
Repo outRepo(outPDRRepo);
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_sensor/good", inPDRRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
handler.getPDR(req, requestPayloadLength);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_STATE_SENSOR_PDR);
diff --git a/test/libpldmresponder_platform_test.cpp b/test/libpldmresponder_platform_test.cpp
index 23241db..a759020 100644
--- a/test/libpldmresponder_platform_test.cpp
+++ b/test/libpldmresponder_platform_test.cpp
@@ -9,6 +9,7 @@
#include "mocked_utils.hpp"
#include <sdbusplus/test/sdbus_mock.hpp>
+#include <sdeventplus/event.hpp>
#include <iostream>
@@ -39,8 +40,9 @@
.WillRepeatedly(Return("foo.bar"));
auto pdrRepo = pldm_pdr_init();
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", pdrRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
Repo repo(pdrRepo);
ASSERT_EQ(repo.empty(), false);
auto response = handler.getPDR(req, requestPayloadLength);
@@ -76,8 +78,9 @@
.WillRepeatedly(Return("foo.bar"));
auto pdrRepo = pldm_pdr_init();
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", pdrRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
Repo repo(pdrRepo);
ASSERT_EQ(repo.empty(), false);
auto response = handler.getPDR(req, requestPayloadLength);
@@ -107,8 +110,9 @@
.WillRepeatedly(Return("foo.bar"));
auto pdrRepo = pldm_pdr_init();
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", pdrRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
Repo repo(pdrRepo);
ASSERT_EQ(repo.empty(), false);
auto response = handler.getPDR(req, requestPayloadLength);
@@ -136,8 +140,9 @@
.WillRepeatedly(Return("foo.bar"));
auto pdrRepo = pldm_pdr_init();
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", pdrRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
Repo repo(pdrRepo);
ASSERT_EQ(repo.empty(), false);
auto response = handler.getPDR(req, requestPayloadLength);
@@ -167,8 +172,9 @@
.WillRepeatedly(Return("foo.bar"));
auto pdrRepo = pldm_pdr_init();
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", pdrRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
Repo repo(pdrRepo);
ASSERT_EQ(repo.empty(), false);
auto response = handler.getPDR(req, requestPayloadLength);
@@ -229,8 +235,9 @@
auto inPDRRepo = pldm_pdr_init();
auto outPDRRepo = pldm_pdr_init();
Repo outRepo(outPDRRepo);
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", inPDRRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
handler.getPDR(req, requestPayloadLength);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_STATE_EFFECTER_PDR);
@@ -275,8 +282,9 @@
auto inPDRRepo = pldm_pdr_init();
auto outPDRRepo = pldm_pdr_init();
Repo outRepo(outPDRRepo);
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", inPDRRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
handler.getPDR(req, requestPayloadLength);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_STATE_EFFECTER_PDR);
@@ -320,8 +328,9 @@
auto inPDRRepo = pldm_pdr_init();
auto numericEffecterPdrRepo = pldm_pdr_init();
Repo numericEffecterPDRs(numericEffecterPdrRepo);
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", inPDRRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, numericEffecterPDRs, PLDM_NUMERIC_EFFECTER_PDR);
@@ -362,8 +371,9 @@
auto inPDRRepo = pldm_pdr_init();
auto numericEffecterPdrRepo = pldm_pdr_init();
Repo numericEffecterPDRs(numericEffecterPdrRepo);
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", inPDRRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, numericEffecterPDRs, PLDM_NUMERIC_EFFECTER_PDR);
@@ -535,8 +545,9 @@
auto outPDRRepo = pldm_pdr_init();
Repo outRepo(outPDRRepo);
MockdBusHandler mockedUtils;
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "", inPDRRepo, nullptr, nullptr, nullptr,
- nullptr);
+ nullptr, event);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_TERMINUS_LOCATOR_PDR);
@@ -579,8 +590,9 @@
auto inPDRRepo = pldm_pdr_init();
auto outPDRRepo = pldm_pdr_init();
Repo outRepo(outPDRRepo);
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_sensor/good", inPDRRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_STATE_SENSOR_PDR);
pdr_utils::PdrEntry e;
@@ -625,8 +637,9 @@
auto inPDRRepo = pldm_pdr_init();
auto outPDRRepo = pldm_pdr_init();
Repo outRepo(outPDRRepo);
+ auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, "./pdr_jsons/state_sensor/good", inPDRRepo,
- nullptr, nullptr, nullptr, nullptr);
+ nullptr, nullptr, nullptr, nullptr, event);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_STATE_SENSOR_PDR);
pdr_utils::PdrEntry e;