A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
27 namespace ns3 {
28 
29 class EventImpl;
30 
57 class Scheduler : public Object
58 {
59 public:
60  static TypeId GetTypeId (void);
61 
63  struct EventKey
64  {
65  uint64_t m_ts;
66  uint32_t m_uid;
67  uint32_t m_context;
68  };
70  struct Event
71  {
74  };
75 
76  virtual ~Scheduler () = 0;
77 
81  virtual void Insert (const Event &ev) = 0;
85  virtual bool IsEmpty (void) const = 0;
92  virtual Event PeekNext (void) const = 0;
97  virtual Event RemoveNext (void) = 0;
103  virtual void Remove (const Event &ev) = 0;
104 };
105 
106 /* Note the invariants which this function must provide:
107  * - irreflexibility: f (x,x) is false)
108  * - antisymmetry: f(x,y) = !f(y,x)
109  * - transitivity: f(x,y) and f(y,z) => f(x,z)
110  */
111 inline bool operator < (const Scheduler::EventKey &a, const Scheduler::EventKey &b)
112 {
113  if (a.m_ts < b.m_ts)
114  {
115  return true;
116  }
117  else if (a.m_ts == b.m_ts
118  && a.m_uid < b.m_uid)
119  {
120  return true;
121  }
122  else
123  {
124  return false;
125  }
126 }
127 inline bool operator != (const Scheduler::EventKey &a, const Scheduler::EventKey &b)
128 {
129  return a.m_uid != b.m_uid;
130 }
131 inline bool operator > (const Scheduler::EventKey &a, const Scheduler::EventKey &b)
132 {
133  if (a.m_ts > b.m_ts)
134  {
135  return true;
136  }
137  else if (a.m_ts == b.m_ts
138  && a.m_uid > b.m_uid)
139  {
140  return true;
141  }
142  else
143  {
144  return false;
145  }
146 }
147 
148 
149 
150 inline bool operator < (const Scheduler::Event &a, const Scheduler::Event &b)
151 {
152  return a.key < b.key;
153 }
154 
155 
156 } // namespace ns3
157 
158 
159 #endif /* SCHEDULER_H */
virtual Event PeekNext(void) const =0
EventImpl * impl
Definition: scheduler.h:72
bool operator>(const Time &lhs, const Time &rhs)
Definition: nstime.h:645
virtual bool IsEmpty(void) const =0
bool operator<(const Room &a, const Room &b)
virtual Event RemoveNext(void)=0
This method cannot be invoked if the list is empty.
virtual void Remove(const Event &ev)=0
virtual void Insert(const Event &ev)=0
static TypeId GetTypeId(void)
Definition: scheduler.cc:38
Maintain the event list.
Definition: scheduler.h:57
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:1213
a simulation event
Definition: event-impl.h:39
virtual ~Scheduler()=0
Definition: scheduler.cc:32
a base class which provides memory management and object aggregation
Definition: object.h:63
a unique identifier for an interface.
Definition: type-id.h:49