xref: /openbmc/phosphor-objmgr/src/types.hpp (revision 0aa15907)
1 #pragma once
2 
3 #include <boost/container/flat_map.hpp>
4 #include <boost/container/flat_set.hpp>
5 #include <memory>
6 #include <sdbusplus/asio/object_server.hpp>
7 #include <string>
8 #include <tuple>
9 #include <vector>
10 
11 /** @brief interface_map_type is the underlying datastructure the mapper uses.
12  *
13  * The 3 levels of map are
14  * object paths
15  *   connection names
16  *      interface names
17  */
18 using interface_map_type = boost::container::flat_map<
19     std::string, boost::container::flat_map<
20                      std::string, boost::container::flat_set<std::string>>>;
21 
22 /**
23  *  Associations and some metadata are stored in associationInterfaces.
24  *  The fields are:
25  *   * ifacePos - holds the D-Bus interface object
26  *   * endpointsPos - holds the endpoints array that shadows the property
27  */
28 static constexpr auto ifacePos = 0;
29 static constexpr auto endpointsPos = 1;
30 using Endpoints = std::vector<std::string>;
31 
32 // map[interface path: tuple[dbus_interface,vector[endpoint paths]]]
33 using AssociationInterfaces = boost::container::flat_map<
34     std::string,
35     std::tuple<std::shared_ptr<sdbusplus::asio::dbus_interface>, Endpoints>>;
36 
37 /**
38  * The associationOwners map contains information about creators of
39  * associations, so that when a org.openbmc.Association interface is
40  * removed or its 'associations' property is changed, the mapper owned
41  * association objects can be correctly handled.  It is a map of the
42  * object path of the org.openbmc.Association owner to a map of the
43  * service the path is owned by, to a map of the association objects to
44  * their endpoint paths:
45  * map[ownerPath : map[service : map[assocPath : [endpoint paths]]]
46  * For example:
47  * [/logging/entry/1 :
48  *   [xyz.openbmc_project.Logging :
49  *     [/logging/entry/1/callout : [/system/cpu0],
50  *      /system/cpu0/fault : [/logging/entry/1]]]]
51  */
52 using AssociationPaths =
53     boost::container::flat_map<std::string,
54                                boost::container::flat_set<std::string>>;
55 
56 using AssociationOwnersType = boost::container::flat_map<
57     std::string, boost::container::flat_map<std::string, AssociationPaths>>;
58 
59 /**
60  * Store the contents of the associations property on the interface
61  * For example:
62  * ["inventory", "activation", "/xyz/openbmc_project/inventory/system/chassis"]
63  */
64 constexpr auto forwardTypePos = 0;
65 constexpr auto reverseTypePos = 1;
66 constexpr auto reversePathPos = 2;
67 using Association = std::tuple<std::string, std::string, std::string>;
68 
69 /**
70  * PendingAssociations tracks associations that cannot be created because
71  * the endpoint (the last element of the Association tuple) doesn't exist.
72  * When that endpoint shows up on D-Bus, both association paths can then
73  * be created.  Also, if a valid association has an endpoint removed from
74  * D-Bus, then a new PendingAssociations entry will be created until it
75  * reappears.  It has all of the information it needs to recreate the
76  * association.
77  */
78 constexpr auto ownerPos = 0;
79 constexpr auto assocPos = 1;
80 using ExistingEndpoint = std::tuple<std::string, Association>;
81 using ExistingEndpoints = std::vector<ExistingEndpoint>;
82 using PendingAssociations = std::map<std::string, ExistingEndpoints>;
83 
84 /**
85  *  The return type of findAssociations().
86  *  The string in the tuple is the association owner.
87  */
88 using FindAssocResults = std::vector<std::tuple<std::string, Association>>;
89 
90 /**
91  * Keeps all association related maps together.
92  */
93 struct AssociationMaps
94 {
95     AssociationInterfaces ifaces;
96     AssociationOwnersType owners;
97     PendingAssociations pending;
98 };
99