xref: /openbmc/pldm/host-bmc/utils.hpp (revision fa084700)
1 #include "libpldm/pdr.h"
2 
3 #include "libpldmresponder/oem_handler.hpp"
4 
5 #include <nlohmann/json.hpp>
6 #include <phosphor-logging/lg2.hpp>
7 
8 #include <filesystem>
9 #include <fstream>
10 #include <map>
11 #include <string>
12 #include <vector>
13 
14 PHOSPHOR_LOG2_USING;
15 namespace pldm
16 {
17 using Json = nlohmann::json;
18 namespace fs = std::filesystem;
19 using ObjectPath = fs::path;
20 using EntityName = std::string;
21 using EntityType = uint16_t;
22 using Entities = std::vector<pldm_entity_node*>;
23 using EntityAssociations = std::vector<Entities>;
24 using ObjectPathMaps = std::map<ObjectPath, pldm_entity_node*>;
25 using EntityMaps = std::map<EntityType, EntityName>;
26 namespace hostbmc
27 {
28 namespace utils
29 {
30 
31 /** @brief Vector a entity name to pldm_entity from entity association tree
32  *  @param[in]  entityAssoc    - Vector of associated pldm entities
33  *  @param[in]  entityTree     - entity association tree
34  *  @param[out] objPathMap     - maps an object path to pldm_entity from the
35  *                               BMC's entity association tree
36  *  @return
37  */
38 void updateEntityAssociation(
39     const EntityAssociations& entityAssoc,
40     pldm_entity_association_tree* entityTree, ObjectPathMaps& objPathMap,
41     EntityMaps entityMaps,
42     pldm::responder::oem_platform::Handler* oemPlatformHandler);
43 
44 /** @brief Parsing entity to DBus string mapping from json file
45  *
46  *  @param[in]  filePath - JSON file path for parsing
47  *
48  *  @return returns the entity to DBus string mapping object
49  */
50 EntityMaps parseEntityMap(const fs::path& filePath);
51 
52 } // namespace utils
53 } // namespace hostbmc
54 } // namespace pldm
55