xref: /aosp_15_r20/external/libchrome-gestures/include/activity_log.h (revision aed3e5085e770be5b69ce25295ecf6ddf906af95)
1*aed3e508SAndroid Build Coastguard Worker // Copyright 2012 The ChromiumOS Authors
2*aed3e508SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*aed3e508SAndroid Build Coastguard Worker // found in the LICENSE file.
4*aed3e508SAndroid Build Coastguard Worker 
5*aed3e508SAndroid Build Coastguard Worker #ifndef GESTURES_ACTIVITY_LOG_H_
6*aed3e508SAndroid Build Coastguard Worker #define GESTURES_ACTIVITY_LOG_H_
7*aed3e508SAndroid Build Coastguard Worker 
8*aed3e508SAndroid Build Coastguard Worker #include "include/gestures.h"
9*aed3e508SAndroid Build Coastguard Worker 
10*aed3e508SAndroid Build Coastguard Worker #include <string>
11*aed3e508SAndroid Build Coastguard Worker #include <variant>
12*aed3e508SAndroid Build Coastguard Worker 
13*aed3e508SAndroid Build Coastguard Worker #include <gtest/gtest.h>  // For FRIEND_TEST
14*aed3e508SAndroid Build Coastguard Worker #include <json/value.h>
15*aed3e508SAndroid Build Coastguard Worker 
16*aed3e508SAndroid Build Coastguard Worker // This should be set by build system:
17*aed3e508SAndroid Build Coastguard Worker #ifndef VCSID
18*aed3e508SAndroid Build Coastguard Worker #define VCSID "Unknown"
19*aed3e508SAndroid Build Coastguard Worker #endif  // VCSID
20*aed3e508SAndroid Build Coastguard Worker 
21*aed3e508SAndroid Build Coastguard Worker // This is a class that circularly buffers all incoming and outgoing activity
22*aed3e508SAndroid Build Coastguard Worker // so that end users can report issues and engineers can reproduce them.
23*aed3e508SAndroid Build Coastguard Worker 
24*aed3e508SAndroid Build Coastguard Worker namespace gestures {
25*aed3e508SAndroid Build Coastguard Worker 
26*aed3e508SAndroid Build Coastguard Worker class PropRegistry;
27*aed3e508SAndroid Build Coastguard Worker 
28*aed3e508SAndroid Build Coastguard Worker class ActivityLog {
29*aed3e508SAndroid Build Coastguard Worker   FRIEND_TEST(ActivityLogTest, SimpleTest);
30*aed3e508SAndroid Build Coastguard Worker   FRIEND_TEST(ActivityLogTest, WrapAroundTest);
31*aed3e508SAndroid Build Coastguard Worker   FRIEND_TEST(ActivityLogTest, VersionTest);
32*aed3e508SAndroid Build Coastguard Worker   FRIEND_TEST(ActivityLogTest, EncodePropChangeBoolTest);
33*aed3e508SAndroid Build Coastguard Worker   FRIEND_TEST(ActivityLogTest, EncodePropChangeDoubleTest);
34*aed3e508SAndroid Build Coastguard Worker   FRIEND_TEST(ActivityLogTest, EncodePropChangeIntTest);
35*aed3e508SAndroid Build Coastguard Worker   FRIEND_TEST(ActivityLogTest, EncodePropChangeShortTest);
36*aed3e508SAndroid Build Coastguard Worker   FRIEND_TEST(ActivityLogTest, GestureConsumeTest);
37*aed3e508SAndroid Build Coastguard Worker   FRIEND_TEST(ActivityLogTest, GestureProduceTest);
38*aed3e508SAndroid Build Coastguard Worker   FRIEND_TEST(ActivityLogTest, HardwareStatePreTest);
39*aed3e508SAndroid Build Coastguard Worker   FRIEND_TEST(ActivityLogTest, HardwareStatePostTest);
40*aed3e508SAndroid Build Coastguard Worker   FRIEND_TEST(LoggingFilterInterpreterTest, SimpleTest);
41*aed3e508SAndroid Build Coastguard Worker   FRIEND_TEST(PropRegistryTest, PropChangeTest);
42*aed3e508SAndroid Build Coastguard Worker  public:
43*aed3e508SAndroid Build Coastguard Worker   struct TimerCallbackEntry {
44*aed3e508SAndroid Build Coastguard Worker     stime_t timestamp;
45*aed3e508SAndroid Build Coastguard Worker   };
46*aed3e508SAndroid Build Coastguard Worker   struct CallbackRequestEntry {
47*aed3e508SAndroid Build Coastguard Worker     stime_t timestamp;
48*aed3e508SAndroid Build Coastguard Worker   };
49*aed3e508SAndroid Build Coastguard Worker   struct PropChangeEntry {
50*aed3e508SAndroid Build Coastguard Worker     std::string name;
51*aed3e508SAndroid Build Coastguard Worker     // No string variant because string values can't change
52*aed3e508SAndroid Build Coastguard Worker     std::variant<GesturesPropBool,
53*aed3e508SAndroid Build Coastguard Worker                  double,
54*aed3e508SAndroid Build Coastguard Worker                  int,
55*aed3e508SAndroid Build Coastguard Worker                  short> value;
56*aed3e508SAndroid Build Coastguard Worker   };
57*aed3e508SAndroid Build Coastguard Worker 
58*aed3e508SAndroid Build Coastguard Worker   struct HardwareStatePre {
59*aed3e508SAndroid Build Coastguard Worker     std::string name;
60*aed3e508SAndroid Build Coastguard Worker     HardwareState hwstate;
61*aed3e508SAndroid Build Coastguard Worker   };
62*aed3e508SAndroid Build Coastguard Worker   struct HardwareStatePost {
63*aed3e508SAndroid Build Coastguard Worker     std::string name;
64*aed3e508SAndroid Build Coastguard Worker     HardwareState hwstate;
65*aed3e508SAndroid Build Coastguard Worker   };
66*aed3e508SAndroid Build Coastguard Worker   struct GestureConsume {
67*aed3e508SAndroid Build Coastguard Worker     std::string name;
68*aed3e508SAndroid Build Coastguard Worker     Gesture gesture;
69*aed3e508SAndroid Build Coastguard Worker   };
70*aed3e508SAndroid Build Coastguard Worker   struct GestureProduce {
71*aed3e508SAndroid Build Coastguard Worker     std::string name;
72*aed3e508SAndroid Build Coastguard Worker     Gesture gesture;
73*aed3e508SAndroid Build Coastguard Worker   };
74*aed3e508SAndroid Build Coastguard Worker   struct HandleTimerPre {
75*aed3e508SAndroid Build Coastguard Worker     std::string name;
76*aed3e508SAndroid Build Coastguard Worker     bool timeout_is_present;
77*aed3e508SAndroid Build Coastguard Worker     stime_t now;
78*aed3e508SAndroid Build Coastguard Worker     stime_t timeout;
79*aed3e508SAndroid Build Coastguard Worker   };
80*aed3e508SAndroid Build Coastguard Worker   struct HandleTimerPost {
81*aed3e508SAndroid Build Coastguard Worker     std::string name;
82*aed3e508SAndroid Build Coastguard Worker     bool timeout_is_present;
83*aed3e508SAndroid Build Coastguard Worker     stime_t now;
84*aed3e508SAndroid Build Coastguard Worker     stime_t timeout;
85*aed3e508SAndroid Build Coastguard Worker   };
86*aed3e508SAndroid Build Coastguard Worker   struct AccelGestureDebug {
87*aed3e508SAndroid Build Coastguard Worker     bool no_accel_for_gesture_type;
88*aed3e508SAndroid Build Coastguard Worker     bool no_accel_for_small_dt;
89*aed3e508SAndroid Build Coastguard Worker     bool no_accel_for_small_speed;
90*aed3e508SAndroid Build Coastguard Worker     bool no_accel_for_bad_gain;
91*aed3e508SAndroid Build Coastguard Worker     bool dropped_gesture;
92*aed3e508SAndroid Build Coastguard Worker     bool x_y_are_velocity;
93*aed3e508SAndroid Build Coastguard Worker     float x_scale, y_scale;
94*aed3e508SAndroid Build Coastguard Worker     float dt;
95*aed3e508SAndroid Build Coastguard Worker     float adjusted_dt;
96*aed3e508SAndroid Build Coastguard Worker     float speed;
97*aed3e508SAndroid Build Coastguard Worker     float smoothed_speed;
98*aed3e508SAndroid Build Coastguard Worker     float gain_x, gain_y;
99*aed3e508SAndroid Build Coastguard Worker   };
100*aed3e508SAndroid Build Coastguard Worker   struct TimestampGestureDebug {
101*aed3e508SAndroid Build Coastguard Worker     stime_t skew;
102*aed3e508SAndroid Build Coastguard Worker   };
103*aed3e508SAndroid Build Coastguard Worker   struct TimestampHardwareStateDebug {
104*aed3e508SAndroid Build Coastguard Worker     bool is_using_fake;
105*aed3e508SAndroid Build Coastguard Worker     union {
106*aed3e508SAndroid Build Coastguard Worker       struct {
107*aed3e508SAndroid Build Coastguard Worker         bool was_first_or_backward;
108*aed3e508SAndroid Build Coastguard Worker         stime_t prev_msc_timestamp_in;
109*aed3e508SAndroid Build Coastguard Worker         stime_t prev_msc_timestamp_out;
110*aed3e508SAndroid Build Coastguard Worker       };
111*aed3e508SAndroid Build Coastguard Worker       struct {
112*aed3e508SAndroid Build Coastguard Worker         bool was_divergence_reset;
113*aed3e508SAndroid Build Coastguard Worker         stime_t fake_timestamp_in;
114*aed3e508SAndroid Build Coastguard Worker         stime_t fake_timestamp_delta;
115*aed3e508SAndroid Build Coastguard Worker         stime_t fake_timestamp_out;
116*aed3e508SAndroid Build Coastguard Worker       };
117*aed3e508SAndroid Build Coastguard Worker     };
118*aed3e508SAndroid Build Coastguard Worker     stime_t skew;
119*aed3e508SAndroid Build Coastguard Worker     stime_t max_skew;
120*aed3e508SAndroid Build Coastguard Worker   };
121*aed3e508SAndroid Build Coastguard Worker 
122*aed3e508SAndroid Build Coastguard Worker   struct Entry {
123*aed3e508SAndroid Build Coastguard Worker     std::variant<HardwareState,
124*aed3e508SAndroid Build Coastguard Worker                  TimerCallbackEntry,
125*aed3e508SAndroid Build Coastguard Worker                  CallbackRequestEntry,
126*aed3e508SAndroid Build Coastguard Worker                  Gesture,
127*aed3e508SAndroid Build Coastguard Worker                  PropChangeEntry,
128*aed3e508SAndroid Build Coastguard Worker                  HardwareStatePre,
129*aed3e508SAndroid Build Coastguard Worker                  HardwareStatePost,
130*aed3e508SAndroid Build Coastguard Worker                  GestureConsume,
131*aed3e508SAndroid Build Coastguard Worker                  GestureProduce,
132*aed3e508SAndroid Build Coastguard Worker                  HandleTimerPre,
133*aed3e508SAndroid Build Coastguard Worker                  HandleTimerPost,
134*aed3e508SAndroid Build Coastguard Worker                  AccelGestureDebug,
135*aed3e508SAndroid Build Coastguard Worker                  TimestampGestureDebug,
136*aed3e508SAndroid Build Coastguard Worker                  TimestampHardwareStateDebug> details;
137*aed3e508SAndroid Build Coastguard Worker   };
138*aed3e508SAndroid Build Coastguard Worker 
139*aed3e508SAndroid Build Coastguard Worker   enum class EventDebug {
140*aed3e508SAndroid Build Coastguard Worker     // Base Event Types
141*aed3e508SAndroid Build Coastguard Worker     Gesture = 0,
142*aed3e508SAndroid Build Coastguard Worker     HardwareState,
143*aed3e508SAndroid Build Coastguard Worker     HandleTimer,
144*aed3e508SAndroid Build Coastguard Worker     // FilterInterpreter Debug Detail Event Types
145*aed3e508SAndroid Build Coastguard Worker     Accel,
146*aed3e508SAndroid Build Coastguard Worker     Box,
147*aed3e508SAndroid Build Coastguard Worker     ClickWiggle,
148*aed3e508SAndroid Build Coastguard Worker     FingerMerge,
149*aed3e508SAndroid Build Coastguard Worker     FlingStop,
150*aed3e508SAndroid Build Coastguard Worker     HapticButtonGenerator,
151*aed3e508SAndroid Build Coastguard Worker     Iir,
152*aed3e508SAndroid Build Coastguard Worker     IntegratGesture,
153*aed3e508SAndroid Build Coastguard Worker     Logging,
154*aed3e508SAndroid Build Coastguard Worker     Lookahead,
155*aed3e508SAndroid Build Coastguard Worker     Metrics,
156*aed3e508SAndroid Build Coastguard Worker     NonLinearity,
157*aed3e508SAndroid Build Coastguard Worker     PalmClassifying,
158*aed3e508SAndroid Build Coastguard Worker     Scaling,
159*aed3e508SAndroid Build Coastguard Worker     SensorJump,
160*aed3e508SAndroid Build Coastguard Worker     SplitCorrecting,
161*aed3e508SAndroid Build Coastguard Worker     StationaryWiggle,
162*aed3e508SAndroid Build Coastguard Worker     StuckButtonInhibitor,
163*aed3e508SAndroid Build Coastguard Worker     T5R2Correcting,
164*aed3e508SAndroid Build Coastguard Worker     Timestamp,
165*aed3e508SAndroid Build Coastguard Worker     TrendClassifying,
166*aed3e508SAndroid Build Coastguard Worker     // Interpreter Debug Detail Event Types
167*aed3e508SAndroid Build Coastguard Worker     ImmediateInterpreter,
168*aed3e508SAndroid Build Coastguard Worker     MouseInterpreter,
169*aed3e508SAndroid Build Coastguard Worker     MultitouchMouseInterpreter,
170*aed3e508SAndroid Build Coastguard Worker   };
171*aed3e508SAndroid Build Coastguard Worker 
172*aed3e508SAndroid Build Coastguard Worker   explicit ActivityLog(PropRegistry* prop_reg);
173*aed3e508SAndroid Build Coastguard Worker   void SetHardwareProperties(const HardwareProperties& hwprops);
174*aed3e508SAndroid Build Coastguard Worker 
175*aed3e508SAndroid Build Coastguard Worker   // Log*() functions record an argument into the buffer
176*aed3e508SAndroid Build Coastguard Worker   void LogHardwareState(const HardwareState& hwstate);
177*aed3e508SAndroid Build Coastguard Worker   void LogTimerCallback(stime_t now);
178*aed3e508SAndroid Build Coastguard Worker   void LogCallbackRequest(stime_t when);
179*aed3e508SAndroid Build Coastguard Worker   void LogGesture(const Gesture& gesture);
180*aed3e508SAndroid Build Coastguard Worker   void LogPropChange(const PropChangeEntry& prop_change);
181*aed3e508SAndroid Build Coastguard Worker 
182*aed3e508SAndroid Build Coastguard Worker   // Debug extensions for Log*()
183*aed3e508SAndroid Build Coastguard Worker   void LogGestureConsume(const std::string& name, const Gesture& gesture);
184*aed3e508SAndroid Build Coastguard Worker   void LogGestureProduce(const std::string& name, const Gesture& gesture);
185*aed3e508SAndroid Build Coastguard Worker   void LogHardwareStatePre(const std::string& name,
186*aed3e508SAndroid Build Coastguard Worker                            const HardwareState& hwstate);
187*aed3e508SAndroid Build Coastguard Worker   void LogHardwareStatePost(const std::string& name,
188*aed3e508SAndroid Build Coastguard Worker                             const HardwareState& hwstate);
189*aed3e508SAndroid Build Coastguard Worker   void LogHandleTimerPre(const std::string& name,
190*aed3e508SAndroid Build Coastguard Worker                          stime_t now, const stime_t* timeout);
191*aed3e508SAndroid Build Coastguard Worker   void LogHandleTimerPost(const std::string& name,
192*aed3e508SAndroid Build Coastguard Worker                           stime_t now, const stime_t* timeout);
193*aed3e508SAndroid Build Coastguard Worker 
194*aed3e508SAndroid Build Coastguard Worker   template<typename T>
LogDebugData(const T & debug_data)195*aed3e508SAndroid Build Coastguard Worker   void LogDebugData(const T& debug_data) {
196*aed3e508SAndroid Build Coastguard Worker     Entry* entry = PushBack();
197*aed3e508SAndroid Build Coastguard Worker     entry->details = debug_data;
198*aed3e508SAndroid Build Coastguard Worker   }
199*aed3e508SAndroid Build Coastguard Worker 
200*aed3e508SAndroid Build Coastguard Worker   // Dump allocates, and thus must not be called on a signal handler.
201*aed3e508SAndroid Build Coastguard Worker   void Dump(const char* filename);
Clear()202*aed3e508SAndroid Build Coastguard Worker   void Clear() { head_idx_ = size_ = 0; }
203*aed3e508SAndroid Build Coastguard Worker 
204*aed3e508SAndroid Build Coastguard Worker   // Returns a JSON string representing all the state in the buffer
205*aed3e508SAndroid Build Coastguard Worker   std::string Encode();
206*aed3e508SAndroid Build Coastguard Worker   void AddEncodeInfo(Json::Value* root);
207*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeCommonInfo();
size()208*aed3e508SAndroid Build Coastguard Worker   size_t size() const { return size_; }
MaxSize()209*aed3e508SAndroid Build Coastguard Worker   size_t MaxSize() const { return kBufferSize; }
GetEntry(size_t idx)210*aed3e508SAndroid Build Coastguard Worker   Entry* GetEntry(size_t idx) {
211*aed3e508SAndroid Build Coastguard Worker     return &buffer_[(head_idx_ + idx) % kBufferSize];
212*aed3e508SAndroid Build Coastguard Worker   }
213*aed3e508SAndroid Build Coastguard Worker 
214*aed3e508SAndroid Build Coastguard Worker   static const char kKeyInterpreterName[];
215*aed3e508SAndroid Build Coastguard Worker   static const char kKeyNext[];
216*aed3e508SAndroid Build Coastguard Worker   static const char kKeyRoot[];
217*aed3e508SAndroid Build Coastguard Worker   static const char kKeyType[];
218*aed3e508SAndroid Build Coastguard Worker   static const char kKeyMethodName[];
219*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwareState[];
220*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwareStatePre[];
221*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwareStatePost[];
222*aed3e508SAndroid Build Coastguard Worker   static const char kKeyTimerCallback[];
223*aed3e508SAndroid Build Coastguard Worker   static const char kKeyCallbackRequest[];
224*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGesture[];
225*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureConsume[];
226*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureProduce[];
227*aed3e508SAndroid Build Coastguard Worker   static const char kKeyPropChange[];
228*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHandleTimerPre[];
229*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHandleTimerPost[];
230*aed3e508SAndroid Build Coastguard Worker   // HardwareState keys:
231*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwareStateTimestamp[];
232*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwareStateButtonsDown[];
233*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwareStateTouchCnt[];
234*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwareStateFingers[];
235*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwareStateRelX[];
236*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwareStateRelY[];
237*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwareStateRelWheel[];
238*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwareStateRelHWheel[];
239*aed3e508SAndroid Build Coastguard Worker   // FingerState keys (part of HardwareState):
240*aed3e508SAndroid Build Coastguard Worker   static const char kKeyFingerStateTouchMajor[];
241*aed3e508SAndroid Build Coastguard Worker   static const char kKeyFingerStateTouchMinor[];
242*aed3e508SAndroid Build Coastguard Worker   static const char kKeyFingerStateWidthMajor[];
243*aed3e508SAndroid Build Coastguard Worker   static const char kKeyFingerStateWidthMinor[];
244*aed3e508SAndroid Build Coastguard Worker   static const char kKeyFingerStatePressure[];
245*aed3e508SAndroid Build Coastguard Worker   static const char kKeyFingerStateOrientation[];
246*aed3e508SAndroid Build Coastguard Worker   static const char kKeyFingerStatePositionX[];
247*aed3e508SAndroid Build Coastguard Worker   static const char kKeyFingerStatePositionY[];
248*aed3e508SAndroid Build Coastguard Worker   static const char kKeyFingerStateTrackingId[];
249*aed3e508SAndroid Build Coastguard Worker   static const char kKeyFingerStateFlags[];
250*aed3e508SAndroid Build Coastguard Worker   // Timer/Callback keys:
251*aed3e508SAndroid Build Coastguard Worker   static const char kKeyTimerNow[];
252*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHandleTimerTimeout[];
253*aed3e508SAndroid Build Coastguard Worker   static const char kKeyCallbackRequestWhen[];
254*aed3e508SAndroid Build Coastguard Worker   // Gesture keys:
255*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureType[];
256*aed3e508SAndroid Build Coastguard Worker   static const char kValueGestureTypeContactInitiated[];
257*aed3e508SAndroid Build Coastguard Worker   static const char kValueGestureTypeMove[];
258*aed3e508SAndroid Build Coastguard Worker   static const char kValueGestureTypeScroll[];
259*aed3e508SAndroid Build Coastguard Worker   static const char kValueGestureTypeMouseWheel[];
260*aed3e508SAndroid Build Coastguard Worker   static const char kValueGestureTypePinch[];
261*aed3e508SAndroid Build Coastguard Worker   static const char kValueGestureTypeButtonsChange[];
262*aed3e508SAndroid Build Coastguard Worker   static const char kValueGestureTypeFling[];
263*aed3e508SAndroid Build Coastguard Worker   static const char kValueGestureTypeSwipe[];
264*aed3e508SAndroid Build Coastguard Worker   static const char kValueGestureTypeSwipeLift[];
265*aed3e508SAndroid Build Coastguard Worker   static const char kValueGestureTypeFourFingerSwipe[];
266*aed3e508SAndroid Build Coastguard Worker   static const char kValueGestureTypeFourFingerSwipeLift[];
267*aed3e508SAndroid Build Coastguard Worker   static const char kValueGestureTypeMetrics[];
268*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureStartTime[];
269*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureEndTime[];
270*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureDX[];
271*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureDY[];
272*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureOrdinalDX[];
273*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureOrdinalDY[];
274*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureMouseWheelTicksDX[];
275*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureMouseWheelTicksDY[];
276*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGesturePinchDZ[];
277*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGesturePinchOrdinalDZ[];
278*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGesturePinchZoomState[];
279*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureButtonsChangeDown[];
280*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureButtonsChangeUp[];
281*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureFlingVX[];
282*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureFlingVY[];
283*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureFlingOrdinalVX[];
284*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureFlingOrdinalVY[];
285*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureFlingState[];
286*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureMetricsType[];
287*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureMetricsData1[];
288*aed3e508SAndroid Build Coastguard Worker   static const char kKeyGestureMetricsData2[];
289*aed3e508SAndroid Build Coastguard Worker   // PropChange keys:
290*aed3e508SAndroid Build Coastguard Worker   static const char kKeyPropChangeType[];
291*aed3e508SAndroid Build Coastguard Worker   static const char kKeyPropChangeName[];
292*aed3e508SAndroid Build Coastguard Worker   static const char kKeyPropChangeValue[];
293*aed3e508SAndroid Build Coastguard Worker   static const char kValuePropChangeTypeBool[];
294*aed3e508SAndroid Build Coastguard Worker   static const char kValuePropChangeTypeDouble[];
295*aed3e508SAndroid Build Coastguard Worker   static const char kValuePropChangeTypeInt[];
296*aed3e508SAndroid Build Coastguard Worker   static const char kValuePropChangeTypeShort[];
297*aed3e508SAndroid Build Coastguard Worker 
298*aed3e508SAndroid Build Coastguard Worker   // Hardware Properties keys:
299*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropRoot[];
300*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropLeft[];
301*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropTop[];
302*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropRight[];
303*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropBottom[];
304*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropXResolution[];
305*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropYResolution[];
306*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropXDpi[];
307*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropYDpi[];
308*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropOrientationMinimum[];
309*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropOrientationMaximum[];
310*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropMaxFingerCount[];
311*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropMaxTouchCount[];
312*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropSupportsT5R2[];
313*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropSemiMt[];
314*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropIsButtonPad[];
315*aed3e508SAndroid Build Coastguard Worker   static const char kKeyHardwarePropHasWheel[];
316*aed3e508SAndroid Build Coastguard Worker 
317*aed3e508SAndroid Build Coastguard Worker   static const char kKeyProperties[];
318*aed3e508SAndroid Build Coastguard Worker 
319*aed3e508SAndroid Build Coastguard Worker   // AccelFilterInterpreter Debug Data keys:
320*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelGestureDebug[];
321*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelDebugNoAccelBadGain[];
322*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelDebugNoAccelGestureType[];
323*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelDebugNoAccelSmallDt[];
324*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelDebugNoAccelSmallSpeed[];
325*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelDebugDroppedGesture[];
326*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelDebugXYAreVelocity[];
327*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelDebugXScale[];
328*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelDebugYScale[];
329*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelDebugDt[];
330*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelDebugAdjustedDt[];
331*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelDebugSpeed[];
332*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelDebugSmoothSpeed[];
333*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelDebugGainX[];
334*aed3e508SAndroid Build Coastguard Worker   static const char kKeyAccelDebugGainY[];
335*aed3e508SAndroid Build Coastguard Worker 
336*aed3e508SAndroid Build Coastguard Worker   // Timestamp Debug Data keys:
337*aed3e508SAndroid Build Coastguard Worker   static const char kKeyTimestampGestureDebug[];
338*aed3e508SAndroid Build Coastguard Worker   static const char kKeyTimestampHardwareStateDebug[];
339*aed3e508SAndroid Build Coastguard Worker   static const char kKeyTimestampDebugIsUsingFake[];
340*aed3e508SAndroid Build Coastguard Worker   static const char kKeyTimestampDebugWasFirstOrBackward[];
341*aed3e508SAndroid Build Coastguard Worker   static const char kKeyTimestampDebugPrevMscTimestampIn[];
342*aed3e508SAndroid Build Coastguard Worker   static const char kKeyTimestampDebugPrevMscTimestampOut[];
343*aed3e508SAndroid Build Coastguard Worker   static const char kKeyTimestampDebugWasDivergenceReset[];
344*aed3e508SAndroid Build Coastguard Worker   static const char kKeyTimestampDebugFakeTimestampIn[];
345*aed3e508SAndroid Build Coastguard Worker   static const char kKeyTimestampDebugFakeTimestampDelta[];
346*aed3e508SAndroid Build Coastguard Worker   static const char kKeyTimestampDebugFakeTimestampOut[];
347*aed3e508SAndroid Build Coastguard Worker   static const char kKeyTimestampDebugSkew[];
348*aed3e508SAndroid Build Coastguard Worker   static const char kKeyTimestampDebugMaxSkew[];
349*aed3e508SAndroid Build Coastguard Worker 
350*aed3e508SAndroid Build Coastguard Worker  private:
351*aed3e508SAndroid Build Coastguard Worker   // Extends the tail of the buffer by one element and returns that new element.
352*aed3e508SAndroid Build Coastguard Worker   // This may cause an older element to be overwritten if the buffer is full.
353*aed3e508SAndroid Build Coastguard Worker   Entry* PushBack();
354*aed3e508SAndroid Build Coastguard Worker 
TailIdx()355*aed3e508SAndroid Build Coastguard Worker   size_t TailIdx() const { return (head_idx_ + size_ - 1) % kBufferSize; }
356*aed3e508SAndroid Build Coastguard Worker 
357*aed3e508SAndroid Build Coastguard Worker   // JSON-encoders for various types
358*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeHardwareProperties() const;
359*aed3e508SAndroid Build Coastguard Worker 
360*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeHardwareStateCommon(const HardwareState& hwstate);
361*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeHardwareState(const HardwareState& hwstate);
362*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeHardwareState(const HardwareStatePre& hwstate);
363*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeHardwareState(const HardwareStatePost& hwstate);
364*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeHardwareStateDebug(
365*aed3e508SAndroid Build Coastguard Worker       const TimestampHardwareStateDebug& debug_data);
366*aed3e508SAndroid Build Coastguard Worker 
367*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeTimerCallback(stime_t timestamp);
368*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeHandleTimer(const HandleTimerPre& handle);
369*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeHandleTimer(const HandleTimerPost& handle);
370*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeCallbackRequest(stime_t timestamp);
371*aed3e508SAndroid Build Coastguard Worker 
372*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeGestureCommon(const Gesture& gesture);
373*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeGesture(const Gesture& gesture);
374*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeGesture(const GestureConsume& gesture);
375*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeGesture(const GestureProduce& gesture);
376*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeGestureDebug(const AccelGestureDebug& debug_data);
377*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodeGestureDebug(const TimestampGestureDebug& debug_data);
378*aed3e508SAndroid Build Coastguard Worker 
379*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodePropChange(const PropChangeEntry& prop_change);
380*aed3e508SAndroid Build Coastguard Worker 
381*aed3e508SAndroid Build Coastguard Worker   // Encode user-configurable properties
382*aed3e508SAndroid Build Coastguard Worker   Json::Value EncodePropRegistry();
383*aed3e508SAndroid Build Coastguard Worker 
384*aed3e508SAndroid Build Coastguard Worker #ifdef GESTURES_LARGE_LOGGING_BUFFER
385*aed3e508SAndroid Build Coastguard Worker   static const size_t kBufferSize = 65536;
386*aed3e508SAndroid Build Coastguard Worker #else
387*aed3e508SAndroid Build Coastguard Worker   static const size_t kBufferSize = 8192;
388*aed3e508SAndroid Build Coastguard Worker #endif
389*aed3e508SAndroid Build Coastguard Worker 
390*aed3e508SAndroid Build Coastguard Worker   Entry buffer_[kBufferSize];
391*aed3e508SAndroid Build Coastguard Worker   size_t head_idx_;
392*aed3e508SAndroid Build Coastguard Worker   size_t size_;
393*aed3e508SAndroid Build Coastguard Worker 
394*aed3e508SAndroid Build Coastguard Worker   // We allocate this to be number of entries * max fingers/entry, and
395*aed3e508SAndroid Build Coastguard Worker   // if buffer_[i] is a kHardwareState type, then the fingers for it are
396*aed3e508SAndroid Build Coastguard Worker   // at finger_states_[i * (max fingers/entry)].
397*aed3e508SAndroid Build Coastguard Worker   std::unique_ptr<FingerState[]> finger_states_;
398*aed3e508SAndroid Build Coastguard Worker   size_t max_fingers_;
399*aed3e508SAndroid Build Coastguard Worker 
400*aed3e508SAndroid Build Coastguard Worker   HardwareProperties hwprops_;
401*aed3e508SAndroid Build Coastguard Worker   PropRegistry* prop_reg_;
402*aed3e508SAndroid Build Coastguard Worker };
403*aed3e508SAndroid Build Coastguard Worker 
404*aed3e508SAndroid Build Coastguard Worker }  // namespace gestures
405*aed3e508SAndroid Build Coastguard Worker 
406*aed3e508SAndroid Build Coastguard Worker #endif  // GESTURES_ACTIVITY_LOG_H_
407