blob: 1d7b77881ddacd6d4c0401934d9c50ed73857243 [file] [log] [blame]
Andrew Geisslera80a3af2019-02-04 14:01:49 -06001#pragma once
2
Matt Spinler35396c12019-04-05 11:46:57 -05003#include "types.hpp"
Andrew Geisslera80a3af2019-02-04 14:01:49 -06004
Brad Bishopa098a372022-05-05 15:19:04 -04005constexpr const char* xyzAssociationInterface =
Andrew Geissler4511b332019-02-21 15:40:40 -06006 "xyz.openbmc_project.Association";
7
Kallas, Pawel5b4357d2022-10-12 15:36:37 +02008constexpr size_t endpointsCountTimerThreshold = 100;
9constexpr int endpointUpdateDelaySeconds = 1;
10
Andrew Geisslera80a3af2019-02-04 14:01:49 -060011/** @brief Remove input association
12 *
Kallas, Pawel5b4357d2022-10-12 15:36:37 +020013 * @param[in] io - io context
Andrew Geisslera80a3af2019-02-04 14:01:49 -060014 * @param[in] sourcePath - Path of the object that contains the
15 * org.openbmc.Associations
16 * @param[in] owner - The Dbus service having its associations
17 * removed
18 * @param[in,out] server - sdbus system object
Matt Spinlere2359fb2019-04-05 14:11:33 -050019 * @param[in,out] assocMaps - The association maps
Andrew Geisslera80a3af2019-02-04 14:01:49 -060020 *
Matt Spinlere2359fb2019-04-05 14:11:33 -050021 * @return Void, server, assocMaps updated if needed
Andrew Geisslera80a3af2019-02-04 14:01:49 -060022 */
Kallas, Pawel5b4357d2022-10-12 15:36:37 +020023void removeAssociation(boost::asio::io_context& io,
24 const std::string& sourcePath, const std::string& owner,
Andrew Geisslera80a3af2019-02-04 14:01:49 -060025 sdbusplus::asio::object_server& server,
Matt Spinlere2359fb2019-04-05 14:11:33 -050026 AssociationMaps& assocMaps);
Andrew Geisslerff5ce922019-02-21 12:43:09 -060027
28/** @brief Remove input paths from endpoints of an association
29 *
30 * If the last endpoint was removed, then remove the whole
31 * association object, otherwise just set the property
32 *
Kallas, Pawel5b4357d2022-10-12 15:36:37 +020033 * @param[in] io - io context
Andrew Geisslerff5ce922019-02-21 12:43:09 -060034 * @param[in] objectServer - sdbus system object
35 * @param[in] assocPath - Path of the object that contains the
36 * org.openbmc.Associations
37 * @param[in] endpointsToRemove - Endpoints to remove
Matt Spinlere2359fb2019-04-05 14:11:33 -050038 * @param[in,out] assocMaps - The association maps
Andrew Geisslerff5ce922019-02-21 12:43:09 -060039 *
Matt Spinlere2359fb2019-04-05 14:11:33 -050040 * @return Void, objectServer and assocMaps updated if needed
Andrew Geisslerff5ce922019-02-21 12:43:09 -060041 */
42void removeAssociationEndpoints(
Kallas, Pawel5b4357d2022-10-12 15:36:37 +020043 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
44 const std::string& assocPath,
Andrew Geisslerff5ce922019-02-21 12:43:09 -060045 const boost::container::flat_set<std::string>& endpointsToRemove,
Matt Spinlere2359fb2019-04-05 14:11:33 -050046 AssociationMaps& assocMaps);
Andrew Geissler7f1c44d2019-02-21 13:44:16 -060047
48/** @brief Check and remove any changed associations
49 *
50 * Based on the latest values of the org.openbmc.Associations.associations
51 * property, passed in via the newAssociations param, check if any of the
52 * paths in the xyz.openbmc_project.Association.endpoints D-Bus property
53 * for that association need to be removed. If the last path is removed
54 * from the endpoints property, remove that whole association object from
55 * D-Bus.
56 *
Kallas, Pawel5b4357d2022-10-12 15:36:37 +020057 * @param[in] io - io context
Andrew Geissler7f1c44d2019-02-21 13:44:16 -060058 * @param[in] sourcePath - Path of the object that contains the
59 * org.openbmc.Associations
60 * @param[in] owner - The Dbus service having it's associatons
61 * changed
62 * @param[in] newAssociations - New associations to look at for change
63 * @param[in,out] objectServer - sdbus system object
Matt Spinlere2359fb2019-04-05 14:11:33 -050064 * @param[in,out] assocMaps - The association maps
Andrew Geissler7f1c44d2019-02-21 13:44:16 -060065 *
Matt Spinlere2359fb2019-04-05 14:11:33 -050066 * @return Void, objectServer and assocMaps updated if needed
Andrew Geissler7f1c44d2019-02-21 13:44:16 -060067 */
68void checkAssociationEndpointRemoves(
Kallas, Pawel5b4357d2022-10-12 15:36:37 +020069 boost::asio::io_context& io, const std::string& sourcePath,
70 const std::string& owner, const AssociationPaths& newAssociations,
Matt Spinlere2359fb2019-04-05 14:11:33 -050071 sdbusplus::asio::object_server& objectServer, AssociationMaps& assocMaps);
Andrew Geissler4511b332019-02-21 15:40:40 -060072
73/** @brief Handle new or changed association interfaces
74 *
75 * Called when either a new org.openbmc.Associations interface was
76 * created, or the associations property on that interface changed
77 *
Kallas, Pawel5b4357d2022-10-12 15:36:37 +020078 * @param[in] io - io context
Andrew Geissler4511b332019-02-21 15:40:40 -060079 * @param[in,out] objectServer - sdbus system object
80 * @param[in] associations - New associations to look at for change
81 * @param[in] path - Path of the object that contains the
82 * org.openbmc.Associations
83 * @param[in] owner - The Dbus service having it's associatons
84 * changed
Matt Spinlere0b0e3a2019-04-08 10:39:23 -050085 * @param[in] interfaceMap - The full interface map
Matt Spinlere2359fb2019-04-05 14:11:33 -050086 * @param[in,out] assocMaps - The association maps
Andrew Geissler4511b332019-02-21 15:40:40 -060087 *
Matt Spinlere2359fb2019-04-05 14:11:33 -050088 * @return Void, objectServer and assocMaps updated if needed
Andrew Geissler4511b332019-02-21 15:40:40 -060089 */
Kallas, Pawel5b4357d2022-10-12 15:36:37 +020090void associationChanged(boost::asio::io_context& io,
91 sdbusplus::asio::object_server& objectServer,
Andrew Geissler4511b332019-02-21 15:40:40 -060092 const std::vector<Association>& associations,
93 const std::string& path, const std::string& owner,
Brad Bishopa098a372022-05-05 15:19:04 -040094 const InterfaceMapType& interfaceMap,
Matt Spinlere2359fb2019-04-05 14:11:33 -050095 AssociationMaps& assocMaps);
Matt Spinlere0b0e3a2019-04-08 10:39:23 -050096
97/** @brief Add a pending associations entry
98 *
99 * Used when a client wants to create an association between
100 * 2 D-Bus endpoint paths, but one of the paths doesn't exist.
101 * When the path does show up in D-Bus, if there is a pending
102 * association then the real association objects can be created.
103 *
104 * @param[in] objectPath - The D-Bus object path that should be an
105 * association endpoint but doesn't exist
106 * on D-Bus.
107 * @param[in] type - The association type. Gets used in the final
108 * association path of <objectPath>/<type>.
109 * @param[in] endpointPath - The D-Bus path on the other side
110 * of the association. This path exists.
111 * @param[in] endpointType - The endpoint association type. Gets used
112 * in the final association path of
113 * <endpointPath>/<endpointType>.
114 * @param[in] owner - The service name that owns the association.
115 * @param[in,out] assocMaps - The association maps
116 */
117void addPendingAssociation(const std::string& objectPath,
118 const std::string& type,
119 const std::string& endpointPath,
120 const std::string& endpointType,
121 const std::string& owner,
122 AssociationMaps& assocMaps);
Matt Spinlercb9bcdb2019-04-08 10:58:49 -0500123
124/** @brief Removes an endpoint from the pending associations map
125 *
126 * If the last endpoint is removed, removes the whole entry
127 *
128 * @param[in] endpointPath - the endpoint path to remove
129 * @param[in,out] assocMaps - The association maps
130 */
131void removeFromPendingAssociations(const std::string& endpointPath,
132 AssociationMaps& assocMaps);
Matt Spinler11401e22019-04-08 13:13:25 -0500133
134/** @brief Adds a single association D-Bus object (<path>/<type>)
135 *
Kallas, Pawel5b4357d2022-10-12 15:36:37 +0200136 * @param[in] io - io context
Matt Spinler11401e22019-04-08 13:13:25 -0500137 * @param[in,out] server - sdbus system object
138 * @param[in] assocPath - The association D-Bus path
139 * @param[in] endpoint - The association's D-Bus endpoint path
140 * @param[in] owner - The owning D-Bus well known name
141 * @param[in] ownerPath - The D-Bus path hosting the Associations property
142 * @param[in,out] assocMaps - The association maps
143 */
Kallas, Pawel5b4357d2022-10-12 15:36:37 +0200144void addSingleAssociation(boost::asio::io_context& io,
145 sdbusplus::asio::object_server& server,
Matt Spinler11401e22019-04-08 13:13:25 -0500146 const std::string& assocPath,
147 const std::string& endpoint, const std::string& owner,
148 const std::string& ownerPath,
149 AssociationMaps& assocMaps);
150
151/** @brief Create a real association out of a pending association
152 * if there is one for this path.
153 *
154 * If objectPath is now on D-Bus, and it is also in the pending associations
155 * map, create the 2 real association objects and remove its pending
156 * associations entry. Used when a new path shows up in D-Bus.
157 *
Kallas, Pawel5b4357d2022-10-12 15:36:37 +0200158 * @param[in] io - io context
Matt Spinler11401e22019-04-08 13:13:25 -0500159 * @param[in] objectPath - the path to check
160 * @param[in] interfaceMap - The master interface map
161 * @param[in,out] assocMaps - The association maps
162 * @param[in,out] server - sdbus system object
163 */
Kallas, Pawel5b4357d2022-10-12 15:36:37 +0200164void checkIfPendingAssociation(boost::asio::io_context& io,
165 const std::string& objectPath,
Brad Bishopa098a372022-05-05 15:19:04 -0400166 const InterfaceMapType& interfaceMap,
Matt Spinler11401e22019-04-08 13:13:25 -0500167 AssociationMaps& assocMaps,
168 sdbusplus::asio::object_server& server);
Matt Spinler7f8fd1f2019-04-08 15:21:59 -0500169
170/** @brief Find all associations in the association owners map with the
171 * specified endpoint path.
172 *
173 * @param[in] endpointPath - the endpoint path to look for
174 * @param[in] assocMaps - The association maps
175 * @param[out] associationData - A vector of {owner, Association} tuples
176 * of all the associations with that endpoint.
177 */
178void findAssociations(const std::string& endpointPath,
179 AssociationMaps& assocMaps,
180 FindAssocResults& associationData);
Matt Spinler9c3d2852019-04-08 15:57:19 -0500181
182/** @brief If endpointPath is in an association, move that association
183 * to pending and remove the association objects.
184 *
185 * Called when a path is going off of D-Bus. If this path is an
186 * association endpoint (the path that owns the association is still
187 * on D-Bus), then move the association it's involved in to pending.
188 *
Kallas, Pawel5b4357d2022-10-12 15:36:37 +0200189 * @param[in] io - io context
Matt Spinler9c3d2852019-04-08 15:57:19 -0500190 * @param[in] endpointPath - the D-Bus endpoint path to check
191 * @param[in,out] assocMaps - The association maps
192 * @param[in,out] server - sdbus system object
193 */
Kallas, Pawel5b4357d2022-10-12 15:36:37 +0200194void moveAssociationToPending(boost::asio::io_context& io,
195 const std::string& endpointPath,
Matt Spinler9c3d2852019-04-08 15:57:19 -0500196 AssociationMaps& assocMaps,
197 sdbusplus::asio::object_server& server);