pinhole: move power policy service to utils

Move the getProperty() function to utils and use it for all utility
functions

Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I3128d6006dc5f72a579daaf168b9976ee5bcb2e8
diff --git a/utils.cpp b/utils.cpp
index a93fa39..1e5e9e2 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -55,6 +55,40 @@
     return mapperResponse.begin()->first;
 }
 
+std::string getProperty(sdbusplus::bus::bus& bus, const std::string& path,
+                        const std::string& interface,
+                        const std::string& propertyName)
+{
+    std::variant<std::string> property;
+    std::string service = getService(bus, path, interface);
+
+    auto method = bus.new_method_call(service.c_str(), path.c_str(),
+                                      PROPERTY_INTERFACE, "Get");
+
+    method.append(interface, propertyName);
+
+    try
+    {
+        auto reply = bus.call(method);
+        reply.read(property);
+    }
+    catch (const sdbusplus::exception::exception& e)
+    {
+        error("Error in property Get, error {ERROR}, property {PROPERTY}",
+              "ERROR", e, "PROPERTY", propertyName);
+        throw;
+    }
+
+    if (std::get<std::string>(property).empty())
+    {
+        error("Error reading property response for {PROPERTY}", "PROPERTY",
+              propertyName);
+        throw std::runtime_error("Error reading property response");
+    }
+
+    return std::get<std::string>(property);
+}
+
 void setProperty(sdbusplus::bus::bus& bus, const std::string& path,
                  const std::string& interface, const std::string& property,
                  const std::string& value)