pdr: Update D-Bus mapping structure
For most PDR types, the D-Bus object structure(paths, interfaces, and
properties) should be defined in the JSON file instead of hard-coded.
Tested with JSON files:
https://gist.github.com/lxwinspur/2c3fd68cdb35e06480c4a5f7890e3a06#file-effecter_pdr-json.
pldmtool platform GetPDR -d 1
Encode request successfully
Request Message:
08 01 80 02 51 01 00 00 00 00 00 00 00 01 80 00 00 00
Success in creating the socket : RC = 3
Success in connecting to socket : RC = 0
Success in sending message type as pldm to mctp : RC = 0
Write to socket successful : RC = 18
Total length:18
Loopback response message:
08 01 80 02 51 01 00 00 00 00 00 00 00 01 80 00 00 00
On first recv(),response == request : RC = 0
Total length: 46
Shutdown Socket successful : RC = 0
Response Message:
08 01 00 02 51 00 02 00 00 00 00 00 00 00 01 1d 00 01 00 00 00 01 0b 00 00 13 00 00 00 01 00 21 00 00 00 00 00 00 00 00 00 01 c4 00 01 06
Parsed Response Msg:
nextRecordHandle: 2
responseCount: 29
recordHandle: 1
PDRHeaderVersion: 1
PDRType: 11
recordChangeNumber: 0
dataLength: 19
PLDMTerminusHandle: 0
effecterID: 1
entityType: 33
entityInstanceNumber: 0
containerID: 0
effecterSemanticID: 0
effecterInit: 0
effecterDescriptionPDR: false
compositeEffecterCount: 1
stateSetID: 196
possibleStatesSize: 1
possibleStates: 6
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Ifc0cd1540b08e9b73e03d99d71a0980ef6353e72
diff --git a/libpldmresponder/examples/pdr/state_effecter_pdr.json b/libpldmresponder/examples/pdr/state_effecter_pdr.json
index 2b5d946..7e7a421 100644
--- a/libpldmresponder/examples/pdr/state_effecter_pdr.json
+++ b/libpldmresponder/examples/pdr/state_effecter_pdr.json
@@ -1,52 +1,103 @@
{
- "pdrType": 11,
- "entries": [
+ "effecterPDRs": [
{
- "type": 33,
- "instance": 0,
- "container": 0,
- "effecters": [
+ "pdrType": 11,
+ "entries": [
{
- "set": {
- "id": 196,
- "size": 1,
- "states": [
- 1
- ]
- },
- "dbus": "/foo/bar"
- }
- ]
- },
- {
- "type": 100,
- "instance": 0,
- "container": 0,
- "effecters": [
- {
- "set": {
- "id": 197,
- "size": 1,
- "states": [
- 1
- ]
- },
- "dbus": "/foo/bar"
+ "type": 33,
+ "instance": 0,
+ "container": 0,
+ "effecters": [
+ {
+ "set": {
+ "id": 196,
+ "size": 1,
+ "states": [
+ 1
+ ]
+ },
+ "dbus": {
+ "path": "/foo/bar",
+ "interface": "xyz.openbmc_project.Foo.Bar",
+ "property_name": "propertyName",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.Foo.Bar.V1"
+ ]
+ }
+ },
+ {
+ "set": {
+ "id": 196,
+ "size": 1,
+ "states": [
+ 1,
+ 2
+ ]
+ },
+ "dbus": {
+ "path": "/foo/bar",
+ "interface": "xyz.openbmc_project.Foo.Bar",
+ "property_name": "propertyName",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.Foo.Bar.V1",
+ "xyz.openbmc_project.Foo.Bar.V2"
+ ]
+ }
+ }
+ ]
},
{
- "set": {
- "id": 198,
- "size": 2,
- "states": [
- 1,
- 2,
- 5,
- 15
- ]
- },
- "dbus": "/foo/bar/baz"
+ "type": 100,
+ "instance": 0,
+ "container": 0,
+ "effecters": [
+ {
+ "set": {
+ "id": 197,
+ "size": 1,
+ "states": [
+ 1
+ ]
+ },
+ "dbus": {
+ "path": "/foo/bar",
+ "interface": "xyz.openbmc_project.Foo.Bar",
+ "property_name": "propertyName",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.Foo.Bar.V1"
+ ]
+ }
+ },
+ {
+ "set": {
+ "id": 198,
+ "size": 2,
+ "states": [
+ 1,
+ 2,
+ 5,
+ 15
+ ]
+ },
+ "dbus": {
+ "path": "/foo/bar/baz",
+ "interface": "xyz.openbmc_project.Foo.Bar.Baz",
+ "property_name": "propertyName",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.Foo.Bar.Baz.V1",
+ "xyz.openbmc_project.Foo.Bar.Baz.V2",
+ "xyz.openbmc_project.Foo.Bar.Baz.V5",
+ "xyz.openbmc_project.Foo.Bar.Baz.V15"
+ ]
+ }
+ }
+ ]
}
]
}
]
-}
\ No newline at end of file
+}
diff --git a/libpldmresponder/pdr_utils.cpp b/libpldmresponder/pdr_utils.cpp
index 9a68ca9..185a6ce 100644
--- a/libpldmresponder/pdr_utils.cpp
+++ b/libpldmresponder/pdr_utils.cpp
@@ -65,6 +65,76 @@
return !getRecordCount();
}
+StatestoDbusVal populateMapping(const std::string& type, const Json& dBusValues,
+ const PossibleValues& pv)
+{
+ size_t pos = 0;
+ pldm::utils::PropertyValue value;
+ StatestoDbusVal valueMap;
+ if (dBusValues.size() != pv.size())
+ {
+ std::cerr
+ << "dBusValues size is not equal to pv size, dBusValues Size: "
+ << dBusValues.size() << ", pv Size: " << pv.size() << "\n";
+
+ return {};
+ }
+
+ for (auto it = dBusValues.begin(); it != dBusValues.end(); ++it, ++pos)
+ {
+ if (type == "uint8_t")
+ {
+ value = static_cast<uint8_t>(it.value());
+ }
+ else if (type == "uint16_t")
+ {
+ value = static_cast<uint16_t>(it.value());
+ }
+ else if (type == "uint32_t")
+ {
+ value = static_cast<uint32_t>(it.value());
+ }
+ else if (type == "uint64_t")
+ {
+ value = static_cast<uint64_t>(it.value());
+ }
+ else if (type == "int16_t")
+ {
+ value = static_cast<int16_t>(it.value());
+ }
+ else if (type == "int32_t")
+ {
+ value = static_cast<int32_t>(it.value());
+ }
+ else if (type == "int64_t")
+ {
+ value = static_cast<int64_t>(it.value());
+ }
+ else if (type == "bool")
+ {
+ value = static_cast<bool>(it.value());
+ }
+ else if (type == "double")
+ {
+ value = static_cast<double>(it.value());
+ }
+ else if (type == "string")
+ {
+ value = static_cast<std::string>(it.value());
+ }
+ else
+ {
+ std::cerr << "Unknown D-Bus property type, TYPE=" << type.c_str()
+ << "\n";
+ return {};
+ }
+
+ valueMap.emplace(pv[pos], value);
+ }
+
+ return valueMap;
+}
+
} // namespace pdr_utils
} // namespace responder
} // namespace pldm
diff --git a/libpldmresponder/pdr_utils.hpp b/libpldmresponder/pdr_utils.hpp
index 0c3f634..1f03863 100644
--- a/libpldmresponder/pdr_utils.hpp
+++ b/libpldmresponder/pdr_utils.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include "utils.hpp"
+
#include <stdint.h>
#include <filesystem>
@@ -43,6 +45,12 @@
using Type = uint8_t;
using Json = nlohmann::json;
using RecordHandle = uint32_t;
+using State = uint8_t;
+using PossibleValues = std::vector<uint8_t>;
+
+/** @brief Map of DBus property State to attribute value
+ */
+using StatestoDbusVal = std::map<State, pldm::utils::PropertyValue>;
/** @brief Parse PDR JSON file and output Json object
*
@@ -68,6 +76,18 @@
return Json::parse(jsonFile);
}
+/** @brief Populate the mapping between D-Bus property stateId and attribute
+ * value for the effecter PDR enumeration attribute.
+ *
+ * @param[in] type - type of the D-Bus property
+ * @param[in] dBusValues - json array of D-Bus property values
+ * @param[in] pv - Possible values for the effecter PDR enumeration attribute
+ *
+ * @return StatestoDbusVal - Map of D-Bus property stateId to attribute value
+ */
+StatestoDbusVal populateMapping(const std::string& type, const Json& dBusValues,
+ const PossibleValues& pv);
+
/**
* @class RepoInterface
*
diff --git a/libpldmresponder/platform.cpp b/libpldmresponder/platform.cpp
index 6ace46b..45bd041 100644
--- a/libpldmresponder/platform.cpp
+++ b/libpldmresponder/platform.cpp
@@ -13,16 +13,28 @@
using InternalFailure =
sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
+static const Json empty{};
+
+void Handler::addDbusObjMaps(uint16_t effecterId,
+ std::tuple<DbusMappings, DbusValMaps> dbusObj)
+{
+ dbusObjMaps.emplace(effecterId, dbusObj);
+}
+
+const std::tuple<DbusMappings, DbusValMaps>&
+ Handler::getDbusObjMaps(uint16_t effecterId) const
+{
+ return dbusObjMaps.at(effecterId);
+}
+
void Handler::generateStateEffecterRepo(const Json& json, Repo& repo)
{
static const std::vector<Json> emptyList{};
- static const Json empty{};
auto entries = json.value("entries", emptyList);
for (const auto& e : entries)
{
size_t pdrSize = 0;
auto effecters = e.value("effecters", emptyList);
- static const Json empty{};
for (const auto& effecter : effecters)
{
auto set = effecter.value("set", empty);
@@ -61,7 +73,8 @@
pdr->has_description_pdr = false;
pdr->composite_effecter_count = effecters.size();
- EffecterObjs paths{};
+ DbusMappings dbusMappings{};
+ DbusValMaps dbusValMaps{};
uint8_t* start =
entry.data() + sizeof(pldm_state_effecter_pdr) - sizeof(uint8_t);
for (const auto& effecter : effecters)
@@ -75,6 +88,7 @@
start += sizeof(possibleStates->state_set_id) +
sizeof(possibleStates->possible_states_size);
static const std::vector<uint8_t> emptyStates{};
+ PossibleValues stateValues;
auto states = set.value("states", emptyStates);
for (const auto& state : states)
{
@@ -82,13 +96,31 @@
auto bit = state - (index * 8);
bitfield8_t* bf = reinterpret_cast<bitfield8_t*>(start + index);
bf->byte |= 1 << bit;
+ stateValues.emplace_back(std::move(state));
}
start += possibleStates->possible_states_size;
- auto dbus = effecter.value("dbus", empty);
- paths.emplace_back(std::move(dbus));
+ auto dbusEntry = effecter.value("dbus", empty);
+ auto objectPath = dbusEntry.value("path", "");
+ auto interface = dbusEntry.value("interface", "");
+ auto propertyName = dbusEntry.value("property_name", "");
+ auto propertyType = dbusEntry.value("property_type", "");
+ pldm::utils::DBusMapping dbusMapping{objectPath, interface,
+ propertyName, propertyType};
+ dbusMappings.emplace_back(std::move(dbusMapping));
+
+ Json propValues = dbusEntry["property_values"];
+ StatestoDbusVal dbusIdToValMap =
+ populateMapping(propertyType, propValues, stateValues);
+ if (!dbusIdToValMap.empty())
+ {
+ dbusValMaps.emplace_back(std::move(dbusIdToValMap));
+ }
}
- addEffecterObjs(pdr->effecter_id, std::move(paths));
+
+ addDbusObjMaps(
+ pdr->effecter_id,
+ std::make_tuple(std::move(dbusMappings), std::move(dbusValMaps)));
PdrEntry pdrEntry{};
pdrEntry.data = entry.data();
pdrEntry.size = pdrSize;
@@ -116,8 +148,12 @@
auto json = readJson(dirEntry.path().string());
if (!json.empty())
{
- pdrType = json.value("pdrType", 0);
- generators.at(pdrType)(json, repo);
+ auto effecterPDRs = json.value("effecterPDRs", empty);
+ for (const auto& effecter : effecterPDRs)
+ {
+ pdrType = effecter.value("pdrType", 0);
+ generators.at(pdrType)(effecter, repo);
+ }
}
}
catch (const InternalFailure& e)
diff --git a/libpldmresponder/platform.hpp b/libpldmresponder/platform.hpp
index 8c9e45c..9c8860e 100644
--- a/libpldmresponder/platform.hpp
+++ b/libpldmresponder/platform.hpp
@@ -21,8 +21,13 @@
namespace platform
{
-using DbusPath = std::string;
-using EffecterObjs = std::vector<DbusPath>;
+using namespace pldm::utils;
+using namespace pldm::responder::pdr_utils;
+
+using EffecterId = uint16_t;
+using DbusMappings = std::vector<DBusMapping>;
+using DbusValMaps = std::vector<StatestoDbusVal>;
+using DbusObjMaps = std::map<EffecterId, std::tuple<DbusMappings, DbusValMaps>>;
class Handler : public CmdHandler
{
@@ -42,15 +47,31 @@
});
}
- const EffecterObjs& getEffecterObjs(uint16_t effecterId) const
+ pdr_utils::Repo& getRepo()
{
- return effecterObjs.at(effecterId);
+ return this->pdrRepo;
}
- void addEffecterObjs(uint16_t effecterId, EffecterObjs&& paths)
- {
- effecterObjs.emplace(effecterId, std::move(paths));
- }
+ /** @brief Add D-Bus mapping and value mapping(stateId to D-Bus) for the
+ * effecterId. If the same id is added, the previous dbusObjs will
+ * be "over-written".
+ *
+ * @param[in] effecterId - effecter id
+ * @param[in] dbusObj - list of D-Bus object structure and list of D-Bus
+ * property value to attribute value
+ */
+ void addDbusObjMaps(uint16_t effecterId,
+ std::tuple<DbusMappings, DbusValMaps> dbusObj);
+
+ /** @brief Retrieve an effecter id -> D-Bus objects mapping
+ *
+ * @param[in] effecterId - effecter id
+ *
+ * @return std::tuple<DbusMappings, DbusValMaps> - list of D-Bus object
+ * structure and list of D-Bus property value to attribute value
+ */
+ const std::tuple<DbusMappings, DbusValMaps>&
+ getDbusObjMaps(uint16_t effecterId) const;
uint16_t getNextEffecterId()
{
@@ -103,37 +124,32 @@
{
using namespace pldm::responder::pdr;
using namespace pldm::utils;
- using namespace std::string_literals;
- using DBusProperty = std::variant<std::string, bool>;
- using StateSetId = uint16_t;
using StateSetNum = uint8_t;
- using PropertyMap =
- std::map<StateSetId, std::map<StateSetNum, DBusProperty>>;
- static const PropertyMap stateNumToDbusProp = {
- {PLDM_BOOT_PROGRESS_STATE,
- {{PLDM_BOOT_NOT_ACTIVE,
- "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus."
- "Standby"s},
- {PLDM_BOOT_COMPLETED,
- "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus."
- "BootComplete"s}}},
- {PLDM_SYSTEM_POWER_STATE,
- {{PLDM_OFF_SOFT_GRACEFUL,
- "xyz.openbmc_project.State.Chassis.Transition.Off"s}}}};
- using namespace pldm::responder::pdr;
state_effecter_possible_states* states = nullptr;
pldm_state_effecter_pdr* pdr = nullptr;
uint8_t compEffecterCnt = stateField.size();
+
+ std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)>
+ stateEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy);
+ Repo stateEffecterPDRs(stateEffecterPdrRepo.get());
+ getRepoByType(pdrRepo, stateEffecterPDRs, PLDM_STATE_EFFECTER_PDR);
+ if (stateEffecterPDRs.empty())
+ {
+ std::cerr << "Failed to get record by PDR type\n";
+ return PLDM_PLATFORM_INVALID_EFFECTER_ID;
+ }
+
PdrEntry pdrEntry{};
- auto pdrRecord = pdrRepo.getFirstRecord(pdrEntry);
+ auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry);
while (pdrRecord)
{
pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data);
if (pdr->effecter_id != effecterId)
{
pdr = nullptr;
- pdrRecord = pdrRepo.getNextRecord(pdrRecord, pdrEntry);
+ pdrRecord =
+ stateEffecterPDRs.getNextRecord(pdrRecord, pdrEntry);
continue;
}
@@ -155,152 +171,77 @@
return PLDM_PLATFORM_INVALID_EFFECTER_ID;
}
- std::map<StateSetId, std::function<int(const std::string& objPath,
- const uint8_t currState)>>
- effecterToDbusEntries = {
- {PLDM_BOOT_PROGRESS_STATE,
- [&](const std::string& objPath, const uint8_t currState) {
- auto stateSet =
- stateNumToDbusProp.find(PLDM_BOOT_PROGRESS_STATE);
- if (stateSet == stateNumToDbusProp.end())
- {
- std::cerr << "Couldn't find D-Bus mapping for "
- << "PLDM_BOOT_PROGRESS_STATE, EFFECTER_ID="
- << effecterId << "\n";
- return PLDM_ERROR;
- }
- auto iter = stateSet->second.find(
- stateField[currState].effecter_state);
- if (iter == stateSet->second.end())
- {
- std::cerr << "Invalid state field passed or field not "
- << "found for PLDM_BOOT_PROGRESS_STATE, "
- "EFFECTER_ID="
- << effecterId << " FIELD="
- << stateField[currState].effecter_state
- << " OBJECT_PATH=" << objPath.c_str()
- << "\n";
- return PLDM_ERROR_INVALID_DATA;
- }
- PropertyValue value{std::get<std::string>(iter->second)};
- DBusMapping dbusMapping{
- objPath,
- "xyz.openbmc_project.State.OperatingSystem.Status",
- "OperatingSystemState", "string"};
- try
- {
- dBusIntf.setDbusProperty(dbusMapping, value);
- }
- catch (const std::exception& e)
- {
- std::cerr
- << "Error setting property, ERROR=" << e.what()
- << " PROPERTY=" << dbusMapping.propertyName
- << " INTERFACE="
- << dbusMapping.interface << " PATH="
- << dbusMapping.objectPath << "\n";
- return PLDM_ERROR;
- }
- return PLDM_SUCCESS;
- }},
- {PLDM_SYSTEM_POWER_STATE,
- [&](const std::string& objPath, const uint8_t currState) {
- auto stateSet =
- stateNumToDbusProp.find(PLDM_SYSTEM_POWER_STATE);
- if (stateSet == stateNumToDbusProp.end())
- {
- std::cerr << "Couldn't find D-Bus mapping for "
- << "PLDM_SYSTEM_POWER_STATE, EFFECTER_ID="
- << effecterId << "\n";
- return PLDM_ERROR;
- }
- auto iter = stateSet->second.find(
- stateField[currState].effecter_state);
- if (iter == stateSet->second.end())
- {
- std::cerr << "Invalid state field passed or field not "
- << "found for PLDM_SYSTEM_POWER_STATE, "
- "EFFECTER_ID="
- << effecterId << " FIELD="
- << stateField[currState].effecter_state
- << " OBJECT_PATH=" << objPath.c_str()
- << "\n";
- return PLDM_ERROR_INVALID_DATA;
- }
- PropertyValue value{std::get<std::string>(iter->second)};
- DBusMapping dbusMapping{
- objPath, "xyz.openbmc_project.State.Chassis",
- "RequestedPowerTransition", "string"};
- try
- {
- dBusIntf.setDbusProperty(dbusMapping, value);
- }
- catch (const std::exception& e)
- {
- std::cerr
- << "Error setting property, ERROR=" << e.what()
- << " PROPERTY=" << dbusMapping.propertyName
- << " INTERFACE="
- << dbusMapping.interface << " PATH="
- << dbusMapping.objectPath << "\n";
- return PLDM_ERROR;
- }
- return PLDM_SUCCESS;
- }}};
-
int rc = PLDM_SUCCESS;
- const auto& paths = getEffecterObjs(effecterId);
- for (uint8_t currState = 0; currState < compEffecterCnt; ++currState)
+ try
{
- std::vector<StateSetNum> allowed{};
- // computation is based on table 79 from DSP0248 v1.1.1
- uint8_t bitfieldIndex = stateField[currState].effecter_state / 8;
- uint8_t bit =
- stateField[currState].effecter_state - (8 * bitfieldIndex);
- if (states->possible_states_size < bitfieldIndex ||
- !(states->states[bitfieldIndex].byte & (1 << bit)))
+ const auto& [dbusMappings, dbusValMaps] =
+ dbusObjMaps.at(effecterId);
+ for (uint8_t currState = 0; currState < compEffecterCnt;
+ ++currState)
{
- std::cerr << "Invalid state set value, EFFECTER_ID="
- << effecterId
- << " VALUE=" << stateField[currState].effecter_state
- << " COMPOSITE_EFFECTER_ID=" << currState
- << " DBUS_PATH=" << paths[currState].c_str() << "\n";
- rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
- break;
- }
- auto iter = effecterToDbusEntries.find(states->state_set_id);
- if (iter == effecterToDbusEntries.end())
- {
- uint16_t setId = states->state_set_id;
- std::cerr << "Did not find the state set for the"
- << " state effecter pdr, STATE=" << setId
- << " EFFECTER_ID=" << effecterId << "\n";
- rc = PLDM_PLATFORM_INVALID_STATE_VALUE;
- break;
- }
- if (stateField[currState].set_request == PLDM_REQUEST_SET)
- {
- rc = iter->second(paths[currState], currState);
- if (rc != PLDM_SUCCESS)
+ std::vector<StateSetNum> allowed{};
+ // computation is based on table 79 from DSP0248 v1.1.1
+ uint8_t bitfieldIndex =
+ stateField[currState].effecter_state / 8;
+ uint8_t bit =
+ stateField[currState].effecter_state - (8 * bitfieldIndex);
+ if (states->possible_states_size < bitfieldIndex ||
+ !(states->states[bitfieldIndex].byte & (1 << bit)))
{
+ std::cerr
+ << "Invalid state set value, EFFECTER_ID=" << effecterId
+ << " VALUE=" << stateField[currState].effecter_state
+ << " COMPOSITE_EFFECTER_ID=" << currState
+ << " DBUS_PATH=" << dbusMappings[currState].objectPath
+ << "\n";
+ rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
break;
}
+ const DBusMapping& dbusMapping = dbusMappings[currState];
+ const StatestoDbusVal& dbusValToMap = dbusValMaps[currState];
+
+ if (stateField[currState].set_request == PLDM_REQUEST_SET)
+ {
+ try
+ {
+ dBusIntf.setDbusProperty(
+ dbusMapping,
+ dbusValToMap.at(
+ stateField[currState].effecter_state));
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr
+ << "Error setting property, ERROR=" << e.what()
+ << " PROPERTY=" << dbusMapping.propertyName
+ << " INTERFACE="
+ << dbusMapping.interface << " PATH="
+ << dbusMapping.objectPath << "\n";
+ return PLDM_ERROR;
+ }
+ }
+ uint8_t* nextState =
+ reinterpret_cast<uint8_t*>(states) +
+ sizeof(state_effecter_possible_states) -
+ sizeof(states->states) +
+ (states->possible_states_size * sizeof(states->states));
+ states = reinterpret_cast<state_effecter_possible_states*>(
+ nextState);
}
- uint8_t* nextState =
- reinterpret_cast<uint8_t*>(states) +
- sizeof(state_effecter_possible_states) -
- sizeof(states->states) +
- (states->possible_states_size * sizeof(states->states));
- states =
- reinterpret_cast<state_effecter_possible_states*>(nextState);
}
+ catch (const std::out_of_range& e)
+ {
+ std::cerr << "the effecterId does not exist. effecter id: "
+ << effecterId << e.what() << '\n';
+ }
+
return rc;
}
private:
pdr_utils::Repo pdrRepo;
uint16_t nextEffecterId{};
- std::map<uint16_t, EffecterObjs> effecterObjs{};
+ DbusObjMaps dbusObjMaps{};
};
} // namespace platform
diff --git a/test/libpldmresponder_pdr_state_effecter_test.cpp b/test/libpldmresponder_pdr_state_effecter_test.cpp
index 5c197dd..73bcfbb 100644
--- a/test/libpldmresponder_pdr_state_effecter_test.cpp
+++ b/test/libpldmresponder_pdr_state_effecter_test.cpp
@@ -52,8 +52,9 @@
bf1.byte = 2;
ASSERT_EQ(states->states[0].byte, bf1.byte);
- const auto& paths = handler.getEffecterObjs(pdr->effecter_id);
- ASSERT_EQ(paths[0], "/foo/bar");
+ const auto& [dbusMappings1, dbusValMaps1] =
+ handler.getDbusObjMaps(pdr->effecter_id);
+ ASSERT_EQ(dbusMappings1[0].objectPath, "/foo/bar");
// Check second PDR
auto record2 = pdr::getRecordByHandle(outRepo, 2, e);
@@ -91,11 +92,12 @@
ASSERT_EQ(states->states[0].byte, bf2[0].byte);
ASSERT_EQ(states->states[1].byte, bf2[1].byte);
- const auto& paths1 = handler.getEffecterObjs(pdr->effecter_id);
- ASSERT_EQ(paths1[0], "/foo/bar");
- ASSERT_EQ(paths1[1], "/foo/bar/baz");
+ const auto& [dbusMappings2, dbusValMaps2] =
+ handler.getDbusObjMaps(pdr->effecter_id);
+ ASSERT_EQ(dbusMappings2[0].objectPath, "/foo/bar");
+ ASSERT_EQ(dbusMappings2[1].objectPath, "/foo/bar/baz");
- ASSERT_THROW(handler.getEffecterObjs(0xDEAD), std::exception);
+ ASSERT_THROW(handler.getDbusObjMaps(0xDEAD), std::exception);
pldm_pdr_destroy(inPDRRepo);
pldm_pdr_destroy(outPDRRepo);
diff --git a/test/libpldmresponder_platform_test.cpp b/test/libpldmresponder_platform_test.cpp
index 2e99f5a..8dfe6f1 100644
--- a/test/libpldmresponder_platform_test.cpp
+++ b/test/libpldmresponder_platform_test.cpp
@@ -192,14 +192,12 @@
std::vector<set_effecter_state_field> stateField;
stateField.push_back({PLDM_REQUEST_SET, 1});
stateField.push_back({PLDM_REQUEST_SET, 1});
- std::string value = "xyz.openbmc_project.State.OperatingSystem."
- "Status.OSStatus.Standby";
+ std::string value = "xyz.openbmc_project.Foo.Bar.V1";
PropertyValue propertyValue = value;
MockdBusHandler handlerObj;
- DBusMapping dbusMapping{"/foo/bar",
- "xyz.openbmc_project.State.OperatingSystem.Status",
- "OperatingSystemState", "string"};
+ DBusMapping dbusMapping{"/foo/bar", "xyz.openbmc_project.Foo.Bar",
+ "propertyName", "string"};
EXPECT_CALL(handlerObj, setDbusProperty(dbusMapping, propertyValue))
.Times(2);
@@ -244,13 +242,6 @@
stateField);
ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
- std::vector<set_effecter_state_field> newStateField;
- newStateField.push_back({PLDM_REQUEST_SET, 1});
-
- rc = handler.setStateEffecterStatesHandler<MockdBusHandler>(handlerObj, 0x2,
- newStateField);
- ASSERT_EQ(rc, PLDM_PLATFORM_INVALID_STATE_VALUE);
-
pldm_pdr_destroy(inPDRRepo);
pldm_pdr_destroy(outPDRRepo);
}
diff --git a/test/pdr_jsons/state_effecter/good/state_effecter_pdr.json b/test/pdr_jsons/state_effecter/good/state_effecter_pdr.json
index 90e068d..e4c7311 100644
--- a/test/pdr_jsons/state_effecter/good/state_effecter_pdr.json
+++ b/test/pdr_jsons/state_effecter/good/state_effecter_pdr.json
@@ -1,63 +1,103 @@
{
- "pdrType": 11,
- "entries": [
+ "effecterPDRs": [
{
- "type": 33,
- "instance": 0,
- "container": 0,
- "effecters": [
+ "pdrType": 11,
+ "entries": [
{
- "set": {
- "id": 196,
- "size": 1,
- "states": [
- 1
- ]
- },
- "dbus": "/foo/bar"
+ "type": 33,
+ "instance": 0,
+ "container": 0,
+ "effecters": [
+ {
+ "set": {
+ "id": 196,
+ "size": 1,
+ "states": [
+ 1
+ ]
+ },
+ "dbus": {
+ "path": "/foo/bar",
+ "interface": "xyz.openbmc_project.Foo.Bar",
+ "property_name": "propertyName",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.Foo.Bar.V1"
+ ]
+ }
+ },
+ {
+ "set": {
+ "id": 196,
+ "size": 1,
+ "states": [
+ 1,
+ 2
+ ]
+ },
+ "dbus": {
+ "path": "/foo/bar",
+ "interface": "xyz.openbmc_project.Foo.Bar",
+ "property_name": "propertyName",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.Foo.Bar.V1",
+ "xyz.openbmc_project.Foo.Bar.V2"
+ ]
+ }
+ }
+ ]
},
{
- "set": {
- "id": 196,
- "size": 1,
- "states": [
- 1,
- 2
- ]
- },
- "dbus": "/foo/bar"
- }
- ]
- },
- {
- "type": 100,
- "instance": 0,
- "container": 0,
- "effecters": [
- {
- "set": {
- "id": 197,
- "size": 1,
- "states": [
- 1
- ]
- },
- "dbus": "/foo/bar"
- },
- {
- "set": {
- "id": 198,
- "size": 2,
- "states": [
- 1,
- 2,
- 5,
- 15
- ]
- },
- "dbus": "/foo/bar/baz"
+ "type": 100,
+ "instance": 0,
+ "container": 0,
+ "effecters": [
+ {
+ "set": {
+ "id": 197,
+ "size": 1,
+ "states": [
+ 1
+ ]
+ },
+ "dbus": {
+ "path": "/foo/bar",
+ "interface": "xyz.openbmc_project.Foo.Bar",
+ "property_name": "propertyName",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.Foo.Bar.V1"
+ ]
+ }
+ },
+ {
+ "set": {
+ "id": 198,
+ "size": 2,
+ "states": [
+ 1,
+ 2,
+ 5,
+ 15
+ ]
+ },
+ "dbus": {
+ "path": "/foo/bar/baz",
+ "interface": "xyz.openbmc_project.Foo.Bar.Baz",
+ "property_name": "propertyName",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.Foo.Bar.Baz.V1",
+ "xyz.openbmc_project.Foo.Bar.Baz.V2",
+ "xyz.openbmc_project.Foo.Bar.Baz.V5",
+ "xyz.openbmc_project.Foo.Bar.Baz.V15"
+ ]
+ }
+ }
+ ]
}
]
}
]
-}
\ No newline at end of file
+}
diff --git a/test/pdr_jsons/state_effecter/malformed/state_effecter_pdr.json b/test/pdr_jsons/state_effecter/malformed/state_effecter_pdr.json
index 3f4276e..bcbc37d 100644
--- a/test/pdr_jsons/state_effecter/malformed/state_effecter_pdr.json
+++ b/test/pdr_jsons/state_effecter/malformed/state_effecter_pdr.json
@@ -1,49 +1,103 @@
{
- "pdrType": 11,
- "entries": [
+ "effecterPDRs": [
{
- "type": 33
- "instance": 0,
- "container": 0,
- "effecters": [
+ "pdrType": 11,
+ "entries": [
{
- "set": {
- "id": 196,
- "size": 1,
- "states": [
- 1
- ]
- }
- }
- ]
- },
- {
- "type": 100,
- "instance": 0,
- "container": 0,
- "effecters": [
- {
- "set": {
- "id": 197,
- "size": 1,
- "states": [
- 1
- ]
- }
+ "type": 33
+ "instance": 0,
+ "container": 0,
+ "effecters": [
+ {
+ "set": {
+ "id": 196,
+ "size": 1,
+ "states": [
+ 1
+ ]
+ },
+ "dbus": {
+ "path": "/foo/bar",
+ "interface": "xyz.openbmc_project.Foo.Bar",
+ "property_name": "propertyName",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.Foo.Bar.V1"
+ ]
+ }
+ },
+ {
+ "set": {
+ "id": 196,
+ "size": 1,
+ "states": [
+ 1,
+ 2
+ ]
+ },
+ "dbus": {
+ "path": "/foo/bar",
+ "interface": "xyz.openbmc_project.Foo.Bar",
+ "property_name": "propertyName",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.Foo.Bar.V1",
+ "xyz.openbmc_project.Foo.Bar.V2"
+ ]
+ }
+ }
+ ]
},
{
- "set": {
- "id": 198,
- "size": 2,
- "states": [
- 1,
- 2,
- 5,
- 15
- ]
- }
+ "type": 100,
+ "instance": 0,
+ "container": 0,
+ "effecters": [
+ {
+ "set": {
+ "id": 197,
+ "size": 1,
+ "states": [
+ 1
+ ]
+ },
+ "dbus": {
+ "path": "/foo/bar",
+ "interface": "xyz.openbmc_project.Foo.Bar",
+ "property_name": "propertyName",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.Foo.Bar.V1"
+ ]
+ }
+ },
+ {
+ "set": {
+ "id": 198,
+ "size": 2,
+ "states": [
+ 1,
+ 2,
+ 5,
+ 15
+ ]
+ },
+ "dbus": {
+ "path": "/foo/bar/baz",
+ "interface": "xyz.openbmc_project.Foo.Bar.Baz",
+ "property_name": "propertyName",
+ "property_type": "string",
+ "property_values": [
+ "xyz.openbmc_project.Foo.Bar.Baz.V1",
+ "xyz.openbmc_project.Foo.Bar.Baz.V2",
+ "xyz.openbmc_project.Foo.Bar.Baz.V5",
+ "xyz.openbmc_project.Foo.Bar.Baz.V15"
+ ]
+ }
+ }
+ ]
}
]
}
]
-}
\ No newline at end of file
+}