Invoke SetNTP and UpdateUseNtpField in time manager

1. When time mode is changed, invoke systemd timedate1's SetNTP
method to update NTP settings;
2. When settings use_dhcp_ntp property is changed, invoke
NetworkManager's UpdateUseNtpField method to update its setting;
3. Move the common code of getProperty() into utils.hpp

Change-Id: I981e0e9de9c0430282b3364c38c282312bb2be89
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/utils.hpp b/utils.hpp
index 0589613..97b26e7 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -1,5 +1,7 @@
 #pragma once
 
+#include <phosphor-logging/log.hpp>
+
 #include <fstream>
 
 namespace phosphor
@@ -9,6 +11,8 @@
 namespace utils
 {
 
+using namespace phosphor::logging;
+
 /** @brief Read data with type T from file
  *
  * @param[in] fileName - The name of file to read from
@@ -42,6 +46,46 @@
     }
 }
 
+/** @brief The template function to get property from the requested dbus path
+ *
+ * @param[in] bus          - The Dbus bus object
+ * @param[in] service      - The Dbus service name
+ * @param[in] path         - The Dbus object path
+ * @param[in] interface    - The Dbus interface
+ * @param[in] propertyName - The property name to get
+ *
+ * @return The value of the property
+ */
+template <typename T>
+T getProperty(sdbusplus::bus::bus& bus,
+              const char* service,
+              const char* path,
+              const char* interface,
+              const char* propertyName)
+{
+    sdbusplus::message::variant<T> value{};
+    auto method = bus.new_method_call(service,
+                                      path,
+                                      "org.freedesktop.DBus.Properties",
+                                      "Get");
+    method.append(interface, propertyName);
+    auto reply = bus.call(method);
+    if (reply)
+    {
+        reply.read(value);
+    }
+    else
+    {
+        // TODO: use elog to throw exception
+        log<level::ERR>("Failed to get property",
+                        entry("SERVICE=%s", service),
+                        entry("PATH=%s", path),
+                        entry("INTERFACE=%s", interface),
+                        entry("PROPERTY=%s", propertyName));
+    }
+    return value.template get<T>();
+}
+
 }
 }
 }