1 #pragma once
2 
3 #include <sdbusplus/bus.hpp>
4 
5 #include <optional>
6 #include <string>
7 #include <tuple>
8 
9 namespace open_power
10 {
11 namespace occ
12 {
13 namespace utils
14 {
15 
16 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
17 constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper";
18 constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper";
19 constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
20 
21 // The value of the property(type: variant, contains some basic types)
22 using PropertyValue = std::variant<uint32_t, bool>;
23 
24 /** @brief Get the bus connection. */
25 static auto& getBus()
26 {
27     static auto bus = sdbusplus::bus::new_default();
28     return bus;
29 }
30 
31 /**
32  *  @brief Get service name by the path and interface of the DBus.
33  *
34  *  @param[in] path      -  D-Bus object path
35  *  @param[in] interface -  D-Bus Interface
36  *
37  *  @return std::string  -  the D-Bus service name
38  *
39  */
40 const std::string getService(const std::string& path,
41                              const std::string& interface);
42 
43 /** @brief Get property(type: variant)
44  *
45  *  @param[in] objectPath       -   D-Bus object path
46  *  @param[in] interface        -   D-Bus interface
47  *  @param[in] propertyName     -   D-Bus property name
48  *
49  *  @return The value of the property(type: variant)
50  *
51  *  @throw sdbusplus::exception::exception when it fails
52  */
53 const PropertyValue getProperty(const std::string& objectPath,
54                                 const std::string& interface,
55                                 const std::string& propertyName);
56 
57 /** @brief Get subtree paths
58  *
59  *  @param[in] interfaces -   D-Bus interfaces
60  *  @param[in] path       -   D-Bus object path
61  *
62  *  @return The D-Bus paths from the GetSubTree method
63  *
64  *  @throw sdbusplus::exception::exception when it fails
65  */
66 std::vector<std::string>
67     getSubtreePaths(const std::vector<std::string>& interfaces,
68                     const std::string& path = "/");
69 
70 } // namespace utils
71 } // namespace occ
72 } // namespace open_power
73