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