1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h"
7 #include <gestures/gestures.h>
9 #include "base/timer/timer.h"
11 // libgestures requires that this be in the top level namespace.
14 GesturesTimer() : callback_(NULL
), callback_data_(NULL
) {}
17 void Set(stime_t delay
, GesturesTimerCallback callback
, void* callback_data
) {
19 callback_data_
= callback_data
;
20 timer_
.Start(FROM_HERE
,
21 base::TimeDelta::FromMicroseconds(
22 delay
* base::Time::kMicrosecondsPerSecond
),
24 &GesturesTimer::OnTimerExpired
);
27 void Cancel() { timer_
.Stop(); }
30 void OnTimerExpired() {
32 CHECK(!clock_gettime(CLOCK_MONOTONIC
, &ts
));
33 stime_t next_delay
= callback_(StimeFromTimespec(&ts
), callback_data_
);
34 if (next_delay
>= 0) {
35 timer_
.Start(FROM_HERE
,
36 base::TimeDelta::FromMicroseconds(
37 next_delay
* base::Time::kMicrosecondsPerSecond
),
39 &GesturesTimer::OnTimerExpired
);
43 GesturesTimerCallback callback_
;
45 base::OneShotTimer
<GesturesTimer
> timer_
;
52 GesturesTimer
* GesturesTimerCreate(void* data
) { return new GesturesTimer
; }
54 void GesturesTimerSet(void* data
,
57 GesturesTimerCallback callback
,
58 void* callback_data
) {
59 timer
->Set(delay
, callback
, callback_data
);
62 void GesturesTimerCancel(void* data
, GesturesTimer
* timer
) { timer
->Cancel(); }
64 void GesturesTimerFree(void* data
, GesturesTimer
* timer
) { delete timer
; }
68 const GesturesTimerProvider kGestureTimerProvider
= {
69 GesturesTimerCreate
, GesturesTimerSet
, GesturesTimerCancel
,