Matt Spinler | 852db67 | 2019-03-06 13:46:14 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "config.h" |
| 4 | |
Matt Spinler | c47ca58 | 2019-03-06 14:37:42 -0600 | [diff] [blame^] | 5 | #include <xyz/openbmc_project/Association/Definitions/server.hpp> |
Matt Spinler | 852db67 | 2019-03-06 13:46:14 -0600 | [diff] [blame] | 6 | |
| 7 | namespace phosphor |
| 8 | { |
| 9 | namespace inventory |
| 10 | { |
| 11 | namespace manager |
| 12 | { |
| 13 | namespace associations |
| 14 | { |
| 15 | |
Matt Spinler | 99e66a0 | 2019-03-06 14:11:22 -0600 | [diff] [blame] | 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 | |
Matt Spinler | c47ca58 | 2019-03-06 14:37:42 -0600 | [diff] [blame^] | 27 | using AssociationObject = sdbusplus::server::object::object< |
| 28 | sdbusplus::xyz::openbmc_project::Association::server::Definitions>; |
| 29 | |
| 30 | using AssociationIfaceMap = |
| 31 | std::map<std::string, std::unique_ptr<AssociationObject>>; |
| 32 | |
Matt Spinler | 852db67 | 2019-03-06 13:46:14 -0600 | [diff] [blame] | 33 | /** |
| 34 | * @class Manager |
| 35 | * |
| 36 | * @brief This class provides the ability to add org.openbmc.Associations |
| 37 | * interfaces on inventory D-Bus objects, based on a definition in a |
| 38 | * JSON file. |
| 39 | * |
| 40 | * The purpose for this is to be able to associate other D-Bus paths |
| 41 | * with the inventory items they relate to. |
| 42 | * |
| 43 | * For example, a card temperature sensor D-Bus object can be associated |
| 44 | * with the D-Bus object for that card's inventory entry so that some |
| 45 | * code can tie them together. |
| 46 | */ |
| 47 | class Manager |
| 48 | { |
| 49 | public: |
| 50 | Manager() = delete; |
| 51 | ~Manager() = default; |
| 52 | Manager(const Manager&) = delete; |
| 53 | Manager& operator=(const Manager&) = delete; |
| 54 | Manager(Manager&&) = delete; |
| 55 | Manager& operator=(Manager&&) = delete; |
| 56 | |
| 57 | /** |
| 58 | * @brief Constructor |
| 59 | * |
| 60 | * @param[in] bus - sdbusplus object |
| 61 | * @param[in] jsonPath - path to the JSON File that contains associations |
| 62 | */ |
| 63 | Manager(sdbusplus::bus::bus& bus, const std::string& jsonPath); |
| 64 | |
| 65 | /** |
| 66 | * @brief Constructor |
| 67 | * |
| 68 | * @param[in] bus - sdbusplus object |
| 69 | */ |
| 70 | explicit Manager(sdbusplus::bus::bus& bus) : |
| 71 | Manager(bus, ASSOCIATIONS_FILE_PATH) |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @brief Creates any association D-Bus interfaces required based on |
| 77 | * the JSON associations definition for the object path passed |
| 78 | * in. |
| 79 | * |
| 80 | * Called after PIM creates a new inventory D-Bus interface on objectPath. |
| 81 | * |
| 82 | * @param[in] objectPath - the D-Bus object path to check for associations |
| 83 | */ |
| 84 | void createAssociations(const std::string& objectPath); |
| 85 | |
Matt Spinler | 99e66a0 | 2019-03-06 14:11:22 -0600 | [diff] [blame] | 86 | /** |
| 87 | * @brief Returned the association configuration. |
| 88 | * Used for testing. |
| 89 | * |
| 90 | * @return AssociationMap& - the association config |
| 91 | */ |
| 92 | const AssociationMap& getAssociationsConfig() |
| 93 | { |
| 94 | return _associations; |
| 95 | } |
| 96 | |
Matt Spinler | 852db67 | 2019-03-06 13:46:14 -0600 | [diff] [blame] | 97 | private: |
| 98 | /** |
Matt Spinler | 99e66a0 | 2019-03-06 14:11:22 -0600 | [diff] [blame] | 99 | * @brief Loads the association YAML into the _associations data |
| 100 | * structure. This file is optional, so if it doesn't exist |
| 101 | * it will just not load anything. |
| 102 | */ |
| 103 | void load(); |
| 104 | |
| 105 | /** |
Matt Spinler | c47ca58 | 2019-03-06 14:37:42 -0600 | [diff] [blame^] | 106 | * @brief Creates an instance of an org.openbmc.Associations |
| 107 | * interface using the passed in properties. |
| 108 | * |
| 109 | * @param[in] forwardPath - the path of the forward association |
| 110 | * @param[in] forwardType - the type of the forward association |
| 111 | * @param[in] reversePath - the path of the reverse association |
| 112 | * @param[in] reverseType - the type of the reverse association |
| 113 | */ |
| 114 | void createAssociation(const std::string& forwardPath, |
| 115 | const std::string& forwardType, |
| 116 | const std::string& reversePath, |
| 117 | const std::string& reverseType); |
| 118 | |
| 119 | /** |
Matt Spinler | 99e66a0 | 2019-03-06 14:11:22 -0600 | [diff] [blame] | 120 | * @brief The map of association data that is loaded from its |
| 121 | * JSON definition. Association D-Bus objects will be |
| 122 | * created from this data. |
| 123 | */ |
| 124 | AssociationMap _associations; |
| 125 | |
| 126 | /** |
Matt Spinler | c47ca58 | 2019-03-06 14:37:42 -0600 | [diff] [blame^] | 127 | * @brief The map of org.openbmc_project.Associations D-Bus |
| 128 | * interfaces objects based on their object path. |
| 129 | */ |
| 130 | AssociationIfaceMap _associationIfaces; |
| 131 | |
| 132 | /** |
Matt Spinler | 852db67 | 2019-03-06 13:46:14 -0600 | [diff] [blame] | 133 | * @brief The sdbusplus bus object. |
| 134 | */ |
| 135 | sdbusplus::bus::bus& _bus; |
| 136 | |
| 137 | /** |
| 138 | * @brief The path to the associations JSON File. |
| 139 | */ |
| 140 | const std::string _jsonFile; |
Matt Spinler | c47ca58 | 2019-03-06 14:37:42 -0600 | [diff] [blame^] | 141 | |
| 142 | /** |
| 143 | * A list of the inventory association paths that have already been handled. |
| 144 | */ |
| 145 | std::vector<std::string> _handled; |
Matt Spinler | 852db67 | 2019-03-06 13:46:14 -0600 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | } // namespace associations |
| 149 | } // namespace manager |
| 150 | } // namespace inventory |
| 151 | } // namespace phosphor |