xref: /openbmc/phosphor-objmgr/src/test/util/association_objects.hpp (revision 7dd2029eb1755a5ad59ac33bf462837d7e906dbf)
1 #include "src/associations.hpp"
2 #include "src/processing.hpp"
3 
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 =
8     "/xyz/openbmc_project/inventory/system/chassis";
9 const std::string defaultRevPath = {defaultEndpoint + "/" + "error"};
10 const std::string extraEndpoint = "/xyz/openbmc_project/different/endpoint";
11 
12 // Create a default AssociationOwnersType object
createDefaultOwnerAssociation()13 inline AssociationOwnersType createDefaultOwnerAssociation()
14 {
15     AssociationPaths assocPathMap = {{defaultFwdPath, {defaultEndpoint}},
16                                      {defaultRevPath, {defaultSourcePath}}};
17     boost::container::flat_map<std::string, AssociationPaths> serviceMap = {
18         {defaultDbusSvc, assocPathMap}};
19     AssociationOwnersType ownerAssoc = {{defaultSourcePath, serviceMap}};
20     return ownerAssoc;
21 }
22 
23 // Create a default AssociationInterfaces object
createDefaultInterfaceAssociation(sdbusplus::asio::object_server * server)24 inline AssociationInterfaces createDefaultInterfaceAssociation(
25     sdbusplus::asio::object_server* server)
26 {
27     AssociationInterfaces interfaceAssoc;
28 
29     auto& iface = interfaceAssoc[defaultFwdPath];
30     auto& endpoints = std::get<endpointsPos>(iface);
31     endpoints.push_back(defaultEndpoint);
32     server->add_interface(defaultFwdPath, defaultDbusSvc);
33 
34     auto& iface2 = interfaceAssoc[defaultRevPath];
35     auto& endpoints2 = std::get<endpointsPos>(iface2);
36     endpoints2.push_back(defaultSourcePath);
37     server->add_interface(defaultRevPath, defaultDbusSvc);
38 
39     return interfaceAssoc;
40 }
41 
42 // Just add an extra endpoint to the first association
addEndpointToInterfaceAssociation(AssociationInterfaces & interfaceAssoc)43 inline void addEndpointToInterfaceAssociation(
44     AssociationInterfaces& interfaceAssoc)
45 {
46     auto iface = interfaceAssoc[defaultFwdPath];
47     auto endpoints = std::get<endpointsPos>(iface);
48     endpoints.push_back(extraEndpoint);
49 }
50 
51 // Create a default interfaceMapType with input values
createInterfaceMap(const std::string & path,const std::string & connectionName,const InterfaceNames & interfaceNames)52 inline InterfaceMapType createInterfaceMap(const std::string& path,
53                                            const std::string& connectionName,
54                                            const InterfaceNames& interfaceNames)
55 {
56     ConnectionNames connectionMap{{connectionName, interfaceNames}};
57     InterfaceMapType interfaceMap{{path, connectionMap}};
58 
59     return interfaceMap;
60 }
61 
62 // Create a default interfaceMapType with 2 entries with the same
63 // owner.
createDefaultInterfaceMap()64 inline InterfaceMapType createDefaultInterfaceMap()
65 {
66     InterfaceMapType interfaceMap = {
67         {defaultSourcePath, {{defaultDbusSvc, {"a"}}}},
68         {defaultEndpoint, {{defaultDbusSvc, {"b"}}}}};
69 
70     return interfaceMap;
71 }
72