Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 4 | |
| 5 | #include <optional> |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 6 | #include <string> |
George Liu | 1390159 | 2021-06-03 14:13:21 +0800 | [diff] [blame] | 7 | #include <tuple> |
| 8 | |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 9 | namespace open_power |
| 10 | { |
| 11 | namespace occ |
| 12 | { |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 13 | namespace utils |
| 14 | { |
George Liu | 1390159 | 2021-06-03 14:13:21 +0800 | [diff] [blame] | 15 | |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 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) |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 22 | using PropertyValue = std::variant<uint32_t, bool, double, std::string>; |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 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 | |
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 | * @brief Get service name by the path and interface of the DBus. |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 33 | * |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 34 | * @param[in] path - D-Bus object path |
| 35 | * @param[in] interface - D-Bus Interface |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 36 | * |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 37 | * @return std::string - the D-Bus service name |
| 38 | * |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 39 | */ |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 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 | * |
Patrick Williams | 2561362 | 2021-09-02 09:29:54 -0500 | [diff] [blame] | 51 | * @throw sdbusplus::exception::exception when it fails |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 52 | */ |
| 53 | const PropertyValue getProperty(const std::string& objectPath, |
| 54 | const std::string& interface, |
| 55 | const std::string& propertyName); |
| 56 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 57 | /** |
| 58 | * @brief Sets a given object's property value |
| 59 | * |
| 60 | * @param[in] object - Name of the object containing the property |
| 61 | * @param[in] interface - Interface name containing the property |
| 62 | * @param[in] property - Property name |
| 63 | * @param[in] value - Property value |
| 64 | */ |
| 65 | void setProperty(const std::string& objectPath, const std::string& interface, |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 66 | const std::string& propertyName, PropertyValue&& value); |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 67 | |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 68 | /** @brief Get subtree paths |
| 69 | * |
| 70 | * @param[in] interfaces - D-Bus interfaces |
| 71 | * @param[in] path - D-Bus object path |
| 72 | * |
| 73 | * @return The D-Bus paths from the GetSubTree method |
| 74 | * |
| 75 | * @throw sdbusplus::exception::exception when it fails |
| 76 | */ |
| 77 | std::vector<std::string> |
| 78 | getSubtreePaths(const std::vector<std::string>& interfaces, |
| 79 | const std::string& path = "/"); |
| 80 | |
Chris Cain | 1be4337 | 2021-12-09 19:29:37 -0600 | [diff] [blame] | 81 | /** |
| 82 | * @brief Get the D-Bus service and object path for an interface |
| 83 | * |
| 84 | * @param[in] interface - D-Bus interface name |
| 85 | * @param[in,out] path - D-Bus object path |
| 86 | * |
| 87 | * @return D-Bus service name |
| 88 | */ |
| 89 | std::string getServiceUsingSubTree(const std::string& interface, |
| 90 | std::string& path); |
| 91 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 92 | /** |
| 93 | * @brief Get status of the host |
| 94 | * |
| 95 | * @return true is the host is running, else false |
| 96 | */ |
| 97 | bool isHostRunning(); |
| 98 | |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 99 | } // namespace utils |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 100 | } // namespace occ |
| 101 | } // namespace open_power |