xref: /openbmc/ibm-logging/dbus.hpp (revision 3e71c977)
1 #pragma once
2 
3 #include <map>
4 #include <sdbusplus/server.hpp>
5 #include <string>
6 #include <vector>
7 
8 namespace ibm
9 {
10 namespace logging
11 {
12 
13 using DbusInterface = std::string;
14 using DbusProperty = std::string;
15 using DbusService = std::string;
16 using DbusPath = std::string;
17 
18 static constexpr auto forwardPos = 0;
19 static constexpr auto reversePos = 1;
20 static constexpr auto endpointPos = 2;
21 using AssociationsPropertyType =
22     std::vector<std::tuple<std::string, std::string, std::string>>;
23 
24 using Value = sdbusplus::message::variant<bool, uint32_t, uint64_t, std::string,
25                                           std::vector<std::string>,
26                                           AssociationsPropertyType>;
27 
28 using DbusPropertyMap = std::map<DbusProperty, Value>;
29 using DbusInterfaceMap = std::map<DbusInterface, DbusPropertyMap>;
30 using DbusInterfaceList = std::vector<DbusInterface>;
31 
32 using ObjectValueTree =
33     std::map<sdbusplus::message::object_path, DbusInterfaceMap>;
34 
35 using DbusSubtree =
36     std::map<DbusPath, std::map<DbusService, DbusInterfaceList>>;
37 
38 /**
39  * Returns the managed objects for an object path and service
40  *
41  * Returns an empty map if there are any failures.
42  *
43  * @param[in] bus - the D-Bus object
44  * @param[in] service - the D-Bus service name
45  * @param[in] objPath - the D-Bus object path
46  *
47  * @return ObjectValueTree - A map of object paths to their
48  *                           interfaces and properties.
49  */
50 ObjectValueTree getManagedObjects(sdbusplus::bus::bus& bus,
51                                   const std::string& service,
52                                   const std::string& objPath);
53 
54 /**
55  * Returns the subtree for a root, depth, and interface.
56  *
57  * Returns an empty map if there are any failures.
58  *
59  * @param[in] bus - the D-Bus object
60  * @param[in] root - the point from which to provide results
61  * @param[in] depth - the number of path elements to descend
62  *
63  * @return DbusSubtree - A map of object paths to their
64  *                       services and interfaces.
65  */
66 DbusSubtree getSubtree(sdbusplus::bus::bus& bus, const std::string& root,
67                        size_t depth, const std::string& interface);
68 
69 /**
70  * Get the D-Bus service name for the object path and interface from
71  * the data returned from a GetSubTree call.
72  *
73  * Returns an empty string if the service can't be found.
74  *
75  * @param[in] objPath - the D-Bus object path
76  * @param[in] interface - the D-Bus interface name
77  * @param[in] tree - the D-Bus GetSubTree response
78  *
79  * @return string - the service name
80  */
81 DbusService getService(const std::string& objPath, const std::string& interface,
82                        const DbusSubtree& tree);
83 
84 /**
85  * Returns all properties on a particular interface on a
86  * particular D-Bus object.
87  *
88  * Returns an empty map if there are any failures.
89  *
90  * @param[in] bus - the D-Bus object
91  * @param[in] service - the D-Bus service name
92  * @param[in] objPath - the D-Bus object path
93  * @param[in] interface - the D-Bus interface name
94  *
95  * @return DbusPropertyMap - The map of property names to values
96  */
97 DbusPropertyMap getAllProperties(sdbusplus::bus::bus& bus,
98                                  const std::string& service,
99                                  const std::string& objPath,
100                                  const std::string& interface);
101 }
102 }
103