Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
George Liu | 1390159 | 2021-06-03 14:13:21 +0800 | [diff] [blame] | 3 | #include <optional> |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 4 | #include <sdbusplus/bus.hpp> |
| 5 | #include <string> |
George Liu | 1390159 | 2021-06-03 14:13:21 +0800 | [diff] [blame] | 6 | #include <tuple> |
| 7 | |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 8 | namespace open_power |
| 9 | { |
| 10 | namespace occ |
| 11 | { |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 12 | namespace utils |
| 13 | { |
George Liu | 1390159 | 2021-06-03 14:13:21 +0800 | [diff] [blame] | 14 | |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 15 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 16 | constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper"; |
| 17 | constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper"; |
| 18 | constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties"; |
| 19 | |
| 20 | // The value of the property(type: variant, contains some basic types) |
| 21 | using PropertyValue = std::variant<uint32_t, bool>; |
| 22 | |
| 23 | /** @brief Get the bus connection. */ |
| 24 | static auto& getBus() |
| 25 | { |
| 26 | static auto bus = sdbusplus::bus::new_default(); |
| 27 | return bus; |
| 28 | } |
| 29 | |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 30 | /** |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 31 | * @brief Get service name by the path and interface of the DBus. |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 32 | * |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 33 | * @param[in] path - D-Bus object path |
| 34 | * @param[in] interface - D-Bus Interface |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 35 | * |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 36 | * @return std::string - the D-Bus service name |
| 37 | * |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 38 | */ |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 39 | const std::string getService(const std::string& path, |
| 40 | const std::string& interface); |
| 41 | |
| 42 | /** @brief Get property(type: variant) |
| 43 | * |
| 44 | * @param[in] objectPath - D-Bus object path |
| 45 | * @param[in] interface - D-Bus interface |
| 46 | * @param[in] propertyName - D-Bus property name |
| 47 | * |
| 48 | * @return The value of the property(type: variant) |
| 49 | * |
| 50 | * @throw sdbusplus::exception::SdBusError when it fails |
| 51 | */ |
| 52 | const PropertyValue getProperty(const std::string& objectPath, |
| 53 | const std::string& interface, |
| 54 | const std::string& propertyName); |
| 55 | |
| 56 | } // namespace utils |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 57 | } // namespace occ |
| 58 | } // namespace open_power |