1 #pragma once 2 3 #include "config.h" 4 5 #include <sdbusplus/bus.hpp> 6 7 namespace phosphor 8 { 9 namespace inventory 10 { 11 namespace manager 12 { 13 namespace associations 14 { 15 16 static constexpr auto forwardTypePos = 0; 17 static constexpr auto reverseTypePos = 1; 18 using Types = std::tuple<std::string, std::string>; 19 using Paths = std::vector<std::string>; 20 21 static constexpr auto typesPos = 0; 22 static constexpr auto pathsPos = 1; 23 using EndpointsEntry = std::vector<std::tuple<Types, Paths>>; 24 25 using AssociationMap = std::map<std::string, EndpointsEntry>; 26 27 /** 28 * @class Manager 29 * 30 * @brief This class provides the ability to add org.openbmc.Associations 31 * interfaces on inventory D-Bus objects, based on a definition in a 32 * JSON file. 33 * 34 * The purpose for this is to be able to associate other D-Bus paths 35 * with the inventory items they relate to. 36 * 37 * For example, a card temperature sensor D-Bus object can be associated 38 * with the D-Bus object for that card's inventory entry so that some 39 * code can tie them together. 40 */ 41 class Manager 42 { 43 public: 44 Manager() = delete; 45 ~Manager() = default; 46 Manager(const Manager&) = delete; 47 Manager& operator=(const Manager&) = delete; 48 Manager(Manager&&) = delete; 49 Manager& operator=(Manager&&) = delete; 50 51 /** 52 * @brief Constructor 53 * 54 * @param[in] bus - sdbusplus object 55 * @param[in] jsonPath - path to the JSON File that contains associations 56 */ 57 Manager(sdbusplus::bus::bus& bus, const std::string& jsonPath); 58 59 /** 60 * @brief Constructor 61 * 62 * @param[in] bus - sdbusplus object 63 */ 64 explicit Manager(sdbusplus::bus::bus& bus) : 65 Manager(bus, ASSOCIATIONS_FILE_PATH) 66 { 67 } 68 69 /** 70 * @brief Creates any association D-Bus interfaces required based on 71 * the JSON associations definition for the object path passed 72 * in. 73 * 74 * Called after PIM creates a new inventory D-Bus interface on objectPath. 75 * 76 * @param[in] objectPath - the D-Bus object path to check for associations 77 */ 78 void createAssociations(const std::string& objectPath); 79 80 /** 81 * @brief Returned the association configuration. 82 * Used for testing. 83 * 84 * @return AssociationMap& - the association config 85 */ 86 const AssociationMap& getAssociationsConfig() 87 { 88 return _associations; 89 } 90 91 private: 92 /** 93 * @brief Loads the association YAML into the _associations data 94 * structure. This file is optional, so if it doesn't exist 95 * it will just not load anything. 96 */ 97 void load(); 98 99 /** 100 * @brief The map of association data that is loaded from its 101 * JSON definition. Association D-Bus objects will be 102 * created from this data. 103 */ 104 AssociationMap _associations; 105 106 /** 107 * @brief The sdbusplus bus object. 108 */ 109 sdbusplus::bus::bus& _bus; 110 111 /** 112 * @brief The path to the associations JSON File. 113 */ 114 const std::string _jsonFile; 115 }; 116 117 } // namespace associations 118 } // namespace manager 119 } // namespace inventory 120 } // namespace phosphor 121