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