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 "
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
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
/**
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
154
inline
bool
155
operator==(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
161
inline
bool
162
operator!=
(
const
EventId
& a,
const
EventId
& b)
163
{
164
return
!(a == b);
165
}
166
167
inline
bool
168
operator<
(
const
EventId
& a,
const
EventId
& b)
169
{
170
return
(a.
GetTs
() < b.
GetTs
());
171
}
172
173
}
// namespace ns3
174
175
#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:99
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::operator!=
friend bool operator!=(const EventId &a, const EventId &b)
Test if two EventId's are not equal.
Definition
event-id.h:162
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:168
ns3::EventId::PeekEventImpl
EventImpl * PeekEventImpl() const
Definition
event-id.cc:78
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:145
ns3::EventId::m_uid
uint32_t m_uid
The unique id.
Definition
event-id.h:147
ns3::EventId::Remove
void Remove()
This method is syntactic sugar for the ns3::Simulator::Remove method.
Definition
event-id.cc:51
ns3::EventId::IsRunning
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
Definition
event-id.cc:72
ns3::EventId::GetContext
uint32_t GetContext() const
Definition
event-id.cc:92
ns3::EventId::GetTs
uint64_t GetTs() const
Definition
event-id.cc:85
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:146
ns3::EventId::m_eventImpl
Ptr< EventImpl > m_eventImpl
The underlying event implementation.
Definition
event-id.h:144
ns3::EventImpl
A simulation event.
Definition
event-impl.h:35
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
uint32_t
deprecated.h
NS_DEPRECATED macro definition.
event-impl.h
ns3::EventImpl declarations.
NS_DEPRECATED_3_42
#define NS_DEPRECATED_3_42(msg)
Tag for things deprecated in version ns-3.42.
Definition
deprecated.h:98
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
private
#define private
Definition
openflow-interface.h:33
ptr.h
ns3::Ptr smart pointer declaration and implementation.
src
core
model
event-id.h
Generated on Wed Oct 9 2024 01:03:22 for ns-3 by
1.11.0