A Discrete-Event Network Simulator
API
scheduler.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #ifndef SCHEDULER_H
22 #define SCHEDULER_H
23 
24 #include <stdint.h>
25 #include "object.h"
26 
35 namespace ns3 {
36 
37 class EventImpl;
38 
66 class Scheduler : public Object
67 {
68 public:
69  static TypeId GetTypeId (void);
70 
75  struct EventKey
76  {
77  uint64_t m_ts;
78  uint32_t m_uid;
79  uint32_t m_context;
80  };
88  struct Event
89  {
92  };
93 
94  virtual ~Scheduler () = 0;
95 
99  virtual void Insert (const Event &ev) = 0;
103  virtual bool IsEmpty (void) const = 0;
110  virtual Event PeekNext (void) const = 0;
115  virtual Event RemoveNext (void) = 0;
121  virtual void Remove (const Event &ev) = 0;
122 };
123 
124 /* Note the invariants which this function must provide:
125  * - irreflexibility: f (x,x) is false)
126  * - antisymmetry: f(x,y) = !f(y,x)
127  * - transitivity: f(x,y) and f(y,z) => f(x,z)
128  */
129 inline bool operator < (const Scheduler::EventKey &a, const Scheduler::EventKey &b)
130 {
131  if (a.m_ts < b.m_ts)
132  {
133  return true;
134  }
135  else if (a.m_ts == b.m_ts
136  && a.m_uid < b.m_uid)
137  {
138  return true;
139  }
140  else
141  {
142  return false;
143  }
144 }
145 inline bool operator != (const Scheduler::EventKey &a, const Scheduler::EventKey &b)
146 {
147  return a.m_uid != b.m_uid;
148 }
149 inline bool operator > (const Scheduler::EventKey &a, const Scheduler::EventKey &b)
150 {
151  if (a.m_ts > b.m_ts)
152  {
153  return true;
154  }
155  else if (a.m_ts == b.m_ts
156  && a.m_uid > b.m_uid)
157  {
158  return true;
159  }
160  else
161  {
162  return false;
163  }
164 }
165 
166 
167 
168 inline bool operator < (const Scheduler::Event &a, const Scheduler::Event &b)
169 {
170  return a.key < b.key;
171 }
172 
173 
174 } // namespace ns3
175 
176 
177 #endif /* SCHEDULER_H */
virtual Event PeekNext(void) const =0
uint64_t m_ts
Event time stamp.
Definition: scheduler.h:77
EventImpl * impl
Pointer to the event implementation.
Definition: scheduler.h:90
virtual bool IsEmpty(void) const =0
virtual Event RemoveNext(void)=0
This method cannot be invoked if the list is empty.
virtual void Remove(const Event &ev)=0
EventKey key
Key for sorting and ordering Events.
Definition: scheduler.h:91
uint32_t m_uid
Event unique id.
Definition: scheduler.h:78
virtual void Insert(const Event &ev)=0
static TypeId GetTypeId(void)
Definition: scheduler.cc:43
Maintain the event list.
Definition: scheduler.h:66
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:350
Scheduler event.
Definition: scheduler.h:88
bool operator!=(Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > a, Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > b)
Inequality test.
Definition: callback.h:1272
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
A simulation event.
Definition: event-impl.h:44
virtual ~Scheduler()=0
Definition: scheduler.cc:37
bool operator>(const int64x64_t &lhs, const int64x64_t &rhs)
Greater operator.
Definition: int64x64-128.h:358
Structure for sorting and comparing Events.
Definition: scheduler.h:75
A base class which provides memory management and object aggregation.
Definition: object.h:87
a unique identifier for an interface.
Definition: type-id.h:51
uint32_t m_context
Event context.
Definition: scheduler.h:79