James Kuszmaul | 9a816a7 | 2023-03-23 15:10:34 -0700 | [diff] [blame] | 1 | #include <map> |
| 2 | |
| 3 | #include "aos/events/event_loop.h" |
| 4 | #include "aos/events/simulated_event_loop.h" |
| 5 | #include "aos/starter/starter_generated.h" |
| 6 | #include "aos/starter/starter_rpc_generated.h" |
| 7 | #include "aos/starter/starterd_lib.h" |
| 8 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame^] | 9 | namespace aos::starter { |
James Kuszmaul | 9a816a7 | 2023-03-23 15:10:34 -0700 | [diff] [blame] | 10 | |
| 11 | // Simple mock of starterd that updates the starter status message to act as |
| 12 | // though applications are started and stopped when requested. |
| 13 | // TODO(james.kuszmaul): Consider integrating with SimulatedEventLoopFactory. |
| 14 | class MockStarter { |
| 15 | public: |
| 16 | struct ApplicationStatus { |
| 17 | int id; |
| 18 | bool running; |
| 19 | aos::monotonic_clock::time_point start_time; |
| 20 | }; |
| 21 | |
| 22 | MockStarter(aos::EventLoop *event_loop); |
| 23 | |
| 24 | const aos::Node *node() const { return event_loop_->node(); } |
| 25 | |
| 26 | const std::map<std::string, ApplicationStatus> &statuses() const { |
| 27 | return statuses_; |
| 28 | } |
| 29 | |
| 30 | private: |
| 31 | void SendStatus(); |
| 32 | |
| 33 | aos::EventLoop *event_loop_; |
| 34 | aos::Sender<aos::starter::Status> status_sender_; |
| 35 | std::map<std::string, ApplicationStatus> statuses_; |
| 36 | int next_id_ = 0; |
| 37 | }; |
| 38 | |
| 39 | // Spins up MockStarter's for each node. |
| 40 | class MockStarters { |
| 41 | public: |
| 42 | MockStarters(aos::SimulatedEventLoopFactory *event_loop_factory); |
| 43 | const std::vector<std::unique_ptr<MockStarter>> &starters() const { |
| 44 | return mock_starters_; |
| 45 | } |
| 46 | |
| 47 | private: |
| 48 | std::vector<std::unique_ptr<aos::EventLoop>> event_loops_; |
| 49 | std::vector<std::unique_ptr<MockStarter>> mock_starters_; |
| 50 | }; |
| 51 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame^] | 52 | } // namespace aos::starter |