blob: 1241834ddede8f0659b3718b8473b8d3a9af4d19 [file] [log] [blame]
Alex Perrycb7da4b2019-08-28 19:35:56 -07001#include "aos/events/simulated_event_loop.h"
2
3#include <algorithm>
4#include <deque>
Austin Schuh5f1cc5c2019-12-01 18:01:11 -08005#include <string_view>
Alex Perrycb7da4b2019-08-28 19:35:56 -07006
7#include "absl/container/btree_map.h"
Austin Schuh898f4972020-01-11 17:21:25 -08008#include "aos/events/simulated_network_bridge.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -07009#include "aos/json_to_flatbuffer.h"
10#include "aos/util/phased_loop.h"
Tyler Chatow67ddb032020-01-12 14:30:04 -080011#include "aos/events/aos_logging.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070012
13namespace aos {
14
15// Container for both a message, and the context for it for simulation. This
16// makes tracking the timestamps associated with the data easy.
17struct SimulatedMessage {
Alex Perrycb7da4b2019-08-28 19:35:56 -070018 // Context for the data.
19 Context context;
20
21 // The data.
Brian Silvermana1652f32020-01-29 20:41:44 -080022 char *data(size_t buffer_size) {
23 return RoundChannelData(&actual_data[0], buffer_size);
24 }
Alex Perrycb7da4b2019-08-28 19:35:56 -070025
Brian Silvermana1652f32020-01-29 20:41:44 -080026 // Then the data, including padding on the end so we can align the buffer we
27 // actually return from data().
28 char actual_data[];
Alex Perrycb7da4b2019-08-28 19:35:56 -070029};
30
Austin Schuh7d87b672019-12-01 20:23:49 -080031class SimulatedEventLoop;
Alex Perrycb7da4b2019-08-28 19:35:56 -070032class SimulatedFetcher;
Austin Schuh39788ff2019-12-01 18:22:57 -080033class SimulatedChannel;
34
Austin Schuh7d87b672019-12-01 20:23:49 -080035class SimulatedWatcher : public WatcherState {
Austin Schuh39788ff2019-12-01 18:22:57 -080036 public:
Austin Schuh7d87b672019-12-01 20:23:49 -080037 SimulatedWatcher(
38 SimulatedEventLoop *simulated_event_loop, EventScheduler *scheduler,
39 const Channel *channel,
40 std::function<void(const Context &context, const void *message)> fn);
Austin Schuh39788ff2019-12-01 18:22:57 -080041
Austin Schuh7d87b672019-12-01 20:23:49 -080042 ~SimulatedWatcher() override;
Austin Schuh39788ff2019-12-01 18:22:57 -080043
44 void Startup(EventLoop * /*event_loop*/) override {}
45
Austin Schuh7d87b672019-12-01 20:23:49 -080046 void Schedule(std::shared_ptr<SimulatedMessage> message);
47
48 void HandleEvent();
Austin Schuh39788ff2019-12-01 18:22:57 -080049
50 void SetSimulatedChannel(SimulatedChannel *channel) {
51 simulated_channel_ = channel;
52 }
53
54 private:
Austin Schuh7d87b672019-12-01 20:23:49 -080055 void DoSchedule(monotonic_clock::time_point event_time);
56
57 ::std::deque<std::shared_ptr<SimulatedMessage>> msgs_;
58
59 SimulatedEventLoop *simulated_event_loop_;
60 EventHandler<SimulatedWatcher> event_;
61 EventScheduler *scheduler_;
62 EventScheduler::Token token_;
Austin Schuh39788ff2019-12-01 18:22:57 -080063 SimulatedChannel *simulated_channel_ = nullptr;
64};
Alex Perrycb7da4b2019-08-28 19:35:56 -070065
66class SimulatedChannel {
67 public:
68 explicit SimulatedChannel(const Channel *channel, EventScheduler *scheduler)
Austin Schuh39788ff2019-12-01 18:22:57 -080069 : channel_(channel),
Alex Perrycb7da4b2019-08-28 19:35:56 -070070 scheduler_(scheduler),
71 next_queue_index_(ipc_lib::QueueIndex::Zero(channel->max_size())) {}
72
73 ~SimulatedChannel() { CHECK_EQ(0u, fetchers_.size()); }
74
75 // Makes a connected raw sender which calls Send below.
76 ::std::unique_ptr<RawSender> MakeRawSender(EventLoop *event_loop);
77
78 // Makes a connected raw fetcher.
Austin Schuh39788ff2019-12-01 18:22:57 -080079 ::std::unique_ptr<RawFetcher> MakeRawFetcher(EventLoop *event_loop);
Alex Perrycb7da4b2019-08-28 19:35:56 -070080
81 // Registers a watcher for the queue.
Austin Schuh7d87b672019-12-01 20:23:49 -080082 void MakeRawWatcher(SimulatedWatcher *watcher);
Austin Schuh39788ff2019-12-01 18:22:57 -080083
Austin Schuh7d87b672019-12-01 20:23:49 -080084 void RemoveWatcher(SimulatedWatcher *watcher) {
Austin Schuh39788ff2019-12-01 18:22:57 -080085 watchers_.erase(std::find(watchers_.begin(), watchers_.end(), watcher));
86 }
Alex Perrycb7da4b2019-08-28 19:35:56 -070087
Austin Schuhad154822019-12-27 15:45:13 -080088 // Sends the message to all the connected receivers and fetchers. Returns the
89 // sent queue index.
90 uint32_t Send(std::shared_ptr<SimulatedMessage> message);
Alex Perrycb7da4b2019-08-28 19:35:56 -070091
92 // Unregisters a fetcher.
93 void UnregisterFetcher(SimulatedFetcher *fetcher);
94
95 std::shared_ptr<SimulatedMessage> latest_message() { return latest_message_; }
96
Austin Schuh39788ff2019-12-01 18:22:57 -080097 size_t max_size() const { return channel()->max_size(); }
Alex Perrycb7da4b2019-08-28 19:35:56 -070098
Austin Schuh5f1cc5c2019-12-01 18:01:11 -080099 const std::string_view name() const {
Austin Schuh39788ff2019-12-01 18:22:57 -0800100 return channel()->name()->string_view();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700101 }
102
Austin Schuh39788ff2019-12-01 18:22:57 -0800103 const Channel *channel() const { return channel_; }
104
Alex Perrycb7da4b2019-08-28 19:35:56 -0700105 private:
Austin Schuh39788ff2019-12-01 18:22:57 -0800106 const Channel *channel_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700107
108 // List of all watchers.
Austin Schuh7d87b672019-12-01 20:23:49 -0800109 ::std::vector<SimulatedWatcher *> watchers_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700110
111 // List of all fetchers.
112 ::std::vector<SimulatedFetcher *> fetchers_;
113 std::shared_ptr<SimulatedMessage> latest_message_;
114 EventScheduler *scheduler_;
115
116 ipc_lib::QueueIndex next_queue_index_;
117};
118
119namespace {
120
121// Creates a SimulatedMessage with size bytes of storage.
122// This is a shared_ptr so we don't have to implement refcounting or copying.
123std::shared_ptr<SimulatedMessage> MakeSimulatedMessage(size_t size) {
124 SimulatedMessage *message = reinterpret_cast<SimulatedMessage *>(
Brian Silvermana1652f32020-01-29 20:41:44 -0800125 malloc(sizeof(SimulatedMessage) + size + kChannelDataAlignment - 1));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700126 message->context.size = size;
Brian Silvermana1652f32020-01-29 20:41:44 -0800127 message->context.data = message->data(size);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700128
129 return std::shared_ptr<SimulatedMessage>(message, free);
130}
131
132class SimulatedSender : public RawSender {
133 public:
134 SimulatedSender(SimulatedChannel *simulated_channel, EventLoop *event_loop)
Austin Schuh39788ff2019-12-01 18:22:57 -0800135 : RawSender(event_loop, simulated_channel->channel()),
Austin Schuh54cf95f2019-11-29 13:14:18 -0800136 simulated_channel_(simulated_channel),
137 event_loop_(event_loop) {}
Alex Perrycb7da4b2019-08-28 19:35:56 -0700138 ~SimulatedSender() {}
139
140 void *data() override {
141 if (!message_) {
142 message_ = MakeSimulatedMessage(simulated_channel_->max_size());
143 }
Brian Silvermana1652f32020-01-29 20:41:44 -0800144 return message_->data(simulated_channel_->max_size());
Alex Perrycb7da4b2019-08-28 19:35:56 -0700145 }
146
147 size_t size() override { return simulated_channel_->max_size(); }
148
Austin Schuhad154822019-12-27 15:45:13 -0800149 bool DoSend(size_t length,
150 aos::monotonic_clock::time_point monotonic_remote_time,
151 aos::realtime_clock::time_point realtime_remote_time,
152 uint32_t remote_queue_index) override {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700153 CHECK_LE(length, size()) << ": Attempting to send too big a message.";
Austin Schuhad154822019-12-27 15:45:13 -0800154 message_->context.monotonic_event_time = event_loop_->monotonic_now();
155 message_->context.monotonic_remote_time = monotonic_remote_time;
156 message_->context.remote_queue_index = remote_queue_index;
157 message_->context.realtime_event_time = event_loop_->realtime_now();
158 message_->context.realtime_remote_time = realtime_remote_time;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700159 CHECK_LE(length, message_->context.size);
160 message_->context.size = length;
161
162 // TODO(austin): Track sending too fast.
Austin Schuhad154822019-12-27 15:45:13 -0800163 sent_queue_index_ = simulated_channel_->Send(message_);
164 monotonic_sent_time_ = event_loop_->monotonic_now();
165 realtime_sent_time_ = event_loop_->realtime_now();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700166
167 // Drop the reference to the message so that we allocate a new message for
168 // next time. Otherwise we will continue to reuse the same memory for all
169 // messages and corrupt it.
170 message_.reset();
171 return true;
172 }
173
Austin Schuhad154822019-12-27 15:45:13 -0800174 bool DoSend(const void *msg, size_t size,
175 aos::monotonic_clock::time_point monotonic_remote_time,
176 aos::realtime_clock::time_point realtime_remote_time,
177 uint32_t remote_queue_index) override {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700178 CHECK_LE(size, this->size()) << ": Attempting to send too big a message.";
179
180 // This is wasteful, but since flatbuffers fill from the back end of the
181 // queue, we need it to be full sized.
182 message_ = MakeSimulatedMessage(simulated_channel_->max_size());
183
184 // Now fill in the message. size is already populated above, and
Austin Schuhac0771c2020-01-07 18:36:30 -0800185 // queue_index will be populated in simulated_channel_. Put this at the
186 // back of the data segment.
Brian Silvermana1652f32020-01-29 20:41:44 -0800187 memcpy(message_->data(simulated_channel_->max_size()) +
188 simulated_channel_->max_size() - size,
189 msg, size);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700190
Austin Schuhac0771c2020-01-07 18:36:30 -0800191 return DoSend(size, monotonic_remote_time, realtime_remote_time,
192 remote_queue_index);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700193 }
194
Alex Perrycb7da4b2019-08-28 19:35:56 -0700195 private:
196 SimulatedChannel *simulated_channel_;
197 EventLoop *event_loop_;
198
199 std::shared_ptr<SimulatedMessage> message_;
200};
201} // namespace
202
203class SimulatedFetcher : public RawFetcher {
204 public:
Austin Schuhac0771c2020-01-07 18:36:30 -0800205 explicit SimulatedFetcher(EventLoop *event_loop,
206 SimulatedChannel *simulated_channel)
207 : RawFetcher(event_loop, simulated_channel->channel()),
208 simulated_channel_(simulated_channel) {}
209 ~SimulatedFetcher() { simulated_channel_->UnregisterFetcher(this); }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700210
Austin Schuh39788ff2019-12-01 18:22:57 -0800211 std::pair<bool, monotonic_clock::time_point> DoFetchNext() override {
212 if (msgs_.size() == 0) {
213 return std::make_pair(false, monotonic_clock::min_time);
214 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700215
216 SetMsg(msgs_.front());
217 msgs_.pop_front();
Austin Schuha5e14192020-01-06 18:02:41 -0800218 return std::make_pair(true, event_loop()->monotonic_now());
Alex Perrycb7da4b2019-08-28 19:35:56 -0700219 }
220
Austin Schuh39788ff2019-12-01 18:22:57 -0800221 std::pair<bool, monotonic_clock::time_point> DoFetch() override {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700222 if (msgs_.size() == 0) {
Austin Schuh7d87b672019-12-01 20:23:49 -0800223 // TODO(austin): Can we just do this logic unconditionally? It is a lot
224 // simpler. And call clear, obviously.
Austin Schuhac0771c2020-01-07 18:36:30 -0800225 if (!msg_ && simulated_channel_->latest_message()) {
226 SetMsg(simulated_channel_->latest_message());
Austin Schuha5e14192020-01-06 18:02:41 -0800227 return std::make_pair(true, event_loop()->monotonic_now());
Alex Perrycb7da4b2019-08-28 19:35:56 -0700228 } else {
Austin Schuh39788ff2019-12-01 18:22:57 -0800229 return std::make_pair(false, monotonic_clock::min_time);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700230 }
231 }
232
233 // We've had a message enqueued, so we don't need to go looking for the
234 // latest message from before we started.
235 SetMsg(msgs_.back());
236 msgs_.clear();
Austin Schuha5e14192020-01-06 18:02:41 -0800237 return std::make_pair(true, event_loop()->monotonic_now());
Alex Perrycb7da4b2019-08-28 19:35:56 -0700238 }
239
240 private:
241 friend class SimulatedChannel;
242
243 // Updates the state inside RawFetcher to point to the data in msg_.
244 void SetMsg(std::shared_ptr<SimulatedMessage> msg) {
245 msg_ = msg;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700246 context_ = msg_->context;
Austin Schuhad154822019-12-27 15:45:13 -0800247 if (context_.remote_queue_index == 0xffffffffu) {
248 context_.remote_queue_index = context_.queue_index;
249 }
250 if (context_.monotonic_remote_time == aos::monotonic_clock::min_time) {
251 context_.monotonic_remote_time = context_.monotonic_event_time;
252 }
253 if (context_.realtime_remote_time == aos::realtime_clock::min_time) {
254 context_.realtime_remote_time = context_.realtime_event_time;
255 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700256 }
257
258 // Internal method for Simulation to add a message to the buffer.
259 void Enqueue(std::shared_ptr<SimulatedMessage> buffer) {
260 msgs_.emplace_back(buffer);
261 }
262
Austin Schuhac0771c2020-01-07 18:36:30 -0800263 SimulatedChannel *simulated_channel_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700264 std::shared_ptr<SimulatedMessage> msg_;
265
266 // Messages queued up but not in use.
267 ::std::deque<std::shared_ptr<SimulatedMessage>> msgs_;
268};
269
270class SimulatedTimerHandler : public TimerHandler {
271 public:
272 explicit SimulatedTimerHandler(EventScheduler *scheduler,
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800273 SimulatedEventLoop *simulated_event_loop,
Austin Schuh39788ff2019-12-01 18:22:57 -0800274 ::std::function<void()> fn);
Austin Schuh7d87b672019-12-01 20:23:49 -0800275 ~SimulatedTimerHandler() { Disable(); }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700276
277 void Setup(monotonic_clock::time_point base,
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800278 monotonic_clock::duration repeat_offset) override;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700279
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800280 void HandleEvent();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700281
Austin Schuh7d87b672019-12-01 20:23:49 -0800282 void Disable() override;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700283
Alex Perrycb7da4b2019-08-28 19:35:56 -0700284 private:
Austin Schuh7d87b672019-12-01 20:23:49 -0800285 SimulatedEventLoop *simulated_event_loop_;
286 EventHandler<SimulatedTimerHandler> event_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700287 EventScheduler *scheduler_;
288 EventScheduler::Token token_;
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800289
Alex Perrycb7da4b2019-08-28 19:35:56 -0700290 monotonic_clock::time_point base_;
291 monotonic_clock::duration repeat_offset_;
292};
293
294class SimulatedPhasedLoopHandler : public PhasedLoopHandler {
295 public:
296 SimulatedPhasedLoopHandler(EventScheduler *scheduler,
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800297 SimulatedEventLoop *simulated_event_loop,
Alex Perrycb7da4b2019-08-28 19:35:56 -0700298 ::std::function<void(int)> fn,
299 const monotonic_clock::duration interval,
Austin Schuh39788ff2019-12-01 18:22:57 -0800300 const monotonic_clock::duration offset);
Austin Schuh7d87b672019-12-01 20:23:49 -0800301 ~SimulatedPhasedLoopHandler();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700302
Austin Schuh7d87b672019-12-01 20:23:49 -0800303 void HandleEvent();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700304
Austin Schuh7d87b672019-12-01 20:23:49 -0800305 void Schedule(monotonic_clock::time_point sleep_time) override;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700306
307 private:
Austin Schuh39788ff2019-12-01 18:22:57 -0800308 SimulatedEventLoop *simulated_event_loop_;
Austin Schuh7d87b672019-12-01 20:23:49 -0800309 EventHandler<SimulatedPhasedLoopHandler> event_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700310
Austin Schuh39788ff2019-12-01 18:22:57 -0800311 EventScheduler *scheduler_;
312 EventScheduler::Token token_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700313};
314
315class SimulatedEventLoop : public EventLoop {
316 public:
317 explicit SimulatedEventLoop(
318 EventScheduler *scheduler,
Austin Schuhac0771c2020-01-07 18:36:30 -0800319 NodeEventLoopFactory *node_event_loop_factory,
Alex Perrycb7da4b2019-08-28 19:35:56 -0700320 absl::btree_map<SimpleChannel, std::unique_ptr<SimulatedChannel>>
321 *channels,
322 const Configuration *configuration,
323 std::vector<std::pair<EventLoop *, std::function<void(bool)>>>
Austin Schuh39788ff2019-12-01 18:22:57 -0800324 *raw_event_loops,
Austin Schuh217a9782019-12-21 23:02:50 -0800325 const Node *node, pid_t tid)
Austin Schuh39788ff2019-12-01 18:22:57 -0800326 : EventLoop(CHECK_NOTNULL(configuration)),
Alex Perrycb7da4b2019-08-28 19:35:56 -0700327 scheduler_(scheduler),
Austin Schuhac0771c2020-01-07 18:36:30 -0800328 node_event_loop_factory_(node_event_loop_factory),
Alex Perrycb7da4b2019-08-28 19:35:56 -0700329 channels_(channels),
Austin Schuh39788ff2019-12-01 18:22:57 -0800330 raw_event_loops_(raw_event_loops),
Austin Schuh217a9782019-12-21 23:02:50 -0800331 node_(node),
Austin Schuh39788ff2019-12-01 18:22:57 -0800332 tid_(tid) {
333 raw_event_loops_->push_back(std::make_pair(this, [this](bool value) {
334 if (!has_setup_) {
335 Setup();
336 has_setup_ = true;
337 }
338 set_is_running(value);
339 }));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700340 }
341 ~SimulatedEventLoop() override {
Austin Schuh39788ff2019-12-01 18:22:57 -0800342 // Trigger any remaining senders or fetchers to be cleared before destroying
343 // the event loop so the book keeping matches.
344 timing_report_sender_.reset();
345
346 // Force everything with a registered fd with epoll to be destroyed now.
347 timers_.clear();
348 phased_loops_.clear();
349 watchers_.clear();
350
Alex Perrycb7da4b2019-08-28 19:35:56 -0700351 for (auto it = raw_event_loops_->begin(); it != raw_event_loops_->end();
352 ++it) {
353 if (it->first == this) {
354 raw_event_loops_->erase(it);
355 break;
356 }
357 }
358 }
359
Austin Schuh7d87b672019-12-01 20:23:49 -0800360 std::chrono::nanoseconds send_delay() const { return send_delay_; }
361 void set_send_delay(std::chrono::nanoseconds send_delay) {
362 send_delay_ = send_delay;
363 }
364
Alex Perrycb7da4b2019-08-28 19:35:56 -0700365 ::aos::monotonic_clock::time_point monotonic_now() override {
Austin Schuhac0771c2020-01-07 18:36:30 -0800366 return node_event_loop_factory_->monotonic_now();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700367 }
368
369 ::aos::realtime_clock::time_point realtime_now() override {
Austin Schuhac0771c2020-01-07 18:36:30 -0800370 return node_event_loop_factory_->realtime_now();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700371 }
372
373 ::std::unique_ptr<RawSender> MakeRawSender(const Channel *channel) override;
374
375 ::std::unique_ptr<RawFetcher> MakeRawFetcher(const Channel *channel) override;
376
377 void MakeRawWatcher(
378 const Channel *channel,
379 ::std::function<void(const Context &context, const void *message)>
380 watcher) override;
381
382 TimerHandler *AddTimer(::std::function<void()> callback) override {
Austin Schuh39788ff2019-12-01 18:22:57 -0800383 CHECK(!is_running());
Austin Schuh8bd96322020-02-13 21:18:22 -0800384 return NewTimer(::std::unique_ptr<TimerHandler>(
385 new SimulatedTimerHandler(scheduler_, this, callback)));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700386 }
387
388 PhasedLoopHandler *AddPhasedLoop(::std::function<void(int)> callback,
389 const monotonic_clock::duration interval,
390 const monotonic_clock::duration offset =
391 ::std::chrono::seconds(0)) override {
Austin Schuh8bd96322020-02-13 21:18:22 -0800392 return NewPhasedLoop(
393 ::std::unique_ptr<PhasedLoopHandler>(new SimulatedPhasedLoopHandler(
394 scheduler_, this, callback, interval, offset)));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700395 }
396
397 void OnRun(::std::function<void()> on_run) override {
Austin Schuh39788ff2019-12-01 18:22:57 -0800398 scheduler_->ScheduleOnRun(on_run);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700399 }
400
Austin Schuh217a9782019-12-21 23:02:50 -0800401 const Node *node() const override { return node_; }
402
James Kuszmaul3ae42262019-11-08 12:33:41 -0800403 void set_name(const std::string_view name) override {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700404 name_ = std::string(name);
405 }
James Kuszmaul3ae42262019-11-08 12:33:41 -0800406 const std::string_view name() const override { return name_; }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700407
408 SimulatedChannel *GetSimulatedChannel(const Channel *channel);
409
Austin Schuh39788ff2019-12-01 18:22:57 -0800410 void SetRuntimeRealtimePriority(int priority) override {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700411 CHECK(!is_running()) << ": Cannot set realtime priority while running.";
Austin Schuh39788ff2019-12-01 18:22:57 -0800412 priority_ = priority;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700413 }
414
Austin Schuh39788ff2019-12-01 18:22:57 -0800415 int priority() const override { return priority_; }
416
Brian Silverman6a54ff32020-04-28 16:41:39 -0700417 void SetRuntimeAffinity(const cpu_set_t & /*cpuset*/) override {
418 CHECK(!is_running()) << ": Cannot set affinity while running.";
419 }
420
Tyler Chatow67ddb032020-01-12 14:30:04 -0800421 void Setup() {
422 MaybeScheduleTimingReports();
423 if (!skip_logger_) {
424 logging::ScopedLogRestorer prev_logger;
425 log_sender_.Initialize(MakeSender<logging::LogMessageFbs>("/aos"));
426 log_impl_ = logging::GetImplementation();
427 }
428 }
Austin Schuh39788ff2019-12-01 18:22:57 -0800429
Alex Perrycb7da4b2019-08-28 19:35:56 -0700430 private:
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800431 friend class SimulatedTimerHandler;
Austin Schuh7d87b672019-12-01 20:23:49 -0800432 friend class SimulatedPhasedLoopHandler;
433 friend class SimulatedWatcher;
434
435 void HandleEvent() {
436 while (true) {
437 if (EventCount() == 0 || PeekEvent()->event_time() > monotonic_now()) {
438 break;
439 }
440
441 EventLoopEvent *event = PopEvent();
442 event->HandleEvent();
443 }
444 }
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800445
Austin Schuh39788ff2019-12-01 18:22:57 -0800446 pid_t GetTid() override { return tid_; }
447
Alex Perrycb7da4b2019-08-28 19:35:56 -0700448 EventScheduler *scheduler_;
Austin Schuhac0771c2020-01-07 18:36:30 -0800449 NodeEventLoopFactory *node_event_loop_factory_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700450 absl::btree_map<SimpleChannel, std::unique_ptr<SimulatedChannel>> *channels_;
451 std::vector<std::pair<EventLoop *, std::function<void(bool)>>>
452 *raw_event_loops_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700453
454 ::std::string name_;
Austin Schuh39788ff2019-12-01 18:22:57 -0800455
456 int priority_ = 0;
457
458 bool has_setup_ = false;
459
Austin Schuh7d87b672019-12-01 20:23:49 -0800460 std::chrono::nanoseconds send_delay_;
461
Austin Schuh217a9782019-12-21 23:02:50 -0800462 const Node *const node_;
Austin Schuh39788ff2019-12-01 18:22:57 -0800463 const pid_t tid_;
Tyler Chatow67ddb032020-01-12 14:30:04 -0800464
465 AosLogToFbs log_sender_;
466 logging::LogImplementation *log_impl_ = nullptr;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700467};
468
Austin Schuh7d87b672019-12-01 20:23:49 -0800469void SimulatedEventLoopFactory::set_send_delay(
470 std::chrono::nanoseconds send_delay) {
471 send_delay_ = send_delay;
472 for (std::pair<EventLoop *, std::function<void(bool)>> &loop :
473 raw_event_loops_) {
474 reinterpret_cast<SimulatedEventLoop *>(loop.first)
475 ->set_send_delay(send_delay_);
476 }
477}
478
Alex Perrycb7da4b2019-08-28 19:35:56 -0700479void SimulatedEventLoop::MakeRawWatcher(
480 const Channel *channel,
481 std::function<void(const Context &channel, const void *message)> watcher) {
Brian Silverman0fc69932020-01-24 21:54:02 -0800482 TakeWatcher(channel);
Austin Schuh217a9782019-12-21 23:02:50 -0800483
Austin Schuh8bd96322020-02-13 21:18:22 -0800484 std::unique_ptr<SimulatedWatcher> shm_watcher(
485 new SimulatedWatcher(this, scheduler_, channel, std::move(watcher)));
Austin Schuh39788ff2019-12-01 18:22:57 -0800486
487 GetSimulatedChannel(channel)->MakeRawWatcher(shm_watcher.get());
488 NewWatcher(std::move(shm_watcher));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700489}
490
491std::unique_ptr<RawSender> SimulatedEventLoop::MakeRawSender(
492 const Channel *channel) {
Brian Silverman0fc69932020-01-24 21:54:02 -0800493 TakeSender(channel);
494
Alex Perrycb7da4b2019-08-28 19:35:56 -0700495 return GetSimulatedChannel(channel)->MakeRawSender(this);
496}
497
498std::unique_ptr<RawFetcher> SimulatedEventLoop::MakeRawFetcher(
499 const Channel *channel) {
Austin Schuh39788ff2019-12-01 18:22:57 -0800500 ChannelIndex(channel);
Austin Schuh217a9782019-12-21 23:02:50 -0800501
Austin Schuhca4828c2019-12-28 14:21:35 -0800502 if (!configuration::ChannelIsReadableOnNode(channel, node())) {
503 LOG(FATAL) << "Channel { \"name\": \"" << channel->name()->string_view()
504 << "\", \"type\": \"" << channel->type()->string_view()
505 << "\" } is not able to be fetched on this node. Check your "
506 "configuration.";
Austin Schuh217a9782019-12-21 23:02:50 -0800507 }
508
Austin Schuh39788ff2019-12-01 18:22:57 -0800509 return GetSimulatedChannel(channel)->MakeRawFetcher(this);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700510}
511
512SimulatedChannel *SimulatedEventLoop::GetSimulatedChannel(
513 const Channel *channel) {
514 auto it = channels_->find(SimpleChannel(channel));
515 if (it == channels_->end()) {
516 it = channels_
517 ->emplace(SimpleChannel(channel),
518 std::unique_ptr<SimulatedChannel>(
519 new SimulatedChannel(channel, scheduler_)))
520 .first;
521 }
522 return it->second.get();
523}
524
Austin Schuh7d87b672019-12-01 20:23:49 -0800525SimulatedWatcher::SimulatedWatcher(
526 SimulatedEventLoop *simulated_event_loop, EventScheduler *scheduler,
Austin Schuh8bd96322020-02-13 21:18:22 -0800527 const Channel *channel,
Austin Schuh7d87b672019-12-01 20:23:49 -0800528 std::function<void(const Context &context, const void *message)> fn)
529 : WatcherState(simulated_event_loop, channel, std::move(fn)),
530 simulated_event_loop_(simulated_event_loop),
531 event_(this),
532 scheduler_(scheduler),
533 token_(scheduler_->InvalidToken()) {}
534
535SimulatedWatcher::~SimulatedWatcher() {
536 simulated_event_loop_->RemoveEvent(&event_);
537 if (token_ != scheduler_->InvalidToken()) {
538 scheduler_->Deschedule(token_);
539 }
540 simulated_channel_->RemoveWatcher(this);
541}
542
543void SimulatedWatcher::Schedule(std::shared_ptr<SimulatedMessage> message) {
Austin Schuha5e14192020-01-06 18:02:41 -0800544 monotonic_clock::time_point event_time =
545 simulated_event_loop_->monotonic_now();
Austin Schuh7d87b672019-12-01 20:23:49 -0800546
547 // Messages are queued in order. If we are the first, add ourselves.
548 // Otherwise, don't.
549 if (msgs_.size() == 0) {
Austin Schuhad154822019-12-27 15:45:13 -0800550 event_.set_event_time(message->context.monotonic_event_time);
Austin Schuh7d87b672019-12-01 20:23:49 -0800551 simulated_event_loop_->AddEvent(&event_);
552
553 DoSchedule(event_time);
554 }
555
556 msgs_.emplace_back(message);
557}
558
559void SimulatedWatcher::HandleEvent() {
560 CHECK_NE(msgs_.size(), 0u) << ": No events to handle.";
561
562 const monotonic_clock::time_point monotonic_now =
563 simulated_event_loop_->monotonic_now();
Tyler Chatow67ddb032020-01-12 14:30:04 -0800564 logging::ScopedLogRestorer prev_logger;
565 if (simulated_event_loop_->log_impl_ != nullptr) {
566 logging::SetImplementation(simulated_event_loop_->log_impl_);
567 }
Austin Schuhad154822019-12-27 15:45:13 -0800568 Context context = msgs_.front()->context;
569
570 if (context.remote_queue_index == 0xffffffffu) {
571 context.remote_queue_index = context.queue_index;
572 }
573 if (context.monotonic_remote_time == aos::monotonic_clock::min_time) {
574 context.monotonic_remote_time = context.monotonic_event_time;
575 }
576 if (context.realtime_remote_time == aos::realtime_clock::min_time) {
577 context.realtime_remote_time = context.realtime_event_time;
578 }
579
580 DoCallCallback([monotonic_now]() { return monotonic_now; }, context);
Austin Schuh7d87b672019-12-01 20:23:49 -0800581
582 msgs_.pop_front();
583 if (msgs_.size() != 0) {
Austin Schuhad154822019-12-27 15:45:13 -0800584 event_.set_event_time(msgs_.front()->context.monotonic_event_time);
Austin Schuh7d87b672019-12-01 20:23:49 -0800585 simulated_event_loop_->AddEvent(&event_);
586
587 DoSchedule(event_.event_time());
588 } else {
589 token_ = scheduler_->InvalidToken();
590 }
591}
592
593void SimulatedWatcher::DoSchedule(monotonic_clock::time_point event_time) {
Austin Schuh8bd96322020-02-13 21:18:22 -0800594 token_ =
595 scheduler_->Schedule(event_time + simulated_event_loop_->send_delay(),
596 [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuh7d87b672019-12-01 20:23:49 -0800597}
598
599void SimulatedChannel::MakeRawWatcher(SimulatedWatcher *watcher) {
Austin Schuh39788ff2019-12-01 18:22:57 -0800600 watcher->SetSimulatedChannel(this);
601 watchers_.emplace_back(watcher);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700602}
603
604::std::unique_ptr<RawSender> SimulatedChannel::MakeRawSender(
605 EventLoop *event_loop) {
606 return ::std::unique_ptr<RawSender>(new SimulatedSender(this, event_loop));
607}
608
Austin Schuh39788ff2019-12-01 18:22:57 -0800609::std::unique_ptr<RawFetcher> SimulatedChannel::MakeRawFetcher(
610 EventLoop *event_loop) {
611 ::std::unique_ptr<SimulatedFetcher> fetcher(
612 new SimulatedFetcher(event_loop, this));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700613 fetchers_.push_back(fetcher.get());
614 return ::std::move(fetcher);
615}
616
Austin Schuhad154822019-12-27 15:45:13 -0800617uint32_t SimulatedChannel::Send(std::shared_ptr<SimulatedMessage> message) {
618 const uint32_t queue_index = next_queue_index_.index();
619 message->context.queue_index = queue_index;
Brian Silvermana1652f32020-01-29 20:41:44 -0800620 message->context.data = message->data(channel()->max_size()) +
621 channel()->max_size() - message->context.size;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700622 next_queue_index_ = next_queue_index_.Increment();
623
624 latest_message_ = message;
625 if (scheduler_->is_running()) {
Austin Schuh7d87b672019-12-01 20:23:49 -0800626 for (SimulatedWatcher *watcher : watchers_) {
627 watcher->Schedule(message);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700628 }
629 }
630 for (auto &fetcher : fetchers_) {
631 fetcher->Enqueue(message);
632 }
Austin Schuhad154822019-12-27 15:45:13 -0800633
634 return queue_index;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700635}
636
637void SimulatedChannel::UnregisterFetcher(SimulatedFetcher *fetcher) {
638 fetchers_.erase(::std::find(fetchers_.begin(), fetchers_.end(), fetcher));
639}
640
Austin Schuh39788ff2019-12-01 18:22:57 -0800641SimulatedTimerHandler::SimulatedTimerHandler(
Austin Schuh8bd96322020-02-13 21:18:22 -0800642 EventScheduler *scheduler, SimulatedEventLoop *simulated_event_loop,
643 ::std::function<void()> fn)
Austin Schuh39788ff2019-12-01 18:22:57 -0800644 : TimerHandler(simulated_event_loop, std::move(fn)),
Austin Schuh7d87b672019-12-01 20:23:49 -0800645 simulated_event_loop_(simulated_event_loop),
646 event_(this),
Austin Schuh39788ff2019-12-01 18:22:57 -0800647 scheduler_(scheduler),
648 token_(scheduler_->InvalidToken()) {}
649
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800650void SimulatedTimerHandler::Setup(monotonic_clock::time_point base,
651 monotonic_clock::duration repeat_offset) {
652 Disable();
653 const ::aos::monotonic_clock::time_point monotonic_now =
Austin Schuha5e14192020-01-06 18:02:41 -0800654 simulated_event_loop_->monotonic_now();
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800655 base_ = base;
656 repeat_offset_ = repeat_offset;
657 if (base < monotonic_now) {
Austin Schuh7d87b672019-12-01 20:23:49 -0800658 token_ = scheduler_->Schedule(
Austin Schuh8bd96322020-02-13 21:18:22 -0800659 monotonic_now, [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800660 } else {
Austin Schuh7d87b672019-12-01 20:23:49 -0800661 token_ = scheduler_->Schedule(
Austin Schuh8bd96322020-02-13 21:18:22 -0800662 base, [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800663 }
Austin Schuh7d87b672019-12-01 20:23:49 -0800664 event_.set_event_time(base_);
665 simulated_event_loop_->AddEvent(&event_);
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800666}
667
668void SimulatedTimerHandler::HandleEvent() {
669 const ::aos::monotonic_clock::time_point monotonic_now =
Austin Schuha5e14192020-01-06 18:02:41 -0800670 simulated_event_loop_->monotonic_now();
Tyler Chatow67ddb032020-01-12 14:30:04 -0800671 logging::ScopedLogRestorer prev_logger;
672 if (simulated_event_loop_->log_impl_ != nullptr) {
673 logging::SetImplementation(simulated_event_loop_->log_impl_);
674 }
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800675 if (repeat_offset_ != ::aos::monotonic_clock::zero()) {
676 // Reschedule.
677 while (base_ <= monotonic_now) base_ += repeat_offset_;
Austin Schuh7d87b672019-12-01 20:23:49 -0800678 token_ = scheduler_->Schedule(
Austin Schuh8bd96322020-02-13 21:18:22 -0800679 base_, [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuh7d87b672019-12-01 20:23:49 -0800680 event_.set_event_time(base_);
681 simulated_event_loop_->AddEvent(&event_);
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800682 } else {
683 token_ = scheduler_->InvalidToken();
684 }
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800685
Austin Schuh39788ff2019-12-01 18:22:57 -0800686 Call([monotonic_now]() { return monotonic_now; }, monotonic_now);
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800687}
688
Austin Schuh7d87b672019-12-01 20:23:49 -0800689void SimulatedTimerHandler::Disable() {
690 simulated_event_loop_->RemoveEvent(&event_);
691 if (token_ != scheduler_->InvalidToken()) {
692 scheduler_->Deschedule(token_);
693 token_ = scheduler_->InvalidToken();
694 }
695}
696
Austin Schuh39788ff2019-12-01 18:22:57 -0800697SimulatedPhasedLoopHandler::SimulatedPhasedLoopHandler(
Austin Schuh8bd96322020-02-13 21:18:22 -0800698 EventScheduler *scheduler, SimulatedEventLoop *simulated_event_loop,
699 ::std::function<void(int)> fn, const monotonic_clock::duration interval,
Austin Schuh39788ff2019-12-01 18:22:57 -0800700 const monotonic_clock::duration offset)
701 : PhasedLoopHandler(simulated_event_loop, std::move(fn), interval, offset),
702 simulated_event_loop_(simulated_event_loop),
Austin Schuh7d87b672019-12-01 20:23:49 -0800703 event_(this),
Austin Schuh39788ff2019-12-01 18:22:57 -0800704 scheduler_(scheduler),
705 token_(scheduler_->InvalidToken()) {}
706
Austin Schuh7d87b672019-12-01 20:23:49 -0800707SimulatedPhasedLoopHandler::~SimulatedPhasedLoopHandler() {
708 if (token_ != scheduler_->InvalidToken()) {
709 scheduler_->Deschedule(token_);
710 token_ = scheduler_->InvalidToken();
711 }
712 simulated_event_loop_->RemoveEvent(&event_);
713}
714
715void SimulatedPhasedLoopHandler::HandleEvent() {
Austin Schuh39788ff2019-12-01 18:22:57 -0800716 monotonic_clock::time_point monotonic_now =
717 simulated_event_loop_->monotonic_now();
Tyler Chatow67ddb032020-01-12 14:30:04 -0800718 logging::ScopedLogRestorer prev_logger;
719 if (simulated_event_loop_->log_impl_ != nullptr) {
720 logging::SetImplementation(simulated_event_loop_->log_impl_);
721 }
Austin Schuh39788ff2019-12-01 18:22:57 -0800722 Call(
723 [monotonic_now]() { return monotonic_now; },
724 [this](monotonic_clock::time_point sleep_time) { Schedule(sleep_time); });
725}
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800726
Austin Schuh7d87b672019-12-01 20:23:49 -0800727void SimulatedPhasedLoopHandler::Schedule(
728 monotonic_clock::time_point sleep_time) {
729 token_ = scheduler_->Schedule(
Austin Schuh8bd96322020-02-13 21:18:22 -0800730 sleep_time, [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuh7d87b672019-12-01 20:23:49 -0800731 event_.set_event_time(sleep_time);
732 simulated_event_loop_->AddEvent(&event_);
733}
734
Austin Schuhac0771c2020-01-07 18:36:30 -0800735NodeEventLoopFactory::NodeEventLoopFactory(
Austin Schuh8bd96322020-02-13 21:18:22 -0800736 EventSchedulerScheduler *scheduler_scheduler,
737 SimulatedEventLoopFactory *factory, const Node *node,
Austin Schuhac0771c2020-01-07 18:36:30 -0800738 std::vector<std::pair<EventLoop *, std::function<void(bool)>>>
739 *raw_event_loops)
Austin Schuh8bd96322020-02-13 21:18:22 -0800740 : factory_(factory), node_(node), raw_event_loops_(raw_event_loops) {
741 scheduler_scheduler->AddEventScheduler(&scheduler_);
742}
Austin Schuhac0771c2020-01-07 18:36:30 -0800743
Alex Perrycb7da4b2019-08-28 19:35:56 -0700744SimulatedEventLoopFactory::SimulatedEventLoopFactory(
745 const Configuration *configuration)
Austin Schuh6f3babe2020-01-26 20:34:50 -0800746 : configuration_(CHECK_NOTNULL(configuration)),
747 nodes_(configuration::GetNodes(configuration_)) {
Austin Schuhac0771c2020-01-07 18:36:30 -0800748 for (const Node *node : nodes_) {
Austin Schuh8bd96322020-02-13 21:18:22 -0800749 node_factories_.emplace_back(new NodeEventLoopFactory(
750 &scheduler_scheduler_, this, node, &raw_event_loops_));
Austin Schuh15649d62019-12-28 16:36:38 -0800751 }
Austin Schuh898f4972020-01-11 17:21:25 -0800752
753 if (configuration::MultiNode(configuration)) {
754 bridge_ = std::make_unique<message_bridge::SimulatedMessageBridge>(this);
755 }
Austin Schuh15649d62019-12-28 16:36:38 -0800756}
757
Alex Perrycb7da4b2019-08-28 19:35:56 -0700758SimulatedEventLoopFactory::~SimulatedEventLoopFactory() {}
759
Austin Schuhac0771c2020-01-07 18:36:30 -0800760NodeEventLoopFactory *SimulatedEventLoopFactory::GetNodeEventLoopFactory(
761 const Node *node) {
762 auto result = std::find_if(
763 node_factories_.begin(), node_factories_.end(),
764 [node](const std::unique_ptr<NodeEventLoopFactory> &node_factory) {
765 return node_factory->node() == node;
766 });
767
768 CHECK(result != node_factories_.end())
769 << ": Failed to find node " << FlatbufferToJson(node);
770
771 return result->get();
772}
773
Austin Schuh5f1cc5c2019-12-01 18:01:11 -0800774::std::unique_ptr<EventLoop> SimulatedEventLoopFactory::MakeEventLoop(
Austin Schuhac0771c2020-01-07 18:36:30 -0800775 std::string_view name, const Node *node) {
776 if (node == nullptr) {
777 CHECK(!configuration::MultiNode(configuration()))
778 << ": Can't make a single node event loop in a multi-node world.";
779 } else {
780 CHECK(configuration::MultiNode(configuration()))
781 << ": Can't make a multi-node event loop in a single-node world.";
782 }
783 return GetNodeEventLoopFactory(node)->MakeEventLoop(name);
784}
785
786::std::unique_ptr<EventLoop> NodeEventLoopFactory::MakeEventLoop(
Austin Schuh5f1cc5c2019-12-01 18:01:11 -0800787 std::string_view name) {
Austin Schuh8bd96322020-02-13 21:18:22 -0800788 CHECK(!scheduler_.is_running())
789 << ": Can't create an event loop while running";
790
Austin Schuh39788ff2019-12-01 18:22:57 -0800791 pid_t tid = tid_;
792 ++tid_;
Austin Schuh7d87b672019-12-01 20:23:49 -0800793 ::std::unique_ptr<SimulatedEventLoop> result(new SimulatedEventLoop(
Austin Schuh8bd96322020-02-13 21:18:22 -0800794 &scheduler_, this, &channels_, factory_->configuration(),
795 raw_event_loops_, node_, tid));
Austin Schuh5f1cc5c2019-12-01 18:01:11 -0800796 result->set_name(name);
Austin Schuhac0771c2020-01-07 18:36:30 -0800797 result->set_send_delay(factory_->send_delay());
Austin Schuh7d87b672019-12-01 20:23:49 -0800798 return std::move(result);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700799}
800
801void SimulatedEventLoopFactory::RunFor(monotonic_clock::duration duration) {
802 for (const std::pair<EventLoop *, std::function<void(bool)>> &event_loop :
803 raw_event_loops_) {
804 event_loop.second(true);
805 }
Austin Schuh8bd96322020-02-13 21:18:22 -0800806 scheduler_scheduler_.RunFor(duration);
Austin Schuh39788ff2019-12-01 18:22:57 -0800807 for (const std::pair<EventLoop *, std::function<void(bool)>> &event_loop :
808 raw_event_loops_) {
809 event_loop.second(false);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700810 }
811}
812
813void SimulatedEventLoopFactory::Run() {
814 for (const std::pair<EventLoop *, std::function<void(bool)>> &event_loop :
815 raw_event_loops_) {
816 event_loop.second(true);
817 }
Austin Schuh8bd96322020-02-13 21:18:22 -0800818 scheduler_scheduler_.Run();
Austin Schuh39788ff2019-12-01 18:22:57 -0800819 for (const std::pair<EventLoop *, std::function<void(bool)>> &event_loop :
820 raw_event_loops_) {
821 event_loop.second(false);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700822 }
823}
824
Austin Schuh6f3babe2020-01-26 20:34:50 -0800825void SimulatedEventLoopFactory::DisableForwarding(const Channel *channel) {
826 bridge_->DisableForwarding(channel);
827}
828
Alex Perrycb7da4b2019-08-28 19:35:56 -0700829} // namespace aos