NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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 : noncopyable
45 {
46 public:
50  typedef function<void()> Event;
51 
52  explicit
53  Scheduler(boost::asio::io_service& ioService);
54 
55  ~Scheduler();
56 
61  EventId
62  scheduleEvent(const time::nanoseconds& after, const Event& event);
63 
67  void
68  cancelEvent(const EventId& eventId);
69 
73  void
75 
76 private:
77  struct EventInfo
78  {
79  EventInfo(const time::nanoseconds& after, const Event& event);
80 
81  EventInfo(const time::steady_clock::TimePoint& when, const EventInfo& previousEvent);
82 
83  bool
84  operator <=(const EventInfo& other) const
85  {
86  return this->m_scheduledTime <= other.m_scheduledTime;
87  }
88 
89  bool
90  operator <(const EventInfo& other) const
91  {
92  return this->m_scheduledTime < other.m_scheduledTime;
93  }
94 
95  time::nanoseconds
96  expiresFromNow() const;
97 
98  time::steady_clock::TimePoint m_scheduledTime;
99  Event m_event;
100  mutable EventId m_eventId;
101  };
102 
103  typedef std::multiset<EventId> EventQueue;
104 
105  EventQueue m_events;
106  EventQueue::iterator m_scheduledEvent;
107 };
108 
109 } // namespace scheduler
110 
112 
113 } // namespace util
114 
115 // for backwards compatibility
118 
119 } // namespace ndn
120 
121 #endif // NDN_UTIL_SCHEDULER_HPP
time_point TimePoint
Definition: time.hpp:120
Copyright (c) 2011-2015 Regents of the University of California.
EventId scheduleEvent(const time::nanoseconds &after, const Event &event)
Schedule a one-time event after the specified delay.
Definition: scheduler.cpp:58
void cancelEvent(const EventId &eventId)
Cancel a scheduled event.
Definition: scheduler.cpp:79
void cancelAllEvents()
Cancel all scheduled events.
Definition: scheduler.cpp:89
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:47
constexpr bool operator<(const optional< T > &lhs, const optional< T > &rhs)
constexpr bool operator<=(const optional< T > &lhs, const optional< T > &rhs)