xref: /aosp_15_r20/external/libchrome-gestures/include/filter_interpreter.h (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 <memory>
6 
7 #include <gtest/gtest.h>
8 #include <json/value.h>
9 
10 #include "include/interpreter.h"
11 #include "include/macros.h"
12 #include "include/prop_registry.h"
13 #include "include/tracer.h"
14 
15 #ifndef GESTURES_FILTER_INTERPRETER_H__
16 #define GESTURES_FILTER_INTERPRETER_H__
17 
18 namespace gestures {
19 
20 // Interface for all filter interpreters.
21 
22 class FilterInterpreter : public Interpreter, public GestureConsumer {
23   FRIEND_TEST(FilterInterpreterTest, DeadlineSettingNoDeadlines);
24   FRIEND_TEST(FilterInterpreterTest, DeadlineSettingLocalOnly);
25   FRIEND_TEST(FilterInterpreterTest, DeadlineSettingNextOnly);
26   FRIEND_TEST(FilterInterpreterTest, DeadlineSettingLocalBeforeNext);
27   FRIEND_TEST(FilterInterpreterTest, DeadlineSettingNextBeforeLocal);
28  public:
FilterInterpreter(PropRegistry * prop_reg,Interpreter * next,Tracer * tracer,bool force_log_creation)29   FilterInterpreter(PropRegistry* prop_reg,
30                     Interpreter* next,
31                     Tracer* tracer,
32                     bool force_log_creation)
33       : Interpreter(prop_reg, tracer, force_log_creation) { next_.reset(next); }
~FilterInterpreter()34   virtual ~FilterInterpreter() {}
35 
36   Json::Value EncodeCommonInfo();
37   void Clear();
38 
39   virtual void Initialize(const HardwareProperties* hwprops,
40                           Metrics* metrics, MetricsProperties* mprops,
41                           GestureConsumer* consumer);
42 
43   virtual void ConsumeGesture(const Gesture& gesture);
44 
45  protected:
46   virtual void SyncInterpretImpl(HardwareState& hwstate, stime_t* timeout);
47   virtual void HandleTimerImpl(stime_t now, stime_t* timeout);
48 
49   // When we need to call HandlerTimer on next_, or NO_DEADLINE if there's no
50   // outstanding timer for next_.
51   stime_t next_timer_deadline_ = NO_DEADLINE;
52   // Sets the next timer deadline, taking into account the deadline needed for
53   // this interpreter and the one from the next in the chain.
54   stime_t SetNextDeadlineAndReturnTimeoutVal(stime_t now,
55                                              stime_t local_deadline,
56                                              stime_t next_timeout);
57   // Utility method for determining whether the timer callback is for this
58   // interpreter or one further down the chain.
59   bool ShouldCallNextTimer(stime_t local_deadline);
60 
61   std::unique_ptr<Interpreter> next_;
62 
63  private:
64   DISALLOW_COPY_AND_ASSIGN(FilterInterpreter);
65 };
66 }  // namespace gestures
67 
68 #endif  // GESTURES_FILTER_INTERPRETER_H__
69