summaryrefslogtreecommitdiff
path: root/src/activity_replay.cc
diff options
context:
space:
mode:
authorAndrew de los Reyes <adlr@chromium.org>2014-04-02 17:44:48 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-04-09 19:05:43 +0000
commitffeae345598771967398e94511b13dfaba0cad80 (patch)
tree1c4177b4c55e634ba470c1f7712ae15e47bec638 /src/activity_replay.cc
parent9b0c6c28c9a60b506a7a7374361ff0317165a8e4 (diff)
downloadlibchrome-gestures-ffeae345598771967398e94511b13dfaba0cad80.tar.gz
Switch from libchrome (base) to jsoncpp for JSON
We're dropping the base dependency with this change. BUG=chromium:351168 TEST=unittests, tested on device CQ-DEPEND=CL:193283, CL:193284 Change-Id: Id86267a926f0dd06ccf696930f0e84ef1f511c45 Reviewed-on: https://chromium-review.googlesource.com/193285 Commit-Queue: Andrew de los Reyes <adlr@chromium.org> Reviewed-by: Andrew de los Reyes <adlr@chromium.org> Tested-by: Andrew de los Reyes <adlr@chromium.org>
Diffstat (limited to 'src/activity_replay.cc')
-rwxr-xr-xsrc/activity_replay.cc437
1 files changed, 218 insertions, 219 deletions
diff --git a/src/activity_replay.cc b/src/activity_replay.cc
index 69174fe..1fc2215 100755
--- a/src/activity_replay.cc
+++ b/src/activity_replay.cc
@@ -4,11 +4,12 @@
#include "gestures/include/activity_replay.h"
+#include <limits.h>
#include <string>
-#include <base/json/json_reader.h>
-#include <base/json/json_writer.h>
#include <gtest/gtest.h>
+#include <json/reader.h>
+#include <json/writer.h>
#include "gestures/include/logging.h"
#include "gestures/include/prop_registry.h"
@@ -16,9 +17,6 @@
#include "gestures/include/unittest_util.h"
#include "gestures/include/util.h"
-using base::DictionaryValue;
-using base::ListValue;
-using base::Value;
using std::endl;
using std::set;
using std::string;
@@ -38,52 +36,55 @@ bool ActivityReplay::Parse(const string& data,
log_.Clear();
names_.clear();
- int error_code;
string error_msg;
- Value* root =
- base::JSONReader::ReadAndReturnError(data, true, &error_code, &error_msg);
- if (!root) {
- Err("Parse failed: %s", error_msg.c_str());
- return false;
+ Json::Value root;
+ {
+ Json::Reader reader;
+ if (!reader.parse(data, root, false)) { // root modified in parse()
+ Err("Parse failed: %s", error_msg.c_str());
+ return false;
+ }
}
- if (root->GetType() != Value::TYPE_DICTIONARY) {
+ if (root.type() != Json::objectValue) {
Err("Root type is %d, but expected %d (dictionary)",
- root->GetType(), Value::TYPE_DICTIONARY);
+ root.type(), Json::objectValue);
return false;
}
- DictionaryValue* dict = static_cast<DictionaryValue*>(root);
// Get and apply user-configurable properties
- DictionaryValue* props_dict = NULL;
- if (dict->GetDictionary(ActivityLog::kKeyProperties, &props_dict) &&
+ Json::Value props_dict =
+ root.get(ActivityLog::kKeyProperties, Json::Value());
+ if (root.isMember(ActivityLog::kKeyProperties) &&
!ParseProperties(props_dict, honor_props)) {
Err("Unable to parse properties.");
return false;
}
// Get and apply hardware properties
- DictionaryValue* hwprops_dict = NULL;
- if (!dict->GetDictionary(ActivityLog::kKeyHardwarePropRoot, &hwprops_dict)) {
+ if (!root.isMember(ActivityLog::kKeyHardwarePropRoot)) {
Err("Unable to get hwprops dict.");
return false;
}
+ Json::Value hwprops_dict =
+ root.get(ActivityLog::kKeyHardwarePropRoot, Json::Value());
if (!ParseHardwareProperties(hwprops_dict, &hwprops_))
return false;
log_.SetHardwareProperties(hwprops_);
- ListValue* entries = NULL;
- ListValue* next_layer_entries = NULL;
+ Json::Value entries = root.get(ActivityLog::kKeyRoot, Json::Value());
char next_layer_path[PATH_MAX];
snprintf(next_layer_path, sizeof(next_layer_path), "%s.%s",
ActivityLog::kKeyNext, ActivityLog::kKeyRoot);
- if (!dict->GetList(ActivityLog::kKeyRoot, &entries)) {
+ if (!root.isMember(ActivityLog::kKeyRoot)) {
Err("Unable to get list of entries from root.");
return false;
}
- if (dict->GetList(next_layer_path, &next_layer_entries) &&
- (entries->GetSize() < next_layer_entries->GetSize()))
- entries = next_layer_entries;
+ if (root.isMember(next_layer_path)) {
+ Json::Value next_layer_entries = root[next_layer_path];
+ if (entries.size() < next_layer_entries.size())
+ entries = next_layer_entries;
+ }
- for (size_t i = 0; i < entries->GetSize(); ++i) {
- DictionaryValue* entry = NULL;
- if (!entries->GetDictionary(i, &entry)) {
+ for (size_t i = 0; i < entries.size(); ++i) {
+ Json::Value entry = entries.get(i, Json::Value());
+ if (!entries.isValidIndex(i)) {
Err("Invalid entry at index %zu", i);
return false;
}
@@ -93,7 +94,7 @@ bool ActivityReplay::Parse(const string& data,
return true;
}
-bool ActivityReplay::ParseProperties(DictionaryValue* dict,
+bool ActivityReplay::ParseProperties(const Json::Value& dict,
const std::set<string>& honor_props) {
if (!prop_reg_)
return true;
@@ -112,11 +113,11 @@ bool ActivityReplay::ParseProperties(DictionaryValue* dict,
if (!honor_props.empty() && !SetContainsValue(honor_props, string(key)))
continue;
- Value* value = NULL;
- if (!dict->Get(key, &value)) {
+ if (!dict.isMember(key)) {
Err("Log doesn't have value for property %s", key);
continue;
}
+ const Json::Value& value = dict[key];
if (!(*it)->SetValue(value)) {
Err("Unable to restore value for property %s", key);
return false;
@@ -125,51 +126,50 @@ bool ActivityReplay::ParseProperties(DictionaryValue* dict,
return true;
}
-#define PARSE_HP(obj, key, KeyType, KeyFn, var, VarType, required) \
+#define PARSE_HP(obj, key, IsTypeFn, KeyFn, var, VarType, required) \
do { \
- KeyType temp; \
- if (!obj->KeyFn(key, &temp)) { \
+ if (!obj.isMember(key) || !obj[key].IsTypeFn()) { \
Err("Parse failed for key %s", key); \
if (required) \
return false; \
} \
- var = static_cast<VarType>(temp); \
+ var = obj[key].KeyFn(); \
} while (0)
-bool ActivityReplay::ParseHardwareProperties(DictionaryValue* obj,
+bool ActivityReplay::ParseHardwareProperties(const Json::Value& obj,
HardwareProperties* out_props) {
HardwareProperties props;
- PARSE_HP(obj, ActivityLog::kKeyHardwarePropLeft, double, GetDouble,
+ PARSE_HP(obj, ActivityLog::kKeyHardwarePropLeft, isDouble, asDouble,
props.left, float, true);
- PARSE_HP(obj, ActivityLog::kKeyHardwarePropTop, double, GetDouble,
+ PARSE_HP(obj, ActivityLog::kKeyHardwarePropTop, isDouble, asDouble,
props.top, float, true);
- PARSE_HP(obj, ActivityLog::kKeyHardwarePropRight, double, GetDouble,
+ PARSE_HP(obj, ActivityLog::kKeyHardwarePropRight, isDouble, asDouble,
props.right, float, true);
- PARSE_HP(obj, ActivityLog::kKeyHardwarePropBottom, double, GetDouble,
+ PARSE_HP(obj, ActivityLog::kKeyHardwarePropBottom, isDouble, asDouble,
props.bottom, float, true);
- PARSE_HP(obj, ActivityLog::kKeyHardwarePropXResolution, double, GetDouble,
+ PARSE_HP(obj, ActivityLog::kKeyHardwarePropXResolution, isDouble, asDouble,
props.res_x, float, true);
- PARSE_HP(obj, ActivityLog::kKeyHardwarePropYResolution, double, GetDouble,
+ PARSE_HP(obj, ActivityLog::kKeyHardwarePropYResolution, isDouble, asDouble,
props.res_y, float, true);
- PARSE_HP(obj, ActivityLog::kKeyHardwarePropXDpi, double, GetDouble,
+ PARSE_HP(obj, ActivityLog::kKeyHardwarePropXDpi, isDouble, asDouble,
props.screen_x_dpi, float, true);
- PARSE_HP(obj, ActivityLog::kKeyHardwarePropYDpi, double, GetDouble,
+ PARSE_HP(obj, ActivityLog::kKeyHardwarePropYDpi, isDouble, asDouble,
props.screen_y_dpi, float, true);
PARSE_HP(obj, ActivityLog::kKeyHardwarePropOrientationMinimum,
- double, GetDouble, props.orientation_minimum, float, false);
+ isDouble, asDouble, props.orientation_minimum, float, false);
PARSE_HP(obj, ActivityLog::kKeyHardwarePropOrientationMaximum,
- double, GetDouble, props.orientation_maximum, float, false);
- PARSE_HP(obj, ActivityLog::kKeyHardwarePropMaxFingerCount, int, GetInteger,
+ isDouble, asDouble, props.orientation_maximum, float, false);
+ PARSE_HP(obj, ActivityLog::kKeyHardwarePropMaxFingerCount, isInt, asUInt,
props.max_finger_cnt, unsigned short, true);
- PARSE_HP(obj, ActivityLog::kKeyHardwarePropMaxTouchCount, int, GetInteger,
+ PARSE_HP(obj, ActivityLog::kKeyHardwarePropMaxTouchCount, isInt, asUInt,
props.max_touch_cnt, unsigned short, true);
- PARSE_HP(obj, ActivityLog::kKeyHardwarePropSupportsT5R2, bool, GetBoolean,
+ PARSE_HP(obj, ActivityLog::kKeyHardwarePropSupportsT5R2, isBool, asBool,
props.supports_t5r2, bool, true);
- PARSE_HP(obj, ActivityLog::kKeyHardwarePropSemiMt, bool, GetBoolean,
+ PARSE_HP(obj, ActivityLog::kKeyHardwarePropSemiMt,isBool, asBool,
props.support_semi_mt, bool, true);
- PARSE_HP(obj, ActivityLog::kKeyHardwarePropIsButtonPad, bool, GetBoolean,
+ PARSE_HP(obj, ActivityLog::kKeyHardwarePropIsButtonPad,isBool, asBool,
props.is_button_pad, bool, true);
- PARSE_HP(obj, ActivityLog::kKeyHardwarePropHasWheel, bool, GetBoolean,
+ PARSE_HP(obj, ActivityLog::kKeyHardwarePropHasWheel,isBool, asBool,
props.has_wheel, bool, true);
*out_props = props;
return true;
@@ -177,12 +177,13 @@ bool ActivityReplay::ParseHardwareProperties(DictionaryValue* obj,
#undef PARSE_HP
-bool ActivityReplay::ParseEntry(DictionaryValue* entry) {
- string type;
- if (!entry->GetString(ActivityLog::kKeyType, &type)) {
+bool ActivityReplay::ParseEntry(const Json::Value& entry) {
+ if (!entry.isMember(ActivityLog::kKeyType) ||
+ entry[ActivityLog::kKeyType].type() != Json::stringValue) {
Err("Can't get entry type.");
return false;
}
+ string type = entry[ActivityLog::kKeyType].asString();
if (type == ActivityLog::kKeyHardwareState)
return ParseHardwareState(entry);
if (type == ActivityLog::kKeyTimerCallback)
@@ -197,174 +198,163 @@ bool ActivityReplay::ParseEntry(DictionaryValue* entry) {
return false;
}
-bool ActivityReplay::ParseHardwareState(DictionaryValue* entry) {
+bool ActivityReplay::ParseHardwareState(const Json::Value& entry) {
HardwareState hs = HardwareState();
- if (!entry->GetInteger(ActivityLog::kKeyHardwareStateButtonsDown,
- &hs.buttons_down)) {
+ if (!entry.isMember(ActivityLog::kKeyHardwareStateButtonsDown)) {
Err("Unable to parse hardware state buttons down");
return false;
}
- int temp;
- if (!entry->GetInteger(ActivityLog::kKeyHardwareStateTouchCnt,
- &temp)) {
+ hs.buttons_down = entry[ActivityLog::kKeyHardwareStateButtonsDown].asUInt();
+ if (!entry.isMember(ActivityLog::kKeyHardwareStateTouchCnt)) {
Err("Unable to parse hardware state touch count");
return false;
}
- hs.touch_cnt = temp;
- if (!entry->GetDouble(ActivityLog::kKeyHardwareStateTimestamp,
- &hs.timestamp)) {
+ hs.touch_cnt = entry[ActivityLog::kKeyHardwareStateTouchCnt].asUInt();
+ if (!entry.isMember(ActivityLog::kKeyHardwareStateTimestamp)) {
Err("Unable to parse hardware state timestamp");
return false;
}
- ListValue* fingers = NULL;
- if (!entry->GetList(ActivityLog::kKeyHardwareStateFingers, &fingers)) {
+ hs.timestamp = entry[ActivityLog::kKeyHardwareStateTimestamp].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyHardwareStateFingers)) {
Err("Unable to parse hardware state fingers");
return false;
}
+ Json::Value fingers = entry[ActivityLog::kKeyHardwareStateFingers];
// Sanity check
- if (fingers->GetSize() > 30) {
+ if (fingers.size() > 30) {
Err("Too many fingers in hardware state");
return false;
}
- FingerState fs[fingers->GetSize()];
- for (size_t i = 0; i < fingers->GetSize(); ++i) {
- DictionaryValue* finger_state = NULL;
- if (!fingers->GetDictionary(i, &finger_state)) {
+ FingerState fs[fingers.size()];
+ for (size_t i = 0; i < fingers.size(); ++i) {
+ if (!fingers.isValidIndex(i)) {
Err("Invalid entry at index %zu", i);
return false;
}
+ const Json::Value& finger_state = fingers[static_cast<int>(i)];
if (!ParseFingerState(finger_state, &fs[i]))
return false;
}
hs.fingers = fs;
- hs.finger_cnt = fingers->GetSize();
- double temp_double;
- if (!entry->GetDouble(ActivityLog::kKeyHardwareStateRelX,
- &temp_double)) {
- // There may not have rel_ entries for old logs
- Log("Unable to parse hardware state rel_x");
- } else {
- hs.rel_x = temp_double;
- if (!entry->GetDouble(ActivityLog::kKeyHardwareStateRelY,
- &temp_double)) {
+ hs.finger_cnt = fingers.size();
+ // There may not have rel_ entries for old logs
+ if (entry.isMember(ActivityLog::kKeyHardwareStateRelX)) {
+ hs.rel_x = entry[ActivityLog::kKeyHardwareStateRelX].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyHardwareStateRelY)) {
Err("Unable to parse hardware state rel_y");
return false;
}
- hs.rel_y = temp_double;
- if (!entry->GetDouble(ActivityLog::kKeyHardwareStateRelWheel,
- &temp_double)) {
+ hs.rel_x = entry[ActivityLog::kKeyHardwareStateRelY].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyHardwareStateRelWheel)) {
Err("Unable to parse hardware state rel_wheel");
return false;
}
- hs.rel_wheel = temp_double;
- if (!entry->GetDouble(ActivityLog::kKeyHardwareStateRelHWheel,
- &temp_double)) {
+ hs.rel_wheel = entry[ActivityLog::kKeyHardwareStateRelWheel].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyHardwareStateRelHWheel)) {
Err("Unable to parse hardware state rel_hwheel");
return false;
}
- hs.rel_hwheel = temp_double;
+ hs.rel_hwheel = entry[ActivityLog::kKeyHardwareStateRelHWheel].asDouble();
}
log_.LogHardwareState(hs);
return true;
}
-bool ActivityReplay::ParseFingerState(DictionaryValue* entry,
+bool ActivityReplay::ParseFingerState(const Json::Value& entry,
FingerState* out_fs) {
- double dbl = 0.0;
- if (!entry->GetDouble(ActivityLog::kKeyFingerStateTouchMajor, &dbl)) {
+ if (!entry.isMember(ActivityLog::kKeyFingerStateTouchMajor)) {
Err("can't parse finger's touch major");
return false;
}
- out_fs->touch_major = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyFingerStateTouchMinor, &dbl)) {
+ out_fs->touch_major =
+ entry[ActivityLog::kKeyFingerStateTouchMajor].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyFingerStateTouchMinor)) {
Err("can't parse finger's touch minor");
return false;
}
- out_fs->touch_minor = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyFingerStateWidthMajor, &dbl)) {
+ out_fs->touch_minor =
+ entry[ActivityLog::kKeyFingerStateTouchMinor].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyFingerStateWidthMajor)) {
Err("can't parse finger's width major");
return false;
}
- out_fs->width_major = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyFingerStateWidthMinor, &dbl)) {
+ out_fs->width_major =
+ entry[ActivityLog::kKeyFingerStateWidthMajor].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyFingerStateWidthMinor)) {
Err("can't parse finger's width minor");
return false;
}
- out_fs->width_minor = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyFingerStatePressure, &dbl)) {
+ out_fs->width_minor =
+ entry[ActivityLog::kKeyFingerStateWidthMinor].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyFingerStatePressure)) {
Err("can't parse finger's pressure");
return false;
}
- out_fs->pressure = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyFingerStateOrientation, &dbl)) {
+ out_fs->pressure = entry[ActivityLog::kKeyFingerStatePressure].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyFingerStateOrientation)) {
Err("can't parse finger's orientation");
return false;
}
- out_fs->orientation = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyFingerStatePositionX, &dbl)) {
+ out_fs->orientation =
+ entry[ActivityLog::kKeyFingerStateOrientation].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyFingerStatePositionX)) {
Err("can't parse finger's position x");
return false;
}
- out_fs->position_x = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyFingerStatePositionY, &dbl)) {
+ out_fs->position_x = entry[ActivityLog::kKeyFingerStatePositionX].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyFingerStatePositionY)) {
Err("can't parse finger's position y");
return false;
}
- out_fs->position_y = dbl;
- int tr_id;
- if (!entry->GetInteger(ActivityLog::kKeyFingerStateTrackingId, &tr_id)) {
+ out_fs->position_y = entry[ActivityLog::kKeyFingerStatePositionY].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyFingerStateTrackingId)) {
Err("can't parse finger's tracking id");
- string json;
- base::JSONWriter::WriteWithOptions(entry,
- base::JSONWriter::OPTIONS_PRETTY_PRINT,
- &json);
- Err("fs: %s", json.c_str());
return false;
}
- out_fs->tracking_id = tr_id;
- int flags = 0;
- if (!entry->GetInteger(ActivityLog::kKeyFingerStateFlags, &flags))
+ out_fs->tracking_id = entry[ActivityLog::kKeyFingerStateTrackingId].asInt();
+ if (!entry.isMember(ActivityLog::kKeyFingerStateFlags))
Err("can't parse finger's flags; continuing.");
- out_fs->flags = static_cast<unsigned>(flags);
+ out_fs->flags = entry[ActivityLog::kKeyFingerStateFlags].asUInt();
return true;
}
-bool ActivityReplay::ParseTimerCallback(DictionaryValue* entry) {
- stime_t now = 0.0;
- if (!entry->GetDouble(ActivityLog::kKeyTimerCallbackNow, &now)) {
+bool ActivityReplay::ParseTimerCallback(const Json::Value& entry) {
+ if (!entry.isMember(ActivityLog::kKeyTimerCallbackNow)) {
Err("can't parse timercallback");
return false;
}
- log_.LogTimerCallback(now);
+ log_.LogTimerCallback(entry[ActivityLog::kKeyTimerCallbackNow].asDouble());
return true;
}
-bool ActivityReplay::ParseCallbackRequest(DictionaryValue* entry) {
- stime_t when = 0.0;
- if (!entry->GetDouble(ActivityLog::kKeyCallbackRequestWhen, &when)) {
+bool ActivityReplay::ParseCallbackRequest(const Json::Value& entry) {
+ if (!entry.isMember(ActivityLog::kKeyCallbackRequestWhen)) {
Err("can't parse callback request");
return false;
}
- log_.LogCallbackRequest(when);
+ log_.LogCallbackRequest(
+ entry[ActivityLog::kKeyCallbackRequestWhen].asDouble());
return true;
}
-bool ActivityReplay::ParseGesture(DictionaryValue* entry) {
- string gesture_type;
- if (!entry->GetString(ActivityLog::kKeyGestureType, &gesture_type)) {
+bool ActivityReplay::ParseGesture(const Json::Value& entry) {
+ if (!entry.isMember(ActivityLog::kKeyGestureType)) {
Err("can't parse gesture type");
return false;
}
+ string gesture_type = entry[ActivityLog::kKeyGestureType].asString();
Gesture gs;
- if (!entry->GetDouble(ActivityLog::kKeyGestureStartTime, &gs.start_time)) {
+ if (!entry.isMember(ActivityLog::kKeyGestureStartTime)) {
Err("Failed to parse gesture start time");
return false;
}
- if (!entry->GetDouble(ActivityLog::kKeyGestureEndTime, &gs.end_time)) {
+ gs.start_time = entry[ActivityLog::kKeyGestureStartTime].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureEndTime)) {
Err("Failed to parse gesture end time");
return false;
}
+ gs.end_time = entry[ActivityLog::kKeyGestureEndTime].asDouble();
if (gesture_type == ActivityLog::kValueGestureTypeContactInitiated) {
gs.type = kGestureTypeContactInitiated;
@@ -399,180 +389,187 @@ bool ActivityReplay::ParseGesture(DictionaryValue* entry) {
return true;
}
-bool ActivityReplay::ParseGestureMove(DictionaryValue* entry, Gesture* out_gs) {
+bool ActivityReplay::ParseGestureMove(const Json::Value& entry,
+ Gesture* out_gs) {
out_gs->type = kGestureTypeMove;
- double dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureMoveDX, &dbl)) {
+ if (!entry.isMember(ActivityLog::kKeyGestureMoveDX)) {
Err("can't parse move dx");
return false;
}
- out_gs->details.move.dx = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureMoveDY, &dbl)) {
+ out_gs->details.move.dx = entry[ActivityLog::kKeyGestureMoveDX].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureMoveDY)) {
Err("can't parse move dy");
return false;
}
- out_gs->details.move.dy = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureMoveOrdinalDX, &dbl)) {
+ out_gs->details.move.dy = entry[ActivityLog::kKeyGestureMoveDY].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureMoveOrdinalDX)) {
Err("can't parse move ordinal_dx");
return false;
}
- out_gs->details.move.ordinal_dx = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureMoveOrdinalDY, &dbl)) {
+ out_gs->details.move.ordinal_dx =
+ entry[ActivityLog::kKeyGestureMoveOrdinalDX].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureMoveOrdinalDY)) {
Err("can't parse move ordinal_dy");
return false;
}
- out_gs->details.move.ordinal_dy = dbl;
+ out_gs->details.move.ordinal_dy =
+ entry[ActivityLog::kKeyGestureMoveOrdinalDY].asDouble();
return true;
}
-bool ActivityReplay::ParseGestureScroll(DictionaryValue* entry,
+bool ActivityReplay::ParseGestureScroll(const Json::Value& entry,
Gesture* out_gs) {
out_gs->type = kGestureTypeScroll;
- double dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureScrollDX, &dbl)) {
+ if (!entry.isMember(ActivityLog::kKeyGestureScrollDX)) {
Err("can't parse scroll dx");
return false;
}
- out_gs->details.scroll.dx = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureScrollDY, &dbl)) {
+ out_gs->details.scroll.dx =
+ entry[ActivityLog::kKeyGestureScrollDX].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureScrollDY)) {
Err("can't parse scroll dy");
return false;
}
- out_gs->details.scroll.dy = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureScrollOrdinalDX, &dbl)) {
+ out_gs->details.scroll.dy =
+ entry[ActivityLog::kKeyGestureScrollDY].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureScrollOrdinalDX)) {
Err("can't parse scroll ordinal_dx");
return false;
}
- out_gs->details.scroll.ordinal_dx = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureScrollOrdinalDY, &dbl)) {
+ out_gs->details.scroll.ordinal_dx =
+ entry[ActivityLog::kKeyGestureScrollOrdinalDX].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureScrollOrdinalDY)) {
Err("can't parse scroll ordinal_dy");
return false;
}
- out_gs->details.scroll.ordinal_dy = dbl;
+ out_gs->details.scroll.ordinal_dy =
+ entry[ActivityLog::kKeyGestureScrollOrdinalDY].asDouble();
return true;
}
-bool ActivityReplay::ParseGestureSwipe(DictionaryValue* entry,
+bool ActivityReplay::ParseGestureSwipe(const Json::Value& entry,
Gesture* out_gs) {
out_gs->type = kGestureTypeSwipe;
- double dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureSwipeDX, &dbl)) {
+ if (!entry.isMember(ActivityLog::kKeyGestureSwipeDX)) {
Err("can't parse swipe dx");
return false;
}
- out_gs->details.swipe.dx = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureSwipeDY, &dbl)) {
+ out_gs->details.swipe.dx = entry[ActivityLog::kKeyGestureSwipeDX].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureSwipeDY)) {
Err("can't parse swipe dy");
return false;
}
- out_gs->details.swipe.dy = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureSwipeOrdinalDX, &dbl)) {
+ out_gs->details.swipe.dy = entry[ActivityLog::kKeyGestureSwipeDY].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureSwipeOrdinalDX)) {
Err("can't parse swipe ordinal_dx");
return false;
}
- out_gs->details.swipe.ordinal_dx = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureSwipeOrdinalDY, &dbl)) {
+ out_gs->details.swipe.ordinal_dx =
+ entry[ActivityLog::kKeyGestureSwipeOrdinalDX].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureSwipeOrdinalDY)) {
Err("can't parse swipe ordinal_dy");
return false;
}
- out_gs->details.swipe.ordinal_dy = dbl;
+ out_gs->details.swipe.ordinal_dy =
+ entry[ActivityLog::kKeyGestureSwipeOrdinalDY].asDouble();
return true;
}
-bool ActivityReplay::ParseGestureSwipeLift(DictionaryValue* entry,
+bool ActivityReplay::ParseGestureSwipeLift(const Json::Value& entry,
Gesture* out_gs) {
out_gs->type = kGestureTypeSwipeLift;
return true;
}
-bool ActivityReplay::ParseGesturePinch(DictionaryValue* entry,
+bool ActivityReplay::ParseGesturePinch(const Json::Value& entry,
Gesture* out_gs) {
out_gs->type = kGestureTypePinch;
- double dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGesturePinchDZ, &dbl)) {
+ if (!entry.isMember(ActivityLog::kKeyGesturePinchDZ)) {
Err("can't parse pinch dz");
return false;
}
- out_gs->details.pinch.dz = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGesturePinchOrdinalDZ, &dbl)) {
+ out_gs->details.pinch.dz = entry[ActivityLog::kKeyGesturePinchDZ].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGesturePinchOrdinalDZ)) {
Err("can't parse pinch ordinal_dz");
return false;
}
- out_gs->details.pinch.ordinal_dz = dbl;
+ out_gs->details.pinch.ordinal_dz =
+ entry[ActivityLog::kKeyGesturePinchOrdinalDZ].asDouble();
return true;
}
-bool ActivityReplay::ParseGestureButtonsChange(DictionaryValue* entry,
+bool ActivityReplay::ParseGestureButtonsChange(const Json::Value& entry,
Gesture* out_gs) {
out_gs->type = kGestureTypeButtonsChange;
- int temp;
- if (!entry->GetInteger(ActivityLog::kKeyGestureButtonsChangeDown,
- &temp)) {
+ if (!entry.isMember(ActivityLog::kKeyGestureButtonsChangeDown)) {
Err("can't parse buttons down");
return false;
}
- out_gs->details.buttons.down = temp;
- if (!entry->GetInteger(ActivityLog::kKeyGestureButtonsChangeUp,
- &temp)) {
+ out_gs->details.buttons.down =
+ entry[ActivityLog::kKeyGestureButtonsChangeDown].asUInt();
+ if (!entry.isMember(ActivityLog::kKeyGestureButtonsChangeUp)) {
Err("can't parse buttons up");
return false;
}
- out_gs->details.buttons.up = temp;
+ out_gs->details.buttons.up =
+ entry[ActivityLog::kKeyGestureButtonsChangeUp].asUInt();
return true;
}
-bool ActivityReplay::ParseGestureFling(DictionaryValue* entry,
+bool ActivityReplay::ParseGestureFling(const Json::Value& entry,
Gesture* out_gs) {
out_gs->type = kGestureTypeFling;
- double dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureFlingVX, &dbl)) {
+ if (!entry.isMember(ActivityLog::kKeyGestureFlingVX)) {
Err("can't parse fling vx");
return false;
}
- out_gs->details.fling.vx = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureFlingVY, &dbl)) {
+ out_gs->details.fling.vx = entry[ActivityLog::kKeyGestureFlingVX].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureFlingVY)) {
Err("can't parse fling vy");
return false;
}
- out_gs->details.fling.vy = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureFlingOrdinalVX, &dbl)) {
+ out_gs->details.fling.vy = entry[ActivityLog::kKeyGestureFlingVY].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureFlingOrdinalVX)) {
Err("can't parse fling ordinal_vx");
return false;
}
- out_gs->details.fling.ordinal_vx = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureFlingOrdinalVY, &dbl)) {
+ out_gs->details.fling.ordinal_vx =
+ entry[ActivityLog::kKeyGestureFlingOrdinalVX].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureFlingOrdinalVY)) {
Err("can't parse fling ordinal_vy");
return false;
}
- out_gs->details.fling.ordinal_vy = dbl;
- int state;
- if (!entry->GetInteger(ActivityLog::kKeyGestureFlingState, &state)) {
+ out_gs->details.fling.ordinal_vy =
+ entry[ActivityLog::kKeyGestureFlingOrdinalVY].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureFlingState)) {
Err("can't parse scroll is_scroll_begin");
return false;
}
- out_gs->details.fling.fling_state = state;
+ out_gs->details.fling.fling_state =
+ entry[ActivityLog::kKeyGestureFlingState].asInt();
return true;
}
-bool ActivityReplay::ParseGestureMetrics(DictionaryValue* entry,
+bool ActivityReplay::ParseGestureMetrics(const Json::Value& entry,
Gesture* out_gs) {
out_gs->type = kGestureTypeMetrics;
- double dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureMetricsData1, &dbl)) {
+ if (!entry.isMember(ActivityLog::kKeyGestureMetricsData1)) {
Err("can't parse metrics data 1");
return false;
}
- out_gs->details.metrics.data[0] = dbl;
- if (!entry->GetDouble(ActivityLog::kKeyGestureMetricsData2, &dbl)) {
+ out_gs->details.metrics.data[0] =
+ entry[ActivityLog::kKeyGestureMetricsData1].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureMetricsData2)) {
Err("can't parse metrics data 2");
return false;
}
- out_gs->details.metrics.data[1] = dbl;
- int type;
- if (!entry->GetInteger(ActivityLog::kKeyGestureMetricsType, &type)) {
+ out_gs->details.metrics.data[1] =
+ entry[ActivityLog::kKeyGestureMetricsData2].asDouble();
+ if (!entry.isMember(ActivityLog::kKeyGestureMetricsType)) {
Err("can't parse metrics type");
return false;
}
+ int type = entry[ActivityLog::kKeyGestureMetricsType].asInt();
if (type == 0) {
out_gs->details.metrics.type = kGestureMetricsTypeNoisyGround;
return true;
@@ -581,55 +578,56 @@ bool ActivityReplay::ParseGestureMetrics(DictionaryValue* entry,
return true;
}
-bool ActivityReplay::ParsePropChange(DictionaryValue* entry) {
+bool ActivityReplay::ParsePropChange(const Json::Value& entry) {
ActivityLog::PropChangeEntry prop_change;
- string type;
- if (!entry->GetString(ActivityLog::kKeyPropChangeType, &type)) {
+ if (!entry.isMember(ActivityLog::kKeyPropChangeType)) {
Err("Can't get prop change type");
return false;
}
+ string type = entry[ActivityLog::kKeyPropChangeType].asString();
if (type == ActivityLog::kValuePropChangeTypeBool) {
prop_change.type = ActivityLog::PropChangeEntry::kBoolProp;
- bool val;
- if (!entry->GetBoolean(ActivityLog::kKeyPropChangeValue, &val)) {
+ if (!entry.isMember(ActivityLog::kKeyPropChangeValue)) {
Err("Can't parse prop change value");
return false;
}
- prop_change.value.bool_val = val;
+ prop_change.value.bool_val =
+ entry[ActivityLog::kKeyPropChangeValue].asBool();
} else if (type == ActivityLog::kValuePropChangeTypeDouble) {
prop_change.type = ActivityLog::PropChangeEntry::kDoubleProp;
- if (!entry->GetDouble(ActivityLog::kKeyPropChangeValue,
- &prop_change.value.double_val)) {
+ if (!entry.isMember(ActivityLog::kKeyPropChangeValue)) {
Err("Can't parse prop change value");
return false;
}
+ prop_change.value.double_val =
+ entry[ActivityLog::kKeyPropChangeValue].asDouble();
} else if (type == ActivityLog::kValuePropChangeTypeInt) {
prop_change.type = ActivityLog::PropChangeEntry::kIntProp;
- if (!entry->GetInteger(ActivityLog::kKeyPropChangeValue,
- &prop_change.value.int_val)) {
+ if (!entry.isMember(ActivityLog::kKeyPropChangeValue)) {
Err("Can't parse prop change value");
return false;
}
+ prop_change.value.int_val =
+ entry[ActivityLog::kKeyPropChangeValue].asInt();
} else if (type == ActivityLog::kValuePropChangeTypeShort) {
prop_change.type = ActivityLog::PropChangeEntry::kIntProp;
- int val;
- if (!entry->GetInteger(ActivityLog::kKeyPropChangeValue,
- &val)) {
+ if (!entry.isMember(ActivityLog::kKeyPropChangeValue)) {
Err("Can't parse prop change value");
return false;
}
- prop_change.value.short_val = val;
+ prop_change.value.short_val =
+ entry[ActivityLog::kKeyPropChangeValue].asInt();
} else {
Err("Unable to parse prop change type %s", type.c_str());
return false;
}
- string name;
- if (!entry->GetString(ActivityLog::kKeyPropChangeName, &name)) {
+ if (!entry.isMember(ActivityLog::kKeyPropChangeName)) {
Err("Unable to parse prop change name.");
return false;
}
- const string* stored_name = new string(name.c_str()); // alloc
+ const string* stored_name =
+ new string(entry[ActivityLog::kKeyPropChangeName].asString()); // alloc
// transfer ownership:
names_.push_back(std::tr1::shared_ptr<const string>(stored_name));
prop_change.name = stored_name->c_str();
@@ -671,7 +669,8 @@ void ActivityReplay::Replay(Interpreter* interpreter,
bool matched = false;
while (!consumed_gestures_.empty() && !matched) {
if (consumed_gestures_.front() == entry->details.gesture) {
- Log("Gesture matched:\n Actual gesture: %s.\nExpected gesture: %s",
+ Log("Gesture matched:\n Actual gesture: %s.\n"
+ "Expected gesture: %s",
consumed_gestures_.front().String().c_str(),
entry->details.gesture.String().c_str());
matched = true;
@@ -725,22 +724,22 @@ bool ActivityReplay::ReplayPropChange(
Err("Unable to find prop %s to set.", entry.name);
return false;
}
- std::unique_ptr<Value> value;
+ Json::Value value;
switch (entry.type) {
case ActivityLog::PropChangeEntry::kBoolProp:
- value.reset(Value::CreateBooleanValue(entry.value.bool_val));
+ value = Json::Value(entry.value.bool_val);
break;
case ActivityLog::PropChangeEntry::kDoubleProp:
- value.reset(Value::CreateDoubleValue(entry.value.double_val));
+ value = Json::Value(entry.value.double_val);
break;
case ActivityLog::PropChangeEntry::kIntProp:
- value.reset(Value::CreateIntegerValue(entry.value.int_val));
+ value = Json::Value(entry.value.int_val);
break;
case ActivityLog::PropChangeEntry::kShortProp:
- value.reset(Value::CreateIntegerValue(entry.value.short_val));
+ value = Json::Value(entry.value.short_val);
break;
}
- prop->SetValue(value.get());
+ prop->SetValue(value);
prop->HandleGesturesPropWritten();
return true;
}