Recreate the network objects once the timer expires

As we get multiple network change events once systemd-
networkd starts,This commit starts the timer once it
gets the network change event and refresh the network
objects once the timer expires.

Change-Id: I86d1547763d03f527a8bdb04e2b2780f6cd6fdc2
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/rtnetlink_server.cpp b/rtnetlink_server.cpp
index d3cac19..8e636a1 100644
--- a/rtnetlink_server.cpp
+++ b/rtnetlink_server.cpp
@@ -1,5 +1,5 @@
-#include "xyz/openbmc_project/Common/error.hpp"
 #include "rtnetlink_server.hpp"
+#include "timer.hpp"
 #include "types.hpp"
 #include "util.hpp"
 
@@ -13,18 +13,22 @@
 #include <unistd.h>
 
 #include <phosphor-logging/log.hpp>
-#include <phosphor-logging/elog-errors.hpp>
 
 #include <memory>
-#include <iostream>
 
 namespace phosphor
 {
 namespace network
 {
+
+extern std::unique_ptr<phosphor::network::Timer> refreshTimer;
+
 namespace rtnetlink
 {
 
+using namespace std::chrono_literals;
+constexpr auto networkChangeTimeout = 1s; //seconds
+
 /* Call Back for the sd event loop */
 static int eventHandler(sd_event_source* es, int fd, uint32_t revents,
                         void* userdata)
@@ -43,9 +47,16 @@
             if (netLinkHeader->nlmsg_type == RTM_NEWADDR ||
                 netLinkHeader->nlmsg_type == RTM_DELADDR)
             {
-                // TODO delete the below trace in later commit.
-                std::cout << "Address Changed\n";
-
+                // starting the timer here to make sure that we don't want
+                // create the child objects multiple times.
+                if (refreshTimer->isExpired())
+                {
+                    using namespace std::chrono;
+                    auto time = duration_cast<microseconds>(networkChangeTimeout);
+                    // if start timer throws exception then let the application
+                    // crash
+                    refreshTimer->startTimer(time);
+                } // end if
             } // end if
 
         } // end for