1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/browser/api/bluetooth_low_energy/utils.h"
9 namespace bluetooth_low_energy
{
13 // Converts a list of CharacteristicProperty to a base::ListValue of strings.
14 scoped_ptr
<base::ListValue
> CharacteristicPropertiesToValue(
15 const std::vector
<CharacteristicProperty
> properties
) {
16 scoped_ptr
<base::ListValue
> property_list(new base::ListValue());
17 for (std::vector
<CharacteristicProperty
>::const_iterator iter
=
19 iter
!= properties
.end();
21 property_list
->Append(new base::StringValue(ToString(*iter
)));
22 return property_list
.Pass();
27 scoped_ptr
<base::DictionaryValue
> CharacteristicToValue(Characteristic
* from
) {
28 // Copy the properties. Use Characteristic::ToValue to generate the result
29 // dictionary without the properties, to prevent json_schema_compiler from
31 std::vector
<CharacteristicProperty
> properties
= from
->properties
;
32 from
->properties
.clear();
33 scoped_ptr
<base::DictionaryValue
> to
= from
->ToValue();
34 to
->SetWithoutPathExpansion(
35 "properties", CharacteristicPropertiesToValue(properties
).release());
39 scoped_ptr
<base::DictionaryValue
> DescriptorToValue(Descriptor
* from
) {
40 // Copy the characteristic properties and set them later manually.
41 std::vector
<CharacteristicProperty
> properties
=
42 from
->characteristic
.properties
;
43 from
->characteristic
.properties
.clear();
44 scoped_ptr
<base::DictionaryValue
> to
= from
->ToValue();
46 base::DictionaryValue
* chrc_value
= NULL
;
47 to
->GetDictionaryWithoutPathExpansion("characteristic", &chrc_value
);
49 chrc_value
->SetWithoutPathExpansion(
50 "properties", CharacteristicPropertiesToValue(properties
).release());
54 } // namespace bluetooth_low_energy
55 } // namespace core_api
56 } // namespace extensions