Make LogReader::OnStart able to start applications at times
There are 2 main features missing from OnStart to make it truly useful
at scale.
1) We need to be able to start applications...
2) Only replaying a time range (typically on the RT clock) is very
helpful.
Add support for 1.
2 is more tricky. I considered putting the logic outside LogReader, but
in the end, the bookkeeping for starting and stopping is bad enough that
it really helps to have LogReader manage and synchronize it. Maybe we
can refactor it back out later.
Change-Id: I4ddf6e18819d3aadd02f38776bbc7aef843a96b0
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
diff --git a/aos/events/event_scheduler.h b/aos/events/event_scheduler.h
index 55c1cf8..b64728c 100644
--- a/aos/events/event_scheduler.h
+++ b/aos/events/event_scheduler.h
@@ -126,7 +126,12 @@
started_ = std::move(callback);
}
+ void set_stopped(std::function<void()> callback) {
+ stopped_ = std::move(callback);
+ }
+
std::function<void()> started_;
+ std::function<void()> stopped_;
std::function<void()> on_shutdown_;
Token InvalidToken() { return events_list_.end(); }
@@ -138,10 +143,12 @@
void RunOnRun();
// Runs the OnStartup callbacks.
- void RunOnStartup();
+ void RunOnStartup() noexcept;
// Runs the Started callback.
void RunStarted();
+ // Runs the Started callback.
+ void RunStopped();
// Returns true if events are being handled.
inline bool is_running() const;
@@ -283,6 +290,13 @@
}
}
+ void RunStopped() {
+ CHECK(!is_running_);
+ for (EventScheduler *scheduler : schedulers_) {
+ scheduler->RunStopped();
+ }
+ }
+
void SetTimeConverter(TimeConverter *time_converter) {
time_converter->set_reboot_found(
[this](distributed_clock::time_point reboot_time,
@@ -294,6 +308,11 @@
});
}
+ // Runs the provided callback now. Stops everything, runs the callback, then
+ // starts it all up again. This lets us do operations like starting and
+ // stopping applications while running.
+ void TemporarilyStopAndRun(std::function<void()> fn);
+
private:
// Handles running the OnRun functions.
void RunOnRun() {