usb: Add utility for D-Bus
Putting all D-Bus related operation to the utils file.
Tested: Call the set/getProperty functions locally and successfully
set/get the corresponding attribute value.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I0e0c33fd6ec5db3a47babaf417b0c708709e580b
diff --git a/utils.hpp b/utils.hpp
index a6db7f9..fc8144c 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -9,6 +9,8 @@
namespace utils
{
+using PropertyValue = std::variant<std::string>;
+
/**
* @brief Get the bus service
*
@@ -17,6 +19,36 @@
std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
const std::string& interface);
+/** @brief Get property(type: variant)
+ *
+ * @param[in] bus - bus handler
+ * @param[in] objectPath - D-Bus object path
+ * @param[in] interface - D-Bus interface
+ * @param[in] propertyName - D-Bus property name
+ *
+ * @return The value of the property(type: variant)
+ *
+ * @throw sdbusplus::exception::exception when it fails
+ */
+const PropertyValue getProperty(sdbusplus::bus::bus& bus,
+ const std::string& objectPath,
+ const std::string& interface,
+ const std::string& propertyName);
+
+/** @brief Set D-Bus property
+ *
+ * @param[in] bus - bus handler
+ * @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::exception when it fails
+ */
+void setProperty(sdbusplus::bus::bus& bus, const std::string& objectPath,
+ const std::string& interface, const std::string& propertyName,
+ const PropertyValue& value);
+
/**
* @brief Merge more files
*