A Discrete-Event Network Simulator
API
scheduler.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 
20 #ifndef SCHEDULER_H
21 #define SCHEDULER_H
22 
23 #include "object.h"
24 
25 #include <stdint.h>
26 
35 namespace ns3
36 {
37 
38 class EventImpl;
39 
156 class Scheduler : public Object
157 {
158  public:
163  static TypeId GetTypeId();
164 
169  struct EventKey
170  {
171  uint64_t m_ts;
172  uint32_t m_uid;
173  uint32_t m_context;
174  };
175 
183  struct Event
184  {
187  };
188 
190  ~Scheduler() override = 0;
191 
197  virtual void Insert(const Event& ev) = 0;
203  virtual bool IsEmpty() const = 0;
212  virtual Event PeekNext() const = 0;
220  virtual Event RemoveNext() = 0;
228  virtual void Remove(const Event& ev) = 0;
229 };
230 
239 inline bool
241 {
242  return a.m_uid == b.m_uid;
243 }
244 
253 inline bool
255 {
256  return a.m_uid != b.m_uid;
257 }
258 
272 inline bool
274 {
275  if (a.m_ts < b.m_ts)
276  {
277  return true;
278  }
279  else if (a.m_ts == b.m_ts && a.m_uid < b.m_uid)
280  {
281  return true;
282  }
283  else
284  {
285  return false;
286  }
287 }
288 
296 inline bool
298 {
299  if (a.m_ts > b.m_ts)
300  {
301  return true;
302  }
303  else if (a.m_ts == b.m_ts && a.m_uid > b.m_uid)
304  {
305  return true;
306  }
307  else
308  {
309  return false;
310  }
311 }
312 
320 inline bool
322 {
323  return a.key == b.key;
324 }
325 
333 inline bool
335 {
336  return a.key != b.key;
337 }
338 
346 inline bool
347 operator<(const Scheduler::Event& a, const Scheduler::Event& b)
348 {
349  return a.key < b.key;
350 }
351 
359 inline bool
361 {
362  return a.key > b.key;
363 }
364 
365 } // namespace ns3
366 
367 #endif /* SCHEDULER_H */
A simulation event.
Definition: event-impl.h:46
A base class which provides memory management and object aggregation.
Definition: object.h:89
Maintain the event list.
Definition: scheduler.h:157
~Scheduler() override=0
Destructor.
Definition: scheduler.cc:38
virtual bool IsEmpty() const =0
Test if the schedule is empty.
static TypeId GetTypeId()
Register this type.
Definition: scheduler.cc:44
virtual void Remove(const Event &ev)=0
Remove a specific event from the event list.
virtual Event PeekNext() const =0
Get a pointer to the next event.
virtual void Insert(const Event &ev)=0
Insert a new Event in the schedule.
virtual Event RemoveNext()=0
Remove the earliest event from the event list.
a unique identifier for an interface.
Definition: type-id.h:59
bool operator>(const Length &left, const Length &right)
Check if left has a value greater than right.
Definition: length.cc:421
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition: callback.h:678
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
Scheduler event.
Definition: scheduler.h:184
EventKey key
Key for sorting and ordering Events.
Definition: scheduler.h:186
EventImpl * impl
Pointer to the event implementation.
Definition: scheduler.h:185
Structure for sorting and comparing Events.
Definition: scheduler.h:170
uint32_t m_context
Event context.
Definition: scheduler.h:173
uint64_t m_ts
Event time stamp.
Definition: scheduler.h:171
uint32_t m_uid
Event unique id.
Definition: scheduler.h:172