Make Terminus info a class variable
The terminus information is needed at various places in
pldm and instead of passing that structure around via
function arguments, it is cheaper to maintain it as a
class variable.
And this commit also removes the redundant structure that
stores partial terminus information.
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
Change-Id: If34cfe1c47bdeceaabdae779ee7cd8569beedf5d
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index d7051cf..63512a3 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -87,6 +87,15 @@
auto propVal = std::get<std::string>(value);
if (propVal == "xyz.openbmc_project.State.Host.HostState.Off")
{
+ // Delete all the remote terminus information
+ for (const auto& terminusInfo : this->tlPDRInfo)
+ {
+ if (terminusInfo.first != TERMINUS_HANDLE)
+ {
+ this->tlPDRInfo.erase(terminusInfo.first);
+ }
+ }
+
pldm_pdr_remove_remote_pdrs(repo);
pldm_entity_association_tree_destroy_root(entityTree);
pldm_entity_association_tree_copy_root(bmcEntityTree,
@@ -332,8 +341,7 @@
}
}
-void HostPDRHandler::parseStateSensorPDRs(const PDRList& stateSensorPDRs,
- const TLPDRMap& tlpdrInfo)
+void HostPDRHandler::parseStateSensorPDRs(const PDRList& stateSensorPDRs)
{
for (const auto& pdr : stateSensorPDRs)
{
@@ -343,7 +351,7 @@
sensorEntry.sensorID = sensorID;
try
{
- sensorEntry.terminusID = tlpdrInfo.at(terminusHandle);
+ sensorEntry.terminusID = std::get<0>(tlPDRInfo.at(terminusHandle));
}
// If there is no mapping for terminusHandle assign the reserved TID
// value of 0xFF to indicate that.
@@ -361,9 +369,7 @@
{
static bool merged = false;
static PDRList stateSensorPDRs{};
- static TLPDRMap tlpdrInfo{};
uint32_t nextRecordHandle{};
- std::vector<TlInfo> tlInfo;
uint8_t tlEid = 0;
bool tlValid = true;
uint32_t rh = 0;
@@ -440,10 +446,6 @@
auto tlpdr =
reinterpret_cast<const pldm_terminus_locator_pdr*>(
pdr.data());
- tlpdrInfo.emplace(
- static_cast<pldm::pdr::TerminusHandle>(
- tlpdr->terminus_handle),
- static_cast<pldm::pdr::TerminusID>(tlpdr->tid));
terminusHandle = tlpdr->terminus_handle;
tid = tlpdr->tid;
@@ -460,9 +462,9 @@
{
tlValid = false;
}
- tlInfo.emplace_back(
- TlInfo{tlpdr->validity, static_cast<uint8_t>(tlEid),
- tlpdr->tid, tlpdr->terminus_handle});
+ tlPDRInfo.insert_or_assign(
+ tlpdr->terminus_handle,
+ std::make_tuple(tlpdr->tid, tlEid, tlpdr->validity));
}
else if (pdrHdr->type == PLDM_STATE_SENSOR_PDR)
{
@@ -485,13 +487,12 @@
if (!nextRecordHandle)
{
/*received last record*/
- this->parseStateSensorPDRs(stateSensorPDRs, tlpdrInfo);
+ this->parseStateSensorPDRs(stateSensorPDRs);
if (isHostUp())
{
- this->setHostSensorState(stateSensorPDRs, tlInfo);
+ this->setHostSensorState(stateSensorPDRs);
}
stateSensorPDRs.clear();
- tlpdrInfo.clear();
if (merged)
{
merged = false;
@@ -579,8 +580,7 @@
return responseReceived;
}
-void HostPDRHandler::setHostSensorState(const PDRList& stateSensorPDRs,
- const std::vector<TlInfo>& tlinfo)
+void HostPDRHandler::setHostSensorState(const PDRList& stateSensorPDRs)
{
for (const auto& stateSensorPDR : stateSensorPDRs)
{
@@ -597,18 +597,18 @@
uint16_t sensorId = pdr->sensor_id;
- for (auto info : tlinfo)
+ for (const auto& [terminusHandle, terminusInfo] : tlPDRInfo)
{
- if (info.terminusHandle == pdr->terminus_handle)
+ if (terminusHandle == pdr->terminus_handle)
{
- if (info.valid == PLDM_TL_PDR_VALID)
+ if (std::get<2>(terminusInfo) == PLDM_TL_PDR_VALID)
{
- mctp_eid = info.eid;
+ mctp_eid = std::get<1>(terminusInfo);
}
bitfield8_t sensorRearm;
sensorRearm.byte = 0;
- uint8_t tid = info.tid;
+ uint8_t tid = std::get<0>(terminusInfo);
auto instanceId = requester.getInstanceId(mctp_eid);
std::vector<uint8_t> requestMsg(