blob: edb0315eeba6302f8b12ea4dded6f48be0509abd [file] [log] [blame]
George Liu1c737af2020-10-16 09:07:02 +08001#pragma once
2#include <sdbusplus/server.hpp>
3
4#include <map>
5#include <vector>
6namespace phosphor
7{
8namespace led
9{
10namespace utils
11{
12constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
13constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper";
14constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper";
15constexpr 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
19using 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 */
28class 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