Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 1 | #include "src/associations.hpp" |
Andrew Geissler | 2067926 | 2019-02-11 20:20:40 -0600 | [diff] [blame] | 2 | #include "src/processing.hpp" |
Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 3 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 4 | const std::string defaultSourcePath = "/logging/entry/1"; |
| 5 | const std::string defaultDbusSvc = "xyz.openbmc_project.New.Interface"; |
| 6 | const std::string defaultFwdPath = {defaultSourcePath + "/" + "inventory"}; |
| 7 | const std::string defaultEndpoint = |
Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 8 | "/xyz/openbmc_project/inventory/system/chassis"; |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 9 | const std::string defaultRevPath = {defaultEndpoint + "/" + "error"}; |
| 10 | const std::string extraEndpoint = "/xyz/openbmc_project/differnt/endpoint"; |
Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 11 | |
| 12 | // Create a default AssociationOwnersType object |
| 13 | AssociationOwnersType createDefaultOwnerAssociation() |
| 14 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 15 | AssociationPaths assocPathMap = {{defaultFwdPath, {defaultEndpoint}}, |
| 16 | {defaultRevPath, {defaultSourcePath}}}; |
Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 17 | boost::container::flat_map<std::string, AssociationPaths> serviceMap = { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 18 | {defaultDbusSvc, assocPathMap}}; |
| 19 | AssociationOwnersType ownerAssoc = {{defaultSourcePath, serviceMap}}; |
Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 20 | return ownerAssoc; |
| 21 | } |
| 22 | |
| 23 | // Create a default AssociationInterfaces object |
| 24 | AssociationInterfaces |
| 25 | createDefaultInterfaceAssociation(sdbusplus::asio::object_server* server) |
| 26 | { |
| 27 | AssociationInterfaces interfaceAssoc; |
| 28 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 29 | auto& iface = interfaceAssoc[defaultFwdPath]; |
Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 30 | auto& endpoints = std::get<endpointsPos>(iface); |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 31 | endpoints.push_back(defaultEndpoint); |
| 32 | server->add_interface(defaultFwdPath, defaultDbusSvc); |
Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 33 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 34 | auto& iface2 = interfaceAssoc[defaultRevPath]; |
Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 35 | auto& endpoints2 = std::get<endpointsPos>(iface2); |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 36 | endpoints2.push_back(defaultSourcePath); |
| 37 | server->add_interface(defaultRevPath, defaultDbusSvc); |
Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 38 | |
| 39 | return interfaceAssoc; |
| 40 | } |
| 41 | |
| 42 | // Just add an extra endpoint to the first association |
| 43 | void addEndpointToInterfaceAssociation(AssociationInterfaces& interfaceAssoc) |
| 44 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 45 | auto iface = interfaceAssoc[defaultFwdPath]; |
Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 46 | auto endpoints = std::get<endpointsPos>(iface); |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 47 | endpoints.push_back(extraEndpoint); |
Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 48 | } |
Andrew Geissler | 2067926 | 2019-02-11 20:20:40 -0600 | [diff] [blame] | 49 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 50 | // Create a default interfaceMapType with input values |
Ed Tanous | 964681c | 2022-07-08 12:47:24 -0700 | [diff] [blame^] | 51 | InterfaceMapType createInterfaceMap(const std::string& path, |
| 52 | const std::string& connectionName, |
| 53 | const InterfaceNames& interfaceNames) |
Andrew Geissler | 2067926 | 2019-02-11 20:20:40 -0600 | [diff] [blame] | 54 | { |
Ed Tanous | 964681c | 2022-07-08 12:47:24 -0700 | [diff] [blame^] | 55 | ConnectionNames connectionMap{{connectionName, interfaceNames}}; |
| 56 | InterfaceMapType interfaceMap{{path, connectionMap}}; |
| 57 | |
Andrew Geissler | 2067926 | 2019-02-11 20:20:40 -0600 | [diff] [blame] | 58 | return interfaceMap; |
| 59 | } |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 60 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 61 | // Create a default interfaceMapType with 2 entries with the same |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 62 | // owner. |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 63 | InterfaceMapType createDefaultInterfaceMap() |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 64 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 65 | InterfaceMapType interfaceMap = { |
| 66 | {defaultSourcePath, {{defaultDbusSvc, {"a"}}}}, |
| 67 | {defaultEndpoint, {{defaultDbusSvc, {"b"}}}}}; |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 68 | |
| 69 | return interfaceMap; |
| 70 | } |