aboutsummaryrefslogtreecommitdiff
path: root/pw_async/public/pw_async/fake_dispatcher.h
diff options
context:
space:
mode:
Diffstat (limited to 'pw_async/public/pw_async/fake_dispatcher.h')
-rw-r--r--pw_async/public/pw_async/fake_dispatcher.h86
1 files changed, 36 insertions, 50 deletions
diff --git a/pw_async/public/pw_async/fake_dispatcher.h b/pw_async/public/pw_async/fake_dispatcher.h
index 04976374d..43931d032 100644
--- a/pw_async/public/pw_async/fake_dispatcher.h
+++ b/pw_async/public/pw_async/fake_dispatcher.h
@@ -18,71 +18,57 @@
namespace pw::async::test {
-// FakeDispatcher is a facade for an implementation of Dispatcher that is used
-// in unit tests. FakeDispatcher uses simulated time. RunUntil() and RunFor()
-// advance time immediately, and now() returns the current simulated time.
-//
-// To support various Task backends, FakeDispatcher wraps a
-// backend::NativeFakeDispatcher that implements standard FakeDispatcher
-// behavior using backend::NativeTask objects.
+/// FakeDispatcher is a facade for an implementation of Dispatcher that is used
+/// in unit tests. FakeDispatcher uses simulated time. RunUntil() and RunFor()
+/// advance time immediately, and now() returns the current simulated time.
+///
+/// To support various Task backends, FakeDispatcher wraps a
+/// backend::NativeFakeDispatcher that implements standard FakeDispatcher
+/// behavior using backend::NativeTask objects.
class FakeDispatcher final : public Dispatcher {
public:
FakeDispatcher() : native_dispatcher_(*this) {}
- void RequestStop() override { native_dispatcher_.RequestStop(); }
-
- // Post caller owned |task|.
- void PostTask(Task& task) override { native_dispatcher_.PostTask(task); }
+ /// Execute all runnable tasks and return without advancing simulated time.
+ void RunUntilIdle() { native_dispatcher_.RunUntilIdle(); }
- // Post caller owned |task| to be run after |delay|.
- void PostDelayedTask(Task& task,
- chrono::SystemClock::duration delay) override {
- native_dispatcher_.PostDelayedTask(task, delay);
+ /// Run the dispatcher until Now() has reached `end_time`, executing all tasks
+ /// that come due before then.
+ void RunUntil(chrono::SystemClock::time_point end_time) {
+ native_dispatcher_.RunUntil(end_time);
}
- // Post caller owned |task| to be run at |time|.
- void PostTaskForTime(Task& task,
- chrono::SystemClock::time_point time) override {
- native_dispatcher_.PostTaskForTime(task, time);
+ /// Run the Dispatcher until `duration` has elapsed, executing all tasks that
+ /// come due in that period.
+ void RunFor(chrono::SystemClock::duration duration) {
+ native_dispatcher_.RunFor(duration);
}
- // Post caller owned |task| to be run immediately then rerun at a regular
- // |interval|.
- void SchedulePeriodicTask(Task& task,
- chrono::SystemClock::duration interval) override {
- native_dispatcher_.SchedulePeriodicTask(task, interval);
+ /// Stop processing tasks. After calling RequestStop(), the next time the
+ /// Dispatcher is run, all waiting Tasks will be dequeued and their
+ /// TaskFunctions called with a PW_STATUS_CANCELLED status.
+ void RequestStop() { native_dispatcher_.RequestStop(); }
+
+ // Dispatcher overrides:
+ void Post(Task& task) override { native_dispatcher_.Post(task); }
+ void PostAfter(Task& task, chrono::SystemClock::duration delay) override {
+ native_dispatcher_.PostAfter(task, delay);
}
- // Post caller owned |task| to be run at |start_time| then rerun at a regular
- // |interval|.
- void SchedulePeriodicTask(
- Task& task,
- chrono::SystemClock::duration interval,
- chrono::SystemClock::time_point start_time) override {
- native_dispatcher_.SchedulePeriodicTask(task, interval, start_time);
+ void PostAt(Task& task, chrono::SystemClock::time_point time) override {
+ native_dispatcher_.PostAt(task, time);
}
-
- // Returns true if |task| is succesfully canceled.
- // If cancelation fails, the task may be running or completed.
- // Periodic tasks may run once more after they are canceled.
- bool Cancel(Task& task) override { return native_dispatcher_.Cancel(task); }
-
- // Execute tasks until the Dispatcher enters a state where none are queued.
- void RunUntilIdle() override { native_dispatcher_.RunUntilIdle(); }
-
- // Run the Dispatcher until Now() has reached `end_time`, executing all tasks
- // that come due before then.
- void RunUntil(chrono::SystemClock::time_point end_time) override {
- native_dispatcher_.RunUntil(end_time);
+ void PostPeriodic(Task& task,
+ chrono::SystemClock::duration interval) override {
+ native_dispatcher_.PostPeriodic(task, interval);
}
-
- // Run the Dispatcher until `duration` has elapsed, executing all tasks that
- // come due in that period.
- void RunFor(chrono::SystemClock::duration duration) override {
- native_dispatcher_.RunFor(duration);
+ void PostPeriodicAt(Task& task,
+ chrono::SystemClock::duration interval,
+ chrono::SystemClock::time_point start_time) override {
+ native_dispatcher_.PostPeriodicAt(task, interval, start_time);
}
+ bool Cancel(Task& task) override { return native_dispatcher_.Cancel(task); }
// VirtualSystemClock overrides:
-
chrono::SystemClock::time_point now() override {
return native_dispatcher_.now();
}