blob: 699cd504fa9edbb2f8b897830e95af1dd57a21aa [file] [log] [blame]
Kevin DuBois305bef12019-10-09 13:23:27 -07001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <utils/Timers.h>
20#include <functional>
21
22namespace android::scheduler {
23
24/*
25 * TimeKeeper is the interface for a single-shot timer primitive.
26 */
27class TimeKeeper {
28public:
29 virtual ~TimeKeeper();
30
31 /*
32 * Arms callback to fired in time nanoseconds.
33 * There is only one timer, and subsequent calls will reset the callback function and the time.
34 */
35 virtual void alarmIn(std::function<void()> const& callback, nsecs_t time) = 0;
36
37 /*
38 * Cancels an existing pending callback
39 */
40 virtual void alarmCancel() = 0;
41
42 /*
43 * Returns the SYSTEM_TIME_MONOTONIC, used by testing infra to stub time.
44 */
45 virtual nsecs_t now() const = 0;
46
47protected:
48 TimeKeeper(TimeKeeper const&) = delete;
49 TimeKeeper& operator=(TimeKeeper const&) = delete;
50 TimeKeeper() = default;
51};
52
53} // namespace android::scheduler