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.
12 struct GesturesTimer
{
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() {
31 // Run the callback and reschedule the next run if requested.
32 stime_t next_delay
= callback_(ui::StimeNow(), callback_data_
);
33 if (next_delay
>= 0) {
34 timer_
.Start(FROM_HERE
,
35 base::TimeDelta::FromMicroseconds(
36 next_delay
* base::Time::kMicrosecondsPerSecond
),
38 &GesturesTimer::OnTimerExpired
);
42 GesturesTimerCallback callback_
= nullptr;
43 void* callback_data_
= nullptr;
44 base::OneShotTimer
<GesturesTimer
> timer_
;
51 GesturesTimer
* GesturesTimerCreate(void* data
) { return new GesturesTimer
; }
53 void GesturesTimerSet(void* data
,
56 GesturesTimerCallback callback
,
57 void* callback_data
) {
58 timer
->Set(delay
, callback
, callback_data
);
61 void GesturesTimerCancel(void* data
, GesturesTimer
* timer
) { timer
->Cancel(); }
63 void GesturesTimerFree(void* data
, GesturesTimer
* timer
) { delete timer
; }
70 if (clock_gettime(CLOCK_MONOTONIC
, &ts
))
71 PLOG(FATAL
) << "clock_gettime";
73 return StimeFromTimespec(&ts
);
76 const GesturesTimerProvider kGestureTimerProvider
= {
77 GesturesTimerCreate
, GesturesTimerSet
, GesturesTimerCancel
,