Andrew Geissler | 3b025e6 | 2019-02-01 10:33:54 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Andrew Geissler | 2067926 | 2019-02-11 20:20:40 -0600 | [diff] [blame] | 3 | #include "associations.hpp" |
| 4 | |
Andrew Geissler | 3b025e6 | 2019-02-01 10:33:54 -0600 | [diff] [blame] | 5 | #include <boost/container/flat_map.hpp> |
Andrew Geissler | 82815da | 2019-02-04 12:19:41 -0600 | [diff] [blame] | 6 | #include <boost/container/flat_set.hpp> |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame^] | 7 | #include <cassert> |
Andrew Geissler | 3b025e6 | 2019-02-01 10:33:54 -0600 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Andrew Geissler | 82815da | 2019-02-04 12:19:41 -0600 | [diff] [blame] | 10 | /** @brief Define white list and black list data structure */ |
| 11 | using WhiteBlackList = boost::container::flat_set<std::string>; |
| 12 | |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame^] | 13 | /** @brief The old associations definitions interface */ |
| 14 | constexpr const char* orgOpenBMCAssocDefsInterface = "org.openbmc.Associations"; |
| 15 | /** @brief The new associations definitions interface */ |
| 16 | constexpr const char* assocDefsInterface = |
| 17 | "xyz.openbmc_project.Association.Definitions"; |
| 18 | |
| 19 | /** @brief Says if the interface is the association definition interface. |
| 20 | * Supports either the new or old interface. |
| 21 | * |
| 22 | * @param[in] iface - the interface to check |
| 23 | * @return bool - if the interface is one of the association definition |
| 24 | * ones. |
| 25 | */ |
| 26 | inline bool isAssocDefIface(std::string_view iface) |
| 27 | { |
| 28 | return (iface == assocDefsInterface) || |
| 29 | (iface == orgOpenBMCAssocDefsInterface); |
| 30 | } |
| 31 | |
| 32 | /** @brief Returns the property name used by the defs iface. |
| 33 | * |
| 34 | * The old interface broke convention and used a lower case property |
| 35 | * name. This was resolved with the new interface. |
| 36 | * |
| 37 | * @param[in] iface - the interface to check |
| 38 | * @return std::string - the property name |
| 39 | */ |
| 40 | inline std::string getAssocDefPropName(std::string_view iface) |
| 41 | { |
| 42 | assert(isAssocDefIface(iface)); |
| 43 | return (iface == assocDefsInterface) ? "Associations" : "associations"; |
| 44 | } |
Andrew Geissler | 2067926 | 2019-02-11 20:20:40 -0600 | [diff] [blame] | 45 | |
| 46 | /** @brief interface_map_type is the underlying datastructure the mapper uses. |
| 47 | * |
| 48 | * The 3 levels of map are |
| 49 | * object paths |
| 50 | * connection names |
| 51 | * interface names |
| 52 | */ |
| 53 | using interface_map_type = boost::container::flat_map< |
| 54 | std::string, boost::container::flat_map< |
| 55 | std::string, boost::container::flat_set<std::string>>>; |
| 56 | |
Andrew Geissler | 7046189 | 2019-02-27 09:57:37 -0600 | [diff] [blame] | 57 | /** @brief InterfacesAdded represents the dbus data from the signal |
| 58 | * |
| 59 | * There are 2 pairs |
| 60 | * pair1: D-bus Interface,vector[pair2] |
| 61 | * pair2: D-bus Method,vector[Associations] |
| 62 | */ |
| 63 | using InterfacesAdded = std::vector<std::pair< |
| 64 | std::string, |
| 65 | std::vector<std::pair< |
| 66 | std::string, sdbusplus::message::variant<std::vector<Association>>>>>>; |
| 67 | |
Andrew Geissler | 3b025e6 | 2019-02-01 10:33:54 -0600 | [diff] [blame] | 68 | /** @brief Get well known name of input unique name |
| 69 | * |
| 70 | * If user passes in well known name then that will be returned. |
| 71 | * |
| 72 | * @param[in] owners - Current list of owners |
| 73 | * @param[in] request - The name to look up |
| 74 | * @param[out] wellKnown - The well known name if found |
| 75 | * |
| 76 | * @return True if well known name is found, false otherwise |
| 77 | */ |
| 78 | bool getWellKnown( |
| 79 | const boost::container::flat_map<std::string, std::string>& owners, |
Andrew Geissler | 82815da | 2019-02-04 12:19:41 -0600 | [diff] [blame] | 80 | const std::string& request, std::string& well_known); |
| 81 | |
| 82 | /** @brief Determine if dbus service is something to monitor |
| 83 | * |
| 84 | * mapper supports a whitelist and blacklist concept. If a whitelist is provided |
| 85 | * as input then only dbus objects matching that list is monitored. If a |
| 86 | * blacklist is provided then objects matching it will not be monitored. |
| 87 | * |
| 88 | * @param[in] processName - Dbus service name |
| 89 | * @param[in] whiteList - The white list |
| 90 | * @param[in] blackList - The black list |
| 91 | * |
| 92 | * @return True if input process_name should be monitored, false otherwise |
| 93 | */ |
| 94 | bool needToIntrospect(const std::string& processName, |
| 95 | const WhiteBlackList& whiteList, |
| 96 | const WhiteBlackList& blackList); |
Andrew Geissler | 2067926 | 2019-02-11 20:20:40 -0600 | [diff] [blame] | 97 | |
| 98 | /** @brief Handle the removal of an existing name in objmgr data structures |
| 99 | * |
| 100 | * @param[in,out] nameOwners - Map of unique name to well known name |
| 101 | * @param[in] wellKnown - Well known name that has new owner |
| 102 | * @param[in] oldOwner - Old unique name |
| 103 | * @param[in,out] interfaceMap - Map of interfaces |
| 104 | * @param[in,out] assocOwners - Owners of associations |
| 105 | * @param[in,out] assocInterfaces - Associations endpoints |
| 106 | * @param[in,out] server - sdbus system object |
| 107 | * |
| 108 | */ |
| 109 | void processNameChangeDelete( |
| 110 | boost::container::flat_map<std::string, std::string>& nameOwners, |
| 111 | const std::string& wellKnown, const std::string& oldOwner, |
| 112 | interface_map_type& interfaceMap, AssociationOwnersType& assocOwners, |
| 113 | AssociationInterfaces& assocInterfaces, |
| 114 | sdbusplus::asio::object_server& server); |
Andrew Geissler | 7046189 | 2019-02-27 09:57:37 -0600 | [diff] [blame] | 115 | |
| 116 | /** @brief Handle an interfaces added signal |
| 117 | * |
| 118 | * @param[in,out] interfaceMap - Global map of interfaces |
| 119 | * @param[in] objPath - New path to process |
| 120 | * @param[in] interfacesAdded - New interfaces to process |
| 121 | * @param[in] wellKnown - Well known name that has new owner |
| 122 | * @param[in,out] assocOwners - Owners of associations |
| 123 | * @param[in,out] assocInterfaces - Associations endpoints |
| 124 | * @param[in,out] server - sdbus system object |
| 125 | * |
| 126 | */ |
| 127 | void processInterfaceAdded(interface_map_type& interfaceMap, |
| 128 | const sdbusplus::message::object_path& objPath, |
| 129 | const InterfacesAdded& intfAdded, |
| 130 | const std::string& wellKnown, |
| 131 | AssociationOwnersType& assocOwners, |
| 132 | AssociationInterfaces& assocInterfaces, |
| 133 | sdbusplus::asio::object_server& server); |