OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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. |
| 4 |
| 5 #include "components/arc/bluetooth/bluetooth_struct_traits.h" |
| 6 |
| 7 #include <memory> |
| 8 #include <utility> |
| 9 |
| 10 namespace mojo { |
| 11 |
| 12 // static |
| 13 arc::mojom::BluetoothSdpAttrType |
| 14 EnumTraits<arc::mojom::BluetoothSdpAttrType, |
| 15 bluez::BluetoothServiceAttributeValueBlueZ::Type>:: |
| 16 ToMojom(bluez::BluetoothServiceAttributeValueBlueZ::Type input) { |
| 17 switch (input) { |
| 18 case bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE: |
| 19 case bluez::BluetoothServiceAttributeValueBlueZ::UINT: |
| 20 case bluez::BluetoothServiceAttributeValueBlueZ::INT: |
| 21 case bluez::BluetoothServiceAttributeValueBlueZ::UUID: |
| 22 case bluez::BluetoothServiceAttributeValueBlueZ::STRING: |
| 23 case bluez::BluetoothServiceAttributeValueBlueZ::BOOL: |
| 24 case bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE: |
| 25 case bluez::BluetoothServiceAttributeValueBlueZ::URL: |
| 26 return static_cast<arc::mojom::BluetoothSdpAttrType>(input); |
| 27 default: |
| 28 NOTREACHED() << "Invalid type: " << static_cast<uint32_t>(input); |
| 29 return arc::mojom::BluetoothSdpAttrType::NULLTYPE; |
| 30 } |
| 31 } |
| 32 |
| 33 // static |
| 34 bool EnumTraits<arc::mojom::BluetoothSdpAttrType, |
| 35 bluez::BluetoothServiceAttributeValueBlueZ::Type>:: |
| 36 FromMojom(arc::mojom::BluetoothSdpAttrType input, |
| 37 bluez::BluetoothServiceAttributeValueBlueZ::Type* output) { |
| 38 switch (input) { |
| 39 case arc::mojom::BluetoothSdpAttrType::NULLTYPE: |
| 40 case arc::mojom::BluetoothSdpAttrType::UINT: |
| 41 case arc::mojom::BluetoothSdpAttrType::INT: |
| 42 case arc::mojom::BluetoothSdpAttrType::UUID: |
| 43 case arc::mojom::BluetoothSdpAttrType::STRING: |
| 44 case arc::mojom::BluetoothSdpAttrType::BOOL: |
| 45 case arc::mojom::BluetoothSdpAttrType::SEQUENCE: |
| 46 case arc::mojom::BluetoothSdpAttrType::URL: |
| 47 *output = |
| 48 static_cast<bluez::BluetoothServiceAttributeValueBlueZ::Type>(input); |
| 49 return true; |
| 50 default: |
| 51 NOTREACHED() << "Invalid type: " << static_cast<uint32_t>(input); |
| 52 return false; |
| 53 } |
| 54 } |
| 55 |
| 56 // static |
| 57 bool StructTraits<arc::mojom::BluetoothSdpServiceAttr, |
| 58 bluez::BluetoothServiceAttributeValueBlueZ>:: |
| 59 Read(arc::mojom::BluetoothSdpServiceAttrDataView data, |
| 60 bluez::BluetoothServiceAttributeValueBlueZ* output) { |
| 61 bluez::BluetoothServiceAttributeValueBlueZ::Type type; |
| 62 if (!data.ReadType(&type)) |
| 63 return false; |
| 64 |
| 65 switch (type) { |
| 66 case bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE: |
| 67 case bluez::BluetoothServiceAttributeValueBlueZ::UINT: |
| 68 case bluez::BluetoothServiceAttributeValueBlueZ::INT: |
| 69 case bluez::BluetoothServiceAttributeValueBlueZ::UUID: |
| 70 case bluez::BluetoothServiceAttributeValueBlueZ::STRING: |
| 71 case bluez::BluetoothServiceAttributeValueBlueZ::URL: |
| 72 case bluez::BluetoothServiceAttributeValueBlueZ::BOOL: { |
| 73 base::ListValue list_value; |
| 74 if (!data.ReadValue(&list_value) || list_value.GetSize() != 1) |
| 75 return false; |
| 76 |
| 77 size_t size = static_cast<size_t>(data.type_size()); |
| 78 base::Value* value = nullptr; |
| 79 list_value.Get(0, &value); |
| 80 |
| 81 *output = bluez::BluetoothServiceAttributeValueBlueZ( |
| 82 type, size, value->CreateDeepCopy()); |
| 83 break; |
| 84 } |
| 85 case bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE: { |
| 86 std::unique_ptr<bluez::BluetoothServiceAttributeValueBlueZ::Sequence> |
| 87 sequence(new bluez::BluetoothServiceAttributeValueBlueZ::Sequence()); |
| 88 if (!data.ReadSequence(sequence.get()) || sequence->empty()) |
| 89 return false; |
| 90 *output = bluez::BluetoothServiceAttributeValueBlueZ(std::move(sequence)); |
| 91 break; |
| 92 } |
| 93 default: |
| 94 return false; |
| 95 } |
| 96 return true; |
| 97 } |
| 98 |
| 99 // static |
| 100 bool StructTraits<arc::mojom::BluetoothSdpRecord, |
| 101 bluez::BluetoothServiceRecordBlueZ>:: |
| 102 Read(arc::mojom::BluetoothSdpRecordDataView data, |
| 103 bluez::BluetoothServiceRecordBlueZ* output) { |
| 104 std::map<uint16_t, bluez::BluetoothServiceAttributeValueBlueZ> attributes; |
| 105 if (!data.ReadAttrs(&attributes) || attributes.empty()) |
| 106 return false; |
| 107 |
| 108 for (auto& it : attributes) |
| 109 output->AddRecordEntry(it.first, it.second); |
| 110 |
| 111 return true; |
| 112 } |
| 113 |
| 114 } // namespace mojo |
OLD | NEW |