utils: Make getDbusPropertyVariant virtual
Make getDbusPropertyVariant virtual so it can be mocked
Tested: built successfully, no more testing
Change-Id: I83fa8e8a3810f42fea6969722add27d52534072b
diff --git a/libpldmresponder/bios_parser.cpp b/libpldmresponder/bios_parser.cpp
index 0b74059..3a45f3d 100644
--- a/libpldmresponder/bios_parser.cpp
+++ b/libpldmresponder/bios_parser.cpp
@@ -230,10 +230,9 @@
}
const auto& dbusValToValMap = internal::dbusValToValMaps.at(attrName);
- propValue =
- pldm::utils::DBusHandler().getDbusPropertyVariant<PropertyValue>(
- dBusMap->objectPath.c_str(), dBusMap->propertyName.c_str(),
- dBusMap->interface.c_str());
+ propValue = pldm::utils::DBusHandler().getDbusPropertyVariant(
+ dBusMap->objectPath.c_str(), dBusMap->propertyName.c_str(),
+ dBusMap->interface.c_str());
auto iter = dbusValToValMap.find(propValue);
if (iter != dbusValToValMap.end())
diff --git a/utils.cpp b/utils.cpp
index 1152783..20d2b06 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -186,5 +186,19 @@
}
}
+PropertyValue DBusHandler::getDbusPropertyVariant(
+ const char* objPath, const char* dbusProp, const char* dbusInterface) const
+{
+ auto& bus = DBusHandler::getBus();
+ auto service = getService(objPath, dbusInterface);
+ auto method =
+ bus.new_method_call(service.c_str(), objPath, dbusProperties, "Get");
+ method.append(dbusInterface, dbusProp);
+ PropertyValue value{};
+ auto reply = bus.call(method);
+ reply.read(value);
+ return value;
+}
+
} // namespace utils
} // namespace pldm
diff --git a/utils.hpp b/utils.hpp
index 6e128be..567138a 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -142,6 +142,10 @@
virtual void setDbusProperty(const DBusMapping& dBusMap,
const PropertyValue& value) const = 0;
+
+ virtual PropertyValue
+ getDbusPropertyVariant(const char* objPath, const char* dbusProp,
+ const char* dbusInterface) const = 0;
};
/**
@@ -165,34 +169,51 @@
/**
* @brief Get the DBUS Service name for the input dbus path
+ *
* @param[in] path - DBUS object path
* @param[in] interface - DBUS Interface
+ *
* @return std::string - the dbus service name
+ *
+ * @throw sdbusplus::exception::SdBusError when it fails
*/
std::string getService(const char* path, const char* interface) const;
- template <typename Variant>
- auto getDbusPropertyVariant(const char* objPath, const char* dbusProp,
- const char* dbusInterface)
- {
- Variant value;
- auto& bus = DBusHandler::getBus();
- auto service = getService(objPath, dbusInterface);
- auto method = bus.new_method_call(service.c_str(), objPath,
- dbusProperties, "Get");
- method.append(dbusInterface, dbusProp);
- auto reply = bus.call(method);
- reply.read(value);
+ /** @brief Get property(type: variant) from the requested dbus
+ *
+ * @param[in] objPath - The Dbus object path
+ * @param[in] dbusProp - The property name to get
+ * @param[in] dbusInterface - The Dbus interface
+ *
+ * @return The value of the property(type: variant)
+ *
+ * @throw sdbusplus::exception::SdBusError when it fails
+ */
+ PropertyValue
+ getDbusPropertyVariant(const char* objPath, const char* dbusProp,
+ const char* dbusInterface) const override;
- return value;
- }
-
+ /** @brief The template function to get property from the requested dbus
+ * path
+ *
+ * @tparam Property - Excepted type of the property on dbus
+ *
+ * @param[in] objPath - The Dbus object path
+ * @param[in] dbusProp - The property name to get
+ * @param[in] dbusInterface - The Dbus interface
+ *
+ * @return The value of the property
+ *
+ * @throw sdbusplus::exception::SdBusError when dbus request fails
+ * std::bad_variant_access when \p Property and property on dbus do
+ * not match
+ */
template <typename Property>
auto getDbusProperty(const char* objPath, const char* dbusProp,
const char* dbusInterface)
{
- auto VariantValue = getDbusPropertyVariant<std::variant<Property>>(
- objPath, dbusProp, dbusInterface);
+ auto VariantValue =
+ getDbusPropertyVariant(objPath, dbusProp, dbusInterface);
return std::get<Property>(VariantValue);
}
@@ -201,6 +222,8 @@
* @param[in] dBusMap - Object path, property name, interface and property
* type for the D-Bus object
* @param[in] value - The value to be set
+ *
+ * @throw sdbusplus::exception::SdBusError when it fails
*/
void setDbusProperty(const DBusMapping& dBusMap,
const PropertyValue& value) const override;