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