blob: cf58b469f2436d6937c12028163942ac5a4914f0 [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
Tyler Chatow67ddb032020-01-12 14:30:04 -0800417 void Setup() {
418 MaybeScheduleTimingReports();
419 if (!skip_logger_) {
420 logging::ScopedLogRestorer prev_logger;
421 log_sender_.Initialize(MakeSender<logging::LogMessageFbs>("/aos"));
422 log_impl_ = logging::GetImplementation();
423 }
424 }
Austin Schuh39788ff2019-12-01 18:22:57 -0800425
Alex Perrycb7da4b2019-08-28 19:35:56 -0700426 private:
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800427 friend class SimulatedTimerHandler;
Austin Schuh7d87b672019-12-01 20:23:49 -0800428 friend class SimulatedPhasedLoopHandler;
429 friend class SimulatedWatcher;
430
431 void HandleEvent() {
432 while (true) {
433 if (EventCount() == 0 || PeekEvent()->event_time() > monotonic_now()) {
434 break;
435 }
436
437 EventLoopEvent *event = PopEvent();
438 event->HandleEvent();
439 }
440 }
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800441
Austin Schuh39788ff2019-12-01 18:22:57 -0800442 pid_t GetTid() override { return tid_; }
443
Alex Perrycb7da4b2019-08-28 19:35:56 -0700444 EventScheduler *scheduler_;
Austin Schuhac0771c2020-01-07 18:36:30 -0800445 NodeEventLoopFactory *node_event_loop_factory_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700446 absl::btree_map<SimpleChannel, std::unique_ptr<SimulatedChannel>> *channels_;
447 std::vector<std::pair<EventLoop *, std::function<void(bool)>>>
448 *raw_event_loops_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700449
450 ::std::string name_;
Austin Schuh39788ff2019-12-01 18:22:57 -0800451
452 int priority_ = 0;
453
454 bool has_setup_ = false;
455
Austin Schuh7d87b672019-12-01 20:23:49 -0800456 std::chrono::nanoseconds send_delay_;
457
Austin Schuh217a9782019-12-21 23:02:50 -0800458 const Node *const node_;
Austin Schuh39788ff2019-12-01 18:22:57 -0800459 const pid_t tid_;
Tyler Chatow67ddb032020-01-12 14:30:04 -0800460
461 AosLogToFbs log_sender_;
462 logging::LogImplementation *log_impl_ = nullptr;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700463};
464
Austin Schuh7d87b672019-12-01 20:23:49 -0800465void SimulatedEventLoopFactory::set_send_delay(
466 std::chrono::nanoseconds send_delay) {
467 send_delay_ = send_delay;
468 for (std::pair<EventLoop *, std::function<void(bool)>> &loop :
469 raw_event_loops_) {
470 reinterpret_cast<SimulatedEventLoop *>(loop.first)
471 ->set_send_delay(send_delay_);
472 }
473}
474
Alex Perrycb7da4b2019-08-28 19:35:56 -0700475void SimulatedEventLoop::MakeRawWatcher(
476 const Channel *channel,
477 std::function<void(const Context &channel, const void *message)> watcher) {
Brian Silverman0fc69932020-01-24 21:54:02 -0800478 TakeWatcher(channel);
Austin Schuh217a9782019-12-21 23:02:50 -0800479
Austin Schuh8bd96322020-02-13 21:18:22 -0800480 std::unique_ptr<SimulatedWatcher> shm_watcher(
481 new SimulatedWatcher(this, scheduler_, channel, std::move(watcher)));
Austin Schuh39788ff2019-12-01 18:22:57 -0800482
483 GetSimulatedChannel(channel)->MakeRawWatcher(shm_watcher.get());
484 NewWatcher(std::move(shm_watcher));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700485}
486
487std::unique_ptr<RawSender> SimulatedEventLoop::MakeRawSender(
488 const Channel *channel) {
Brian Silverman0fc69932020-01-24 21:54:02 -0800489 TakeSender(channel);
490
Alex Perrycb7da4b2019-08-28 19:35:56 -0700491 return GetSimulatedChannel(channel)->MakeRawSender(this);
492}
493
494std::unique_ptr<RawFetcher> SimulatedEventLoop::MakeRawFetcher(
495 const Channel *channel) {
Austin Schuh39788ff2019-12-01 18:22:57 -0800496 ChannelIndex(channel);
Austin Schuh217a9782019-12-21 23:02:50 -0800497
Austin Schuhca4828c2019-12-28 14:21:35 -0800498 if (!configuration::ChannelIsReadableOnNode(channel, node())) {
499 LOG(FATAL) << "Channel { \"name\": \"" << channel->name()->string_view()
500 << "\", \"type\": \"" << channel->type()->string_view()
501 << "\" } is not able to be fetched on this node. Check your "
502 "configuration.";
Austin Schuh217a9782019-12-21 23:02:50 -0800503 }
504
Austin Schuh39788ff2019-12-01 18:22:57 -0800505 return GetSimulatedChannel(channel)->MakeRawFetcher(this);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700506}
507
508SimulatedChannel *SimulatedEventLoop::GetSimulatedChannel(
509 const Channel *channel) {
510 auto it = channels_->find(SimpleChannel(channel));
511 if (it == channels_->end()) {
512 it = channels_
513 ->emplace(SimpleChannel(channel),
514 std::unique_ptr<SimulatedChannel>(
515 new SimulatedChannel(channel, scheduler_)))
516 .first;
517 }
518 return it->second.get();
519}
520
Austin Schuh7d87b672019-12-01 20:23:49 -0800521SimulatedWatcher::SimulatedWatcher(
522 SimulatedEventLoop *simulated_event_loop, EventScheduler *scheduler,
Austin Schuh8bd96322020-02-13 21:18:22 -0800523 const Channel *channel,
Austin Schuh7d87b672019-12-01 20:23:49 -0800524 std::function<void(const Context &context, const void *message)> fn)
525 : WatcherState(simulated_event_loop, channel, std::move(fn)),
526 simulated_event_loop_(simulated_event_loop),
527 event_(this),
528 scheduler_(scheduler),
529 token_(scheduler_->InvalidToken()) {}
530
531SimulatedWatcher::~SimulatedWatcher() {
532 simulated_event_loop_->RemoveEvent(&event_);
533 if (token_ != scheduler_->InvalidToken()) {
534 scheduler_->Deschedule(token_);
535 }
536 simulated_channel_->RemoveWatcher(this);
537}
538
539void SimulatedWatcher::Schedule(std::shared_ptr<SimulatedMessage> message) {
Austin Schuha5e14192020-01-06 18:02:41 -0800540 monotonic_clock::time_point event_time =
541 simulated_event_loop_->monotonic_now();
Austin Schuh7d87b672019-12-01 20:23:49 -0800542
543 // Messages are queued in order. If we are the first, add ourselves.
544 // Otherwise, don't.
545 if (msgs_.size() == 0) {
Austin Schuhad154822019-12-27 15:45:13 -0800546 event_.set_event_time(message->context.monotonic_event_time);
Austin Schuh7d87b672019-12-01 20:23:49 -0800547 simulated_event_loop_->AddEvent(&event_);
548
549 DoSchedule(event_time);
550 }
551
552 msgs_.emplace_back(message);
553}
554
555void SimulatedWatcher::HandleEvent() {
556 CHECK_NE(msgs_.size(), 0u) << ": No events to handle.";
557
558 const monotonic_clock::time_point monotonic_now =
559 simulated_event_loop_->monotonic_now();
Tyler Chatow67ddb032020-01-12 14:30:04 -0800560 logging::ScopedLogRestorer prev_logger;
561 if (simulated_event_loop_->log_impl_ != nullptr) {
562 logging::SetImplementation(simulated_event_loop_->log_impl_);
563 }
Austin Schuhad154822019-12-27 15:45:13 -0800564 Context context = msgs_.front()->context;
565
566 if (context.remote_queue_index == 0xffffffffu) {
567 context.remote_queue_index = context.queue_index;
568 }
569 if (context.monotonic_remote_time == aos::monotonic_clock::min_time) {
570 context.monotonic_remote_time = context.monotonic_event_time;
571 }
572 if (context.realtime_remote_time == aos::realtime_clock::min_time) {
573 context.realtime_remote_time = context.realtime_event_time;
574 }
575
576 DoCallCallback([monotonic_now]() { return monotonic_now; }, context);
Austin Schuh7d87b672019-12-01 20:23:49 -0800577
578 msgs_.pop_front();
579 if (msgs_.size() != 0) {
Austin Schuhad154822019-12-27 15:45:13 -0800580 event_.set_event_time(msgs_.front()->context.monotonic_event_time);
Austin Schuh7d87b672019-12-01 20:23:49 -0800581 simulated_event_loop_->AddEvent(&event_);
582
583 DoSchedule(event_.event_time());
584 } else {
585 token_ = scheduler_->InvalidToken();
586 }
587}
588
589void SimulatedWatcher::DoSchedule(monotonic_clock::time_point event_time) {
Austin Schuh8bd96322020-02-13 21:18:22 -0800590 token_ =
591 scheduler_->Schedule(event_time + simulated_event_loop_->send_delay(),
592 [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuh7d87b672019-12-01 20:23:49 -0800593}
594
595void SimulatedChannel::MakeRawWatcher(SimulatedWatcher *watcher) {
Austin Schuh39788ff2019-12-01 18:22:57 -0800596 watcher->SetSimulatedChannel(this);
597 watchers_.emplace_back(watcher);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700598}
599
600::std::unique_ptr<RawSender> SimulatedChannel::MakeRawSender(
601 EventLoop *event_loop) {
602 return ::std::unique_ptr<RawSender>(new SimulatedSender(this, event_loop));
603}
604
Austin Schuh39788ff2019-12-01 18:22:57 -0800605::std::unique_ptr<RawFetcher> SimulatedChannel::MakeRawFetcher(
606 EventLoop *event_loop) {
607 ::std::unique_ptr<SimulatedFetcher> fetcher(
608 new SimulatedFetcher(event_loop, this));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700609 fetchers_.push_back(fetcher.get());
610 return ::std::move(fetcher);
611}
612
Austin Schuhad154822019-12-27 15:45:13 -0800613uint32_t SimulatedChannel::Send(std::shared_ptr<SimulatedMessage> message) {
614 const uint32_t queue_index = next_queue_index_.index();
615 message->context.queue_index = queue_index;
Brian Silvermana1652f32020-01-29 20:41:44 -0800616 message->context.data = message->data(channel()->max_size()) +
617 channel()->max_size() - message->context.size;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700618 next_queue_index_ = next_queue_index_.Increment();
619
620 latest_message_ = message;
621 if (scheduler_->is_running()) {
Austin Schuh7d87b672019-12-01 20:23:49 -0800622 for (SimulatedWatcher *watcher : watchers_) {
623 watcher->Schedule(message);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700624 }
625 }
626 for (auto &fetcher : fetchers_) {
627 fetcher->Enqueue(message);
628 }
Austin Schuhad154822019-12-27 15:45:13 -0800629
630 return queue_index;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700631}
632
633void SimulatedChannel::UnregisterFetcher(SimulatedFetcher *fetcher) {
634 fetchers_.erase(::std::find(fetchers_.begin(), fetchers_.end(), fetcher));
635}
636
Austin Schuh39788ff2019-12-01 18:22:57 -0800637SimulatedTimerHandler::SimulatedTimerHandler(
Austin Schuh8bd96322020-02-13 21:18:22 -0800638 EventScheduler *scheduler, SimulatedEventLoop *simulated_event_loop,
639 ::std::function<void()> fn)
Austin Schuh39788ff2019-12-01 18:22:57 -0800640 : TimerHandler(simulated_event_loop, std::move(fn)),
Austin Schuh7d87b672019-12-01 20:23:49 -0800641 simulated_event_loop_(simulated_event_loop),
642 event_(this),
Austin Schuh39788ff2019-12-01 18:22:57 -0800643 scheduler_(scheduler),
644 token_(scheduler_->InvalidToken()) {}
645
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800646void SimulatedTimerHandler::Setup(monotonic_clock::time_point base,
647 monotonic_clock::duration repeat_offset) {
648 Disable();
649 const ::aos::monotonic_clock::time_point monotonic_now =
Austin Schuha5e14192020-01-06 18:02:41 -0800650 simulated_event_loop_->monotonic_now();
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800651 base_ = base;
652 repeat_offset_ = repeat_offset;
653 if (base < monotonic_now) {
Austin Schuh7d87b672019-12-01 20:23:49 -0800654 token_ = scheduler_->Schedule(
Austin Schuh8bd96322020-02-13 21:18:22 -0800655 monotonic_now, [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800656 } else {
Austin Schuh7d87b672019-12-01 20:23:49 -0800657 token_ = scheduler_->Schedule(
Austin Schuh8bd96322020-02-13 21:18:22 -0800658 base, [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800659 }
Austin Schuh7d87b672019-12-01 20:23:49 -0800660 event_.set_event_time(base_);
661 simulated_event_loop_->AddEvent(&event_);
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800662}
663
664void SimulatedTimerHandler::HandleEvent() {
665 const ::aos::monotonic_clock::time_point monotonic_now =
Austin Schuha5e14192020-01-06 18:02:41 -0800666 simulated_event_loop_->monotonic_now();
Tyler Chatow67ddb032020-01-12 14:30:04 -0800667 logging::ScopedLogRestorer prev_logger;
668 if (simulated_event_loop_->log_impl_ != nullptr) {
669 logging::SetImplementation(simulated_event_loop_->log_impl_);
670 }
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800671 if (repeat_offset_ != ::aos::monotonic_clock::zero()) {
672 // Reschedule.
673 while (base_ <= monotonic_now) base_ += repeat_offset_;
Austin Schuh7d87b672019-12-01 20:23:49 -0800674 token_ = scheduler_->Schedule(
Austin Schuh8bd96322020-02-13 21:18:22 -0800675 base_, [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuh7d87b672019-12-01 20:23:49 -0800676 event_.set_event_time(base_);
677 simulated_event_loop_->AddEvent(&event_);
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800678 } else {
679 token_ = scheduler_->InvalidToken();
680 }
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800681
Austin Schuh39788ff2019-12-01 18:22:57 -0800682 Call([monotonic_now]() { return monotonic_now; }, monotonic_now);
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800683}
684
Austin Schuh7d87b672019-12-01 20:23:49 -0800685void SimulatedTimerHandler::Disable() {
686 simulated_event_loop_->RemoveEvent(&event_);
687 if (token_ != scheduler_->InvalidToken()) {
688 scheduler_->Deschedule(token_);
689 token_ = scheduler_->InvalidToken();
690 }
691}
692
Austin Schuh39788ff2019-12-01 18:22:57 -0800693SimulatedPhasedLoopHandler::SimulatedPhasedLoopHandler(
Austin Schuh8bd96322020-02-13 21:18:22 -0800694 EventScheduler *scheduler, SimulatedEventLoop *simulated_event_loop,
695 ::std::function<void(int)> fn, const monotonic_clock::duration interval,
Austin Schuh39788ff2019-12-01 18:22:57 -0800696 const monotonic_clock::duration offset)
697 : PhasedLoopHandler(simulated_event_loop, std::move(fn), interval, offset),
698 simulated_event_loop_(simulated_event_loop),
Austin Schuh7d87b672019-12-01 20:23:49 -0800699 event_(this),
Austin Schuh39788ff2019-12-01 18:22:57 -0800700 scheduler_(scheduler),
701 token_(scheduler_->InvalidToken()) {}
702
Austin Schuh7d87b672019-12-01 20:23:49 -0800703SimulatedPhasedLoopHandler::~SimulatedPhasedLoopHandler() {
704 if (token_ != scheduler_->InvalidToken()) {
705 scheduler_->Deschedule(token_);
706 token_ = scheduler_->InvalidToken();
707 }
708 simulated_event_loop_->RemoveEvent(&event_);
709}
710
711void SimulatedPhasedLoopHandler::HandleEvent() {
Austin Schuh39788ff2019-12-01 18:22:57 -0800712 monotonic_clock::time_point monotonic_now =
713 simulated_event_loop_->monotonic_now();
Tyler Chatow67ddb032020-01-12 14:30:04 -0800714 logging::ScopedLogRestorer prev_logger;
715 if (simulated_event_loop_->log_impl_ != nullptr) {
716 logging::SetImplementation(simulated_event_loop_->log_impl_);
717 }
Austin Schuh39788ff2019-12-01 18:22:57 -0800718 Call(
719 [monotonic_now]() { return monotonic_now; },
720 [this](monotonic_clock::time_point sleep_time) { Schedule(sleep_time); });
721}
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800722
Austin Schuh7d87b672019-12-01 20:23:49 -0800723void SimulatedPhasedLoopHandler::Schedule(
724 monotonic_clock::time_point sleep_time) {
725 token_ = scheduler_->Schedule(
Austin Schuh8bd96322020-02-13 21:18:22 -0800726 sleep_time, [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuh7d87b672019-12-01 20:23:49 -0800727 event_.set_event_time(sleep_time);
728 simulated_event_loop_->AddEvent(&event_);
729}
730
Austin Schuhac0771c2020-01-07 18:36:30 -0800731NodeEventLoopFactory::NodeEventLoopFactory(
Austin Schuh8bd96322020-02-13 21:18:22 -0800732 EventSchedulerScheduler *scheduler_scheduler,
733 SimulatedEventLoopFactory *factory, const Node *node,
Austin Schuhac0771c2020-01-07 18:36:30 -0800734 std::vector<std::pair<EventLoop *, std::function<void(bool)>>>
735 *raw_event_loops)
Austin Schuh8bd96322020-02-13 21:18:22 -0800736 : factory_(factory), node_(node), raw_event_loops_(raw_event_loops) {
737 scheduler_scheduler->AddEventScheduler(&scheduler_);
738}
Austin Schuhac0771c2020-01-07 18:36:30 -0800739
Alex Perrycb7da4b2019-08-28 19:35:56 -0700740SimulatedEventLoopFactory::SimulatedEventLoopFactory(
741 const Configuration *configuration)
Austin Schuh6f3babe2020-01-26 20:34:50 -0800742 : configuration_(CHECK_NOTNULL(configuration)),
743 nodes_(configuration::GetNodes(configuration_)) {
Austin Schuhac0771c2020-01-07 18:36:30 -0800744 for (const Node *node : nodes_) {
Austin Schuh8bd96322020-02-13 21:18:22 -0800745 node_factories_.emplace_back(new NodeEventLoopFactory(
746 &scheduler_scheduler_, this, node, &raw_event_loops_));
Austin Schuh15649d62019-12-28 16:36:38 -0800747 }
Austin Schuh898f4972020-01-11 17:21:25 -0800748
749 if (configuration::MultiNode(configuration)) {
750 bridge_ = std::make_unique<message_bridge::SimulatedMessageBridge>(this);
751 }
Austin Schuh15649d62019-12-28 16:36:38 -0800752}
753
Alex Perrycb7da4b2019-08-28 19:35:56 -0700754SimulatedEventLoopFactory::~SimulatedEventLoopFactory() {}
755
Austin Schuhac0771c2020-01-07 18:36:30 -0800756NodeEventLoopFactory *SimulatedEventLoopFactory::GetNodeEventLoopFactory(
757 const Node *node) {
758 auto result = std::find_if(
759 node_factories_.begin(), node_factories_.end(),
760 [node](const std::unique_ptr<NodeEventLoopFactory> &node_factory) {
761 return node_factory->node() == node;
762 });
763
764 CHECK(result != node_factories_.end())
765 << ": Failed to find node " << FlatbufferToJson(node);
766
767 return result->get();
768}
769
Austin Schuh5f1cc5c2019-12-01 18:01:11 -0800770::std::unique_ptr<EventLoop> SimulatedEventLoopFactory::MakeEventLoop(
Austin Schuhac0771c2020-01-07 18:36:30 -0800771 std::string_view name, const Node *node) {
772 if (node == nullptr) {
773 CHECK(!configuration::MultiNode(configuration()))
774 << ": Can't make a single node event loop in a multi-node world.";
775 } else {
776 CHECK(configuration::MultiNode(configuration()))
777 << ": Can't make a multi-node event loop in a single-node world.";
778 }
779 return GetNodeEventLoopFactory(node)->MakeEventLoop(name);
780}
781
782::std::unique_ptr<EventLoop> NodeEventLoopFactory::MakeEventLoop(
Austin Schuh5f1cc5c2019-12-01 18:01:11 -0800783 std::string_view name) {
Austin Schuh8bd96322020-02-13 21:18:22 -0800784 CHECK(!scheduler_.is_running())
785 << ": Can't create an event loop while running";
786
Austin Schuh39788ff2019-12-01 18:22:57 -0800787 pid_t tid = tid_;
788 ++tid_;
Austin Schuh7d87b672019-12-01 20:23:49 -0800789 ::std::unique_ptr<SimulatedEventLoop> result(new SimulatedEventLoop(
Austin Schuh8bd96322020-02-13 21:18:22 -0800790 &scheduler_, this, &channels_, factory_->configuration(),
791 raw_event_loops_, node_, tid));
Austin Schuh5f1cc5c2019-12-01 18:01:11 -0800792 result->set_name(name);
Austin Schuhac0771c2020-01-07 18:36:30 -0800793 result->set_send_delay(factory_->send_delay());
Austin Schuh7d87b672019-12-01 20:23:49 -0800794 return std::move(result);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700795}
796
797void SimulatedEventLoopFactory::RunFor(monotonic_clock::duration duration) {
798 for (const std::pair<EventLoop *, std::function<void(bool)>> &event_loop :
799 raw_event_loops_) {
800 event_loop.second(true);
801 }
Austin Schuh8bd96322020-02-13 21:18:22 -0800802 scheduler_scheduler_.RunFor(duration);
Austin Schuh39788ff2019-12-01 18:22:57 -0800803 for (const std::pair<EventLoop *, std::function<void(bool)>> &event_loop :
804 raw_event_loops_) {
805 event_loop.second(false);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700806 }
807}
808
809void SimulatedEventLoopFactory::Run() {
810 for (const std::pair<EventLoop *, std::function<void(bool)>> &event_loop :
811 raw_event_loops_) {
812 event_loop.second(true);
813 }
Austin Schuh8bd96322020-02-13 21:18:22 -0800814 scheduler_scheduler_.Run();
Austin Schuh39788ff2019-12-01 18:22:57 -0800815 for (const std::pair<EventLoop *, std::function<void(bool)>> &event_loop :
816 raw_event_loops_) {
817 event_loop.second(false);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700818 }
819}
820
Austin Schuh6f3babe2020-01-26 20:34:50 -0800821void SimulatedEventLoopFactory::DisableForwarding(const Channel *channel) {
822 bridge_->DisableForwarding(channel);
823}
824
Alex Perrycb7da4b2019-08-28 19:35:56 -0700825} // namespace aos