Refactor SimulatedEventLoopFactory to not have lists of functions
We can use a SimulatedEventLoop * instead of a list of std::function.
The factory is already a friend, and this lets us tell which
event loops are for which nodes much easier. This preps us for
rebooting.
Change-Id: I0fb582e76b51e2cc93b17430a41cb6e65bb0a5f1
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
diff --git a/aos/events/simulated_event_loop.h b/aos/events/simulated_event_loop.h
index 348e7dd..cc016a8 100644
--- a/aos/events/simulated_event_loop.h
+++ b/aos/events/simulated_event_loop.h
@@ -26,6 +26,7 @@
class SimulatedChannel;
class NodeEventLoopFactory;
+class SimulatedEventLoop;
namespace message_bridge {
class SimulatedMessageBridge;
}
@@ -72,6 +73,7 @@
// NodeEventLoopFactory is owned by the SimulatedEventLoopFactory and has a
// lifetime identical to the factory.
NodeEventLoopFactory *GetNodeEventLoopFactory(const Node *node);
+ NodeEventLoopFactory *GetNodeEventLoopFactory(std::string_view node);
// Sets the time converter for all nodes.
void SetTimeConverter(TimeConverter *time_converter);
@@ -122,11 +124,6 @@
const Configuration *const configuration_;
EventSchedulerScheduler scheduler_scheduler_;
- // List of event loops to manage running and not running for.
- // The function is a callback used to set and clear the running bool on each
- // event loop.
- std::vector<std::pair<EventLoop *, std::function<void(bool)>>>
- raw_event_loops_;
std::chrono::nanoseconds send_delay_ = std::chrono::microseconds(50);
std::chrono::nanoseconds network_delay_ = std::chrono::microseconds(100);
@@ -141,7 +138,9 @@
// This class holds all the state required to be a single node.
class NodeEventLoopFactory {
public:
- ::std::unique_ptr<EventLoop> MakeEventLoop(std::string_view name);
+ ~NodeEventLoopFactory();
+
+ std::unique_ptr<EventLoop> MakeEventLoop(std::string_view name);
// Returns the node that this factory is running as, or nullptr if this is a
// single node setup.
@@ -212,11 +211,8 @@
private:
friend class SimulatedEventLoopFactory;
- NodeEventLoopFactory(
- EventSchedulerScheduler *scheduler_scheduler,
- SimulatedEventLoopFactory *factory, const Node *node,
- std::vector<std::pair<EventLoop *, std::function<void(bool)>>>
- *raw_event_loops);
+ NodeEventLoopFactory(EventSchedulerScheduler *scheduler_scheduler,
+ SimulatedEventLoopFactory *factory, const Node *node);
EventScheduler scheduler_;
SimulatedEventLoopFactory *const factory_;
@@ -225,8 +221,7 @@
const Node *const node_;
- std::vector<std::pair<EventLoop *, std::function<void(bool)>>>
- *const raw_event_loops_;
+ std::vector<SimulatedEventLoop *> event_loops_;
std::chrono::nanoseconds realtime_offset_ = std::chrono::seconds(0);