xref: /openbmc/ibm-logging/dbus.hpp (revision 6a2b8956)
1 #pragma once
2 
3 #include <sdbusplus/server.hpp>
4 
5 #include <map>
6 #include <string>
7 #include <vector>
8 
9 namespace ibm
10 {
11 namespace logging
12 {
13 
14 using DbusInterface = std::string;
15 using DbusProperty = std::string;
16 using DbusService = std::string;
17 using DbusPath = std::string;
18 
19 static constexpr auto forwardPos = 0;
20 static constexpr auto reversePos = 1;
21 static constexpr auto endpointPos = 2;
22 using AssociationsPropertyType =
23     std::vector<std::tuple<std::string, std::string, std::string>>;
24 
25 using Value = std::variant<bool, uint32_t, uint64_t, std::string,
26                            std::vector<std::string>, 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_t& 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_t& bus, const std::string& root,
67                        int 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_t& bus,
98                                  const std::string& service,
99                                  const std::string& objPath,
100                                  const std::string& interface);
101 } // namespace logging
102 } // namespace ibm
103