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 "deprecated.h"
23#include "event-impl.h"
24#include "ptr.h"
25
26#include <stdint.h>
27
28/**
29 * \file
30 * \ingroup events
31 * ns3::EventId declarations.
32 */
33
34namespace ns3
35{
36
37class EventImpl;
38
39/**
40 * \ingroup events
41 * \brief An identifier for simulation events.
42 *
43 * Each EventId identifies a unique event scheduled with one
44 * of the many Simulator::Schedule() methods. This EventId can
45 * be used to cancel or remove events after they are scheduled
46 * with Cancel(), Remove(), or Simulator::Cancel() or Simulator::Remove().
47 *
48 * The important thing to remember about this class is that
49 * every variable of this type is _always_ in a valid state,
50 * even when it has not been assigned an EventId coming from a
51 * Simulator::Schedule() method: calling Simulator::Cancel(), IsPending(),
52 * IsExpired() or passing around instances of this object
53 * will not result in crashes or memory leaks.
54 */
56{
57 public:
58 /** Special values of the event UID. */
59 enum UID
60 {
61 /** Invalid UID value. */
63 /** ScheduleNow() events. */
64 NOW = 1,
65 /** ScheduleDestroy() events. */
67 /** Reserved UID. */
69 /** Schedule(), etc. events. */
70 VALID = 4
71 };
72
73 /** Default constructor. This EventId does nothing. */
74 EventId();
75 /**
76 * Construct a real event.
77 *
78 * \param [in] impl The implementation of this event.
79 * \param [in] ts The virtual time stamp this event should occur.
80 * \param [in] context The execution context for this event.
81 * \param [in] uid The unique id for this EventId.
82 */
83 EventId(const Ptr<EventImpl>& impl, uint64_t ts, uint32_t context, uint32_t uid);
84 /**
85 * This method is syntactic sugar for the ns3::Simulator::Cancel
86 * method.
87 */
88 void Cancel();
89 /**
90 * This method is syntactic sugar for the ns3::Simulator::Remove
91 * method.
92 */
93 void Remove();
94 /**
95 * This method is syntactic sugar for the ns3::Simulator::IsExpired
96 * method.
97 * \returns \c true if the event has expired, \c false otherwise.
98 */
99 bool IsExpired() const;
100 /**
101 * This method is syntactic sugar for !IsExpired().
102 *
103 * \returns \c true if the event has not expired, \c false otherwise.
104 */
105 bool IsPending() const;
106
107 /**
108 * This method is syntactic sugar for !IsExpired().
109 *
110 * \returns \c true if the event has not expired, \c false otherwise.
111 */
112 NS_DEPRECATED_3_42("Use IsPending instead")
113 bool IsRunning() const;
114
115 public:
116 /**
117 * \name Scheduler Helpers.
118 * \brief These methods are normally invoked only by
119 * subclasses of the Scheduler base class.
120 */
121 /**@{*/
122 /** \return The underlying EventImpl pointer. */
123 EventImpl* PeekEventImpl() const;
124 /** \return The virtual time stamp. */
125 uint64_t GetTs() const;
126 /** \return The event context. */
127 uint32_t GetContext() const;
128 /** \return The unique id. */
129 uint32_t GetUid() const;
130 /**@}*/
131
132 /**
133 * Test if two EventId's are equal.
134 * \param [in] a The first EventId.
135 * \param [in] b The second EventId.
136 * \return \c true if the \pname{a} and \pname{b} represent the same event.
137 */
138 friend bool operator==(const EventId& a, const EventId& b);
139 /**
140 * Test if two EventId's are not equal.
141 * \param [in] a The first EventId.
142 * \param [in] b The second EventId.
143 * \return \c true if the \pname{a} and \pname{b} are not the same event.
144 */
145 friend bool operator!=(const EventId& a, const EventId& b);
146 /**
147 * Less than operator for two EventId's, based on time stamps.
148 * \param [in] a The first EventId.
149 * \param [in] b The second EventId.
150 * \return \c true if \pname{a} occurs before \pname{b}.
151 */
152 friend bool operator<(const EventId& a, const EventId& b);
153
154 private:
155 Ptr<EventImpl> m_eventImpl; /**< The underlying event implementation. */
156 uint64_t m_ts; /**< The virtual time stamp. */
157 uint32_t m_context; /**< The context. */
158 uint32_t m_uid; /**< The unique id. */
159};
160
161/*************************************************
162 ** Inline implementations
163 ************************************************/
164
165inline bool
166operator==(const EventId& a, const EventId& b)
167{
168 return a.m_uid == b.m_uid && a.m_context == b.m_context && a.m_ts == b.m_ts &&
169 a.m_eventImpl == b.m_eventImpl;
170}
171
172inline bool
173operator!=(const EventId& a, const EventId& b)
174{
175 return !(a == b);
176}
177
178inline bool
179operator<(const EventId& a, const EventId& b)
180{
181 return (a.GetTs() < b.GetTs());
182}
183
184} // namespace ns3
185
186#endif /* EVENT_ID_H */
An identifier for simulation events.
Definition: event-id.h:56
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:110
UID
Special values of the event UID.
Definition: event-id.h:60
@ INVALID
Invalid UID value.
Definition: event-id.h:62
@ RESERVED
Reserved UID.
Definition: event-id.h:68
@ VALID
Schedule(), etc.
Definition: event-id.h:70
@ DESTROY
ScheduleDestroy() events.
Definition: event-id.h:66
@ NOW
ScheduleNow() events.
Definition: event-id.h:64
friend bool operator!=(const EventId &a, const EventId &b)
Test if two EventId's are not equal.
Definition: event-id.h:173
bool IsPending() const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:76
friend bool operator<(const EventId &a, const EventId &b)
Less than operator for two EventId's, based on time stamps.
Definition: event-id.h:179
EventImpl * PeekEventImpl() const
Definition: event-id.cc:89
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:156
uint32_t m_uid
The unique id.
Definition: event-id.h:158
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:83
uint32_t GetContext() const
Definition: event-id.cc:103
uint64_t GetTs() const
Definition: event-id.cc:96
EventId()
Default constructor.
Definition: event-id.cc:36
uint32_t m_context
The context.
Definition: event-id.h:157
Ptr< EventImpl > m_eventImpl
The underlying event implementation.
Definition: event-id.h:155
A simulation event.
Definition: event-impl.h:46
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
NS_DEPRECATED macro definition.
ns3::EventImpl declarations.
#define NS_DEPRECATED_3_42(msg)
Tag for things deprecated in version ns-3.42.
Definition: deprecated.h:102
Every class exported by the ns3 library is enclosed in the ns3 namespace.
#define private
ns3::Ptr smart pointer declaration and implementation.