125 * Force the Simulator::run method to return to the caller |
128 * Force the Simulator::run method to return to the caller |
126 * when the expiration time of the next event to be processed |
129 * when the expiration time of the next event to be processed |
127 * is greater than or equal to the stop time. |
130 * is greater than or equal to the stop time. |
128 * @param at the stop time. |
131 * @param at the stop time. |
129 */ |
132 */ |
130 static void stop_at_us (uint64_t at); |
133 static void stop_at (Time time); |
131 |
134 |
132 /** |
135 /** |
133 * Schedule an event to expire at delta, relative to the |
136 * Schedule an event to expire at time. |
134 * current time. |
137 * |
135 * @param delta the expiration time relative to the current |
138 * @param delta the expiration time of the event. |
136 * time. Expressed in microsecond units. |
|
137 * @param event the event to schedule. |
139 * @param event the event to schedule. |
138 */ |
140 * @returns an id for the scheduled event. |
139 static Event schedule_rel_us (uint64_t delta, Event event); |
141 */ |
140 /** |
142 template <typename T> |
141 * Schedule an event to expire at delta, relative to the |
143 static EventId schedule (Time time, void (T::*mem_ptr) (void), T *obj) { |
142 * current time. |
144 class EventMemberImpl0 : public EventImpl { |
143 * @param delta the expiration time, relative to the current |
145 public: |
144 * time. Expressed in second units. |
146 typedef void (T::*F)(void); |
145 * @param event the event to schedule. |
147 EventMemberImpl0 (T *obj, F function) |
146 */ |
148 : m_obj (obj), |
147 static Event schedule_rel_s (double delta, Event event); |
149 m_function (function) |
148 /** |
150 {} |
149 * Schedule an event to expire at an absolute time. |
151 virtual ~EventMemberImpl0 () {} |
150 * @param time the expiration time. Expressed in |
152 private: |
151 * microsecond units. |
153 virtual void notify (void) { |
152 * @param event the event to schedule. |
154 (m_obj->*m_function) (); |
153 */ |
155 } |
154 static Event schedule_abs_us (uint64_t time, Event event); |
156 T* m_obj; |
155 /** |
157 F m_function; |
156 * Schedule an event to expire at an absolute time. |
158 } *ev = new EventMemberImpl0 (obj, mem_ptr); |
157 * @param time the expiration time. Expressed in |
159 return schedule (time, ev); |
158 * second units. |
160 } |
159 * @param event the event to schedule. |
161 static EventId schedule (Time time, void (*f) (void)) { |
160 */ |
162 class EventFunctionImpl0 : public EventImpl { |
161 static Event schedule_abs_s (double time, Event event); |
163 public: |
|
164 typedef void (*F)(void); |
|
165 |
|
166 EventFunctionImpl0 (F function) |
|
167 : m_function (function) |
|
168 {} |
|
169 protected: |
|
170 virtual void notify (void) { |
|
171 (*m_function) (); |
|
172 } |
|
173 private: |
|
174 virtual ~EventFunctionImpl0 () {} |
|
175 F m_function; |
|
176 } *ev = new EventFunctionImpl0 (f); |
|
177 return schedule (time, ev); |
|
178 } |
|
179 template <typename T1> |
|
180 static EventId schedule (Time time, void (*f) (T1), T1 a1) { |
|
181 class EventFunctionImpl1 : public EventImpl { |
|
182 public: |
|
183 typedef void (*F)(T1); |
|
184 |
|
185 EventFunctionImpl1 (F function, T1 a1) |
|
186 : m_function (function), |
|
187 m_a1 (a1) |
|
188 { } |
|
189 protected: |
|
190 virtual ~EventFunctionImpl1 () {} |
|
191 private: |
|
192 virtual void notify (void) { |
|
193 (*m_function) (m_a1); |
|
194 } |
|
195 F m_function; |
|
196 T1 m_a1; |
|
197 } *ev = new EventFunctionImpl1(f, a1); |
|
198 return schedule (time, ev); |
|
199 } |
162 /** |
200 /** |
163 * Unschedule the event. i.e.: the removed event never expires. |
201 * Unschedule the event. i.e.: the removed event never expires. |
164 * @param id the event to remove from the list of scheduled events. |
202 * @param id the event to remove from the list of scheduled events. |
165 */ |
203 */ |
166 static Event remove (Event const id); |
204 static void remove (EventId id); |
167 /** |
205 /* |
168 * Return the "current time" in microsecond units. |
206 XXX |
169 */ |
207 */ |
170 static uint64_t now_us (void); |
208 static void cancel (EventId id); |
171 /** |
209 /* |
172 * Return the "current time" in second units. |
210 XXX |
173 */ |
211 */ |
174 static double now_s (void); |
212 static bool is_expired (EventId id); |
175 /** |
213 /** |
176 * Schedule an event to expire right now. i.e., it will |
214 * Return the "current time". |
177 * expire after the currently-executing event is executed. |
215 */ |
178 * If multiple events are scheduled with this method, |
216 static Time now (void); |
179 * they are executed in FIFO order: the events scheduled first |
|
180 * are executed first. |
|
181 * @param event the event to schedule now. |
|
182 */ |
|
183 static void schedule_now (Event event); |
|
184 /** |
|
185 * Schedule an event to expire when the Simulator::destroy method |
|
186 * is invoked. Events are executed in FIFO order: the events |
|
187 * scheduled first are executed first. |
|
188 * @param event the event to schedule. |
|
189 */ |
|
190 static void schedule_destroy (Event event); |
|
191 private: |
217 private: |
192 Simulator (); |
218 Simulator (); |
193 ~Simulator (); |
219 ~Simulator (); |
194 static SimulatorPrivate *get_priv (void); |
220 static SimulatorPrivate *get_priv (void); |
|
221 static EventId schedule (Time time, EventImpl *event); |
195 static SimulatorPrivate *m_priv; |
222 static SimulatorPrivate *m_priv; |
196 static enum ListType { |
223 static enum ListType { |
197 LINKED_LIST, |
224 LINKED_LIST, |
198 BINARY_HEAP, |
225 BINARY_HEAP, |
|
226 |
199 STD_MAP |
227 STD_MAP |
200 } m_list_type; |
228 } m_list_type; |
201 }; |
229 }; |
202 |
230 |
203 }; // namespace ns3 |
231 }; // namespace ns3 |