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