summaryrefslogtreecommitdiff
path: root/cras/src/server/polled_interval_checker.h
blob: 1b4619d8f82d9faac47251148dfc62d7799cb661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Copyright 2018 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef POLLED_ACTIVITY_CHECKER_H_
#define POLLED_ACTIVITY_CHECKER_H_

#include <time.h>

/* Represents a time interval, in seconds, which can be checked periodically. */
struct polled_interval;

/*
 * Creates a new polled_interval, of the specified duration. The interval will
 * first elapse interval_sec after it was created.
 *
 * Call pic_update_current_time() shortly before this function.
 */
struct polled_interval *pic_polled_interval_create(int interval_sec);

/*
 * Destroys the specified polled_interval, and set's the pointer to it to NULL.
 */
void pic_polled_interval_destroy(struct polled_interval **interval);

/*
 * Whether the interval's duration has elapsed (since the interval was created
 * or reset).
 *
 * Call pic_update_current_time() shortly before this function.
 */
int pic_interval_elapsed(const struct polled_interval *interval);

/*
 * Resets the interval; it will elapse it's specified duration from now.
 *
 * Call pic_update_current_time() shortly before this function.
 */
void pic_interval_reset(struct polled_interval *pi);

/*
 * Updates the current time, which is used in all other pic_* functions (which
 * will never update the current time). This update is pulled out separately to
 * allow the caller to control when and how often the time is updated.
 */
void pic_update_current_time();

#endif /* POLLED_ACTIVITY_CHECKER_H_ */