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 
8*5b4357daSKallas, Pawel constexpr size_t endpointsCountTimerThreshold = 100;
9*5b4357daSKallas, Pawel constexpr int endpointUpdateDelaySeconds = 1;
10*5b4357daSKallas, Pawel 
11a80a3af0SAndrew Geissler /** @brief Remove input association
12a80a3af0SAndrew Geissler  *
13*5b4357daSKallas, 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  */
23*5b4357daSKallas, Pawel void removeAssociation(boost::asio::io_context& io,
24*5b4357daSKallas, 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  *
33*5b4357daSKallas, 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(
43*5b4357daSKallas, Pawel     boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
44*5b4357daSKallas, 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  *
57*5b4357daSKallas, 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(
69*5b4357daSKallas, Pawel     boost::asio::io_context& io, const std::string& sourcePath,
70*5b4357daSKallas, 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  *
78*5b4357daSKallas, 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*5b4357daSKallas, Pawel void associationChanged(boost::asio::io_context& io,
91*5b4357daSKallas, Pawel                         sdbusplus::asio::object_server& objectServer,
924511b33fSAndrew Geissler                         const std::vector<Association>& associations,
934511b33fSAndrew Geissler                         const std::string& path, const std::string& owner,
94a098a37aSBrad Bishop                         const InterfaceMapType& interfaceMap,
95e0b0e3a2SMatt Spinler                         AssociationMaps& assocMaps);
96e0b0e3a2SMatt Spinler 
97e0b0e3a2SMatt Spinler /** @brief Add a pending associations entry
98e0b0e3a2SMatt Spinler  *
99e0b0e3a2SMatt Spinler  *  Used when a client wants to create an association between
100e0b0e3a2SMatt Spinler  *  2 D-Bus endpoint paths, but one of the paths doesn't exist.
101e0b0e3a2SMatt Spinler  *  When the path does show up in D-Bus, if there is a pending
102e0b0e3a2SMatt Spinler  *  association then the real association objects can be created.
103e0b0e3a2SMatt Spinler  *
104e0b0e3a2SMatt Spinler  * @param[in] objectPath    - The D-Bus object path that should be an
105e0b0e3a2SMatt Spinler  *                            association endpoint but doesn't exist
106e0b0e3a2SMatt Spinler  *                            on D-Bus.
107e0b0e3a2SMatt Spinler  * @param[in] type          - The association type.  Gets used in the final
108e0b0e3a2SMatt Spinler  *                            association path of <objectPath>/<type>.
109e0b0e3a2SMatt Spinler  * @param[in] endpointPath  - The D-Bus path on the other side
110e0b0e3a2SMatt Spinler  *                            of the association. This path exists.
111e0b0e3a2SMatt Spinler  * @param[in] endpointType  - The endpoint association type. Gets used
112e0b0e3a2SMatt Spinler  *                            in the final association path of
113e0b0e3a2SMatt Spinler  *                            <endpointPath>/<endpointType>.
114e0b0e3a2SMatt Spinler  * @param[in] owner         - The service name that owns the association.
115e0b0e3a2SMatt Spinler  * @param[in,out] assocMaps - The association maps
116e0b0e3a2SMatt Spinler  */
117e0b0e3a2SMatt Spinler void addPendingAssociation(const std::string& objectPath,
118e0b0e3a2SMatt Spinler                            const std::string& type,
119e0b0e3a2SMatt Spinler                            const std::string& endpointPath,
120e0b0e3a2SMatt Spinler                            const std::string& endpointType,
121e0b0e3a2SMatt Spinler                            const std::string& owner,
122e2359fb7SMatt Spinler                            AssociationMaps& assocMaps);
123cb9bcdb1SMatt Spinler 
124cb9bcdb1SMatt Spinler /** @brief Removes an endpoint from the pending associations map
125cb9bcdb1SMatt Spinler  *
126cb9bcdb1SMatt Spinler  * If the last endpoint is removed, removes the whole entry
127cb9bcdb1SMatt Spinler  *
128cb9bcdb1SMatt Spinler  * @param[in] endpointPath  - the endpoint path to remove
129cb9bcdb1SMatt Spinler  * @param[in,out] assocMaps - The association maps
130cb9bcdb1SMatt Spinler  */
131cb9bcdb1SMatt Spinler void removeFromPendingAssociations(const std::string& endpointPath,
132cb9bcdb1SMatt Spinler                                    AssociationMaps& assocMaps);
13311401e2eSMatt Spinler 
13411401e2eSMatt Spinler /** @brief Adds a single association D-Bus object (<path>/<type>)
13511401e2eSMatt Spinler  *
136*5b4357daSKallas, Pawel  * @param[in] io            - io context
13711401e2eSMatt Spinler  * @param[in,out] server    - sdbus system object
13811401e2eSMatt Spinler  * @param[in] assocPath     - The association D-Bus path
13911401e2eSMatt Spinler  * @param[in] endpoint      - The association's D-Bus endpoint path
14011401e2eSMatt Spinler  * @param[in] owner         - The owning D-Bus well known name
14111401e2eSMatt Spinler  * @param[in] ownerPath     - The D-Bus path hosting the Associations property
14211401e2eSMatt Spinler  * @param[in,out] assocMaps - The association maps
14311401e2eSMatt Spinler  */
144*5b4357daSKallas, Pawel void addSingleAssociation(boost::asio::io_context& io,
145*5b4357daSKallas, Pawel                           sdbusplus::asio::object_server& server,
14611401e2eSMatt Spinler                           const std::string& assocPath,
14711401e2eSMatt Spinler                           const std::string& endpoint, const std::string& owner,
14811401e2eSMatt Spinler                           const std::string& ownerPath,
14911401e2eSMatt Spinler                           AssociationMaps& assocMaps);
15011401e2eSMatt Spinler 
15111401e2eSMatt Spinler /** @brief Create a real association out of a pending association
15211401e2eSMatt Spinler  *         if there is one for this path.
15311401e2eSMatt Spinler  *
15411401e2eSMatt Spinler  * If objectPath is now on D-Bus, and it is also in the pending associations
15511401e2eSMatt Spinler  * map, create the 2 real association objects and remove its pending
15611401e2eSMatt Spinler  * associations entry.  Used when a new path shows up in D-Bus.
15711401e2eSMatt Spinler  *
158*5b4357daSKallas, Pawel  * @param[in] io            - io context
15911401e2eSMatt Spinler  * @param[in] objectPath    - the path to check
16011401e2eSMatt Spinler  * @param[in] interfaceMap  - The master interface map
16111401e2eSMatt Spinler  * @param[in,out] assocMaps - The association maps
16211401e2eSMatt Spinler  * @param[in,out] server    - sdbus system object
16311401e2eSMatt Spinler  */
164*5b4357daSKallas, Pawel void checkIfPendingAssociation(boost::asio::io_context& io,
165*5b4357daSKallas, Pawel                                const std::string& objectPath,
166a098a37aSBrad Bishop                                const InterfaceMapType& interfaceMap,
16711401e2eSMatt Spinler                                AssociationMaps& assocMaps,
16811401e2eSMatt Spinler                                sdbusplus::asio::object_server& server);
1697f8fd1faSMatt Spinler 
1707f8fd1faSMatt Spinler /** @brief Find all associations in the association owners map with the
1717f8fd1faSMatt Spinler  *         specified endpoint path.
1727f8fd1faSMatt Spinler  *
1737f8fd1faSMatt Spinler  * @param[in] endpointPath     - the endpoint path to look for
1747f8fd1faSMatt Spinler  * @param[in] assocMaps        - The association maps
1757f8fd1faSMatt Spinler  * @param[out] associationData - A vector of {owner, Association} tuples
1767f8fd1faSMatt Spinler  *                               of all the associations with that endpoint.
1777f8fd1faSMatt Spinler  */
1787f8fd1faSMatt Spinler void findAssociations(const std::string& endpointPath,
1797f8fd1faSMatt Spinler                       AssociationMaps& assocMaps,
1807f8fd1faSMatt Spinler                       FindAssocResults& associationData);
1819c3d2859SMatt Spinler 
1829c3d2859SMatt Spinler /** @brief If endpointPath is in an association, move that association
1839c3d2859SMatt Spinler  *         to pending and remove the association objects.
1849c3d2859SMatt Spinler  *
1859c3d2859SMatt Spinler  *  Called when a path is going off of D-Bus.  If this path is an
1869c3d2859SMatt Spinler  *  association endpoint (the path that owns the association is still
1879c3d2859SMatt Spinler  *  on D-Bus), then move the association it's involved in to pending.
1889c3d2859SMatt Spinler  *
189*5b4357daSKallas, Pawel  * @param[in] io            - io context
1909c3d2859SMatt Spinler  * @param[in] endpointPath  - the D-Bus endpoint path to check
1919c3d2859SMatt Spinler  * @param[in,out] assocMaps - The association maps
1929c3d2859SMatt Spinler  * @param[in,out] server    - sdbus system object
1939c3d2859SMatt Spinler  */
194*5b4357daSKallas, Pawel void moveAssociationToPending(boost::asio::io_context& io,
195*5b4357daSKallas, Pawel                               const std::string& endpointPath,
1969c3d2859SMatt Spinler                               AssociationMaps& assocMaps,
1979c3d2859SMatt Spinler                               sdbusplus::asio::object_server& server);
198