1a80a3af0SAndrew Geissler #pragma once 2a80a3af0SAndrew Geissler 335396c10SMatt Spinler #include "types.hpp" 4a80a3af0SAndrew Geissler 5a098a37aSBrad Bishop constexpr const char* xyzAssociationInterface = 64511b33fSAndrew Geissler "xyz.openbmc_project.Association"; 74511b33fSAndrew Geissler 85b4357daSKallas, Pawel constexpr size_t endpointsCountTimerThreshold = 100; 95b4357daSKallas, Pawel constexpr int endpointUpdateDelaySeconds = 1; 105b4357daSKallas, Pawel 11a80a3af0SAndrew Geissler /** @brief Remove input association 12a80a3af0SAndrew Geissler * 135b4357daSKallas, Pawel * @param[in] io - io context 14a80a3af0SAndrew Geissler * @param[in] sourcePath - Path of the object that contains the 15a80a3af0SAndrew Geissler * org.openbmc.Associations 16a80a3af0SAndrew Geissler * @param[in] owner - The Dbus service having its associations 17a80a3af0SAndrew Geissler * removed 18a80a3af0SAndrew Geissler * @param[in,out] server - sdbus system object 19e2359fb7SMatt Spinler * @param[in,out] assocMaps - The association maps 20a80a3af0SAndrew Geissler * 21e2359fb7SMatt Spinler * @return Void, server, assocMaps updated if needed 22a80a3af0SAndrew Geissler */ 235b4357daSKallas, Pawel void removeAssociation(boost::asio::io_context& io, 245b4357daSKallas, Pawel const std::string& sourcePath, const std::string& owner, 25a80a3af0SAndrew Geissler sdbusplus::asio::object_server& server, 26e2359fb7SMatt Spinler AssociationMaps& assocMaps); 27ff5ce924SAndrew Geissler 28ff5ce924SAndrew Geissler /** @brief Remove input paths from endpoints of an association 29ff5ce924SAndrew Geissler * 30ff5ce924SAndrew Geissler * If the last endpoint was removed, then remove the whole 31ff5ce924SAndrew Geissler * association object, otherwise just set the property 32ff5ce924SAndrew Geissler * 335b4357daSKallas, Pawel * @param[in] io - io context 34ff5ce924SAndrew Geissler * @param[in] objectServer - sdbus system object 35ff5ce924SAndrew Geissler * @param[in] assocPath - Path of the object that contains the 36ff5ce924SAndrew Geissler * org.openbmc.Associations 37ff5ce924SAndrew Geissler * @param[in] endpointsToRemove - Endpoints to remove 38e2359fb7SMatt Spinler * @param[in,out] assocMaps - The association maps 39ff5ce924SAndrew Geissler * 40e2359fb7SMatt Spinler * @return Void, objectServer and assocMaps updated if needed 41ff5ce924SAndrew Geissler */ 42ff5ce924SAndrew Geissler void removeAssociationEndpoints( 435b4357daSKallas, Pawel boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer, 445b4357daSKallas, Pawel const std::string& assocPath, 45ff5ce924SAndrew Geissler const boost::container::flat_set<std::string>& endpointsToRemove, 46e2359fb7SMatt Spinler AssociationMaps& assocMaps); 477f1c44dcSAndrew Geissler 487f1c44dcSAndrew Geissler /** @brief Check and remove any changed associations 497f1c44dcSAndrew Geissler * 507f1c44dcSAndrew Geissler * Based on the latest values of the org.openbmc.Associations.associations 517f1c44dcSAndrew Geissler * property, passed in via the newAssociations param, check if any of the 527f1c44dcSAndrew Geissler * paths in the xyz.openbmc_project.Association.endpoints D-Bus property 537f1c44dcSAndrew Geissler * for that association need to be removed. If the last path is removed 547f1c44dcSAndrew Geissler * from the endpoints property, remove that whole association object from 557f1c44dcSAndrew Geissler * D-Bus. 567f1c44dcSAndrew Geissler * 575b4357daSKallas, Pawel * @param[in] io - io context 587f1c44dcSAndrew Geissler * @param[in] sourcePath - Path of the object that contains the 597f1c44dcSAndrew Geissler * org.openbmc.Associations 607f1c44dcSAndrew Geissler * @param[in] owner - The Dbus service having it's associatons 617f1c44dcSAndrew Geissler * changed 627f1c44dcSAndrew Geissler * @param[in] newAssociations - New associations to look at for change 637f1c44dcSAndrew Geissler * @param[in,out] objectServer - sdbus system object 64e2359fb7SMatt Spinler * @param[in,out] assocMaps - The association maps 657f1c44dcSAndrew Geissler * 66e2359fb7SMatt Spinler * @return Void, objectServer and assocMaps updated if needed 677f1c44dcSAndrew Geissler */ 687f1c44dcSAndrew Geissler void checkAssociationEndpointRemoves( 695b4357daSKallas, Pawel boost::asio::io_context& io, const std::string& sourcePath, 705b4357daSKallas, Pawel const std::string& owner, const AssociationPaths& newAssociations, 71e2359fb7SMatt Spinler sdbusplus::asio::object_server& objectServer, AssociationMaps& assocMaps); 724511b33fSAndrew Geissler 734511b33fSAndrew Geissler /** @brief Handle new or changed association interfaces 744511b33fSAndrew Geissler * 754511b33fSAndrew Geissler * Called when either a new org.openbmc.Associations interface was 764511b33fSAndrew Geissler * created, or the associations property on that interface changed 774511b33fSAndrew Geissler * 785b4357daSKallas, Pawel * @param[in] io - io context 794511b33fSAndrew Geissler * @param[in,out] objectServer - sdbus system object 804511b33fSAndrew Geissler * @param[in] associations - New associations to look at for change 814511b33fSAndrew Geissler * @param[in] path - Path of the object that contains the 824511b33fSAndrew Geissler * org.openbmc.Associations 834511b33fSAndrew Geissler * @param[in] owner - The Dbus service having it's associatons 844511b33fSAndrew Geissler * changed 85e0b0e3a2SMatt Spinler * @param[in] interfaceMap - The full interface map 86e2359fb7SMatt Spinler * @param[in,out] assocMaps - The association maps 874511b33fSAndrew Geissler * 88e2359fb7SMatt Spinler * @return Void, objectServer and assocMaps updated if needed 894511b33fSAndrew Geissler */ 90*9052ebd3SPatrick Williams void associationChanged( 91*9052ebd3SPatrick Williams boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer, 92*9052ebd3SPatrick Williams const std::vector<Association>& associations, const std::string& path, 93*9052ebd3SPatrick Williams const std::string& owner, const InterfaceMapType& interfaceMap, 94e0b0e3a2SMatt Spinler AssociationMaps& assocMaps); 95e0b0e3a2SMatt Spinler 96e0b0e3a2SMatt Spinler /** @brief Add a pending associations entry 97e0b0e3a2SMatt Spinler * 98e0b0e3a2SMatt Spinler * Used when a client wants to create an association between 99e0b0e3a2SMatt Spinler * 2 D-Bus endpoint paths, but one of the paths doesn't exist. 100e0b0e3a2SMatt Spinler * When the path does show up in D-Bus, if there is a pending 101e0b0e3a2SMatt Spinler * association then the real association objects can be created. 102e0b0e3a2SMatt Spinler * 103e0b0e3a2SMatt Spinler * @param[in] objectPath - The D-Bus object path that should be an 104e0b0e3a2SMatt Spinler * association endpoint but doesn't exist 105e0b0e3a2SMatt Spinler * on D-Bus. 106e0b0e3a2SMatt Spinler * @param[in] type - The association type. Gets used in the final 107e0b0e3a2SMatt Spinler * association path of <objectPath>/<type>. 108e0b0e3a2SMatt Spinler * @param[in] endpointPath - The D-Bus path on the other side 109e0b0e3a2SMatt Spinler * of the association. This path exists. 110e0b0e3a2SMatt Spinler * @param[in] endpointType - The endpoint association type. Gets used 111e0b0e3a2SMatt Spinler * in the final association path of 112e0b0e3a2SMatt Spinler * <endpointPath>/<endpointType>. 113e0b0e3a2SMatt Spinler * @param[in] owner - The service name that owns the association. 114e0b0e3a2SMatt Spinler * @param[in,out] assocMaps - The association maps 115e0b0e3a2SMatt Spinler */ 116*9052ebd3SPatrick Williams void addPendingAssociation( 117*9052ebd3SPatrick Williams const std::string& objectPath, const std::string& type, 118*9052ebd3SPatrick Williams const std::string& endpointPath, const std::string& endpointType, 119*9052ebd3SPatrick Williams const std::string& owner, AssociationMaps& assocMaps); 120cb9bcdb1SMatt Spinler 121cb9bcdb1SMatt Spinler /** @brief Removes an endpoint from the pending associations map 122cb9bcdb1SMatt Spinler * 123cb9bcdb1SMatt Spinler * If the last endpoint is removed, removes the whole entry 124cb9bcdb1SMatt Spinler * 125cb9bcdb1SMatt Spinler * @param[in] endpointPath - the endpoint path to remove 126cb9bcdb1SMatt Spinler * @param[in,out] assocMaps - The association maps 127cb9bcdb1SMatt Spinler */ 128cb9bcdb1SMatt Spinler void removeFromPendingAssociations(const std::string& endpointPath, 129cb9bcdb1SMatt Spinler AssociationMaps& assocMaps); 13011401e2eSMatt Spinler 13111401e2eSMatt Spinler /** @brief Adds a single association D-Bus object (<path>/<type>) 13211401e2eSMatt Spinler * 1335b4357daSKallas, Pawel * @param[in] io - io context 13411401e2eSMatt Spinler * @param[in,out] server - sdbus system object 13511401e2eSMatt Spinler * @param[in] assocPath - The association D-Bus path 13611401e2eSMatt Spinler * @param[in] endpoint - The association's D-Bus endpoint path 13711401e2eSMatt Spinler * @param[in] owner - The owning D-Bus well known name 13811401e2eSMatt Spinler * @param[in] ownerPath - The D-Bus path hosting the Associations property 13911401e2eSMatt Spinler * @param[in,out] assocMaps - The association maps 14011401e2eSMatt Spinler */ 141*9052ebd3SPatrick Williams void addSingleAssociation( 142*9052ebd3SPatrick Williams boost::asio::io_context& io, sdbusplus::asio::object_server& server, 143*9052ebd3SPatrick Williams const std::string& assocPath, const std::string& endpoint, 144*9052ebd3SPatrick Williams const std::string& owner, const std::string& ownerPath, 14511401e2eSMatt Spinler AssociationMaps& assocMaps); 14611401e2eSMatt Spinler 14711401e2eSMatt Spinler /** @brief Create a real association out of a pending association 14811401e2eSMatt Spinler * if there is one for this path. 14911401e2eSMatt Spinler * 15011401e2eSMatt Spinler * If objectPath is now on D-Bus, and it is also in the pending associations 15111401e2eSMatt Spinler * map, create the 2 real association objects and remove its pending 15211401e2eSMatt Spinler * associations entry. Used when a new path shows up in D-Bus. 15311401e2eSMatt Spinler * 1545b4357daSKallas, Pawel * @param[in] io - io context 15511401e2eSMatt Spinler * @param[in] objectPath - the path to check 15611401e2eSMatt Spinler * @param[in] interfaceMap - The master interface map 15711401e2eSMatt Spinler * @param[in,out] assocMaps - The association maps 15811401e2eSMatt Spinler * @param[in,out] server - sdbus system object 15911401e2eSMatt Spinler */ 160*9052ebd3SPatrick Williams void checkIfPendingAssociation( 161*9052ebd3SPatrick Williams boost::asio::io_context& io, const std::string& objectPath, 162*9052ebd3SPatrick Williams const InterfaceMapType& interfaceMap, AssociationMaps& assocMaps, 16311401e2eSMatt Spinler sdbusplus::asio::object_server& server); 1647f8fd1faSMatt Spinler 1657f8fd1faSMatt Spinler /** @brief Find all associations in the association owners map with the 1667f8fd1faSMatt Spinler * specified endpoint path. 1677f8fd1faSMatt Spinler * 1687f8fd1faSMatt Spinler * @param[in] endpointPath - the endpoint path to look for 1697f8fd1faSMatt Spinler * @param[in] assocMaps - The association maps 1707f8fd1faSMatt Spinler * @param[out] associationData - A vector of {owner, Association} tuples 1717f8fd1faSMatt Spinler * of all the associations with that endpoint. 1727f8fd1faSMatt Spinler */ 1737f8fd1faSMatt Spinler void findAssociations(const std::string& endpointPath, 1747f8fd1faSMatt Spinler AssociationMaps& assocMaps, 1757f8fd1faSMatt Spinler FindAssocResults& associationData); 1769c3d2859SMatt Spinler 1779c3d2859SMatt Spinler /** @brief If endpointPath is in an association, move that association 1789c3d2859SMatt Spinler * to pending and remove the association objects. 1799c3d2859SMatt Spinler * 1809c3d2859SMatt Spinler * Called when a path is going off of D-Bus. If this path is an 1819c3d2859SMatt Spinler * association endpoint (the path that owns the association is still 1829c3d2859SMatt Spinler * on D-Bus), then move the association it's involved in to pending. 1839c3d2859SMatt Spinler * 1845b4357daSKallas, Pawel * @param[in] io - io context 1859c3d2859SMatt Spinler * @param[in] endpointPath - the D-Bus endpoint path to check 1869c3d2859SMatt Spinler * @param[in,out] assocMaps - The association maps 1879c3d2859SMatt Spinler * @param[in,out] server - sdbus system object 1889c3d2859SMatt Spinler */ 189*9052ebd3SPatrick Williams void moveAssociationToPending( 190*9052ebd3SPatrick Williams boost::asio::io_context& io, const std::string& endpointPath, 191*9052ebd3SPatrick Williams AssociationMaps& assocMaps, sdbusplus::asio::object_server& server); 192