[ndnSIM] daemon/common: Redirect event handling to NS-3 routines

Change-Id: I41ac04c4a276cdd6dfafbd29d3a06f74d30e0d03
diff --git a/daemon/common/global.cpp b/daemon/common/global.cpp
index c54f043..903aa65 100644
--- a/daemon/common/global.cpp
+++ b/daemon/common/global.cpp
@@ -27,64 +27,55 @@
 
 namespace nfd {
 
-static thread_local unique_ptr<boost::asio::io_service> g_ioService;
 static thread_local unique_ptr<Scheduler> g_scheduler;
-static boost::asio::io_service* g_mainIoService = nullptr;
-static boost::asio::io_service* g_ribIoService = nullptr;
 
-boost::asio::io_service&
+namespace detail {
+
+void
+SimulatorIo::post(const std::function<void()>& callback)
+{
+  getScheduler().schedule(0_s, callback);
+}
+
+void
+SimulatorIo::dispatch(const std::function<void()>& callback)
+{
+  getScheduler().schedule(0_s, callback);
+}
+
+} // namespace detail
+
+detail::SimulatorIo&
 getGlobalIoService()
 {
-  if (g_ioService == nullptr) {
-    g_ioService = make_unique<boost::asio::io_service>();
-  }
-  return *g_ioService;
+  static detail::SimulatorIo io;
+  return io;
+}
+
+detail::SimulatorIo&
+getMainIoService()
+{
+  static detail::SimulatorIo io;
+  return io;
+}
+
+detail::SimulatorIo&
+getRibIoService()
+{
+  static detail::SimulatorIo io;
+  return io;
 }
 
 Scheduler&
 getScheduler()
 {
   if (g_scheduler == nullptr) {
-    g_scheduler = make_unique<Scheduler>(getGlobalIoService());
+    static ndn::DummyIoService io;
+    g_scheduler = make_unique<Scheduler>(io);
   }
   return *g_scheduler;
 }
 
-#ifdef NFD_WITH_TESTS
-void
-resetGlobalIoService()
-{
-  g_scheduler.reset();
-  g_ioService.reset();
-}
-#endif
-
-boost::asio::io_service&
-getMainIoService()
-{
-  BOOST_ASSERT(g_mainIoService != nullptr);
-  return *g_mainIoService;
-}
-
-boost::asio::io_service&
-getRibIoService()
-{
-  BOOST_ASSERT(g_ribIoService != nullptr);
-  return *g_ribIoService;
-}
-
-void
-setMainIoService(boost::asio::io_service* mainIo)
-{
-  g_mainIoService = mainIo;
-}
-
-void
-setRibIoService(boost::asio::io_service* ribIo)
-{
-  g_ribIoService = ribIo;
-}
-
 void
 runOnMainIoService(const std::function<void()>& f)
 {
@@ -97,4 +88,10 @@
   getRibIoService().post(f);
 }
 
+void
+resetGlobalScheduler()
+{
+  g_scheduler.reset();
+}
+
 } // namespace nfd
diff --git a/daemon/common/global.hpp b/daemon/common/global.hpp
index ccc5160..1253370 100644
--- a/daemon/common/global.hpp
+++ b/daemon/common/global.hpp
@@ -29,9 +29,26 @@
 
 namespace nfd {
 
+namespace detail {
+
+/**
+ * @brief Simulator-based IO that implements a few interfaces from boost::asio::io_service
+ */
+class SimulatorIo
+{
+public:
+  void
+  post(const std::function<void()>& callback);
+
+  void
+  dispatch(const std::function<void()>& callback);
+};
+
+} // namespace detail
+
 /** \brief Returns the global io_service instance for the calling thread.
  */
-boost::asio::io_service&
+detail::SimulatorIo&
 getGlobalIoService();
 
 /** \brief Returns the global Scheduler instance for the calling thread.
@@ -39,18 +56,12 @@
 Scheduler&
 getScheduler();
 
-boost::asio::io_service&
+detail::SimulatorIo&
 getMainIoService();
 
-boost::asio::io_service&
+detail::SimulatorIo&
 getRibIoService();
 
-void
-setMainIoService(boost::asio::io_service* mainIo);
-
-void
-setRibIoService(boost::asio::io_service* ribIo);
-
 /** \brief Run a function on the main io_service instance.
  */
 void
@@ -61,14 +72,8 @@
 void
 runOnRibIoService(const std::function<void()>& f);
 
-#ifdef NFD_WITH_TESTS
-/** \brief Destroy the global io_service instance.
- *
- *  It will be recreated at the next invocation of getGlobalIoService().
- */
 void
-resetGlobalIoService();
-#endif
+resetGlobalScheduler();
 
 } // namespace nfd