George Liu | 1c737af | 2020-10-16 09:07:02 +0800 | [diff] [blame^] | 1 | #pragma once |
| 2 | #include <sdbusplus/server.hpp> |
| 3 | |
| 4 | #include <map> |
| 5 | #include <vector> |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace led |
| 9 | { |
| 10 | namespace utils |
| 11 | { |
| 12 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 13 | constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper"; |
| 14 | constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper"; |
| 15 | constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties"; |
| 16 | |
| 17 | // The value of the property(type: variant, contains some basic types) |
| 18 | // Eg: uint8_t : dutyOn, uint16_t : Period, std::string : Name |
| 19 | using PropertyValue = std::variant<uint8_t, uint16_t, std::string>; |
| 20 | |
| 21 | /** |
| 22 | * @class DBusHandler |
| 23 | * |
| 24 | * Wrapper class to handle the D-Bus calls |
| 25 | * |
| 26 | * This class contains the APIs to handle the D-Bus calls. |
| 27 | */ |
| 28 | class DBusHandler |
| 29 | { |
| 30 | public: |
| 31 | /** @brief Get the bus connection. */ |
| 32 | static auto& getBus() |
| 33 | { |
| 34 | static auto bus = sdbusplus::bus::new_default(); |
| 35 | return bus; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @brief Get service name by the path and interface of the DBus. |
| 40 | * |
| 41 | * @param[in] path - D-Bus object path |
| 42 | * @param[in] interface - D-Bus Interface |
| 43 | * |
| 44 | * @return std::string - the D-Bus service name |
| 45 | * |
| 46 | */ |
| 47 | const std::string getService(const std::string& path, |
| 48 | const std::string& interface) const; |
| 49 | |
| 50 | /** @brief Set D-Bus property |
| 51 | * |
| 52 | * @param[in] objectPath - D-Bus object path |
| 53 | * @param[in] interface - D-Bus interface |
| 54 | * @param[in] propertyName - D-Bus property name |
| 55 | * @param[in] value - The value to be set |
| 56 | * |
| 57 | * @throw sdbusplus::exception::SdBusError when it fails |
| 58 | */ |
| 59 | void setProperty(const std::string& objectPath, |
| 60 | const std::string& interface, |
| 61 | const std::string& propertyName, |
| 62 | const PropertyValue& value) const; |
| 63 | }; |
| 64 | |
| 65 | } // namespace utils |
| 66 | } // namespace led |
| 67 | } // namespace phosphor |