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