A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
scheduler.h
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 
53 class Scheduler : public Object
54 {
55 public:
56  static TypeId GetTypeId (void);
57 
58  struct EventKey
59  {
60  uint64_t m_ts;
61  uint32_t m_uid;
62  uint32_t m_context;
63  };
64  struct Event
65  {
66  EventImpl *impl;
67  EventKey key;
68  };
69 
70  virtual ~Scheduler () = 0;
71 
75  virtual void Insert (const Event &ev) = 0;
79  virtual bool IsEmpty (void) const = 0;
86  virtual Event PeekNext (void) const = 0;
91  virtual Event RemoveNext (void) = 0;
97  virtual void Remove (const Event &ev) = 0;
98 };
99 
100 /* Note the invariants which this function must provide:
101  * - irreflexibility: f (x,x) is false)
102  * - antisymmetry: f(x,y) = !f(y,x)
103  * - transitivity: f(x,y) and f(y,z) => f(x,z)
104  */
105 inline bool operator < (const Scheduler::EventKey &a, const Scheduler::EventKey &b)
106 {
107  if (a.m_ts < b.m_ts)
108  {
109  return true;
110  }
111  else if (a.m_ts == b.m_ts
112  && a.m_uid < b.m_uid)
113  {
114  return true;
115  }
116  else
117  {
118  return false;
119  }
120 }
121 inline bool operator != (const Scheduler::EventKey &a, const Scheduler::EventKey &b)
122 {
123  return a.m_uid != b.m_uid;
124 }
125 inline bool operator > (const Scheduler::EventKey &a, const Scheduler::EventKey &b)
126 {
127  if (a.m_ts > b.m_ts)
128  {
129  return true;
130  }
131  else if (a.m_ts == b.m_ts
132  && a.m_uid > b.m_uid)
133  {
134  return true;
135  }
136  else
137  {
138  return false;
139  }
140 }
141 
142 
143 
144 inline bool operator < (const Scheduler::Event &a, const Scheduler::Event &b)
145 {
146  return a.key < b.key;
147 }
148 
149 
150 } // namespace ns3
151 
152 
153 #endif /* SCHEDULER_H */
virtual Event PeekNext(void) const =0
virtual bool IsEmpty(void) const =0
virtual Event RemoveNext(void)=0
virtual void Remove(const Event &ev)=0
virtual void Insert(const Event &ev)=0
Maintain the event list.
Definition: scheduler.h:53
a simulation event
Definition: event-impl.h:39
a base class which provides memory management and object aggregation
Definition: object.h:63
a unique identifier for an interface.
Definition: type-id.h:44