Andrew Geissler | a80a3af | 2019-02-04 14:01:49 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matt Spinler | 35396c1 | 2019-04-05 11:46:57 -0500 | [diff] [blame] | 3 | #include "types.hpp" |
Andrew Geissler | a80a3af | 2019-02-04 14:01:49 -0600 | [diff] [blame] | 4 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 5 | constexpr const char* xyzAssociationInterface = |
Andrew Geissler | 4511b33 | 2019-02-21 15:40:40 -0600 | [diff] [blame] | 6 | "xyz.openbmc_project.Association"; |
| 7 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 8 | constexpr size_t endpointsCountTimerThreshold = 100; |
| 9 | constexpr int endpointUpdateDelaySeconds = 1; |
| 10 | |
Andrew Geissler | a80a3af | 2019-02-04 14:01:49 -0600 | [diff] [blame] | 11 | /** @brief Remove input association |
| 12 | * |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 13 | * @param[in] io - io context |
Andrew Geissler | a80a3af | 2019-02-04 14:01:49 -0600 | [diff] [blame] | 14 | * @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 Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 19 | * @param[in,out] assocMaps - The association maps |
Andrew Geissler | a80a3af | 2019-02-04 14:01:49 -0600 | [diff] [blame] | 20 | * |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 21 | * @return Void, server, assocMaps updated if needed |
Andrew Geissler | a80a3af | 2019-02-04 14:01:49 -0600 | [diff] [blame] | 22 | */ |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 23 | void removeAssociation(boost::asio::io_context& io, |
| 24 | const std::string& sourcePath, const std::string& owner, |
Andrew Geissler | a80a3af | 2019-02-04 14:01:49 -0600 | [diff] [blame] | 25 | sdbusplus::asio::object_server& server, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 26 | AssociationMaps& assocMaps); |
Andrew Geissler | ff5ce92 | 2019-02-21 12:43:09 -0600 | [diff] [blame] | 27 | |
| 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, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 33 | * @param[in] io - io context |
Andrew Geissler | ff5ce92 | 2019-02-21 12:43:09 -0600 | [diff] [blame] | 34 | * @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 Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 38 | * @param[in,out] assocMaps - The association maps |
Andrew Geissler | ff5ce92 | 2019-02-21 12:43:09 -0600 | [diff] [blame] | 39 | * |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 40 | * @return Void, objectServer and assocMaps updated if needed |
Andrew Geissler | ff5ce92 | 2019-02-21 12:43:09 -0600 | [diff] [blame] | 41 | */ |
| 42 | void removeAssociationEndpoints( |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 43 | boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer, |
| 44 | const std::string& assocPath, |
Andrew Geissler | ff5ce92 | 2019-02-21 12:43:09 -0600 | [diff] [blame] | 45 | const boost::container::flat_set<std::string>& endpointsToRemove, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 46 | AssociationMaps& assocMaps); |
Andrew Geissler | 7f1c44d | 2019-02-21 13:44:16 -0600 | [diff] [blame] | 47 | |
| 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, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 57 | * @param[in] io - io context |
Andrew Geissler | 7f1c44d | 2019-02-21 13:44:16 -0600 | [diff] [blame] | 58 | * @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 Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 64 | * @param[in,out] assocMaps - The association maps |
Andrew Geissler | 7f1c44d | 2019-02-21 13:44:16 -0600 | [diff] [blame] | 65 | * |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 66 | * @return Void, objectServer and assocMaps updated if needed |
Andrew Geissler | 7f1c44d | 2019-02-21 13:44:16 -0600 | [diff] [blame] | 67 | */ |
| 68 | void checkAssociationEndpointRemoves( |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 69 | boost::asio::io_context& io, const std::string& sourcePath, |
| 70 | const std::string& owner, const AssociationPaths& newAssociations, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 71 | sdbusplus::asio::object_server& objectServer, AssociationMaps& assocMaps); |
Andrew Geissler | 4511b33 | 2019-02-21 15:40:40 -0600 | [diff] [blame] | 72 | |
| 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, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 78 | * @param[in] io - io context |
Andrew Geissler | 4511b33 | 2019-02-21 15:40:40 -0600 | [diff] [blame] | 79 | * @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 Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 85 | * @param[in] interfaceMap - The full interface map |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 86 | * @param[in,out] assocMaps - The association maps |
Andrew Geissler | 4511b33 | 2019-02-21 15:40:40 -0600 | [diff] [blame] | 87 | * |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 88 | * @return Void, objectServer and assocMaps updated if needed |
Andrew Geissler | 4511b33 | 2019-02-21 15:40:40 -0600 | [diff] [blame] | 89 | */ |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame^] | 90 | void 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 Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 95 | |
| 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 Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame^] | 116 | void 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 Spinler | cb9bcdb | 2019-04-08 10:58:49 -0500 | [diff] [blame] | 120 | |
| 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 | */ |
| 128 | void removeFromPendingAssociations(const std::string& endpointPath, |
| 129 | AssociationMaps& assocMaps); |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 130 | |
| 131 | /** @brief Adds a single association D-Bus object (<path>/<type>) |
| 132 | * |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 133 | * @param[in] io - io context |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 134 | * @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 Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame^] | 141 | void 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 Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 146 | |
| 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, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 154 | * @param[in] io - io context |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 155 | * @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 Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame^] | 160 | void checkIfPendingAssociation( |
| 161 | boost::asio::io_context& io, const std::string& objectPath, |
| 162 | const InterfaceMapType& interfaceMap, AssociationMaps& assocMaps, |
| 163 | sdbusplus::asio::object_server& server); |
Matt Spinler | 7f8fd1f | 2019-04-08 15:21:59 -0500 | [diff] [blame] | 164 | |
| 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 | */ |
| 173 | void findAssociations(const std::string& endpointPath, |
| 174 | AssociationMaps& assocMaps, |
| 175 | FindAssocResults& associationData); |
Matt Spinler | 9c3d285 | 2019-04-08 15:57:19 -0500 | [diff] [blame] | 176 | |
| 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, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 184 | * @param[in] io - io context |
Matt Spinler | 9c3d285 | 2019-04-08 15:57:19 -0500 | [diff] [blame] | 185 | * @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 Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame^] | 189 | void moveAssociationToPending( |
| 190 | boost::asio::io_context& io, const std::string& endpointPath, |
| 191 | AssociationMaps& assocMaps, sdbusplus::asio::object_server& server); |