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