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 | |
| 15 | using LABELVALUE = std::tuple<std::string, uint16_t>; |
| 16 | |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 17 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 18 | constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper"; |
| 19 | constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper"; |
| 20 | constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties"; |
| 21 | |
| 22 | // The value of the property(type: variant, contains some basic types) |
| 23 | using PropertyValue = std::variant<uint32_t, bool>; |
| 24 | |
| 25 | /** @brief Get the bus connection. */ |
| 26 | static auto& getBus() |
| 27 | { |
| 28 | static auto bus = sdbusplus::bus::new_default(); |
| 29 | return bus; |
| 30 | } |
| 31 | |
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 | * @brief Get service name by the path and interface of the DBus. |
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 | * @param[in] path - D-Bus object path |
| 36 | * @param[in] interface - D-Bus Interface |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 37 | * |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 38 | * @return std::string - the D-Bus service name |
| 39 | * |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 40 | */ |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 41 | const std::string getService(const std::string& path, |
| 42 | const std::string& interface); |
| 43 | |
| 44 | /** @brief Get property(type: variant) |
| 45 | * |
| 46 | * @param[in] objectPath - D-Bus object path |
| 47 | * @param[in] interface - D-Bus interface |
| 48 | * @param[in] propertyName - D-Bus property name |
| 49 | * |
| 50 | * @return The value of the property(type: variant) |
| 51 | * |
| 52 | * @throw sdbusplus::exception::SdBusError when it fails |
| 53 | */ |
| 54 | const PropertyValue getProperty(const std::string& objectPath, |
| 55 | const std::string& interface, |
| 56 | const std::string& propertyName); |
| 57 | |
George Liu | 1390159 | 2021-06-03 14:13:21 +0800 | [diff] [blame] | 58 | /** |
| 59 | * @brief Check the value of the `tempX_label` file |
| 60 | * |
| 61 | * @param[in] value - the value of the `tempX_label` file |
| 62 | * |
| 63 | * @return Sensors type and Sensors ID |
| 64 | */ |
| 65 | std::optional<LABELVALUE> checkLabelValue(const std::string& value); |
| 66 | |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 67 | } // namespace utils |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 68 | } // namespace occ |
| 69 | } // namespace open_power |