NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
scheduler.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_UTIL_SCHEDULER_HPP
23 #define NDN_UTIL_SCHEDULER_HPP
24 
25 #include "../common.hpp"
27 
28 #include "ns3/simulator.h"
29 
30 #include <set>
31 
32 namespace ndn {
33 namespace util {
34 namespace scheduler {
35 
39 typedef std::shared_ptr<ns3::EventId> EventId;
40 
44 class Scheduler
45 {
46 public:
47  typedef function<void()> Event;
48 
49  Scheduler(boost::asio::io_service& ioService);
50 
51  ~Scheduler();
52 
57  EventId
58  scheduleEvent(const time::nanoseconds& after, const Event& event);
59 
63  void
64  cancelEvent(const EventId& eventId);
65 
69  void
71 
72 private:
73  struct EventInfo
74  {
75  EventInfo(const time::nanoseconds& after, const Event& event);
76 
77  EventInfo(const time::steady_clock::TimePoint& when, const EventInfo& previousEvent);
78 
79  bool
80  operator <=(const EventInfo& other) const
81  {
82  return this->m_scheduledTime <= other.m_scheduledTime;
83  }
84 
85  bool
86  operator <(const EventInfo& other) const
87  {
88  return this->m_scheduledTime < other.m_scheduledTime;
89  }
90 
91  time::nanoseconds
92  expiresFromNow() const;
93 
94  time::steady_clock::TimePoint m_scheduledTime;
95  Event m_event;
96  mutable EventId m_eventId;
97  };
98 
99  typedef std::multiset<EventId> EventQueue;
100 
101  EventQueue m_events;
102  EventQueue::iterator m_scheduledEvent;
103 };
104 
105 } // namespace scheduler
106 
108 
109 } // namespace util
110 
111 // for backwards compatibility
114 
115 } // namespace ndn
116 
117 #endif // NDN_UTIL_SCHEDULER_HPP
time_point TimePoint
Definition: time.hpp:108
Copyright (c) 2011-2015 Regents of the University of California.
EventId scheduleEvent(const time::nanoseconds &after, const Event &event)
Schedule one time event after the specified delay.
Definition: scheduler.cpp:85
void cancelEvent(const EventId &eventId)
Cancel scheduled event.
Definition: scheduler.cpp:106
void cancelAllEvents()
Cancel all scheduled events.
Definition: scheduler.cpp:116
Table::const_iterator iterator
Definition: cs-internal.hpp:41
std::shared_ptr< ns3::EventId > EventId
Definition: scheduler.hpp:39
Scheduler(boost::asio::io_service &ioService)
Definition: scheduler.cpp:74