xref: /openbmc/phosphor-objmgr/src/types.hpp (revision 964681ca)
135396c10SMatt Spinler #pragma once
235396c10SMatt Spinler 
335396c10SMatt Spinler #include <boost/container/flat_map.hpp>
435396c10SMatt Spinler #include <boost/container/flat_set.hpp>
535396c10SMatt Spinler #include <sdbusplus/asio/object_server.hpp>
62352088eSBrad Bishop 
72352088eSBrad Bishop #include <memory>
835396c10SMatt Spinler #include <string>
935396c10SMatt Spinler #include <tuple>
1035396c10SMatt Spinler #include <vector>
1135396c10SMatt Spinler 
1235396c10SMatt Spinler /** @brief interface_map_type is the underlying datastructure the mapper uses.
1335396c10SMatt Spinler  *
1435396c10SMatt Spinler  * The 3 levels of map are
1535396c10SMatt Spinler  * object paths
1635396c10SMatt Spinler  *   connection names
1735396c10SMatt Spinler  *      interface names
1835396c10SMatt Spinler  */
19*964681caSEd Tanous using InterfaceNames = boost::container::flat_set<std::string, std::less<>,
20*964681caSEd Tanous                                                   std::vector<std::string>>;
21*964681caSEd Tanous 
22*964681caSEd Tanous using ConnectionNames = boost::container::flat_map<
23*964681caSEd Tanous     std::string, InterfaceNames, std::less<>,
24*964681caSEd Tanous     std::vector<std::pair<std::string, InterfaceNames>>>;
25*964681caSEd Tanous 
26a098a37aSBrad Bishop using InterfaceMapType = boost::container::flat_map<
27*964681caSEd Tanous     std::string, ConnectionNames, std::less<>,
28*964681caSEd Tanous     std::vector<std::pair<std::string, ConnectionNames>>>;
2935396c10SMatt Spinler 
3035396c10SMatt Spinler /**
3135396c10SMatt Spinler  *  Associations and some metadata are stored in associationInterfaces.
3235396c10SMatt Spinler  *  The fields are:
3335396c10SMatt Spinler  *   * ifacePos - holds the D-Bus interface object
3435396c10SMatt Spinler  *   * endpointsPos - holds the endpoints array that shadows the property
3535396c10SMatt Spinler  */
3635396c10SMatt Spinler static constexpr auto ifacePos = 0;
3735396c10SMatt Spinler static constexpr auto endpointsPos = 1;
3835396c10SMatt Spinler using Endpoints = std::vector<std::string>;
3935396c10SMatt Spinler 
4035396c10SMatt Spinler // map[interface path: tuple[dbus_interface,vector[endpoint paths]]]
4135396c10SMatt Spinler using AssociationInterfaces = boost::container::flat_map<
4235396c10SMatt Spinler     std::string,
4335396c10SMatt Spinler     std::tuple<std::shared_ptr<sdbusplus::asio::dbus_interface>, Endpoints>>;
4435396c10SMatt Spinler 
4535396c10SMatt Spinler /**
4635396c10SMatt Spinler  * The associationOwners map contains information about creators of
4735396c10SMatt Spinler  * associations, so that when a org.openbmc.Association interface is
4835396c10SMatt Spinler  * removed or its 'associations' property is changed, the mapper owned
4935396c10SMatt Spinler  * association objects can be correctly handled.  It is a map of the
5035396c10SMatt Spinler  * object path of the org.openbmc.Association owner to a map of the
5135396c10SMatt Spinler  * service the path is owned by, to a map of the association objects to
5235396c10SMatt Spinler  * their endpoint paths:
5335396c10SMatt Spinler  * map[ownerPath : map[service : map[assocPath : [endpoint paths]]]
5435396c10SMatt Spinler  * For example:
5535396c10SMatt Spinler  * [/logging/entry/1 :
5635396c10SMatt Spinler  *   [xyz.openbmc_project.Logging :
5735396c10SMatt Spinler  *     [/logging/entry/1/callout : [/system/cpu0],
5835396c10SMatt Spinler  *      /system/cpu0/fault : [/logging/entry/1]]]]
5935396c10SMatt Spinler  */
6035396c10SMatt Spinler using AssociationPaths =
6135396c10SMatt Spinler     boost::container::flat_map<std::string,
6235396c10SMatt Spinler                                boost::container::flat_set<std::string>>;
6335396c10SMatt Spinler 
6435396c10SMatt Spinler using AssociationOwnersType = boost::container::flat_map<
6535396c10SMatt Spinler     std::string, boost::container::flat_map<std::string, AssociationPaths>>;
6635396c10SMatt Spinler 
6735396c10SMatt Spinler /**
6835396c10SMatt Spinler  * Store the contents of the associations property on the interface
6935396c10SMatt Spinler  * For example:
7035396c10SMatt Spinler  * ["inventory", "activation", "/xyz/openbmc_project/inventory/system/chassis"]
7135396c10SMatt Spinler  */
72cb9bcdb1SMatt Spinler constexpr auto forwardTypePos = 0;
73cb9bcdb1SMatt Spinler constexpr auto reverseTypePos = 1;
74cb9bcdb1SMatt Spinler constexpr auto reversePathPos = 2;
7535396c10SMatt Spinler using Association = std::tuple<std::string, std::string, std::string>;
76e2359fb7SMatt Spinler 
77e2359fb7SMatt Spinler /**
78e0b0e3a2SMatt Spinler  * PendingAssociations tracks associations that cannot be created because
79e0b0e3a2SMatt Spinler  * the endpoint (the last element of the Association tuple) doesn't exist.
80e0b0e3a2SMatt Spinler  * When that endpoint shows up on D-Bus, both association paths can then
81e0b0e3a2SMatt Spinler  * be created.  Also, if a valid association has an endpoint removed from
82e0b0e3a2SMatt Spinler  * D-Bus, then a new PendingAssociations entry will be created until it
83e0b0e3a2SMatt Spinler  * reappears.  It has all of the information it needs to recreate the
84e0b0e3a2SMatt Spinler  * association.
85e0b0e3a2SMatt Spinler  */
86e0b0e3a2SMatt Spinler constexpr auto ownerPos = 0;
87e0b0e3a2SMatt Spinler constexpr auto assocPos = 1;
88e0b0e3a2SMatt Spinler using ExistingEndpoint = std::tuple<std::string, Association>;
89e0b0e3a2SMatt Spinler using ExistingEndpoints = std::vector<ExistingEndpoint>;
90e0b0e3a2SMatt Spinler using PendingAssociations = std::map<std::string, ExistingEndpoints>;
91e0b0e3a2SMatt Spinler 
92e0b0e3a2SMatt Spinler /**
937f8fd1faSMatt Spinler  *  The return type of findAssociations().
947f8fd1faSMatt Spinler  *  The string in the tuple is the association owner.
957f8fd1faSMatt Spinler  */
967f8fd1faSMatt Spinler using FindAssocResults = std::vector<std::tuple<std::string, Association>>;
977f8fd1faSMatt Spinler 
987f8fd1faSMatt Spinler /**
99e2359fb7SMatt Spinler  * Keeps all association related maps together.
100e2359fb7SMatt Spinler  */
101e2359fb7SMatt Spinler struct AssociationMaps
102e2359fb7SMatt Spinler {
103e2359fb7SMatt Spinler     AssociationInterfaces ifaces;
104e2359fb7SMatt Spinler     AssociationOwnersType owners;
105e0b0e3a2SMatt Spinler     PendingAssociations pending;
106e2359fb7SMatt Spinler };
107