Add utility for D-Bus

Putting all D-Bus related operation to the utils file.

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I934e519bca43b73da01ed09fc73f6c7cdc795e1f
diff --git a/utils.hpp b/utils.hpp
new file mode 100644
index 0000000..edb0315
--- /dev/null
+++ b/utils.hpp
@@ -0,0 +1,67 @@
+#pragma once
+#include <sdbusplus/server.hpp>
+
+#include <map>
+#include <vector>
+namespace phosphor
+{
+namespace led
+{
+namespace utils
+{
+constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
+constexpr auto MAPPER_OBJ_PATH = "/xyz/openbmc_project/object_mapper";
+constexpr auto MAPPER_IFACE = "xyz.openbmc_project.ObjectMapper";
+constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
+
+// The value of the property(type: variant, contains some basic types)
+// Eg: uint8_t : dutyOn, uint16_t : Period, std::string : Name
+using PropertyValue = std::variant<uint8_t, uint16_t, std::string>;
+
+/**
+ *  @class DBusHandler
+ *
+ *  Wrapper class to handle the D-Bus calls
+ *
+ *  This class contains the APIs to handle the D-Bus calls.
+ */
+class DBusHandler
+{
+  public:
+    /** @brief Get the bus connection. */
+    static auto& getBus()
+    {
+        static auto bus = sdbusplus::bus::new_default();
+        return bus;
+    }
+
+    /**
+     *  @brief Get service name by the path and interface of the DBus.
+     *
+     *  @param[in] path      -  D-Bus object path
+     *  @param[in] interface -  D-Bus Interface
+     *
+     *  @return std::string  -  the D-Bus service name
+     *
+     */
+    const std::string getService(const std::string& path,
+                                 const std::string& interface) const;
+
+    /** @brief Set D-Bus property
+     *
+     *  @param[in] objectPath       -   D-Bus object path
+     *  @param[in] interface        -   D-Bus interface
+     *  @param[in] propertyName     -   D-Bus property name
+     *  @param[in] value            -   The value to be set
+     *
+     *  @throw sdbusplus::exception::SdBusError when it fails
+     */
+    void setProperty(const std::string& objectPath,
+                     const std::string& interface,
+                     const std::string& propertyName,
+                     const PropertyValue& value) const;
+};
+
+} // namespace utils
+} // namespace led
+} // namespace phosphor