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