blob: 1ea5c2d068a554efc86935d35fcebce1185761ac [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 */
Patrick Williams9052ebd2024-08-16 15:22:16 -040090void associationChanged(
91 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
92 const std::vector<Association>& associations, const std::string& path,
93 const std::string& owner, const InterfaceMapType& interfaceMap,
94 AssociationMaps& assocMaps);
Matt Spinlere0b0e3a2019-04-08 10:39:23 -050095
96/** @brief Add a pending associations entry
97 *
98 * Used when a client wants to create an association between
99 * 2 D-Bus endpoint paths, but one of the paths doesn't exist.
100 * When the path does show up in D-Bus, if there is a pending
101 * association then the real association objects can be created.
102 *
103 * @param[in] objectPath - The D-Bus object path that should be an
104 * association endpoint but doesn't exist
105 * on D-Bus.
106 * @param[in] type - The association type. Gets used in the final
107 * association path of <objectPath>/<type>.
108 * @param[in] endpointPath - The D-Bus path on the other side
109 * of the association. This path exists.
110 * @param[in] endpointType - The endpoint association type. Gets used
111 * in the final association path of
112 * <endpointPath>/<endpointType>.
113 * @param[in] owner - The service name that owns the association.
114 * @param[in,out] assocMaps - The association maps
115 */
Patrick Williams9052ebd2024-08-16 15:22:16 -0400116void addPendingAssociation(
117 const std::string& objectPath, const std::string& type,
118 const std::string& endpointPath, const std::string& endpointType,
119 const std::string& owner, AssociationMaps& assocMaps);
Matt Spinlercb9bcdb2019-04-08 10:58:49 -0500120
121/** @brief Removes an endpoint from the pending associations map
122 *
123 * If the last endpoint is removed, removes the whole entry
124 *
125 * @param[in] endpointPath - the endpoint path to remove
126 * @param[in,out] assocMaps - The association maps
127 */
128void removeFromPendingAssociations(const std::string& endpointPath,
129 AssociationMaps& assocMaps);
Matt Spinler11401e22019-04-08 13:13:25 -0500130
131/** @brief Adds a single association D-Bus object (<path>/<type>)
132 *
Kallas, Pawel5b4357d2022-10-12 15:36:37 +0200133 * @param[in] io - io context
Matt Spinler11401e22019-04-08 13:13:25 -0500134 * @param[in,out] server - sdbus system object
135 * @param[in] assocPath - The association D-Bus path
136 * @param[in] endpoint - The association's D-Bus endpoint path
137 * @param[in] owner - The owning D-Bus well known name
138 * @param[in] ownerPath - The D-Bus path hosting the Associations property
139 * @param[in,out] assocMaps - The association maps
140 */
Patrick Williams9052ebd2024-08-16 15:22:16 -0400141void addSingleAssociation(
142 boost::asio::io_context& io, sdbusplus::asio::object_server& server,
143 const std::string& assocPath, const std::string& endpoint,
144 const std::string& owner, const std::string& ownerPath,
145 AssociationMaps& assocMaps);
Matt Spinler11401e22019-04-08 13:13:25 -0500146
147/** @brief Create a real association out of a pending association
148 * if there is one for this path.
149 *
150 * If objectPath is now on D-Bus, and it is also in the pending associations
151 * map, create the 2 real association objects and remove its pending
152 * associations entry. Used when a new path shows up in D-Bus.
153 *
Kallas, Pawel5b4357d2022-10-12 15:36:37 +0200154 * @param[in] io - io context
Matt Spinler11401e22019-04-08 13:13:25 -0500155 * @param[in] objectPath - the path to check
156 * @param[in] interfaceMap - The master interface map
157 * @param[in,out] assocMaps - The association maps
158 * @param[in,out] server - sdbus system object
159 */
Patrick Williams9052ebd2024-08-16 15:22:16 -0400160void checkIfPendingAssociation(
161 boost::asio::io_context& io, const std::string& objectPath,
162 const InterfaceMapType& interfaceMap, AssociationMaps& assocMaps,
163 sdbusplus::asio::object_server& server);
Matt Spinler7f8fd1f2019-04-08 15:21:59 -0500164
165/** @brief Find all associations in the association owners map with the
166 * specified endpoint path.
167 *
168 * @param[in] endpointPath - the endpoint path to look for
169 * @param[in] assocMaps - The association maps
170 * @param[out] associationData - A vector of {owner, Association} tuples
171 * of all the associations with that endpoint.
172 */
173void findAssociations(const std::string& endpointPath,
174 AssociationMaps& assocMaps,
175 FindAssocResults& associationData);
Matt Spinler9c3d2852019-04-08 15:57:19 -0500176
177/** @brief If endpointPath is in an association, move that association
178 * to pending and remove the association objects.
179 *
180 * Called when a path is going off of D-Bus. If this path is an
181 * association endpoint (the path that owns the association is still
182 * on D-Bus), then move the association it's involved in to pending.
183 *
Kallas, Pawel5b4357d2022-10-12 15:36:37 +0200184 * @param[in] io - io context
Matt Spinler9c3d2852019-04-08 15:57:19 -0500185 * @param[in] endpointPath - the D-Bus endpoint path to check
186 * @param[in,out] assocMaps - The association maps
187 * @param[in,out] server - sdbus system object
188 */
Patrick Williams9052ebd2024-08-16 15:22:16 -0400189void moveAssociationToPending(
190 boost::asio::io_context& io, const std::string& endpointPath,
191 AssociationMaps& assocMaps, sdbusplus::asio::object_server& server);