Move the restart systemdunit function to network manager

Change-Id: I647741fc3976ca82c39998a518b1de7be5365e80
Signed-off-by: Ratan Gupta <ratagupt@linux.vnet.ibm.com>
diff --git a/dhcp_configuration.cpp b/dhcp_configuration.cpp
index e492156..7707461 100644
--- a/dhcp_configuration.cpp
+++ b/dhcp_configuration.cpp
@@ -40,7 +40,7 @@
 
     auto name = ConfigIntf::hostNameEnabled(value);
     manager.writeToConfigurationFile();
-    restartSystemdUnit(phosphor::network::networkdService);
+    manager.restartSystemdUnit(phosphor::network::networkdService);
 
     return name;
 }
@@ -54,8 +54,8 @@
 
     auto ntp = ConfigIntf::nTPEnabled(value);
     manager.writeToConfigurationFile();
-    restartSystemdUnit(phosphor::network::networkdService);
-    restartSystemdUnit(phosphor::network::timeSynchdService);
+    manager.restartSystemdUnit(phosphor::network::networkdService);
+    manager.restartSystemdUnit(phosphor::network::timeSynchdService);
 
     return ntp;
 }
@@ -69,7 +69,7 @@
 
     auto dns = ConfigIntf::dNSEnabled(value);
     manager.writeToConfigurationFile();
-    restartSystemdUnit(phosphor::network::networkdService);
+    manager.restartSystemdUnit(phosphor::network::networkdService);
 
     return dns;
 }
diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp
index 893cd4c..f2ad372 100644
--- a/ethernet_interface.cpp
+++ b/ethernet_interface.cpp
@@ -463,7 +463,7 @@
     writeConfigurationFile();
     // timesynchd reads the NTP server configuration from the
     // network file.
-    restartSystemdUnit(networkdService);
+    manager.restartSystemdUnit(networkdService);
     return ntpServers;
 }
 // Need to merge the below function with the code which writes the
@@ -701,7 +701,7 @@
     // ip for the changed mac address.
     if (dHCPEnabled())
     {
-        restartSystemdUnit(networkdService);
+        manager.restartSystemdUnit(networkdService);
     }
     return mac;
 }
diff --git a/network_manager.hpp b/network_manager.hpp
index 23eaacb..7a98f9a 100644
--- a/network_manager.hpp
+++ b/network_manager.hpp
@@ -115,6 +115,20 @@
     /** @brief restart the network timers. */
     void restartTimers();
 
+    /** @brief Restart the systemd unit
+     *  @param[in] unit - systemd unit name which needs to be
+     *                    restarted.
+     */
+    inline void restartSystemdUnit(const std::string& unit)
+    {
+        auto bus = sdbusplus::bus::new_default();
+        auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+                                          SYSTEMD_INTERFACE, "RestartUnit");
+
+        method.append(unit, "replace");
+        bus.call_noreply(method);
+    }
+
   private:
     /** @brief Persistent sdbusplus DBus bus connection. */
     sdbusplus::bus::bus& bus;
diff --git a/network_manager_main.cpp b/network_manager_main.cpp
index 2bc203f..dfaeecc 100644
--- a/network_manager_main.cpp
+++ b/network_manager_main.cpp
@@ -46,7 +46,10 @@
 /** @brief restart the systemd networkd. */
 void restartNetwork()
 {
-    restartSystemdUnit("systemd-networkd.service");
+    if (manager)
+    {
+        manager->restartSystemdUnit("systemd-networkd.service");
+    }
 }
 
 void initializeTimers()
diff --git a/util.hpp b/util.hpp
index b3ec771..51c2e04 100644
--- a/util.hpp
+++ b/util.hpp
@@ -121,20 +121,6 @@
  */
 IntfAddrMap getInterfaceAddrs();
 
-/** @brief Restart the systemd unit
- *  @param[in] unit - systemd unit name which needs to be
- *                    restarted.
- */
-inline void restartSystemdUnit(const std::string& unit)
-{
-    auto bus = sdbusplus::bus::new_default();
-    auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
-                                      SYSTEMD_INTERFACE, "RestartUnit");
-
-    method.append(unit, "replace");
-    bus.call_noreply(method);
-}
-
 /** @brief Get all the interfaces from the system.
  *  @returns list of interface names.
  */