A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
event-id.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#ifndef EVENT_ID_H
20#define EVENT_ID_H
21
22#include "event-impl.h"
23#include "ptr.h"
24
25#include <stdint.h>
26
27/**
28 * \file
29 * \ingroup events
30 * ns3::EventId declarations.
31 */
32
33namespace ns3
34{
35
36class EventImpl;
37
38/**
39 * \ingroup events
40 * \brief An identifier for simulation events.
41 *
42 * Each EventId identifies a unique event scheduled with one
43 * of the many Simulator::Schedule() methods. This EventId can
44 * be used to cancel or remove events after they are scheduled
45 * with Cancel(), Remove(), or Simulator::Cancel() or Simulator::Remove().
46 *
47 * The important thing to remember about this class is that
48 * every variable of this type is _always_ in a valid state,
49 * even when it has not been assigned an EventId coming from a
50 * Simulator::Schedule() method: calling Simulator::Cancel(), IsRunning(),
51 * IsExpired() or passing around instances of this object
52 * will not result in crashes or memory leaks.
53 */
55{
56 public:
57 /** Special values of the event UID. */
58 enum UID
59 {
60 /** Invalid UID value. */
62 /** ScheduleNow() events. */
63 NOW = 1,
64 /** ScheduleDestroy() events. */
66 /** Reserved UID. */
68 /** Schedule(), etc. events. */
69 VALID = 4
70 };
71
72 /** Default constructor. This EventId does nothing. */
73 EventId();
74 /**
75 * Construct a real event.
76 *
77 * \param [in] impl The implementation of this event.
78 * \param [in] ts The virtual time stamp this event should occur.
79 * \param [in] context The execution context for this event.
80 * \param [in] uid The unique id for this EventId.
81 */
82 EventId(const Ptr<EventImpl>& impl, uint64_t ts, uint32_t context, uint32_t uid);
83 /**
84 * This method is syntactic sugar for the ns3::Simulator::Cancel
85 * method.
86 */
87 void Cancel();
88 /**
89 * This method is syntactic sugar for the ns3::Simulator::Remove
90 * method.
91 */
92 void Remove();
93 /**
94 * This method is syntactic sugar for the ns3::Simulator::IsExpired
95 * method.
96 * \returns \c true if the event has expired, \c false otherwise.
97 */
98 bool IsExpired() const;
99 /**
100 * This method is syntactic sugar for !IsExpired().
101 *
102 * \returns \c true if the event has not expired, \c false otherwise.
103 */
104 bool IsRunning() const;
105
106 public:
107 /**
108 * \name Scheduler Helpers.
109 * \brief These methods are normally invoked only by
110 * subclasses of the Scheduler base class.
111 */
112 /**@{*/
113 /** \return The underlying EventImpl pointer. */
114 EventImpl* PeekEventImpl() const;
115 /** \return The virtual time stamp. */
116 uint64_t GetTs() const;
117 /** \return The event context. */
118 uint32_t GetContext() const;
119 /** \return The unique id. */
120 uint32_t GetUid() const;
121 /**@}*/
122
123 /**
124 * Test if two EventId's are equal.
125 * \param [in] a The first EventId.
126 * \param [in] b The second EventId.
127 * \return \c true if the \pname{a} and \pname{b} represent the same event.
128 */
129 friend bool operator==(const EventId& a, const EventId& b);
130 /**
131 * Test if two EventId's are not equal.
132 * \param [in] a The first EventId.
133 * \param [in] b The second EventId.
134 * \return \c true if the \pname{a} and \pname{b} are not the same event.
135 */
136 friend bool operator!=(const EventId& a, const EventId& b);
137 /**
138 * Less than operator for two EventId's, based on time stamps.
139 * \param [in] a The first EventId.
140 * \param [in] b The second EventId.
141 * \return \c true if \pname{a} occurs before \pname{b}.
142 */
143 friend bool operator<(const EventId& a, const EventId& b);
144
145 private:
146 Ptr<EventImpl> m_eventImpl; /**< The underlying event implementation. */
147 uint64_t m_ts; /**< The virtual time stamp. */
148 uint32_t m_context; /**< The context. */
149 uint32_t m_uid; /**< The unique id. */
150};
151
152/*************************************************
153 ** Inline implementations
154 ************************************************/
155
156inline bool
157operator==(const EventId& a, const EventId& b)
158{
159 return a.m_uid == b.m_uid && a.m_context == b.m_context && a.m_ts == b.m_ts &&
161}
162
163inline bool
164operator!=(const EventId& a, const EventId& b)
165{
166 return !(a == b);
167}
168
169inline bool
170operator<(const EventId& a, const EventId& b)
171{
172 return (a.GetTs() < b.GetTs());
173}
174
175} // namespace ns3
176
177#endif /* EVENT_ID_H */
An identifier for simulation events.
Definition: event-id.h:55
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
uint32_t GetUid() const
Definition: event-id.cc:104
UID
Special values of the event UID.
Definition: event-id.h:59
@ INVALID
Invalid UID value.
Definition: event-id.h:61
@ RESERVED
Reserved UID.
Definition: event-id.h:67
@ VALID
Schedule(), etc.
Definition: event-id.h:69
@ DESTROY
ScheduleDestroy() events.
Definition: event-id.h:65
@ NOW
ScheduleNow() events.
Definition: event-id.h:63
friend bool operator!=(const EventId &a, const EventId &b)
Test if two EventId's are not equal.
Definition: event-id.h:164
friend bool operator<(const EventId &a, const EventId &b)
Less than operator for two EventId's, based on time stamps.
Definition: event-id.h:170
EventImpl * PeekEventImpl() const
Definition: event-id.cc:83
friend bool operator==(const EventId &a, const EventId &b)
Test if two EventId's are equal.
Definition: event-id.h:157
bool IsExpired() const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:69
uint64_t m_ts
The virtual time stamp.
Definition: event-id.h:147
uint32_t m_uid
The unique id.
Definition: event-id.h:149
void Remove()
This method is syntactic sugar for the ns3::Simulator::Remove method.
Definition: event-id.cc:62
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:76
uint32_t GetContext() const
Definition: event-id.cc:97
uint64_t GetTs() const
Definition: event-id.cc:90
EventId()
Default constructor.
Definition: event-id.cc:36
uint32_t m_context
The context.
Definition: event-id.h:148
Ptr< EventImpl > m_eventImpl
The underlying event implementation.
Definition: event-id.h:146
A simulation event.
Definition: event-impl.h:46
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
ns3::EventImpl declarations.
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:680
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
ns3::Ptr smart pointer declaration and implementation.