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 | |
Andrew Geissler | 4511b33 | 2019-02-21 15:40:40 -0600 | [diff] [blame] | 5 | constexpr const char* XYZ_ASSOCIATION_INTERFACE = |
| 6 | "xyz.openbmc_project.Association"; |
| 7 | |
Andrew Geissler | a80a3af | 2019-02-04 14:01:49 -0600 | [diff] [blame] | 8 | /** @brief Remove input association |
| 9 | * |
| 10 | * @param[in] sourcePath - Path of the object that contains the |
| 11 | * org.openbmc.Associations |
| 12 | * @param[in] owner - The Dbus service having its associations |
| 13 | * removed |
| 14 | * @param[in,out] server - sdbus system object |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 15 | * @param[in,out] assocMaps - The association maps |
Andrew Geissler | a80a3af | 2019-02-04 14:01:49 -0600 | [diff] [blame] | 16 | * |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 17 | * @return Void, server, assocMaps updated if needed |
Andrew Geissler | a80a3af | 2019-02-04 14:01:49 -0600 | [diff] [blame] | 18 | */ |
| 19 | void removeAssociation(const std::string& sourcePath, const std::string& owner, |
| 20 | sdbusplus::asio::object_server& server, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 21 | AssociationMaps& assocMaps); |
Andrew Geissler | ff5ce92 | 2019-02-21 12:43:09 -0600 | [diff] [blame] | 22 | |
| 23 | /** @brief Remove input paths from endpoints of an association |
| 24 | * |
| 25 | * If the last endpoint was removed, then remove the whole |
| 26 | * association object, otherwise just set the property |
| 27 | * |
| 28 | * @param[in] objectServer - sdbus system object |
| 29 | * @param[in] assocPath - Path of the object that contains the |
| 30 | * org.openbmc.Associations |
| 31 | * @param[in] endpointsToRemove - Endpoints to remove |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 32 | * @param[in,out] assocMaps - The association maps |
Andrew Geissler | ff5ce92 | 2019-02-21 12:43:09 -0600 | [diff] [blame] | 33 | * |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 34 | * @return Void, objectServer and assocMaps updated if needed |
Andrew Geissler | ff5ce92 | 2019-02-21 12:43:09 -0600 | [diff] [blame] | 35 | */ |
| 36 | void removeAssociationEndpoints( |
| 37 | sdbusplus::asio::object_server& objectServer, const std::string& assocPath, |
| 38 | const boost::container::flat_set<std::string>& endpointsToRemove, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 39 | AssociationMaps& assocMaps); |
Andrew Geissler | 7f1c44d | 2019-02-21 13:44:16 -0600 | [diff] [blame] | 40 | |
| 41 | /** @brief Check and remove any changed associations |
| 42 | * |
| 43 | * Based on the latest values of the org.openbmc.Associations.associations |
| 44 | * property, passed in via the newAssociations param, check if any of the |
| 45 | * paths in the xyz.openbmc_project.Association.endpoints D-Bus property |
| 46 | * for that association need to be removed. If the last path is removed |
| 47 | * from the endpoints property, remove that whole association object from |
| 48 | * D-Bus. |
| 49 | * |
| 50 | * @param[in] sourcePath - Path of the object that contains the |
| 51 | * org.openbmc.Associations |
| 52 | * @param[in] owner - The Dbus service having it's associatons |
| 53 | * changed |
| 54 | * @param[in] newAssociations - New associations to look at for change |
| 55 | * @param[in,out] objectServer - sdbus system object |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 56 | * @param[in,out] assocMaps - The association maps |
Andrew Geissler | 7f1c44d | 2019-02-21 13:44:16 -0600 | [diff] [blame] | 57 | * |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 58 | * @return Void, objectServer and assocMaps updated if needed |
Andrew Geissler | 7f1c44d | 2019-02-21 13:44:16 -0600 | [diff] [blame] | 59 | */ |
| 60 | void checkAssociationEndpointRemoves( |
| 61 | const std::string& sourcePath, const std::string& owner, |
| 62 | const AssociationPaths& newAssociations, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 63 | sdbusplus::asio::object_server& objectServer, AssociationMaps& assocMaps); |
Andrew Geissler | 4511b33 | 2019-02-21 15:40:40 -0600 | [diff] [blame] | 64 | |
| 65 | /** @brief Handle new or changed association interfaces |
| 66 | * |
| 67 | * Called when either a new org.openbmc.Associations interface was |
| 68 | * created, or the associations property on that interface changed |
| 69 | * |
| 70 | * @param[in,out] objectServer - sdbus system object |
| 71 | * @param[in] associations - New associations to look at for change |
| 72 | * @param[in] path - Path of the object that contains the |
| 73 | * org.openbmc.Associations |
| 74 | * @param[in] owner - The Dbus service having it's associatons |
| 75 | * changed |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 76 | * @param[in] interfaceMap - The full interface map |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 77 | * @param[in,out] assocMaps - The association maps |
Andrew Geissler | 4511b33 | 2019-02-21 15:40:40 -0600 | [diff] [blame] | 78 | * |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 79 | * @return Void, objectServer and assocMaps updated if needed |
Andrew Geissler | 4511b33 | 2019-02-21 15:40:40 -0600 | [diff] [blame] | 80 | */ |
| 81 | void associationChanged(sdbusplus::asio::object_server& objectServer, |
| 82 | const std::vector<Association>& associations, |
| 83 | const std::string& path, const std::string& owner, |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 84 | const interface_map_type& interfaceMap, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 85 | AssociationMaps& assocMaps); |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 86 | |
| 87 | /** @brief Add a pending associations entry |
| 88 | * |
| 89 | * Used when a client wants to create an association between |
| 90 | * 2 D-Bus endpoint paths, but one of the paths doesn't exist. |
| 91 | * When the path does show up in D-Bus, if there is a pending |
| 92 | * association then the real association objects can be created. |
| 93 | * |
| 94 | * @param[in] objectPath - The D-Bus object path that should be an |
| 95 | * association endpoint but doesn't exist |
| 96 | * on D-Bus. |
| 97 | * @param[in] type - The association type. Gets used in the final |
| 98 | * association path of <objectPath>/<type>. |
| 99 | * @param[in] endpointPath - The D-Bus path on the other side |
| 100 | * of the association. This path exists. |
| 101 | * @param[in] endpointType - The endpoint association type. Gets used |
| 102 | * in the final association path of |
| 103 | * <endpointPath>/<endpointType>. |
| 104 | * @param[in] owner - The service name that owns the association. |
| 105 | * @param[in,out] assocMaps - The association maps |
| 106 | */ |
| 107 | void addPendingAssociation(const std::string& objectPath, |
| 108 | const std::string& type, |
| 109 | const std::string& endpointPath, |
| 110 | const std::string& endpointType, |
| 111 | const std::string& owner, |
| 112 | AssociationMaps& assocMaps); |
Matt Spinler | cb9bcdb | 2019-04-08 10:58:49 -0500 | [diff] [blame] | 113 | |
| 114 | /** @brief Removes an endpoint from the pending associations map |
| 115 | * |
| 116 | * If the last endpoint is removed, removes the whole entry |
| 117 | * |
| 118 | * @param[in] endpointPath - the endpoint path to remove |
| 119 | * @param[in,out] assocMaps - The association maps |
| 120 | */ |
| 121 | void removeFromPendingAssociations(const std::string& endpointPath, |
| 122 | AssociationMaps& assocMaps); |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 123 | |
| 124 | /** @brief Adds a single association D-Bus object (<path>/<type>) |
| 125 | * |
| 126 | * @param[in,out] server - sdbus system object |
| 127 | * @param[in] assocPath - The association D-Bus path |
| 128 | * @param[in] endpoint - The association's D-Bus endpoint path |
| 129 | * @param[in] owner - The owning D-Bus well known name |
| 130 | * @param[in] ownerPath - The D-Bus path hosting the Associations property |
| 131 | * @param[in,out] assocMaps - The association maps |
| 132 | */ |
| 133 | void addSingleAssociation(sdbusplus::asio::object_server& server, |
| 134 | const std::string& assocPath, |
| 135 | const std::string& endpoint, const std::string& owner, |
| 136 | const std::string& ownerPath, |
| 137 | AssociationMaps& assocMaps); |
| 138 | |
| 139 | /** @brief Create a real association out of a pending association |
| 140 | * if there is one for this path. |
| 141 | * |
| 142 | * If objectPath is now on D-Bus, and it is also in the pending associations |
| 143 | * map, create the 2 real association objects and remove its pending |
| 144 | * associations entry. Used when a new path shows up in D-Bus. |
| 145 | * |
| 146 | * @param[in] objectPath - the path to check |
| 147 | * @param[in] interfaceMap - The master interface map |
| 148 | * @param[in,out] assocMaps - The association maps |
| 149 | * @param[in,out] server - sdbus system object |
| 150 | */ |
| 151 | void checkIfPendingAssociation(const std::string& objectPath, |
| 152 | const interface_map_type& interfaceMap, |
| 153 | AssociationMaps& assocMaps, |
| 154 | sdbusplus::asio::object_server& server); |
Matt Spinler | 7f8fd1f | 2019-04-08 15:21:59 -0500 | [diff] [blame^] | 155 | |
| 156 | /** @brief Find all associations in the association owners map with the |
| 157 | * specified endpoint path. |
| 158 | * |
| 159 | * @param[in] endpointPath - the endpoint path to look for |
| 160 | * @param[in] assocMaps - The association maps |
| 161 | * @param[out] associationData - A vector of {owner, Association} tuples |
| 162 | * of all the associations with that endpoint. |
| 163 | */ |
| 164 | void findAssociations(const std::string& endpointPath, |
| 165 | AssociationMaps& assocMaps, |
| 166 | FindAssocResults& associationData); |