blob: 5d97e27ed251211d2612b03024b6070677d7d3b8 [file] [log] [blame]
Sebastian Jansson0d617cc2019-03-22 14:22:161/*
2 * Copyright 2019 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10#ifndef TEST_TIME_CONTROLLER_TIME_CONTROLLER_H_
11#define TEST_TIME_CONTROLLER_TIME_CONTROLLER_H_
12
13#include <functional>
14#include <memory>
15
16#include "api/task_queue/task_queue_factory.h"
17#include "api/units/time_delta.h"
18#include "modules/utility/include/process_thread.h"
19#include "system_wrappers/include/clock.h"
20
21namespace webrtc {
22
23// Interface for controlling time progress. This allows us to execute test code
24// in either real time or simulated time by using different implementation of
25// this interface.
26class TimeController {
27 public:
28 virtual ~TimeController() = default;
29 // Provides a clock instance that follows implementation defined time
30 // progress.
31 virtual Clock* GetClock() = 0;
32 // The returned factory will created task queues that runs in implementation
33 // defined time domain.
34 virtual TaskQueueFactory* GetTaskQueueFactory() = 0;
35 // Creates a process thread.
36 virtual std::unique_ptr<ProcessThread> CreateProcessThread(
37 const char* thread_name) = 0;
38 // Allow task queues and process threads created by this instance to execute
39 // for the given |duration|.
40 virtual void Sleep(TimeDelta duration) = 0;
41 // Execute closure in an implementation defined scope where rtc::Event::Wait
42 // might yield to execute other tasks. This allows doing blocking waits on
43 // tasks on other task queues froma a task queue without deadlocking.
44 virtual void InvokeWithControlledYield(std::function<void()> closure) = 0;
45};
46} // namespace webrtc
47#endif // TEST_TIME_CONTROLLER_TIME_CONTROLLER_H_