diff options
| author | Ratan Gupta <ratagupt@in.ibm.com> | 2017-09-08 17:05:46 +0530 |
|---|---|---|
| committer | Ratan Gupta <ratagupt@in.ibm.com> | 2017-09-13 17:28:53 +0530 |
| commit | a54d8f8023a42555c549b3e60c1d45e5e2414559 (patch) | |
| tree | 00aa685bde1e8bfd3a65042b16c176806d1e02ab | |
| parent | 4f80c1a7273a7bfc376d2891d2200022f8b38c50 (diff) | |
| download | phosphor-networkd-a54d8f8023a42555c549b3e60c1d45e5e2414559.tar.gz phosphor-networkd-a54d8f8023a42555c549b3e60c1d45e5e2414559.zip | |
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>
| -rw-r--r-- | network_manager_main.cpp | 16 | ||||
| -rw-r--r-- | rtnetlink_server.cpp | 23 |
2 files changed, 32 insertions, 7 deletions
diff --git a/network_manager_main.cpp b/network_manager_main.cpp index 993efc7..7fa3b05 100644 --- a/network_manager_main.cpp +++ b/network_manager_main.cpp @@ -1,5 +1,7 @@ +#include "config.h" #include "network_manager.hpp" #include "rtnetlink_server.hpp" +#include "timer.hpp" #include <memory> @@ -13,6 +15,12 @@ namespace network { std::unique_ptr<phosphor::network::Manager> manager = nullptr; +std::unique_ptr<phosphor::network::Timer> refreshTimer = nullptr; + +void refreshObjects() +{ + manager->createChildObjects(); +} } //namespace network } //namespace phosphor @@ -21,6 +29,12 @@ int main(int argc, char *argv[]) { using namespace phosphor::logging; + std::function<void()> func( + std::bind(&phosphor::network::refreshObjects)); + + phosphor::network::refreshTimer = + std::make_unique<phosphor::network::Timer>(func); + auto bus = sdbusplus::bus::new_default(); // Need sd_event to watch for OCC device errors @@ -51,6 +65,6 @@ int main(int argc, char *argv[]) phosphor::network::manager->createChildObjects(); - return svr.run(); } + 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 @@ static int eventHandler(sd_event_source* es, int fd, uint32_t revents, 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 |

