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
35namespace ns3 {
36
37class EventImpl;
38
155class Scheduler : public Object
156{
157public:
162 static TypeId GetTypeId (void);
163
168 struct EventKey
169 {
170 uint64_t m_ts;
173 };
181 struct Event
182 {
185 };
186
188 virtual ~Scheduler () = 0;
189
195 virtual void Insert (const Event &ev) = 0;
201 virtual bool IsEmpty (void) const = 0;
210 virtual Event PeekNext (void) const = 0;
218 virtual Event RemoveNext (void) = 0;
226 virtual void Remove (const Event &ev) = 0;
227};
228
238 const Scheduler::EventKey &b)
239{
240 return a.m_uid == b.m_uid;
241}
242
252 const Scheduler::EventKey &b)
253{
254 return a.m_uid != b.m_uid;
255}
256
270inline bool operator < (const Scheduler::EventKey &a,
271 const Scheduler::EventKey &b)
272{
273 if (a.m_ts < b.m_ts)
274 {
275 return true;
276 }
277 else if (a.m_ts == b.m_ts
278 && a.m_uid < b.m_uid)
279 {
280 return true;
281 }
282 else
283 {
284 return false;
285 }
286}
287
295inline bool operator > (const Scheduler::EventKey &a,
296 const Scheduler::EventKey &b)
297{
298 if (a.m_ts > b.m_ts)
299 {
300 return true;
301 }
302 else if (a.m_ts == b.m_ts
303 && a.m_uid > b.m_uid)
304 {
305 return true;
306 }
307 else
308 {
309 return false;
310 }
311}
312
320inline bool operator == (const Scheduler::Event &a,
321 const Scheduler::Event &b)
322{
323 return a.key == b.key;
324}
325
333inline bool operator != (const Scheduler::Event &a,
334 const Scheduler::Event &b)
335{
336 return a.key != b.key;
337}
338
346inline bool operator < (const Scheduler::Event &a,
347 const Scheduler::Event &b)
348{
349 return a.key < b.key;
350}
351
359inline bool operator > (const Scheduler::Event &a,
360 const Scheduler::Event &b)
361{
362 return a.key > b.key;
363}
364
365
366} // namespace ns3
367
368
369#endif /* SCHEDULER_H */
A simulation event.
Definition: event-impl.h:45
A base class which provides memory management and object aggregation.
Definition: object.h:88
Maintain the event list.
Definition: scheduler.h:156
static TypeId GetTypeId(void)
Register this type.
Definition: scheduler.cc:43
virtual void Remove(const Event &ev)=0
Remove a specific event from the event list.
virtual bool IsEmpty(void) const =0
Test if the schedule is empty.
virtual Event PeekNext(void) const =0
Get a pointer to the next event.
virtual ~Scheduler()=0
Destructor.
Definition: scheduler.cc:37
virtual void Insert(const Event &ev)=0
Insert a new Event in the schedule.
virtual Event RemoveNext(void)=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:413
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:636
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:158
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:176
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
Scheduler event.
Definition: scheduler.h:182
EventKey key
Key for sorting and ordering Events.
Definition: scheduler.h:184
EventImpl * impl
Pointer to the event implementation.
Definition: scheduler.h:183
Structure for sorting and comparing Events.
Definition: scheduler.h:169
uint32_t m_context
Event context.
Definition: scheduler.h:172
uint64_t m_ts
Event time stamp.
Definition: scheduler.h:170
uint32_t m_uid
Event unique id.
Definition: scheduler.h:171