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:
73  static TypeId GetTypeId (void);
74 
79  struct EventKey
80  {
81  uint64_t m_ts;
82  uint32_t m_uid;
83  uint32_t m_context;
84  };
92  struct Event
93  {
96  };
97 
99  virtual ~Scheduler () = 0;
100 
106  virtual void Insert (const Event &ev) = 0;
112  virtual bool IsEmpty (void) const = 0;
121  virtual Event PeekNext (void) const = 0;
129  virtual Event RemoveNext (void) = 0;
137  virtual void Remove (const Event &ev) = 0;
138 };
139 
153 inline bool operator < (const Scheduler::EventKey &a,
154  const Scheduler::EventKey &b)
155 {
156  if (a.m_ts < b.m_ts)
157  {
158  return true;
159  }
160  else if (a.m_ts == b.m_ts
161  && a.m_uid < b.m_uid)
162  {
163  return true;
164  }
165  else
166  {
167  return false;
168  }
169 }
170 
179 inline bool operator != (const Scheduler::EventKey &a,
180  const Scheduler::EventKey &b)
181 {
182  return a.m_uid != b.m_uid;
183 }
184 
192 inline bool operator > (const Scheduler::EventKey &a,
193  const Scheduler::EventKey &b)
194 {
195  if (a.m_ts > b.m_ts)
196  {
197  return true;
198  }
199  else if (a.m_ts == b.m_ts
200  && a.m_uid > b.m_uid)
201  {
202  return true;
203  }
204  else
205  {
206  return false;
207  }
208 }
209 
217 inline bool operator < (const Scheduler::Event &a,
218  const Scheduler::Event &b)
219 {
220  return a.key < b.key;
221 }
222 
223 
224 } // namespace ns3
225 
226 
227 #endif /* SCHEDULER_H */
virtual Event PeekNext(void) const =0
Get a pointer to the next event.
uint64_t m_ts
Event time stamp.
Definition: scheduler.h:81
EventImpl * impl
Pointer to the event implementation.
Definition: scheduler.h:94
virtual bool IsEmpty(void) const =0
Test if the schedule is empty.
virtual Event RemoveNext(void)=0
Remove the earliest event from the event list.
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:153
virtual void Remove(const Event &ev)=0
Remove a specific event from the event list.
EventKey key
Key for sorting and ordering Events.
Definition: scheduler.h:95
uint32_t m_uid
Event unique id.
Definition: scheduler.h:82
virtual void Insert(const Event &ev)=0
Insert a new Event in the schedule.
static TypeId GetTypeId(void)
Register this type.
Definition: scheduler.cc:43
Maintain the event list.
Definition: scheduler.h:66
Scheduler event.
Definition: scheduler.h:92
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:1471
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
Destructor.
Definition: scheduler.cc:37
bool operator>(const int64x64_t &lhs, const int64x64_t &rhs)
Greater operator.
Definition: int64x64-128.h:364
Structure for sorting and comparing Events.
Definition: scheduler.h:79
A base class which provides memory management and object aggregation.
Definition: object.h:87
a unique identifier for an interface.
Definition: type-id.h:58
uint32_t m_context
Event context.
Definition: scheduler.h:83