xref: /third_party/libinput/src/timer.h (revision a46c0ec8)
1/*
2 * Copyright © 2014 Red Hat, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24#ifndef TIMER_H
25#define TIMER_H
26
27#include <stdint.h>
28
29#include "libinput-util.h"
30
31struct libinput;
32
33struct libinput_timer {
34	struct libinput *libinput;
35	char *timer_name;
36	struct list link;
37	uint64_t expire; /* in absolute us CLOCK_MONOTONIC */
38	void (*timer_func)(uint64_t now, void *timer_func_data);
39	void *timer_func_data;
40};
41
42void
43libinput_timer_init(struct libinput_timer *timer, struct libinput *libinput,
44		    const char *timer_name,
45		    void (*timer_func)(uint64_t now, void *timer_func_data),
46		    void *timer_func_data);
47
48void
49libinput_timer_destroy(struct libinput_timer *timer);
50
51/* Set timer expire time, in absolute us CLOCK_MONOTONIC */
52void
53libinput_timer_set(struct libinput_timer *timer, uint64_t expire);
54
55enum timer_flags {
56	TIMER_FLAG_NONE = 0,
57	TIMER_FLAG_ALLOW_NEGATIVE = bit(0),
58};
59
60void
61libinput_timer_set_flags(struct libinput_timer *timer,
62			 uint64_t expire,
63			 uint32_t flags);
64
65void
66libinput_timer_cancel(struct libinput_timer *timer);
67
68int
69libinput_timer_subsys_init(struct libinput *libinput);
70
71void
72libinput_timer_subsys_destroy(struct libinput *libinput);
73
74void
75libinput_timer_flush(struct libinput *libinput, uint64_t now);
76
77#endif
78