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