make getproperty a templated function
This will make it more generic so other types of properties can be read
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: Icc7c040ec44d470b6b62d8b74200c7e35012e25c
diff --git a/usb/usb_manager.cpp b/usb/usb_manager.cpp
index 4a1f768..2bab2de 100644
--- a/usb/usb_manager.cpp
+++ b/usb/usb_manager.cpp
@@ -109,9 +109,9 @@
try
{
- auto propVal =
- utils::getProperty(bus, path.str, imageInterface, "Activation");
- const auto& imageProp = std::get<std::string>(propVal);
+ auto imageProp = utils::getProperty<std::string>(
+ bus, path.str, imageInterface, "Activation");
+
if (imageProp == readyPro && isUSBCodeUpdate)
{
setApplyTime();
diff --git a/utils.cpp b/utils.cpp
index 6763768..d661fb3 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -41,28 +41,6 @@
return response[0].first;
}
-const PropertyValue getProperty(sdbusplus::bus::bus& bus,
- const std::string& objectPath,
- const std::string& interface,
- const std::string& propertyName)
-{
- PropertyValue value{};
- auto service = getService(bus, objectPath, interface);
- if (service.empty())
- {
- return value;
- }
-
- auto method = bus.new_method_call(service.c_str(), objectPath.c_str(),
- "org.freedesktop.DBus.Properties", "Get");
- method.append(interface, propertyName);
-
- auto reply = bus.call(method);
- reply.read(value);
-
- return value;
-}
-
void setProperty(sdbusplus::bus::bus& bus, const std::string& objectPath,
const std::string& interface, const std::string& propertyName,
const PropertyValue& value)
diff --git a/utils.hpp b/utils.hpp
index 1a695f4..2174938 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -30,10 +30,26 @@
*
* @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);
+template <typename T>
+T getProperty(sdbusplus::bus::bus& bus, const std::string& objectPath,
+ const std::string& interface, const std::string& propertyName)
+{
+ std::variant<T> value{};
+ auto service = getService(bus, objectPath, interface);
+ if (service.empty())
+ {
+ return std::get<T>(value);
+ }
+
+ auto method = bus.new_method_call(service.c_str(), objectPath.c_str(),
+ "org.freedesktop.DBus.Properties", "Get");
+ method.append(interface, propertyName);
+
+ auto reply = bus.call(method);
+ reply.read(value);
+
+ return std::get<T>(value);
+}
/** @brief Set D-Bus property
*