xref: /aosp_15_r20/external/libchrome-gestures/src/filter_interpreter.cc (revision aed3e5085e770be5b69ce25295ecf6ddf906af95)
1 // Copyright 2012 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "include/filter_interpreter.h"
6 
7 #include <json/value.h>
8 
9 namespace gestures {
10 
SyncInterpretImpl(HardwareState & hwstate,stime_t * timeout)11 void FilterInterpreter::SyncInterpretImpl(HardwareState& hwstate,
12                                           stime_t* timeout) {
13   next_->SyncInterpret(hwstate, timeout);
14 }
15 
HandleTimerImpl(stime_t now,stime_t * timeout)16 void FilterInterpreter::HandleTimerImpl(stime_t now, stime_t* timeout) {
17   next_->HandleTimer(now, timeout);
18 }
19 
Initialize(const HardwareProperties * hwprops,Metrics * metrics,MetricsProperties * mprops,GestureConsumer * consumer)20 void FilterInterpreter::Initialize(const HardwareProperties* hwprops,
21                                    Metrics* metrics,
22                                    MetricsProperties* mprops,
23                                    GestureConsumer* consumer) {
24   Interpreter::Initialize(hwprops, metrics, mprops, consumer);
25   if (next_)
26     next_->Initialize(hwprops, metrics, mprops, this);
27 }
28 
ConsumeGesture(const Gesture & gesture)29 void FilterInterpreter::ConsumeGesture(const Gesture& gesture) {
30   ProduceGesture(gesture);
31 }
32 
EncodeCommonInfo()33 Json::Value FilterInterpreter::EncodeCommonInfo() {
34   Json::Value root = Interpreter::EncodeCommonInfo();
35 #ifdef DEEP_LOGS
36   root[ActivityLog::kKeyNext] = next_->EncodeCommonInfo();
37 #endif
38   return root;
39 }
40 
Clear()41 void FilterInterpreter::Clear() {
42   if (log_.get())
43     log_->Clear();
44   next_->Clear();
45 }
46 
SetNextDeadlineAndReturnTimeoutVal(stime_t now,stime_t local_deadline,stime_t next_timeout)47 stime_t FilterInterpreter::SetNextDeadlineAndReturnTimeoutVal(
48     stime_t now, stime_t local_deadline, stime_t next_timeout) {
49   next_timer_deadline_ = next_timeout > 0.0
50                             ? now + next_timeout
51                             : NO_DEADLINE;
52   stime_t local_timeout = local_deadline == NO_DEADLINE ||
53                           local_deadline <= now
54                             ? NO_DEADLINE
55                             : local_deadline - now;
56   if (next_timeout == NO_DEADLINE)
57     return local_timeout;
58   if (local_timeout == NO_DEADLINE)
59     return next_timeout;
60   return std::min(next_timeout, local_timeout);
61 }
62 
ShouldCallNextTimer(stime_t local_deadline)63 bool FilterInterpreter::ShouldCallNextTimer(stime_t local_deadline) {
64   if (local_deadline > 0.0 && next_timer_deadline_ > 0.0)
65     return local_deadline > next_timer_deadline_;
66   else
67     return next_timer_deadline_ > 0.0;
68 }
69 
70 }  // namespace gestures
71