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 
36 struct EventIdImpl;
37 
41 typedef std::shared_ptr<ns3::EventId> EventId;
42 
46 class Scheduler
47 {
48 public:
49  typedef function<void()> Event;
50 
51  Scheduler(boost::asio::io_service& ioService);
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  friend struct EventIdImpl;
101 
102  EventQueue m_events;
103  EventQueue::iterator m_scheduledEvent;
104 };
105 
106 } // namespace scheduler
107 
109 
110 } // namespace util
111 
112 // for backwards compatibility
115 
116 } // namespace ndn
117 
118 #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:117
void cancelEvent(const EventId &eventId)
Cancel scheduled event.
Definition: scheduler.cpp:128
void cancelAllEvents()
Cancel all scheduled events.
Definition: scheduler.cpp:138
Table::const_iterator iterator
Definition: cs-internal.hpp:41
std::shared_ptr< ns3::EventId > EventId
Definition: scheduler.hpp:41
Scheduler(boost::asio::io_service &ioService)
Definition: scheduler.cpp:111