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 
58 class Scheduler : public Object
59 {
60 public:
61  static TypeId GetTypeId (void);
62 
64  struct EventKey
65  {
66  uint64_t m_ts;
67  uint32_t m_uid;
68  uint32_t m_context;
69  };
71  struct Event
72  {
75  };
76 
77  virtual ~Scheduler () = 0;
78 
82  virtual void Insert (const Event &ev) = 0;
86  virtual bool IsEmpty (void) const = 0;
93  virtual Event PeekNext (void) const = 0;
98  virtual Event RemoveNext (void) = 0;
104  virtual void Remove (const Event &ev) = 0;
105 };
106 
107 /* Note the invariants which this function must provide:
108  * - irreflexibility: f (x,x) is false)
109  * - antisymmetry: f(x,y) = !f(y,x)
110  * - transitivity: f(x,y) and f(y,z) => f(x,z)
111  */
112 inline bool operator < (const Scheduler::EventKey &a, const Scheduler::EventKey &b)
113 {
114  if (a.m_ts < b.m_ts)
115  {
116  return true;
117  }
118  else if (a.m_ts == b.m_ts
119  && a.m_uid < b.m_uid)
120  {
121  return true;
122  }
123  else
124  {
125  return false;
126  }
127 }
128 inline bool operator != (const Scheduler::EventKey &a, const Scheduler::EventKey &b)
129 {
130  return a.m_uid != b.m_uid;
131 }
132 inline bool operator > (const Scheduler::EventKey &a, const Scheduler::EventKey &b)
133 {
134  if (a.m_ts > b.m_ts)
135  {
136  return true;
137  }
138  else if (a.m_ts == b.m_ts
139  && a.m_uid > b.m_uid)
140  {
141  return true;
142  }
143  else
144  {
145  return false;
146  }
147 }
148 
149 
150 
151 inline bool operator < (const Scheduler::Event &a, const Scheduler::Event &b)
152 {
153  return a.key < b.key;
154 }
155 
156 
157 } // namespace ns3
158 
159 
160 #endif /* SCHEDULER_H */
virtual Event PeekNext(void) const =0
EventImpl * impl
Definition: scheduler.h:73
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
virtual void Insert(const Event &ev)=0
static TypeId GetTypeId(void)
Definition: scheduler.cc:37
Maintain the event list.
Definition: scheduler.h:58
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:327
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:1217
a simulation event
Definition: event-impl.h:39
virtual ~Scheduler()=0
Definition: scheduler.cc:31
bool operator>(const int64x64_t &lhs, const int64x64_t &rhs)
Greater operator.
Definition: int64x64-128.h:335
a base class which provides memory management and object aggregation
Definition: object.h:64
a unique identifier for an interface.
Definition: type-id.h:49