1 #pragma once 2 3 #include "types.hpp" 4 5 constexpr const char* xyzAssociationInterface = 6 "xyz.openbmc_project.Association"; 7 8 constexpr size_t endpointsCountTimerThreshold = 100; 9 constexpr int endpointUpdateDelaySeconds = 1; 10 11 /** @brief Remove input association 12 * 13 * @param[in] io - io context 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 19 * @param[in,out] assocMaps - The association maps 20 * 21 * @return Void, server, assocMaps updated if needed 22 */ 23 void removeAssociation(boost::asio::io_context& io, 24 const std::string& sourcePath, const std::string& owner, 25 sdbusplus::asio::object_server& server, 26 AssociationMaps& assocMaps); 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 * 33 * @param[in] io - io context 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 38 * @param[in,out] assocMaps - The association maps 39 * 40 * @return Void, objectServer and assocMaps updated if needed 41 */ 42 void removeAssociationEndpoints( 43 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer, 44 const std::string& assocPath, 45 const boost::container::flat_set<std::string>& endpointsToRemove, 46 AssociationMaps& assocMaps); 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 * 57 * @param[in] io - io context 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 64 * @param[in,out] assocMaps - The association maps 65 * 66 * @return Void, objectServer and assocMaps updated if needed 67 */ 68 void checkAssociationEndpointRemoves( 69 boost::asio::io_context& io, const std::string& sourcePath, 70 const std::string& owner, const AssociationPaths& newAssociations, 71 sdbusplus::asio::object_server& objectServer, AssociationMaps& assocMaps); 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 * 78 * @param[in] io - io context 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 85 * @param[in] interfaceMap - The full interface map 86 * @param[in,out] assocMaps - The association maps 87 * 88 * @return Void, objectServer and assocMaps updated if needed 89 */ 90 void associationChanged(boost::asio::io_context& io, 91 sdbusplus::asio::object_server& objectServer, 92 const std::vector<Association>& associations, 93 const std::string& path, const std::string& owner, 94 const InterfaceMapType& interfaceMap, 95 AssociationMaps& assocMaps); 96 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 */ 117 void 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); 123 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 */ 131 void removeFromPendingAssociations(const std::string& endpointPath, 132 AssociationMaps& assocMaps); 133 134 /** @brief Adds a single association D-Bus object (<path>/<type>) 135 * 136 * @param[in] io - io context 137 * @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 */ 144 void addSingleAssociation(boost::asio::io_context& io, 145 sdbusplus::asio::object_server& server, 146 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 * 158 * @param[in] io - io context 159 * @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 */ 164 void checkIfPendingAssociation(boost::asio::io_context& io, 165 const std::string& objectPath, 166 const InterfaceMapType& interfaceMap, 167 AssociationMaps& assocMaps, 168 sdbusplus::asio::object_server& server); 169 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 */ 178 void findAssociations(const std::string& endpointPath, 179 AssociationMaps& assocMaps, 180 FindAssocResults& associationData); 181 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 * 189 * @param[in] io - io context 190 * @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 */ 194 void moveAssociationToPending(boost::asio::io_context& io, 195 const std::string& endpointPath, 196 AssociationMaps& assocMaps, 197 sdbusplus::asio::object_server& server); 198