blob: 212f1e5b3770031697afb47210272bb8e7859e45 [file] [log] [blame]
James Kuszmaul9a816a72023-03-23 15:10:34 -07001#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 Pleinesd99b1ee2024-02-02 20:56:44 -08009namespace aos::starter {
James Kuszmaul9a816a72023-03-23 15:10:34 -070010
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.
14class 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.
40class 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 Pleinesd99b1ee2024-02-02 20:56:44 -080052} // namespace aos::starter