NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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; -*- */
2 /*
3  * Copyright (c) 2013-2018 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_UTIL_SCHEDULER_HPP
23 #define NDN_UTIL_SCHEDULER_HPP
24 
25 #include "time.hpp"
26 #include "../net/asio-fwd.hpp"
27 
28 #include <boost/system/error_code.hpp>
29 #include "../common.hpp"
30 
31 #include "ns3/simulator.h"
32 
33 #include <set>
34 #include <boost/asio/io_service.hpp>
35 #include <set>
36 
37 namespace ndn {
38 namespace util {
39 
40 namespace detail {
41 class SteadyTimer;
42 } // namespace detail
43 
44 namespace scheduler {
45 
46 typedef function<void()> EventCallback;
47 
51 typedef std::shared_ptr<ns3::EventId> EventId;
52 
56 class Scheduler : noncopyable
57 {
58 public:
63 
64  explicit
65  Scheduler(DummyIoService& ioService);
66 
67  ~Scheduler();
68 
73  EventId
74  scheduleEvent(const time::nanoseconds& after, const Event& event);
75 
79  void
80  cancelEvent(const EventId& eventId);
81 
85  void
87 
88 private:
89  struct EventInfo
90  {
91  EventInfo(const time::nanoseconds& after, const Event& event);
92 
93  EventInfo(const time::steady_clock::TimePoint& when, const EventInfo& previousEvent);
94 
95  bool
96  operator <=(const EventInfo& other) const
97  {
98  return this->m_scheduledTime <= other.m_scheduledTime;
99  }
100 
101  bool
102  operator <(const EventInfo& other) const
103  {
104  return this->m_scheduledTime < other.m_scheduledTime;
105  }
106 
107  time::nanoseconds
108  expiresFromNow() const;
109 
110  time::steady_clock::TimePoint m_scheduledTime;
111  Event m_event;
112  mutable EventId m_eventId;
113  };
114 
115  typedef std::multiset<EventId> EventQueue;
116 
117  EventQueue m_events;
118  EventQueue::iterator m_scheduledEvent;
119 };
120 
121 } // namespace scheduler
122 
123 using util::scheduler::Scheduler;
124 
125 } // namespace util
126 
127 // for backwards compatibility
128 using util::scheduler::Scheduler;
130 
131 } // namespace ndn
132 
133 #endif // NDN_UTIL_SCHEDULER_HPP
function< void()> EventCallback
Definition: scheduler.hpp:46
time_point TimePoint
Definition: time.hpp:226
Copyright (c) 2011-2015 Regents of the University of California.
Scheduler(DummyIoService &ioService)
Definition: scheduler.cpp:49
EventId scheduleEvent(const time::nanoseconds &after, const Event &event)
Schedule a one-time event after the specified delay.
Definition: scheduler.cpp:60
bool operator<=(const Delegation &lhs, const Delegation &rhs)
Definition: delegation.cpp:43
void cancelEvent(const EventId &eventId)
Cancel a scheduled event.
Definition: scheduler.cpp:81
void cancelAllEvents()
Cancel all scheduled events.
Definition: scheduler.cpp:91
Table::const_iterator iterator
Definition: cs-internal.hpp:41
std::shared_ptr< ns3::EventId > EventId
Definition: scheduler.hpp:51
Opaque type (shared_ptr) representing ID of a scheduled event.
bool operator<(const Delegation &lhs, const Delegation &rhs)
Definition: delegation.cpp:36