Refactor D-Bus object
- The intent behind this commit is to refactor D-Bus, and abstract
the bus, getService, getProperty and other methods into the utils
file, and other file operations D-Bus only need to include
uitls.hpp.
- We can also continue to add other general methods such as
setPropery, getSubTree in the utils file in the future.
- Also, removed redundant files(occ_finder.hpp and occ_finder.cpp).
Tested: built openpower-occ-control successfully and worked.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I53e61e30a76173c154a9f47fc122936468abbc4b
diff --git a/utils.hpp b/utils.hpp
index 7c8b871..1d173a3 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -6,17 +6,49 @@
{
namespace occ
{
+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)
+using PropertyValue = std::variant<uint32_t, bool>;
+
+/** @brief Get the bus connection. */
+static auto& getBus()
+{
+ static auto bus = sdbusplus::bus::new_default();
+ return bus;
+}
+
/**
- * @brief Gets the D-Bus Service name for the input D-Bus path
+ * @brief Get service name by the path and interface of the DBus.
*
- * @param[in] bus - Bus handler
- * @param[in] path - Object Path
- * @param[in] intf - Interface
+ * @param[in] path - D-Bus object path
+ * @param[in] interface - D-Bus Interface
*
- * @return Service name
- * @error InternalFailure exception thrown
+ * @return std::string - the D-Bus service name
+ *
*/
-std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
- const std::string& intf);
+const std::string getService(const std::string& path,
+ const std::string& interface);
+
+/** @brief Get property(type: variant)
+ *
+ * @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::SdBusError when it fails
+ */
+const PropertyValue getProperty(const std::string& objectPath,
+ const std::string& interface,
+ const std::string& propertyName);
+
+} // namespace utils
} // namespace occ
} // namespace open_power