[ndnSIM] core: Make use of scheduler redirection from ndn-cxx library (avoid code duplication)

Change-Id: I238dff4f25f07cdd05f96714c3dbeca01327c26d
diff --git a/core/scheduler.cpp b/core/scheduler.cpp
index 504a53c..725f81a 100644
--- a/core/scheduler.cpp
+++ b/core/scheduler.cpp
@@ -24,43 +24,41 @@
  */
 
 #include "scheduler.hpp"
+#include "global-io.hpp"
 
-namespace ns3 {
-
-/// @cond include_hidden
-
-template<>
-struct EventMemberImplObjTraits<std::function<void()>> {
-  typedef std::function<void()> T;
-  static T&
-  GetReference(T& p)
-  {
-    return p;
-  }
-};
-
-/// @endcond
-
-} // namespace ns3
+#include <boost/thread/tss.hpp>
 
 namespace nfd {
 namespace scheduler {
 
-EventId
-schedule(const time::nanoseconds& after, const std::function<void()>& event)
+static boost::thread_specific_ptr<Scheduler> g_scheduler;
+
+Scheduler&
+getGlobalScheduler()
 {
-  ns3::EventId id = ns3::Simulator::Schedule(ns3::NanoSeconds(after.count()),
-                                             &std::function<void()>::operator(), event);
-  return std::make_shared<ns3::EventId>(id);
+  if (g_scheduler.get() == nullptr) {
+    g_scheduler.reset(new Scheduler(*static_cast<boost::asio::io_service*>(nullptr)));
+  }
+
+  return *g_scheduler;
+}
+
+EventId
+schedule(const time::nanoseconds& after, const Scheduler::Event& event)
+{
+  return getGlobalScheduler().scheduleEvent(after, event);
 }
 
 void
 cancel(const EventId& eventId)
 {
-  if (eventId != nullptr) {
-    ns3::Simulator::Remove(*eventId);
-    const_cast<EventId&>(eventId).reset();
-  }
+  getGlobalScheduler().cancelEvent(eventId);
+}
+
+void
+resetGlobalScheduler()
+{
+  g_scheduler.reset();
 }
 
 ScopedEventId::ScopedEventId()