A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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 "
event-impl.h
"
12
#include "
nstime.h
"
13
#include "
ptr.h
"
14
15
#include <stdint.h>
16
17
/**
18
* @file
19
* @ingroup events
20
* ns3::EventId declarations.
21
*/
22
23
namespace
ns3
24
{
25
26
class
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
*/
44
class
EventId
45
{
46
public
:
47
/** Special values of the event UID. */
48
enum
UID
49
{
50
/** Invalid UID value. */
51
INVALID
= 0,
52
/** ScheduleNow() events. */
53
NOW
= 1,
54
/** ScheduleDestroy() events. */
55
DESTROY
= 2,
56
/** Reserved UID. */
57
RESERVED
= 3,
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
public
:
97
/**
98
* @name Scheduler Helpers.
99
* @brief These methods are normally invoked only by
100
* subclasses of the Scheduler base class.
101
*/
102
/**@{*/
103
/** @return The underlying EventImpl pointer. */
104
EventImpl
*
PeekEventImpl
()
const
;
105
/** @return The virtual time stamp. */
106
uint64_t
GetTs
()
const
;
107
/** @return The event context. */
108
uint32_t
GetContext
()
const
;
109
/** @return The unique id. */
110
uint32_t
GetUid
()
const
;
111
/**@}*/
112
113
/**
114
* @name Comparison operators
115
* @{
116
*/
117
118
/**
119
* Test if two EventId's are equal.
120
* @param [in] a The first EventId.
121
* @param [in] b The second EventId.
122
* @return \c true if the \pname{a} and \pname{b} represent the same event.
123
*/
124
friend
bool
operator==
(
const
EventId
& a,
const
EventId
& b);
125
126
/**
127
* Less than operator for two EventId's, based on time stamps.
128
* @param [in] a The first EventId.
129
* @param [in] b The second EventId.
130
* @return \c true if \pname{a} occurs before \pname{b}.
131
*/
132
friend
bool
operator<
(
const
EventId
& a,
const
EventId
& b);
133
134
/**
135
* Compare a Time to an EventId.
136
*
137
* This is useful when you have cached a previously scheduled event:
138
*
139
* m_event = Schedule (...);
140
*
141
* and later you want to know the relationship between that event
142
* and some other Time `when`:
143
*
144
* if (when < m_event) ...
145
*
146
* @param [in] time The Time operand.
147
* @param [in] event The EventId
148
* @returns \c true if \p time is before (less than) the
149
* time stamp of the EventId.
150
*/
151
friend
bool
operator<
(
const
Time
& time,
const
EventId
& event);
152
153
/**@}*/
// Comparison operators
154
155
private
:
156
Ptr<EventImpl>
m_eventImpl
;
/**< The underlying event implementation. */
157
uint64_t
m_ts
;
/**< The virtual time stamp. */
158
uint32_t
m_context
;
/**< The context. */
159
uint32_t
m_uid
;
/**< The unique id. */
160
};
161
162
/*************************************************
163
** Inline implementations
164
************************************************/
165
166
inline
bool
167
operator==
(
const
EventId
& a,
const
EventId
& b)
168
{
169
return
a.
m_uid
== b.
m_uid
&& a.
m_context
== b.
m_context
&& a.
m_ts
== b.
m_ts
&&
170
a.
m_eventImpl
== b.
m_eventImpl
;
171
}
172
173
inline
bool
174
operator<
(
const
EventId
& a,
const
EventId
& b)
175
{
176
return
(a.
GetTs
() < b.
GetTs
());
177
}
178
179
inline
bool
180
operator<
(
const
Time
& time,
const
EventId
& event)
181
{
182
// Negative Time is less than any possible EventId, which are all >= 0.
183
if
(time.
IsStrictlyNegative
())
184
{
185
return
true
;
186
}
187
// Time must be >= 0 so casting to unsigned is safe.
188
return
static_cast<
uint64_t
>
(time.
GetTimeStep
()) <
event
.GetTs();
189
}
190
}
// namespace ns3
191
192
#endif
/* EVENT_ID_H */
ns3::EventId
An identifier for simulation events.
Definition
event-id.h:45
ns3::EventId::Cancel
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition
event-id.cc:44
ns3::EventId::GetUid
uint32_t GetUid() const
Definition
event-id.cc:93
ns3::EventId::UID
UID
Special values of the event UID.
Definition
event-id.h:49
ns3::EventId::INVALID
@ INVALID
Invalid UID value.
Definition
event-id.h:51
ns3::EventId::RESERVED
@ RESERVED
Reserved UID.
Definition
event-id.h:57
ns3::EventId::VALID
@ VALID
Schedule(), etc.
Definition
event-id.h:59
ns3::EventId::DESTROY
@ DESTROY
ScheduleDestroy() events.
Definition
event-id.h:55
ns3::EventId::NOW
@ NOW
ScheduleNow() events.
Definition
event-id.h:53
ns3::EventId::IsPending
bool IsPending() const
This method is syntactic sugar for !IsExpired().
Definition
event-id.cc:65
ns3::EventId::operator<
friend bool operator<(const EventId &a, const EventId &b)
Less than operator for two EventId's, based on time stamps.
Definition
event-id.h:174
ns3::EventId::PeekEventImpl
EventImpl * PeekEventImpl() const
Definition
event-id.cc:72
ns3::EventId::operator==
friend bool operator==(const EventId &a, const EventId &b)
Test if two EventId's are equal.
Definition
event-id.h:167
ns3::EventId::IsExpired
bool IsExpired() const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition
event-id.cc:58
ns3::EventId::m_ts
uint64_t m_ts
The virtual time stamp.
Definition
event-id.h:157
ns3::EventId::m_uid
uint32_t m_uid
The unique id.
Definition
event-id.h:159
ns3::EventId::Remove
void Remove()
This method is syntactic sugar for the ns3::Simulator::Remove method.
Definition
event-id.cc:51
ns3::EventId::GetContext
uint32_t GetContext() const
Definition
event-id.cc:86
ns3::EventId::GetTs
uint64_t GetTs() const
Definition
event-id.cc:79
ns3::EventId::EventId
EventId()
Default constructor.
Definition
event-id.cc:25
ns3::EventId::m_context
uint32_t m_context
The context.
Definition
event-id.h:158
ns3::EventId::m_eventImpl
Ptr< EventImpl > m_eventImpl
The underlying event implementation.
Definition
event-id.h:156
ns3::EventImpl
A simulation event.
Definition
event-impl.h:35
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:70
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition
nstime.h:95
ns3::Time::IsStrictlyNegative
bool IsStrictlyNegative() const
Exactly equivalent to t < 0.
Definition
nstime.h:332
ns3::Time::GetTimeStep
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition
nstime.h:440
uint32_t
event-impl.h
ns3::EventImpl declarations.
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::operator==
bool operator==(const EventId &a, const EventId &b)
Definition
event-id.h:167
ns3::operator<
bool operator<(const EventId &a, const EventId &b)
Definition
event-id.h:174
nstime.h
Declaration of classes ns3::Time and ns3::TimeWithUnit, and the TimeValue implementation classes.
ptr.h
ns3::Ptr smart pointer declaration and implementation.
src
core
model
event-id.h
Generated on
for ns-3 by
1.15.0