blob: 0196c36b3c19a902d60210971c657393d70aca28 [file] [log] [blame]
Matt Spinler852db672019-03-06 13:46:14 -06001#pragma once
2
3#include "config.h"
4
5#include <sdbusplus/bus.hpp>
6
7namespace phosphor
8{
9namespace inventory
10{
11namespace manager
12{
13namespace associations
14{
15
Matt Spinler99e66a02019-03-06 14:11:22 -060016static constexpr auto forwardTypePos = 0;
17static constexpr auto reverseTypePos = 1;
18using Types = std::tuple<std::string, std::string>;
19using Paths = std::vector<std::string>;
20
21static constexpr auto typesPos = 0;
22static constexpr auto pathsPos = 1;
23using EndpointsEntry = std::vector<std::tuple<Types, Paths>>;
24
25using AssociationMap = std::map<std::string, EndpointsEntry>;
26
Matt Spinler852db672019-03-06 13:46:14 -060027/**
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 */
41class 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
Matt Spinler99e66a02019-03-06 14:11:22 -060080 /**
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
Matt Spinler852db672019-03-06 13:46:14 -060091 private:
92 /**
Matt Spinler99e66a02019-03-06 14:11:22 -060093 * @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 /**
Matt Spinler852db672019-03-06 13:46:14 -0600107 * @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