Add methods to return property variant
Create methods to return a property variant for use where the overloaded
comparison operations are needed against a property value stored as a
variant.
Tested:
A property is looked up and returned as the given variant type
Change-Id: Iab557781a3ab9e33d3595ad69db5544a25efe2eb
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/sdbusplus.hpp b/sdbusplus.hpp
index 0c70b9c..454fde8 100644
--- a/sdbusplus.hpp
+++ b/sdbusplus.hpp
@@ -245,6 +245,43 @@
property);
}
+ /** @brief Get a property variant with mapper lookup. */
+ template <typename Variant>
+ static auto getPropertyVariant(
+ sdbusplus::bus::bus& bus,
+ const std::string& path,
+ const std::string& interface,
+ const std::string& property)
+ {
+ using namespace std::literals::string_literals;
+
+ auto msg = callMethod(
+ bus,
+ getService(bus, path, interface),
+ path,
+ "org.freedesktop.DBus.Properties"s,
+ "Get"s,
+ interface,
+ property);
+ Variant value;
+ msg.read(value);
+ return value;
+ }
+
+ /** @brief Get a property variant with mapper lookup. */
+ template <typename Variant>
+ static auto getPropertyVariant(
+ const std::string& path,
+ const std::string& interface,
+ const std::string& property)
+ {
+ return getPropertyVariant<Variant>(
+ getBus(),
+ path,
+ interface,
+ property);
+ }
+
/** @brief Get a property without mapper lookup. */
template <typename Property>
static auto getProperty(
@@ -285,6 +322,46 @@
property);
}
+ /** @brief Get a property variant without mapper lookup. */
+ template <typename Variant>
+ static auto getPropertyVariant(
+ sdbusplus::bus::bus& bus,
+ const std::string& service,
+ const std::string& path,
+ const std::string& interface,
+ const std::string& property)
+ {
+ using namespace std::literals::string_literals;
+
+ auto msg = callMethod(
+ bus,
+ service,
+ path,
+ "org.freedesktop.DBus.Properties"s,
+ "Get"s,
+ interface,
+ property);
+ Variant value;
+ msg.read(value);
+ return value;
+ }
+
+ /** @brief Get a property variant without mapper lookup. */
+ template <typename Variant>
+ static auto getPropertyVariant(
+ const std::string& service,
+ const std::string& path,
+ const std::string& interface,
+ const std::string& property)
+ {
+ return getPropertyVariant<Variant>(
+ getBus(),
+ service,
+ path,
+ interface,
+ property);
+ }
+
/** @brief Set a property with mapper lookup. */
template <typename Property>
static void setProperty(