core: global io_service and scheduler

Scheduler and time are imported from ndn-cpp-dev.
Forwarder is using the new scheduler API.
Face system is not transitioned yet.

refs #1290

Change-Id: I5679cb50bbf9890a105f663b038f13951403c2b6
diff --git a/daemon/core/scheduler.hpp b/daemon/core/scheduler.hpp
index a8e60bb..6ba4f80 100644
--- a/daemon/core/scheduler.hpp
+++ b/daemon/core/scheduler.hpp
@@ -7,95 +7,46 @@
 #ifndef NFD_CORE_SCHEDULER_HPP
 #define NFD_CORE_SCHEDULER_HPP
 
-#include "common.hpp"
-#include "monotonic_deadline_timer.hpp"
+#include "global-io.hpp"
+#include "time.hpp"
+#include <ndn-cpp-dev/util/scheduler.hpp>
 
 namespace nfd {
+namespace scheduler {
 
-struct EventIdImpl; ///< \brief Private storage of information about the event
-/**
- * \brief Opaque type (shared_ptr) representing ID of the scheduled event
- */
-typedef shared_ptr<EventIdImpl> EventId;
+using ndn::Scheduler;
 
-/**
- * \brief Generic scheduler
+/** \class EventId
+ *  \brief Opaque type (shared_ptr) representing ID of a scheduled event
  */
-class Scheduler
+using ndn::EventId;
+
+} // namespace scheduler
+
+// TODO delete this after transition
+using scheduler::Scheduler;
+
+using scheduler::EventId;
+
+namespace scheduler {
+
+// TODO delete this after transition
+Scheduler&
+getGlobalScheduler();
+
+inline EventId
+schedule(const time::Duration& after, const Scheduler::Event& event)
 {
-public:
-  typedef function<void()> Event;
+  return getGlobalScheduler().scheduleEvent(after, event);
+}
 
-  Scheduler(boost::asio::io_service& ioService);
+inline void
+cancel(const EventId& eventId)
+{
+  getGlobalScheduler().cancelEvent(eventId);
+}
 
-  /**
-   * \brief Schedule one time event after the specified delay
-   * \returns EventId that can be used to cancel the scheduled event
-   */
-  EventId
-  scheduleEvent(const time::Duration& after, const Event& event);
-
-  /**
-   * \brief Schedule periodic event that should be fired every specified period.
-   *        First event will be fired after the specified delay.
-   * \returns EventId that can be used to cancel the scheduled event
-   */
-  EventId
-  schedulePeriodicEvent(const time::Duration& after,
-                        const time::Duration& period,
-                        const Event& event);
-  
-  /**
-   * \brief Cancel scheduled event
-   */
-  void
-  cancelEvent(const EventId& eventId);
-
-private:
-  void
-  onEvent(const boost::system::error_code& code);
-  
-private:
-  boost::asio::io_service& m_ioService;
-
-  struct EventInfo
-  {
-    EventInfo(const time::Duration& after,
-              const time::Duration& period,
-              const Event& event);
-    EventInfo(const time::Point& when, const EventInfo& previousEvent);
-
-    bool
-    operator <=(const EventInfo& other) const
-    {
-      return this->m_scheduledTime <= other.m_scheduledTime;
-    }
-
-    bool
-    operator <(const EventInfo& other) const
-    {
-      return this->m_scheduledTime < other.m_scheduledTime;
-    }
-
-    time::Duration
-    expiresFromNow() const;
-    
-    time::Point m_scheduledTime;
-    time::Duration m_period;
-    Event m_event;
-    mutable EventId m_eventId;
-  };
-
-  typedef std::multiset<EventInfo> EventQueue;
-  friend struct EventIdImpl;
-
-  EventQueue m_events;
-  EventQueue::iterator m_scheduledEvent;
-  boost::asio::monotonic_deadline_timer m_deadlineTimer;
-
-  bool m_isEventExecuting;
-};
-
+} // namespace scheduler
 } // namespace nfd
 
 #endif // NFD_CORE_SCHEDULER_HPP