libweave: Remove native_types namespace It has only two typedefs. Now they are ValueMap and ValueVector. BUG=brillo:1245 TEST='FEATURES=test emerge-gizmo buffet' Change-Id: Iefd3ee2bc18432450fd13876fadfe23bf62cb2dc Reviewed-on: https://chromium-review.googlesource.com/287167 Tested-by: Vitaly Buka <vitalybuka@chromium.org> Reviewed-by: Alex Vakulenko <avakulenko@chromium.org> Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/libweave/src/base_api_handler.cc b/libweave/src/base_api_handler.cc index acb136e..e6f9f9c 100644 --- a/libweave/src/base_api_handler.cc +++ b/libweave/src/base_api_handler.cc
@@ -13,11 +13,11 @@ namespace { -// Helps to get parameters from native_types::Object representing +// Helps to get parameters from ValueMap representing // CommandInstance parameters. class ParametersReader final { public: - explicit ParametersReader(const native_types::Object* parameters) + explicit ParametersReader(const ValueMap* parameters) : parameters_{parameters} {} bool GetParameter(const std::string& name, std::string* value) const { @@ -43,7 +43,7 @@ } private: - const native_types::Object* parameters_; + const ValueMap* parameters_; }; } // namespace
diff --git a/libweave/src/commands/command_instance.cc b/libweave/src/commands/command_instance.cc index 37a1ddc..2975937 100644 --- a/libweave/src/commands/command_instance.cc +++ b/libweave/src/commands/command_instance.cc
@@ -29,7 +29,7 @@ CommandInstance::CommandInstance(const std::string& name, const std::string& origin, const CommandDefinition* command_definition, - const native_types::Object& parameters) + const ValueMap& parameters) : name_{name}, origin_{origin}, command_definition_{command_definition}, @@ -61,7 +61,7 @@ // |error|. bool GetCommandParameters(const base::DictionaryValue* json, const CommandDefinition* command_def, - native_types::Object* parameters, + ValueMap* parameters, chromeos::ErrorPtr* error) { // Get the command parameters from 'parameters' property. base::DictionaryValue no_params; // Placeholder when no params are specified. @@ -137,7 +137,7 @@ return instance; } - native_types::Object parameters; + ValueMap parameters; if (!GetCommandParameters(json, command_def, ¶meters, error)) { chromeos::Error::AddToPrintf(error, FROM_HERE, errors::commands::kDomain, errors::commands::kCommandFailed, @@ -175,7 +175,7 @@ observers_.push_back(observer); } -bool CommandInstance::SetResults(const native_types::Object& results) { +bool CommandInstance::SetResults(const ValueMap& results) { // TODO(antonm): Add validation. if (results != results_) { results_ = results; @@ -185,7 +185,7 @@ return true; } -bool CommandInstance::SetProgress(const native_types::Object& progress) { +bool CommandInstance::SetProgress(const ValueMap& progress) { // Change status even if progress unchanged, e.g. 0% -> 0%. SetStatus(kStatusInProgress); if (progress != progress_) {
diff --git a/libweave/src/commands/command_instance.h b/libweave/src/commands/command_instance.h index a64fc7c..358cd52 100644 --- a/libweave/src/commands/command_instance.h +++ b/libweave/src/commands/command_instance.h
@@ -36,7 +36,7 @@ CommandInstance(const std::string& name, const std::string& origin, const CommandDefinition* command_definition, - const native_types::Object& parameters); + const ValueMap& parameters); ~CommandInstance() override; // Command overrides. @@ -50,9 +50,9 @@ // Returns the command category. const std::string& GetCategory() const; // Returns the command parameters and their values. - const native_types::Object& GetParameters() const { return parameters_; } + const ValueMap& GetParameters() const { return parameters_; } // Returns the command results and their values. - const native_types::Object& GetResults() const { return results_; } + const ValueMap& GetResults() const { return results_; } // Finds a command parameter value by parameter |name|. If the parameter // with given name does not exist, returns nullptr. const PropValue* FindParameter(const std::string& name) const; @@ -87,11 +87,11 @@ // Updates the command progress. The |progress| should match the schema. // Returns false if |results| value is incorrect. - bool SetProgress(const native_types::Object& progress); + bool SetProgress(const ValueMap& progress); // Updates the command results. The |results| should match the schema. // Returns false if |results| value is incorrect. - bool SetResults(const native_types::Object& results); + bool SetResults(const ValueMap& results); // Aborts command execution. void Abort(); @@ -101,7 +101,7 @@ void Done(); // Command state getters. - const native_types::Object& GetProgress() const { return progress_; } + const ValueMap& GetProgress() const { return progress_; } const std::string& GetStatus() const { return status_; } // Values for command execution status. @@ -132,11 +132,11 @@ // Command definition. const CommandDefinition* command_definition_; // Command parameters and their values. - native_types::Object parameters_; + ValueMap parameters_; // Current command execution progress. - native_types::Object progress_; + ValueMap progress_; // Command results. - native_types::Object results_; + ValueMap results_; // Current command status. std::string status_ = kStatusQueued; // Command observer for the command.
diff --git a/libweave/src/commands/command_instance_unittest.cc b/libweave/src/commands/command_instance_unittest.cc index 0107042..9d2c019 100644 --- a/libweave/src/commands/command_instance_unittest.cc +++ b/libweave/src/commands/command_instance_unittest.cc
@@ -71,13 +71,13 @@ TEST_F(CommandInstanceTest, Test) { StringPropType str_prop; IntPropType int_prop; - native_types::Object params; + ValueMap params; params["phrase"] = str_prop.CreateValue(std::string("iPityDaFool"), nullptr); params["volume"] = int_prop.CreateValue(5, nullptr); CommandInstance instance{ "robot.speak", "cloud", dict_.FindCommand("robot.speak"), params}; - native_types::Object results; + ValueMap results; results["foo"] = int_prop.CreateValue(239, nullptr); instance.SetResults(results); @@ -216,13 +216,13 @@ auto instance = CommandInstance::FromJson(json.get(), "cloud", dict_, nullptr, nullptr); instance->SetProgress( - native_types::Object{{"progress", unittests::make_int_prop_value(15)}}); + ValueMap{{"progress", unittests::make_int_prop_value(15)}}); instance->SetProgress( - native_types::Object{{"progress", unittests::make_int_prop_value(15)}}); + ValueMap{{"progress", unittests::make_int_prop_value(15)}}); instance->SetID("testId"); - native_types::Object results; + ValueMap results; instance->SetResults( - native_types::Object{{"testResult", unittests::make_int_prop_value(17)}}); + ValueMap{{"testResult", unittests::make_int_prop_value(17)}}); json->MergeDictionary(CreateDictionaryValue(R"({ 'id': 'testId',
diff --git a/libweave/src/commands/dbus_command_dispatcher_unittest.cc b/libweave/src/commands/dbus_command_dispatcher_unittest.cc index 7f1ac9a..c488d92 100644 --- a/libweave/src/commands/dbus_command_dispatcher_unittest.cc +++ b/libweave/src/commands/dbus_command_dispatcher_unittest.cc
@@ -121,8 +121,7 @@ void FinishCommand(DBusCommandProxy* proxy) { proxy->Done(); } - void SetProgress(DBusCommandProxy* proxy, - const native_types::Object& progress) { + void SetProgress(DBusCommandProxy* proxy, const ValueMap& progress) { EXPECT_TRUE(proxy->SetProgress(nullptr, ObjectToDBusVariant(progress))); } @@ -146,8 +145,7 @@ // Two properties are set, Progress = 50%, Status = "inProgress" EXPECT_CALL(*mock_exported_command_proxy_, SendSignal(_)).Times(2); - native_types::Object progress{ - {"progress", unittests::make_int_prop_value(50)}}; + ValueMap progress{{"progress", unittests::make_int_prop_value(50)}}; SetProgress(command_proxy, progress); EXPECT_EQ(CommandInstance::kStatusInProgress, command_instance->GetStatus()); EXPECT_EQ(progress, command_instance->GetProgress()); @@ -182,7 +180,7 @@ // One property is set, Status = "inProgress" EXPECT_CALL(*mock_exported_command_proxy_, SendSignal(_)).Times(1); - native_types::Object progress{}; + ValueMap progress{}; SetProgress(command_proxy, progress); EXPECT_EQ(CommandInstance::kStatusInProgress, command_instance->GetStatus()); EXPECT_EQ(progress, command_instance->GetProgress());
diff --git a/libweave/src/commands/dbus_command_proxy.cc b/libweave/src/commands/dbus_command_proxy.cc index 743bc73..5ffcd9d 100644 --- a/libweave/src/commands/dbus_command_proxy.cc +++ b/libweave/src/commands/dbus_command_proxy.cc
@@ -74,7 +74,7 @@ auto progress_schema = command_instance_->GetCommandDefinition()->GetProgress(); - native_types::Object obj; + ValueMap obj; if (!ObjectFromDBusVariant(progress_schema, progress, &obj, error)) return false; @@ -88,7 +88,7 @@ << ">::SetResults()"; auto results_schema = command_instance_->GetCommandDefinition()->GetResults(); - native_types::Object obj; + ValueMap obj; if (!ObjectFromDBusVariant(results_schema, results, &obj, error)) return false;
diff --git a/libweave/src/commands/object_schema_unittest.cc b/libweave/src/commands/object_schema_unittest.cc index 753ad46..d927c7b 100644 --- a/libweave/src/commands/object_schema_unittest.cc +++ b/libweave/src/commands/object_schema_unittest.cc
@@ -27,7 +27,7 @@ namespace { template <typename T> -std::vector<T> GetArrayValues(const native_types::Array& arr) { +std::vector<T> GetArrayValues(const ValueVector& arr) { std::vector<T> values; values.reserve(arr.size()); for (const auto& prop_value : arr) { @@ -665,7 +665,7 @@ ASSERT_NE(nullptr, prop2.GetDefaultValue()); const ObjectValue* defval = prop2.GetDefaultValue()->GetObject(); ASSERT_NE(nullptr, defval); - native_types::Object objval = defval->GetValue(); + ValueMap objval = defval->GetValue(); EXPECT_EQ("Bob", objval["name"]->GetString()->GetValue()); EXPECT_EQ(33, objval["age"]->GetInt()->GetValue()); } @@ -739,7 +739,7 @@ "'enum':[{'width':10,'height':20},{'width':100,'height':200}]}") .get(), nullptr, nullptr)); - native_types::Object obj{ + ValueMap obj{ {"width", int_type.CreateValue(10, nullptr)}, {"height", int_type.CreateValue(20, nullptr)}, }; @@ -748,7 +748,7 @@ auto val = prop.CreateValue(obj, &error); ASSERT_NE(nullptr, val.get()); EXPECT_EQ(nullptr, error.get()); - EXPECT_EQ(obj, val->GetValueAsAny().Get<native_types::Object>()); + EXPECT_EQ(obj, val->GetValueAsAny().Get<ValueMap>()); val = prop.CreateValue("blah", &error); EXPECT_EQ(nullptr, val.get()); @@ -873,12 +873,12 @@ nullptr, nullptr)); chromeos::ErrorPtr error; - native_types::Array arr; + ValueVector arr; auto val = prop.CreateValue(arr, &error); ASSERT_NE(nullptr, val.get()); EXPECT_EQ(nullptr, error.get()); - EXPECT_EQ(arr, val->GetValueAsAny().Get<native_types::Array>()); + EXPECT_EQ(arr, val->GetValueAsAny().Get<ValueVector>()); EXPECT_JSON_EQ("[]", *val->ToJson(nullptr)); IntPropType int_type; @@ -889,13 +889,13 @@ .get(), nullptr, nullptr)); arr.push_back(obj_type.CreateValue( - native_types::Object{ + ValueMap{ {"width", int_type.CreateValue(10, nullptr)}, {"height", int_type.CreateValue(20, nullptr)}, }, nullptr)); arr.push_back(obj_type.CreateValue( - native_types::Object{ + ValueMap{ {"width", int_type.CreateValue(17, nullptr)}, {"height", int_type.CreateValue(18, nullptr)}, }, @@ -904,7 +904,7 @@ val = prop.CreateValue(arr, &error); ASSERT_NE(nullptr, val.get()); EXPECT_EQ(nullptr, error.get()); - EXPECT_EQ(arr, val->GetValueAsAny().Get<native_types::Array>()); + EXPECT_EQ(arr, val->GetValueAsAny().Get<ValueVector>()); EXPECT_JSON_EQ("[{'height':20,'width':10},{'height':18,'width':17}]", *val->ToJson(nullptr)); @@ -1295,15 +1295,15 @@ // Omit all. auto value = prop.CreateValue(); ASSERT_TRUE(value->FromJson(CreateDictionaryValue("{}").get(), nullptr)); - native_types::Object obj = value->GetObject()->GetValue(); + ValueMap obj = value->GetObject()->GetValue(); EXPECT_TRUE(obj["param1"]->GetBoolean()->GetValue()); EXPECT_EQ(2, obj["param2"]->GetInt()->GetValue()); EXPECT_DOUBLE_EQ(3.3, obj["param3"]->GetDouble()->GetValue()); EXPECT_EQ("four", obj["param4"]->GetString()->GetValue()); - native_types::Object param5 = obj["param5"]->GetObject()->GetValue(); + ValueMap param5 = obj["param5"]->GetObject()->GetValue(); EXPECT_EQ(5, param5["x"]->GetInt()->GetValue()); EXPECT_EQ(6, param5["y"]->GetInt()->GetValue()); - native_types::Array param6 = obj["param6"]->GetArray()->GetValue(); + ValueVector param6 = obj["param6"]->GetArray()->GetValue(); EXPECT_EQ((std::vector<int>{1, 2, 3}), GetArrayValues<int>(param6)); // Specify some. @@ -1674,7 +1674,7 @@ 'param4':40 })"; ASSERT_TRUE(value->FromJson(CreateDictionaryValue(val_json).get(), nullptr)); - native_types::Object obj = value->GetObject()->GetValue(); + ValueMap obj = value->GetObject()->GetValue(); EXPECT_EQ(10, obj["param1"]->GetInt()->GetValue()); EXPECT_EQ(20, obj["param2"]->GetInt()->GetValue()); EXPECT_EQ(30, obj["param3"]->GetInt()->GetValue());
diff --git a/libweave/src/commands/prop_constraints.cc b/libweave/src/commands/prop_constraints.cc index f223978..9d9f81e 100644 --- a/libweave/src/commands/prop_constraints.cc +++ b/libweave/src/commands/prop_constraints.cc
@@ -168,12 +168,9 @@ } // ConstraintOneOf -------------------------------------------------- -ConstraintOneOf::ConstraintOneOf(InheritableAttribute<native_types::Array> set) - : set_(std::move(set)) { -} -ConstraintOneOf::ConstraintOneOf(native_types::Array set) - : set_(std::move(set)) { -} +ConstraintOneOf::ConstraintOneOf(InheritableAttribute<ValueVector> set) + : set_(std::move(set)) {} +ConstraintOneOf::ConstraintOneOf(ValueVector set) : set_(std::move(set)) {} bool ConstraintOneOf::Validate(const PropValue& value, chromeos::ErrorPtr* error) const { @@ -190,7 +187,7 @@ } std::unique_ptr<Constraint> ConstraintOneOf::Clone() const { - InheritableAttribute<native_types::Array> attr; + InheritableAttribute<ValueVector> attr; attr.is_inherited = set_.is_inherited; attr.value.reserve(set_.value.size()); for (const auto& prop_value : set_.value) { @@ -200,7 +197,7 @@ } std::unique_ptr<Constraint> ConstraintOneOf::CloneAsInherited() const { - native_types::Array cloned; + ValueVector cloned; cloned.reserve(set_.value.size()); for (const auto& prop_value : set_.value) { cloned.push_back(prop_value->Clone());
diff --git a/libweave/src/commands/prop_constraints.h b/libweave/src/commands/prop_constraints.h index 74f69da..d325a00 100644 --- a/libweave/src/commands/prop_constraints.h +++ b/libweave/src/commands/prop_constraints.h
@@ -286,8 +286,8 @@ // Implementation of OneOf constraint for different data types. class ConstraintOneOf : public Constraint { public: - explicit ConstraintOneOf(InheritableAttribute<native_types::Array> set); - explicit ConstraintOneOf(native_types::Array set); + explicit ConstraintOneOf(InheritableAttribute<ValueVector> set); + explicit ConstraintOneOf(ValueVector set); // Implementation of Constraint::GetType(). ConstraintType GetType() const override { return ConstraintType::OneOf; } @@ -314,7 +314,7 @@ // Stores the list of acceptable values for the parameter. // |set_.is_inherited| indicates whether the constraint is inherited // from base schema or overridden. - InheritableAttribute<native_types::Array> set_; + InheritableAttribute<ValueVector> set_; private: DISALLOW_COPY_AND_ASSIGN(ConstraintOneOf);
diff --git a/libweave/src/commands/prop_types.cc b/libweave/src/commands/prop_types.cc index 54d8028..3105e6d 100644 --- a/libweave/src/commands/prop_types.cc +++ b/libweave/src/commands/prop_types.cc
@@ -331,12 +331,12 @@ const base::Value* list = nullptr; // Owned by |value| CHECK(value->Get(commands::attributes::kOneOf_Enum, &list)) << "'enum' property missing in JSON dictionary"; - native_types::Array choice_list; + ValueVector choice_list; ArrayPropType array_type; array_type.SetItemType(prop_type->Clone()); if (!TypedValueFromJson(list, &array_type, &choice_list, error)) return constraint; - InheritableAttribute<native_types::Array> val(std::move(choice_list), false); + InheritableAttribute<ValueVector> val(std::move(choice_list), false); constraint.reset(new ConstraintOneOf{std::move(val)}); return constraint; } @@ -608,7 +608,7 @@ } chromeos::Any ObjectPropType::ConvertArrayToDBusVariant( - const native_types::Array& source) const { + const ValueVector& source) const { std::vector<chromeos::VariantDictionary> result; result.reserve(source.size()); for (const auto& prop_value : source) { @@ -620,7 +620,7 @@ bool ObjectPropType::ConvertDBusVariantToArray( const chromeos::Any& source, - native_types::Array* result, + ValueVector* result, chromeos::ErrorPtr* error) const { if (!source.IsTypeCompatible<std::vector<chromeos::VariantDictionary>>()) return GenerateErrorValueTypeMismatch(error);
diff --git a/libweave/src/commands/prop_types.h b/libweave/src/commands/prop_types.h index e98d2eb..7a2e695 100644 --- a/libweave/src/commands/prop_types.h +++ b/libweave/src/commands/prop_types.h
@@ -97,7 +97,7 @@ // by this instance of PropType into an Any containing std::vector<T>, where // T corresponds to the native representation of this PropType. virtual chromeos::Any ConvertArrayToDBusVariant( - const native_types::Array& source) const = 0; + const ValueVector& source) const = 0; // ConvertAnyToArray is the opposite of ConvertArrayToAny(). // Given an Any containing std::vector<T>, converts each value into the @@ -105,7 +105,7 @@ // |result| array. If type conversion fails, this function returns false // and specifies the error details in |error|. virtual bool ConvertDBusVariantToArray(const chromeos::Any& source, - native_types::Array* result, + ValueVector* result, chromeos::ErrorPtr* error) const = 0; // Saves the parameter type definition as a JSON object. @@ -238,7 +238,7 @@ } chromeos::Any ConvertArrayToDBusVariant( - const native_types::Array& source) const override { + const ValueVector& source) const override { std::vector<T> result; result.reserve(source.size()); for (const auto& prop_value : source) { @@ -248,7 +248,7 @@ } bool ConvertDBusVariantToArray(const chromeos::Any& source, - native_types::Array* result, + ValueVector* result, chromeos::ErrorPtr* error) const override { if (!source.IsTypeCompatible<std::vector<T>>()) return GenerateErrorValueTypeMismatch(error); @@ -348,9 +348,9 @@ // Parameter definition of Object type. class ObjectPropType - : public PropTypeBase<ObjectPropType, ObjectValue, native_types::Object> { + : public PropTypeBase<ObjectPropType, ObjectValue, ValueMap> { public: - using Base = PropTypeBase<ObjectPropType, ObjectValue, native_types::Object>; + using Base = PropTypeBase<ObjectPropType, ObjectValue, ValueMap>; ObjectPropType(); // Overrides from the ParamType base class. @@ -370,10 +370,10 @@ chromeos::ErrorPtr* error) override; chromeos::Any ConvertArrayToDBusVariant( - const native_types::Array& source) const override; + const ValueVector& source) const override; bool ConvertDBusVariantToArray(const chromeos::Any& source, - native_types::Array* result, + ValueVector* result, chromeos::ErrorPtr* error) const override; // Returns a schema for Object-type parameter. @@ -388,9 +388,9 @@ // Parameter definition of Array type. class ArrayPropType - : public PropTypeBase<ArrayPropType, ArrayValue, native_types::Array> { + : public PropTypeBase<ArrayPropType, ArrayValue, ValueVector> { public: - using Base = PropTypeBase<ArrayPropType, ArrayValue, native_types::Array>; + using Base = PropTypeBase<ArrayPropType, ArrayValue, ValueVector>; ArrayPropType(); // Overrides from the ParamType base class.
diff --git a/libweave/src/commands/prop_values.h b/libweave/src/commands/prop_values.h index 90ce909..4740a3f 100644 --- a/libweave/src/commands/prop_values.h +++ b/libweave/src/commands/prop_values.h
@@ -64,11 +64,11 @@ return ValueType::Boolean; } template <> -inline ValueType GetValueType<native_types::Object>() { +inline ValueType GetValueType<ValueMap>() { return ValueType::Object; } template <> -inline ValueType GetValueType<native_types::Array>() { +inline ValueType GetValueType<ValueVector>() { return ValueType::Array; } @@ -212,8 +212,7 @@ }; // Value of type Object. -class ObjectValue final - : public TypedValueBase<ObjectValue, native_types::Object> { +class ObjectValue final : public TypedValueBase<ObjectValue, ValueMap> { public: using Base::Base; // Expose the custom constructor of the base class. ObjectValue* GetObject() override { return this; } @@ -221,8 +220,7 @@ }; // Value of type Array. -class ArrayValue final - : public TypedValueBase<ArrayValue, native_types::Array> { +class ArrayValue final : public TypedValueBase<ArrayValue, ValueVector> { public: using Base::Base; // Expose the custom constructor of the base class. ArrayValue* GetArray() override { return this; }
diff --git a/libweave/src/commands/schema_utils.cc b/libweave/src/commands/schema_utils.cc index 8e34032..9030415 100644 --- a/libweave/src/commands/schema_utils.cc +++ b/libweave/src/commands/schema_utils.cc
@@ -74,7 +74,7 @@ return std::unique_ptr<base::Value>(new base::StringValue(value)); } -std::unique_ptr<base::Value> TypedValueToJson(const native_types::Object& value, +std::unique_ptr<base::Value> TypedValueToJson(const ValueMap& value, chromeos::ErrorPtr* error) { std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); for (const auto& pair : value) { @@ -86,7 +86,7 @@ return std::move(dict); } -std::unique_ptr<base::Value> TypedValueToJson(const native_types::Array& value, +std::unique_ptr<base::Value> TypedValueToJson(const ValueVector& value, chromeos::ErrorPtr* error) { std::unique_ptr<base::ListValue> list(new base::ListValue); for (const auto& item : value) { @@ -132,7 +132,7 @@ bool TypedValueFromJson(const base::Value* value_in, const PropType* type, - native_types::Object* value_out, + ValueMap* value_out, chromeos::ErrorPtr* error) { const base::DictionaryValue* dict = nullptr; if (!value_in->GetAsDictionary(&dict)) @@ -202,7 +202,7 @@ bool TypedValueFromJson(const base::Value* value_in, const PropType* type, - native_types::Array* value_out, + ValueVector* value_out, chromeos::ErrorPtr* error) { const base::ListValue* list = nullptr; if (!value_in->GetAsList(&list)) @@ -229,13 +229,12 @@ } // Compares two sets of key-value pairs from two Objects. -static bool obj_cmp(const native_types::Object::value_type& v1, - const native_types::Object::value_type& v2) { +static bool obj_cmp(const ValueMap::value_type& v1, + const ValueMap::value_type& v2) { return (v1.first == v2.first) && v1.second->IsEqual(v2.second.get()); } -bool operator==(const native_types::Object& obj1, - const native_types::Object& obj2) { +bool operator==(const ValueMap& obj1, const ValueMap& obj2) { if (obj1.size() != obj2.size()) return false; @@ -243,12 +242,11 @@ return pair == std::make_pair(obj1.end(), obj2.end()); } -bool operator==(const native_types::Array& arr1, - const native_types::Array& arr2) { +bool operator==(const ValueVector& arr1, const ValueVector& arr2) { if (arr1.size() != arr2.size()) return false; - using Type = const native_types::Array::value_type; + using Type = const ValueVector::value_type; // Compare two array items. auto arr_cmp = [](const Type& v1, const Type& v2) { return v1->IsEqual(v2.get()); @@ -257,14 +255,14 @@ return pair == std::make_pair(arr1.end(), arr2.end()); } -std::string ToString(const native_types::Object& obj) { +std::string ToString(const ValueMap& obj) { auto val = TypedValueToJson(obj, nullptr); std::string str; base::JSONWriter::Write(*val, &str); return str; } -std::string ToString(const native_types::Array& arr) { +std::string ToString(const ValueVector& arr) { auto val = TypedValueToJson(arr, nullptr); std::string str; base::JSONWriter::Write(*val, &str); @@ -283,11 +281,10 @@ return value->GetValueAsAny(); } -chromeos::VariantDictionary ObjectToDBusVariant( - const native_types::Object& object) { +chromeos::VariantDictionary ObjectToDBusVariant(const ValueMap& object) { chromeos::VariantDictionary dict; for (const auto& pair : object) { - // Since we are inserting the elements from native_types::Object which is + // Since we are inserting the elements from ValueMap which is // a map, the keys are already sorted. So use the "end()" position as a hint // for dict.insert() so the destination map can optimize its insertion // time. @@ -305,22 +302,22 @@ if (type->GetType() == ValueType::Array) { // Special case for array types. // We expect the |value| to contain std::vector<T>, while PropValue must use - // native_types::Array instead. Do the conversion. - native_types::Array arr; + // ValueVector instead. Do the conversion. + ValueVector arr; const PropType* item_type = type->GetArray()->GetItemTypePtr(); if (item_type->ConvertDBusVariantToArray(value, &arr, error)) result = type->CreateValue(arr, error); } else if (type->GetType() == ValueType::Object) { // Special case for object types. // We expect the |value| to contain chromeos::VariantDictionary, while - // PropValue must use native_types::Object instead. Do the conversion. + // PropValue must use ValueMap instead. Do the conversion. if (!value.IsTypeCompatible<chromeos::VariantDictionary>()) { type->GenerateErrorValueTypeMismatch(error); return result; } CHECK(nullptr != type->GetObject()->GetObjectSchemaPtr()) << "An object type must have a schema defined for it"; - native_types::Object obj; + ValueMap obj; if (!ObjectFromDBusVariant(type->GetObject()->GetObjectSchemaPtr(), value.Get<chromeos::VariantDictionary>(), &obj, error)) { @@ -337,7 +334,7 @@ bool ObjectFromDBusVariant(const ObjectSchema* object_schema, const chromeos::VariantDictionary& dict, - native_types::Object* obj, + ValueMap* obj, chromeos::ErrorPtr* error) { std::set<std::string> keys_processed; obj->clear();
diff --git a/libweave/src/commands/schema_utils.h b/libweave/src/commands/schema_utils.h index 6b756e7..2822a3d 100644 --- a/libweave/src/commands/schema_utils.h +++ b/libweave/src/commands/schema_utils.h
@@ -24,18 +24,17 @@ class ObjectSchema; class ObjectValue; -namespace native_types { // C++ representation of object values. -using Object = std::map<std::string, std::shared_ptr<const PropValue>>; +using ValueMap = std::map<std::string, std::shared_ptr<const PropValue>>; + // C++ representation of array of values. -using Array = std::vector<std::shared_ptr<const PropValue>>; -} // namespace native_types +using ValueVector = std::vector<std::shared_ptr<const PropValue>>; // Converts an object to string. -std::string ToString(const native_types::Object& obj); +std::string ToString(const ValueMap& obj); // Converts an array to string. -std::string ToString(const native_types::Array& arr); +std::string ToString(const ValueVector& arr); // InheritableAttribute class is used for specifying various command parameter // attributes that can be inherited from a base (parent) schema. @@ -65,9 +64,9 @@ chromeos::ErrorPtr* error); std::unique_ptr<base::Value> TypedValueToJson(const std::string& value, chromeos::ErrorPtr* error); -std::unique_ptr<base::Value> TypedValueToJson(const native_types::Object& value, +std::unique_ptr<base::Value> TypedValueToJson(const ValueMap& value, chromeos::ErrorPtr* error); -std::unique_ptr<base::Value> TypedValueToJson(const native_types::Array& value, +std::unique_ptr<base::Value> TypedValueToJson(const ValueVector& value, chromeos::ErrorPtr* error); template <typename T> std::unique_ptr<base::Value> TypedValueToJson(const std::vector<T>& values, @@ -103,17 +102,15 @@ chromeos::ErrorPtr* error); bool TypedValueFromJson(const base::Value* value_in, const PropType* type, - native_types::Object* value_out, + ValueMap* value_out, chromeos::ErrorPtr* error); bool TypedValueFromJson(const base::Value* value_in, const PropType* type, - native_types::Array* value_out, + ValueVector* value_out, chromeos::ErrorPtr* error); -bool operator==(const native_types::Object& obj1, - const native_types::Object& obj2); -bool operator==(const native_types::Array& arr1, - const native_types::Array& arr2); +bool operator==(const ValueMap& obj1, const ValueMap& obj2); +bool operator==(const ValueVector& arr1, const ValueVector& arr2); // CompareValue is a helper function to help with implementing EqualsTo operator // for various data types. For most scalar types it is using operator==(), @@ -139,16 +136,15 @@ } // Converts PropValue to Any in a format understood by D-Bus data serialization. -// Has special handling for Object types where native_types::Object are +// Has special handling for Object types where ValueMap are // converted to chromeos::VariantDictionary. chromeos::Any PropValueToDBusVariant(const PropValue* value); -// Converts native_types::Object to chromeos::VariantDictionary +// Converts ValueMap to chromeos::VariantDictionary // with proper conversion of all nested properties. -chromeos::VariantDictionary ObjectToDBusVariant( - const native_types::Object& object); +chromeos::VariantDictionary ObjectToDBusVariant(const ValueMap& object); // Converts D-Bus variant to PropValue. // Has special handling for Object types where chromeos::VariantDictionary -// is converted to native_types::Object. +// is converted to ValueMap. std::unique_ptr<const PropValue> PropValueFromDBusVariant( const PropType* type, const chromeos::Any& value, @@ -156,7 +152,7 @@ // Converts D-Bus variant to ObjectValue. bool ObjectFromDBusVariant(const ObjectSchema* object_schema, const chromeos::VariantDictionary& dict, - native_types::Object* obj, + ValueMap* obj, chromeos::ErrorPtr* error); } // namespace weave
diff --git a/libweave/src/commands/schema_utils_unittest.cc b/libweave/src/commands/schema_utils_unittest.cc index 6fd5e0f..22e15c7 100644 --- a/libweave/src/commands/schema_utils_unittest.cc +++ b/libweave/src/commands/schema_utils_unittest.cc
@@ -52,7 +52,7 @@ TEST(CommandSchemaUtils, TypedValueToJson_Object) { IntPropType int_type; - native_types::Object object; + ValueMap object; object.insert(std::make_pair("width", int_type.CreateValue(640, nullptr))); object.insert(std::make_pair("height", int_type.CreateValue(480, nullptr))); @@ -62,7 +62,7 @@ TEST(CommandSchemaUtils, TypedValueToJson_Array) { IntPropType int_type; - native_types::Array arr; + ValueVector arr; arr.push_back(int_type.CreateValue(640, nullptr)); arr.push_back(int_type.CreateValue(480, nullptr)); @@ -160,7 +160,7 @@ } TEST(CommandSchemaUtils, TypedValueFromJson_Object) { - native_types::Object value; + ValueMap value; std::unique_ptr<ObjectSchema> schema{new ObjectSchema}; IntPropType age_prop; @@ -175,7 +175,7 @@ type.SetObjectSchema(std::move(schema)); EXPECT_TRUE(TypedValueFromJson(CreateValue("{'age':20,'name':'Bob'}").get(), &type, &value, nullptr)); - native_types::Object value2; + ValueMap value2; value2.insert(std::make_pair("age", age_prop.CreateValue(20, nullptr))); value2.insert(std::make_pair( "name", name_prop.CreateValue(std::string("Bob"), nullptr))); @@ -189,7 +189,7 @@ } TEST(CommandSchemaUtils, TypedValueFromJson_Array) { - native_types::Array arr; + ValueVector arr; StringPropType str_type; str_type.AddLengthConstraint(3, 100); ArrayPropType type; @@ -197,7 +197,7 @@ EXPECT_TRUE(TypedValueFromJson(CreateValue("['foo', 'bar']").get(), &type, &arr, nullptr)); - native_types::Array arr2; + ValueVector arr2; arr2.push_back(str_type.CreateValue(std::string{"foo"}, nullptr)); arr2.push_back(str_type.CreateValue(std::string{"bar"}, nullptr)); EXPECT_EQ(arr2, arr); @@ -233,7 +233,7 @@ "'enum':[{'width':10,'height':20},{'width':100,'height':200}]}") .get(), nullptr, nullptr)); - native_types::Object obj{ + ValueMap obj{ {"width", int_type.CreateValue(10, nullptr)}, {"height", int_type.CreateValue(20, nullptr)}, }; @@ -245,7 +245,7 @@ ArrayPropType arr_type; arr_type.SetItemType(str_type.Clone()); - native_types::Array arr; + ValueVector arr; arr.push_back(str_type.CreateValue(std::string{"foo"}, nullptr)); arr.push_back(str_type.CreateValue(std::string{"bar"}, nullptr)); arr.push_back(str_type.CreateValue(std::string{"baz"}, nullptr)); @@ -335,7 +335,7 @@ }; auto prop_value = PropValueFromDBusVariant(&obj_type, obj, nullptr); ASSERT_NE(nullptr, prop_value.get()); - auto value = prop_value->GetValueAsAny().Get<native_types::Object>(); + auto value = prop_value->GetValueAsAny().Get<ValueMap>(); EXPECT_EQ(100, value["width"].get()->GetValueAsAny().Get<int>()); EXPECT_EQ(200, value["height"].get()->GetValueAsAny().Get<int>()); @@ -355,7 +355,7 @@ std::vector<int> data{0, 1, 1, 100}; auto prop_value = PropValueFromDBusVariant(&arr_type, data, nullptr); ASSERT_NE(nullptr, prop_value.get()); - auto arr = prop_value->GetValueAsAny().Get<native_types::Array>(); + auto arr = prop_value->GetValueAsAny().Get<ValueVector>(); ASSERT_EQ(4u, arr.size()); EXPECT_EQ(0, arr[0]->GetInt()->GetValue()); EXPECT_EQ(1, arr[1]->GetInt()->GetValue());
diff --git a/libweave/src/device_registration_info_unittest.cc b/libweave/src/device_registration_info_unittest.cc index b41e182..9ef7731 100644 --- a/libweave/src/device_registration_info_unittest.cc +++ b/libweave/src/device_registration_info_unittest.cc
@@ -544,7 +544,7 @@ auto command = command_manager_->FindCommand("1234"); ASSERT_NE(nullptr, command); StringPropType string_type; - native_types::Object results{ + ValueMap results{ {"status", string_type.CreateValue(std::string{"Ok"}, nullptr)}}; // UpdateCommand when setting command results. @@ -579,8 +579,7 @@ transport_->AddHandler(command_url, chromeos::http::request_type::kPatch, base::Bind(update_command_progress)); - native_types::Object progress{ - {"progress", unittests::make_int_prop_value(18)}}; + ValueMap progress{{"progress", unittests::make_int_prop_value(18)}}; command->SetProgress(progress); // UpdateCommand when changing command status.
diff --git a/libweave/src/states/mock_state_change_queue_interface.h b/libweave/src/states/mock_state_change_queue_interface.h index b4e6257..fb02347 100644 --- a/libweave/src/states/mock_state_change_queue_interface.h +++ b/libweave/src/states/mock_state_change_queue_interface.h
@@ -17,8 +17,7 @@ public: MOCK_CONST_METHOD0(IsEmpty, bool()); MOCK_METHOD2(NotifyPropertiesUpdated, - bool(base::Time timestamp, - native_types::Object changed_properties)); + bool(base::Time timestamp, ValueMap changed_properties)); MOCK_METHOD0(GetAndClearRecordedStateChanges, std::vector<StateChange>()); MOCK_CONST_METHOD0(GetLastStateChangeId, UpdateID()); MOCK_METHOD1(MockAddOnStateUpdatedCallback,
diff --git a/libweave/src/states/state_change_queue.cc b/libweave/src/states/state_change_queue.cc index a9ae497..fbce5d8 100644 --- a/libweave/src/states/state_change_queue.cc +++ b/libweave/src/states/state_change_queue.cc
@@ -13,9 +13,8 @@ CHECK_GT(max_queue_size_, 0U) << "Max queue size must not be zero"; } -bool StateChangeQueue::NotifyPropertiesUpdated( - base::Time timestamp, - native_types::Object changed_properties) { +bool StateChangeQueue::NotifyPropertiesUpdated(base::Time timestamp, + ValueMap changed_properties) { DCHECK(thread_checker_.CalledOnValidThread()); auto it = state_changes_.lower_bound(timestamp); if (it == state_changes_.end() || it->first != timestamp) {
diff --git a/libweave/src/states/state_change_queue.h b/libweave/src/states/state_change_queue.h index 877db73..436f454 100644 --- a/libweave/src/states/state_change_queue.h +++ b/libweave/src/states/state_change_queue.h
@@ -22,9 +22,8 @@ // Overrides from StateChangeQueueInterface. bool IsEmpty() const override { return state_changes_.empty(); } - bool NotifyPropertiesUpdated( - base::Time timestamp, - native_types::Object changed_properties) override; + bool NotifyPropertiesUpdated(base::Time timestamp, + ValueMap changed_properties) override; std::vector<StateChange> GetAndClearRecordedStateChanges() override; UpdateID GetLastStateChangeId() const override { return last_change_id_; } Token AddOnStateUpdatedCallback( @@ -42,7 +41,7 @@ const size_t max_queue_size_; // Accumulated list of device state change notifications. - std::map<base::Time, native_types::Object> state_changes_; + std::map<base::Time, ValueMap> state_changes_; // An ID of last state change update. Each NotifyPropertiesUpdated() // invocation increments this value by 1.
diff --git a/libweave/src/states/state_change_queue_interface.h b/libweave/src/states/state_change_queue_interface.h index 8e67baa..f92c690 100644 --- a/libweave/src/states/state_change_queue_interface.h +++ b/libweave/src/states/state_change_queue_interface.h
@@ -20,10 +20,10 @@ // |changed_properties| contains a property set with the new property values // which were updated at the time the event was recorded. struct StateChange { - StateChange(base::Time time, native_types::Object properties) + StateChange(base::Time time, ValueMap properties) : timestamp{time}, changed_properties{std::move(properties)} {} base::Time timestamp; - native_types::Object changed_properties; + ValueMap changed_properties; }; // An abstract interface to StateChangeQueue to record and retrieve state @@ -38,9 +38,8 @@ virtual bool IsEmpty() const = 0; // Called by StateManager when device state properties are updated. - virtual bool NotifyPropertiesUpdated( - base::Time timestamp, - native_types::Object changed_properties) = 0; + virtual bool NotifyPropertiesUpdated(base::Time timestamp, + ValueMap changed_properties) = 0; // Returns the recorded state changes since last time this method was called. virtual std::vector<StateChange> GetAndClearRecordedStateChanges() = 0;
diff --git a/libweave/src/states/state_change_queue_unittest.cc b/libweave/src/states/state_change_queue_unittest.cc index 5877eeb..7c8d19b 100644 --- a/libweave/src/states/state_change_queue_unittest.cc +++ b/libweave/src/states/state_change_queue_unittest.cc
@@ -29,7 +29,7 @@ TEST_F(StateChangeQueueTest, UpdateOne) { StateChange change{ base::Time::Now(), - native_types::Object{{"prop.name", unittests::make_int_prop_value(23)}}}; + ValueMap{{"prop.name", unittests::make_int_prop_value(23)}}}; ASSERT_TRUE(queue_->NotifyPropertiesUpdated(change.timestamp, change.changed_properties)); EXPECT_FALSE(queue_->IsEmpty()); @@ -46,12 +46,12 @@ TEST_F(StateChangeQueueTest, UpdateMany) { StateChange change1{ base::Time::Now(), - native_types::Object{{"prop.name1", unittests::make_int_prop_value(23)}}}; + ValueMap{{"prop.name1", unittests::make_int_prop_value(23)}}}; ASSERT_TRUE(queue_->NotifyPropertiesUpdated(change1.timestamp, change1.changed_properties)); StateChange change2{ base::Time::Now(), - native_types::Object{ + ValueMap{ {"prop.name1", unittests::make_int_prop_value(17)}, {"prop.name2", unittests::make_double_prop_value(1.0)}, {"prop.name3", unittests::make_bool_prop_value(false)}, @@ -75,30 +75,27 @@ base::TimeDelta time_delta = base::TimeDelta::FromMinutes(1); ASSERT_TRUE(queue_->NotifyPropertiesUpdated( - timestamp, - native_types::Object{{"prop.name1", unittests::make_int_prop_value(1)}})); + timestamp, ValueMap{{"prop.name1", unittests::make_int_prop_value(1)}})); ASSERT_TRUE(queue_->NotifyPropertiesUpdated( - timestamp, - native_types::Object{{"prop.name2", unittests::make_int_prop_value(2)}})); + timestamp, ValueMap{{"prop.name2", unittests::make_int_prop_value(2)}})); ASSERT_TRUE(queue_->NotifyPropertiesUpdated( - timestamp, - native_types::Object{{"prop.name1", unittests::make_int_prop_value(3)}})); + timestamp, ValueMap{{"prop.name1", unittests::make_int_prop_value(3)}})); ASSERT_TRUE(queue_->NotifyPropertiesUpdated( timestamp + time_delta, - native_types::Object{{"prop.name1", unittests::make_int_prop_value(4)}})); + ValueMap{{"prop.name1", unittests::make_int_prop_value(4)}})); auto changes = queue_->GetAndClearRecordedStateChanges(); EXPECT_EQ(4, queue_->GetLastStateChangeId()); ASSERT_EQ(2, changes.size()); - native_types::Object expected1{ + ValueMap expected1{ {"prop.name1", unittests::make_int_prop_value(3)}, {"prop.name2", unittests::make_int_prop_value(2)}, }; - native_types::Object expected2{ + ValueMap expected2{ {"prop.name1", unittests::make_int_prop_value(4)}, }; EXPECT_EQ(timestamp, changes[0].timestamp); @@ -114,21 +111,21 @@ base::TimeDelta time_delta2 = base::TimeDelta::FromMinutes(3); ASSERT_TRUE(queue_->NotifyPropertiesUpdated( - start_time, native_types::Object{ + start_time, ValueMap{ {"prop.name1", unittests::make_int_prop_value(1)}, {"prop.name2", unittests::make_int_prop_value(2)}, })); ASSERT_TRUE(queue_->NotifyPropertiesUpdated( start_time + time_delta1, - native_types::Object{ + ValueMap{ {"prop.name1", unittests::make_int_prop_value(3)}, {"prop.name3", unittests::make_int_prop_value(4)}, })); ASSERT_TRUE(queue_->NotifyPropertiesUpdated( start_time + time_delta2, - native_types::Object{ + ValueMap{ {"prop.name10", unittests::make_int_prop_value(10)}, {"prop.name11", unittests::make_int_prop_value(11)}, })); @@ -137,7 +134,7 @@ auto changes = queue_->GetAndClearRecordedStateChanges(); ASSERT_EQ(2, changes.size()); - native_types::Object expected1{ + ValueMap expected1{ {"prop.name1", unittests::make_int_prop_value(3)}, {"prop.name2", unittests::make_int_prop_value(2)}, {"prop.name3", unittests::make_int_prop_value(4)}, @@ -145,7 +142,7 @@ EXPECT_EQ(start_time + time_delta1, changes[0].timestamp); EXPECT_EQ(expected1, changes[0].changed_properties); - native_types::Object expected2{ + ValueMap expected2{ {"prop.name10", unittests::make_int_prop_value(10)}, {"prop.name11", unittests::make_int_prop_value(11)}, }; @@ -166,7 +163,7 @@ TEST_F(StateChangeQueueTest, DelayedStateChangeNotification) { // When queue is not empty, registering a new callback will not trigger it. ASSERT_TRUE(queue_->NotifyPropertiesUpdated( - base::Time::Now(), native_types::Object{ + base::Time::Now(), ValueMap{ {"prop.name1", unittests::make_int_prop_value(1)}, {"prop.name2", unittests::make_int_prop_value(2)}, }));
diff --git a/libweave/src/states/state_manager.cc b/libweave/src/states/state_manager.cc index d694464..158d79c 100644 --- a/libweave/src/states/state_manager.cc +++ b/libweave/src/states/state_manager.cc
@@ -159,8 +159,7 @@ if (!package->SetPropertyValue(property_name, value, error)) return false; - native_types::Object prop_set{ - {full_property_name, package->GetProperty(property_name)}}; + ValueMap prop_set{{full_property_name, package->GetProperty(property_name)}}; state_change_queue_->NotifyPropertiesUpdated(timestamp, prop_set); return true; }
diff --git a/libweave/src/states/state_manager_unittest.cc b/libweave/src/states/state_manager_unittest.cc index 6f39dfe..60eafcd 100644 --- a/libweave/src/states/state_manager_unittest.cc +++ b/libweave/src/states/state_manager_unittest.cc
@@ -132,7 +132,7 @@ } TEST_F(StateManagerTest, SetPropertyValue) { - native_types::Object expected_prop_set{ + ValueMap expected_prop_set{ {"terminator.target", unittests::make_string_prop_value("John Connor")}, }; EXPECT_CALL(mock_state_change_queue_, @@ -192,8 +192,7 @@ nullptr)); std::vector<StateChange> expected_val; expected_val.emplace_back( - timestamp_, - native_types::Object{{"terminator.target", + timestamp_, ValueMap{{"terminator.target", unittests::make_string_prop_value("John Connor")}}); EXPECT_CALL(mock_state_change_queue_, GetAndClearRecordedStateChanges()) .WillOnce(Return(expected_val)); @@ -205,7 +204,7 @@ } TEST_F(StateManagerTest, SetProperties) { - native_types::Object expected_prop_set{ + ValueMap expected_prop_set{ {"base.manufacturer", unittests::make_string_prop_value("No Name")}, }; EXPECT_CALL(mock_state_change_queue_,
diff --git a/libweave/src/states/state_package.h b/libweave/src/states/state_package.h index 19b0c0f..e4e9942 100644 --- a/libweave/src/states/state_package.h +++ b/libweave/src/states/state_package.h
@@ -78,7 +78,7 @@ private: std::string name_; ObjectSchema types_; - native_types::Object values_; + ValueMap values_; friend class StatePackageTestHelper; DISALLOW_COPY_AND_ASSIGN(StatePackage);
diff --git a/libweave/src/states/state_package_unittest.cc b/libweave/src/states/state_package_unittest.cc index 1479f79..6d14731 100644 --- a/libweave/src/states/state_package_unittest.cc +++ b/libweave/src/states/state_package_unittest.cc
@@ -26,7 +26,7 @@ return package.types_; } // Returns the all state property values in this package. - static const native_types::Object& GetValues(const StatePackage& package) { + static const ValueMap& GetValues(const StatePackage& package) { return package.values_; } }; @@ -54,7 +54,7 @@ return StatePackageTestHelper::GetTypes(package); } // Returns the all state property values in this package. -inline const native_types::Object& GetValues(const StatePackage& package) { +inline const ValueMap& GetValues(const StatePackage& package) { return StatePackageTestHelper::GetValues(package); }