Fix bug in scheduler (use proper context when dispatching the event)

Change-Id: I3fb96ba079d923c924cf391d50e66f4440076405
diff --git a/ndn-cxx/util/scheduler.cpp b/ndn-cxx/util/scheduler.cpp
index a93cb0c..b7b53a1 100644
--- a/ndn-cxx/util/scheduler.cpp
+++ b/ndn-cxx/util/scheduler.cpp
@@ -32,9 +32,10 @@
 class EventInfo : noncopyable
 {
 public:
-  EventInfo(time::nanoseconds after, EventCallback&& cb)
+  EventInfo(time::nanoseconds after, EventCallback&& cb, uint32_t context)
     : callback(std::move(cb))
     , expireTime(time::steady_clock::now() + after)
+    , context(context)
   {
   }
 
@@ -49,6 +50,7 @@
   Scheduler::EventQueue::const_iterator queueIt;
   time::steady_clock::TimePoint expireTime;
   bool isExpired = false;
+  uint32_t context = 0;
 };
 
 EventId::EventId(Scheduler& sched, weak_ptr<EventInfo> info)
@@ -103,7 +105,7 @@
 {
   BOOST_ASSERT(callback != nullptr);
 
-  auto i = m_queue.insert(make_shared<EventInfo>(after, std::move(callback)));
+  auto i = m_queue.insert(make_shared<EventInfo>(after, std::move(callback), ns3::Simulator::GetContext()));
   (*i)->queueIt = i;
 
   if (!m_isEventExecuting && i == m_queue.begin()) {
@@ -179,7 +181,12 @@
 
     m_queue.erase(head);
     info->isExpired = true;
-    info->callback();
+    if (ns3::Simulator::GetContext() == info->context) {
+      info->callback();
+    }
+    else {
+      ns3::Simulator::ScheduleWithContext(info->context, ns3::Seconds(0), ns3::MakeEvent(info->callback));
+    }
   }
 }