blob: 475133d17ea9e7a08ea7e81d09b0c1105f4d0b35 [file] [log] [blame]
Andrew Geissler3b025e62019-02-01 10:33:54 -06001#pragma once
2
Andrew Geissler20679262019-02-11 20:20:40 -06003#include "associations.hpp"
4
Andrew Geissler3b025e62019-02-01 10:33:54 -06005#include <boost/container/flat_map.hpp>
Andrew Geissler82815da2019-02-04 12:19:41 -06006#include <boost/container/flat_set.hpp>
Matt Spinler8f876a52019-04-15 13:22:50 -05007#include <cassert>
Andrew Geissler3b025e62019-02-01 10:33:54 -06008#include <string>
9
Andrew Geissler82815da2019-02-04 12:19:41 -060010/** @brief Define white list and black list data structure */
11using WhiteBlackList = boost::container::flat_set<std::string>;
12
Matt Spinler8f876a52019-04-15 13:22:50 -050013/** @brief The old associations definitions interface */
14constexpr const char* orgOpenBMCAssocDefsInterface = "org.openbmc.Associations";
15/** @brief The new associations definitions interface */
16constexpr 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 */
26inline 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 */
40inline std::string getAssocDefPropName(std::string_view iface)
41{
42 assert(isAssocDefIface(iface));
43 return (iface == assocDefsInterface) ? "Associations" : "associations";
44}
Andrew Geissler20679262019-02-11 20:20:40 -060045
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 */
53using 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 Geissler70461892019-02-27 09:57:37 -060057/** @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 */
63using InterfacesAdded = std::vector<std::pair<
64 std::string,
65 std::vector<std::pair<
66 std::string, sdbusplus::message::variant<std::vector<Association>>>>>>;
67
Andrew Geissler3b025e62019-02-01 10:33:54 -060068/** @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 */
78bool getWellKnown(
79 const boost::container::flat_map<std::string, std::string>& owners,
Andrew Geissler82815da2019-02-04 12:19:41 -060080 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 */
94bool needToIntrospect(const std::string& processName,
95 const WhiteBlackList& whiteList,
96 const WhiteBlackList& blackList);
Andrew Geissler20679262019-02-11 20:20:40 -060097
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 */
109void 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 Geissler70461892019-02-27 09:57:37 -0600115
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 */
127void 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);