xref: /aosp_15_r20/external/libchrome-gestures/include/activity_replay.h (revision aed3e5085e770be5b69ce25295ecf6ddf906af95)
1 // Copyright 2011 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 #ifndef GESTURES_ACTIVITY_REPLAY_H_
6 #define GESTURES_ACTIVITY_REPLAY_H_
7 
8 #include <deque>
9 #include <string>
10 #include <memory>
11 #include <set>
12 
13 #include <json/value.h>
14 
15 #include "include/activity_log.h"
16 #include "include/gestures.h"
17 #include "include/interpreter.h"
18 
19 // This class can parse a JSON log, as generated by ActivityLog and replay
20 // it on an interpreter.
21 
22 namespace gestures {
23 
24 class PropRegistry;
25 
26 class ActivityReplay : public GestureConsumer {
27  public:
28   explicit ActivityReplay(PropRegistry* prop_reg);
29   // Returns true on success.
30   bool Parse(const std::string& data);
31   // An empty set means honor all properties
32   bool Parse(const std::string& data, const std::set<std::string>& honor_props);
33 
34   // If there is any unexpected behavior, replay continues, but EXPECT_*
35   // reports failure, otherwise no failure is reported.
36   void Replay(Interpreter* interpreter, MetricsProperties* mprops);
37 
38   virtual void ConsumeGesture(const Gesture& gesture);
39 
40  private:
41   // These return true on success
42   bool ParseProperties(const Json::Value& dict,
43                        const std::set<std::string>& honor_props);
44   bool ParseHardwareProperties(const Json::Value& obj,
45                                HardwareProperties* out_props);
46   bool ParseEntry(const Json::Value& entry);
47   bool ParseHardwareState(const Json::Value& entry);
48   bool ParseFingerState(const Json::Value& entry, FingerState* out_fs);
49   bool ParseTimerCallback(const Json::Value& entry);
50   bool ParseCallbackRequest(const Json::Value& entry);
51   bool ParseGesture(const Json::Value& entry);
52   bool ParseGestureMove(const Json::Value& entry, Gesture* out_gs);
53   bool ParseGestureScroll(const Json::Value& entry, Gesture* out_gs);
54   bool ParseGestureSwipe(const Json::Value& entry, Gesture* out_gs);
55   bool ParseGestureSwipeLift(const Json::Value& entry, Gesture* out_gs);
56   bool ParseGesturePinch(const Json::Value& entry, Gesture* out_gs);
57   bool ParseGestureButtonsChange(const Json::Value& entry, Gesture* out_gs);
58   bool ParseGestureFling(const Json::Value& entry, Gesture* out_gs);
59   bool ParseGestureMetrics(const Json::Value& entry, Gesture* out_gs);
60   bool ParsePropChange(const Json::Value& entry);
61 
62   bool ReplayPropChange(const ActivityLog::PropChangeEntry& entry);
63 
64   ActivityLog log_;
65   HardwareProperties hwprops_;
66   PropRegistry* prop_reg_;
67   std::deque<Gesture> consumed_gestures_;
68   std::vector<std::shared_ptr<const std::string> > names_;
69 };
70 
71 }  // namespace gestures
72 
73 #endif  // GESTURES_ACTIVITY_REPLAY_H_
74