Chromium Code Reviews| Index: components/arc/bluetooth/bluetooth_struct_traits.cc |
| diff --git a/components/arc/bluetooth/bluetooth_struct_traits.cc b/components/arc/bluetooth/bluetooth_struct_traits.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..47397eb5fbacd3e07818857763a90d8176a49aeb |
| --- /dev/null |
| +++ b/components/arc/bluetooth/bluetooth_struct_traits.cc |
| @@ -0,0 +1,114 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/arc/bluetooth/bluetooth_struct_traits.h" |
| + |
| +#include <memory> |
| +#include <utility> |
| + |
| +namespace mojo { |
| + |
| +// static |
| +arc::mojom::BluetoothSdpAttrType |
| +EnumTraits<arc::mojom::BluetoothSdpAttrType, |
| + bluez::BluetoothServiceAttributeValueBlueZ::Type>:: |
| + ToMojom(bluez::BluetoothServiceAttributeValueBlueZ::Type input) { |
| + switch (input) { |
| + case bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE: |
| + case bluez::BluetoothServiceAttributeValueBlueZ::UINT: |
| + case bluez::BluetoothServiceAttributeValueBlueZ::INT: |
| + case bluez::BluetoothServiceAttributeValueBlueZ::UUID: |
| + case bluez::BluetoothServiceAttributeValueBlueZ::STRING: |
| + case bluez::BluetoothServiceAttributeValueBlueZ::BOOL: |
| + case bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE: |
| + case bluez::BluetoothServiceAttributeValueBlueZ::URL: |
| + return static_cast<arc::mojom::BluetoothSdpAttrType>(input); |
| + default: |
| + NOTREACHED() << "Invalid type: " << static_cast<uint32_t>(input); |
| + return arc::mojom::BluetoothSdpAttrType::NULLTYPE; |
| + } |
| +} |
| + |
| +// static |
| +bool EnumTraits<arc::mojom::BluetoothSdpAttrType, |
| + bluez::BluetoothServiceAttributeValueBlueZ::Type>:: |
| + FromMojom(arc::mojom::BluetoothSdpAttrType input, |
| + bluez::BluetoothServiceAttributeValueBlueZ::Type* output) { |
| + switch (input) { |
| + case arc::mojom::BluetoothSdpAttrType::NULLTYPE: |
| + case arc::mojom::BluetoothSdpAttrType::UINT: |
| + case arc::mojom::BluetoothSdpAttrType::INT: |
| + case arc::mojom::BluetoothSdpAttrType::UUID: |
| + case arc::mojom::BluetoothSdpAttrType::STRING: |
| + case arc::mojom::BluetoothSdpAttrType::BOOL: |
| + case arc::mojom::BluetoothSdpAttrType::SEQUENCE: |
| + case arc::mojom::BluetoothSdpAttrType::URL: |
| + *output = |
| + static_cast<bluez::BluetoothServiceAttributeValueBlueZ::Type>(input); |
| + return true; |
| + default: |
| + NOTREACHED() << "Invalid type: " << static_cast<uint32_t>(input); |
| + return false; |
| + } |
| +} |
| + |
| +// static |
| +bool StructTraits<arc::mojom::BluetoothSdpServiceAttr, |
| + bluez::BluetoothServiceAttributeValueBlueZ>:: |
| + Read(arc::mojom::BluetoothSdpServiceAttrDataView data, |
| + bluez::BluetoothServiceAttributeValueBlueZ* output) { |
| + bluez::BluetoothServiceAttributeValueBlueZ::Type type; |
| + if (!data.ReadType(&type)) |
| + return false; |
| + |
| + switch (type) { |
| + case bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE: |
| + case bluez::BluetoothServiceAttributeValueBlueZ::UINT: |
| + case bluez::BluetoothServiceAttributeValueBlueZ::INT: |
| + case bluez::BluetoothServiceAttributeValueBlueZ::UUID: |
| + case bluez::BluetoothServiceAttributeValueBlueZ::STRING: |
| + case bluez::BluetoothServiceAttributeValueBlueZ::URL: |
| + case bluez::BluetoothServiceAttributeValueBlueZ::BOOL: { |
| + base::ListValue list_value; |
| + if (!data.ReadValue(&list_value) || list_value.GetSize() != 1) |
| + return false; |
| + |
| + size_t size = static_cast<size_t>(data.type_size()); |
| + base::Value* value = nullptr; |
| + list_value.Get(0, &value); |
| + |
| + *output = bluez::BluetoothServiceAttributeValueBlueZ( |
| + type, size, value->CreateDeepCopy()); |
| + break; |
| + } |
| + case bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE: { |
| + std::unique_ptr<bluez::BluetoothServiceAttributeValueBlueZ::Sequence> |
| + sequence(new bluez::BluetoothServiceAttributeValueBlueZ::Sequence()); |
| + if (!data.ReadSequence(sequence.get()) || sequence->empty()) |
| + return false; |
| + *output = bluez::BluetoothServiceAttributeValueBlueZ(std::move(sequence)); |
|
puthik_chromium
2016/08/24 00:32:20
When I test this. Chrome crash at this line.
Miao
2016/08/25 16:51:36
I think that is by null field. It should be revolv
|
| + break; |
| + } |
| + default: |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +// static |
| +bool StructTraits<arc::mojom::BluetoothSdpRecord, |
| + bluez::BluetoothServiceRecordBlueZ>:: |
| + Read(arc::mojom::BluetoothSdpRecordDataView data, |
| + bluez::BluetoothServiceRecordBlueZ* output) { |
| + std::map<uint16_t, bluez::BluetoothServiceAttributeValueBlueZ> attributes; |
|
yzshen1
2016/08/22 23:42:14
Performance tip: because |attributes| is not direc
Miao
2016/08/25 16:51:36
Adding a setting function is not a preferable way,
|
| + if (!data.ReadAttrs(&attributes) || attributes.empty()) |
| + return false; |
| + |
| + for (auto& it : attributes) |
| + output->AddRecordEntry(it.first, it.second); |
| + |
| + return true; |
| +} |
| + |
| +} // namespace mojo |