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 "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
22namespace ns3
23{
24
25class 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 */
44{
45 public:
46 /** Special values of the event UID. */
47 enum UID
48 {
49 /** Invalid UID value. */
51 /** ScheduleNow() events. */
52 NOW = 1,
53 /** ScheduleDestroy() events. */
55 /** Reserved UID. */
57 /** Schedule(), etc. events. */
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
145inline bool
146operator==(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 &&
150}
151
152inline bool
153operator!=(const EventId& a, const EventId& b)
154{
155 return !(a == b);
156}
157
158inline bool
159operator<(const EventId& a, const EventId& b)
160{
161 return (a.GetTs() < b.GetTs());
162}
163
164} // namespace ns3
165
166#endif /* EVENT_ID_H */
An identifier for simulation events.
Definition event-id.h:44
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:93
UID
Special values of the event UID.
Definition event-id.h:48
@ INVALID
Invalid UID value.
Definition event-id.h:50
@ RESERVED
Reserved UID.
Definition event-id.h:56
@ VALID
Schedule(), etc.
Definition event-id.h:58
@ DESTROY
ScheduleDestroy() events.
Definition event-id.h:54
@ NOW
ScheduleNow() events.
Definition event-id.h:52
friend bool operator!=(const EventId &a, const EventId &b)
Test if two EventId's are not equal.
Definition event-id.h:153
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:159
EventImpl * PeekEventImpl() const
Definition event-id.cc:72
friend bool operator==(const EventId &a, const EventId &b)
Test if two EventId's are equal.
Definition event-id.h:146
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:136
uint32_t m_uid
The unique id.
Definition event-id.h:138
void Remove()
This method is syntactic sugar for the ns3::Simulator::Remove method.
Definition event-id.cc:51
uint32_t GetContext() const
Definition event-id.cc:86
uint64_t GetTs() const
Definition event-id.cc:79
EventId()
Default constructor.
Definition event-id.cc:25
uint32_t m_context
The context.
Definition event-id.h:137
Ptr< EventImpl > m_eventImpl
The underlying event implementation.
Definition event-id.h:135
A simulation event.
Definition event-impl.h:35
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
ns3::EventImpl declarations.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition callback.h:658
bool operator==(const EventId &a, const EventId &b)
Definition event-id.h:146
bool operator<(const EventId &a, const EventId &b)
Definition event-id.h:159
ns3::Ptr smart pointer declaration and implementation.