blob: d3545c972b07cc6dbd6989d45baaf7b76642c75e [file] [log] [blame]
John Grossmanc7f57c62012-06-26 12:50:28 -07001/*
2 * Copyright (C) 2012 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#ifndef __UTILS_H__
18#define __UTILS_H__
19
20#include <stdint.h>
21#include <unistd.h>
22
23#include <utils/Timers.h>
24
25namespace android {
26
27class Timeout {
28 public:
29 Timeout() : mSystemEndTime(0) { }
30
31 // Set a timeout which should occur msec milliseconds from now.
32 // Negative values will cancel any current timeout;
33 void setTimeout(int msec);
34
35 // Return the number of milliseconds until the timeout occurs, or -1 if
36 // no timeout is scheduled.
37 int msecTillTimeout(nsecs_t nowTime);
38 int msecTillTimeout() { return msecTillTimeout(systemTime()); }
39
40 private:
41 // The systemTime() at which the timeout will be complete, or 0 if no
42 // timeout is currently scheduled.
43 nsecs_t mSystemEndTime;
44};
45
46} // namespace android
47
48#endif // __UTILS_H__