OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/bluetooth/BluetoothAttributeInstanceMap.h" | 5 #include "modules/bluetooth/BluetoothAttributeInstanceMap.h" |
6 | 6 |
7 #include "modules/bluetooth/BluetoothDevice.h" | 7 #include "modules/bluetooth/BluetoothDevice.h" |
8 #include "modules/bluetooth/BluetoothRemoteGATTService.h" | 8 #include "modules/bluetooth/BluetoothRemoteGATTService.h" |
9 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristic
Init.h" | 9 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristic
Init.h" |
| 10 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTDescriptorInit
.h" |
| 11 |
10 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTService.h" | 12 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTService.h" |
11 #include <memory> | 13 #include <memory> |
12 #include <utility> | 14 #include <utility> |
13 | 15 |
14 namespace blink { | 16 namespace blink { |
15 | 17 |
16 BluetoothAttributeInstanceMap::BluetoothAttributeInstanceMap( | 18 BluetoothAttributeInstanceMap::BluetoothAttributeInstanceMap( |
17 BluetoothDevice* device) | 19 BluetoothDevice* device) |
18 : m_device(device) {} | 20 : m_device(device) {} |
19 | 21 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 58 } |
57 | 59 |
58 return characteristic; | 60 return characteristic; |
59 } | 61 } |
60 | 62 |
61 bool BluetoothAttributeInstanceMap::containsCharacteristic( | 63 bool BluetoothAttributeInstanceMap::containsCharacteristic( |
62 const String& characteristicInstanceId) { | 64 const String& characteristicInstanceId) { |
63 return m_characteristicIdToObject.contains(characteristicInstanceId); | 65 return m_characteristicIdToObject.contains(characteristicInstanceId); |
64 } | 66 } |
65 | 67 |
| 68 BluetoothRemoteGATTDescriptor* |
| 69 BluetoothAttributeInstanceMap::getOrCreateBluetoothRemoteGATTDescriptor( |
| 70 std::unique_ptr<WebBluetoothRemoteGATTDescriptorInit> webDescriptor, |
| 71 BluetoothRemoteGATTCharacteristic* characteristic) { |
| 72 String descriptorInstanceId = webDescriptor->descriptorInstanceID; |
| 73 |
| 74 BluetoothRemoteGATTDescriptor* descriptor = |
| 75 m_descriptorIdToObject.get(descriptorInstanceId); |
| 76 |
| 77 if (!descriptor) { |
| 78 descriptor = BluetoothRemoteGATTDescriptor::create(std::move(webDescriptor), |
| 79 characteristic); |
| 80 m_descriptorIdToObject.add(descriptorInstanceId, descriptor); |
| 81 } |
| 82 |
| 83 return descriptor; |
| 84 } |
| 85 |
| 86 bool BluetoothAttributeInstanceMap::containsDescriptor( |
| 87 const String& descriptorInstanceId) { |
| 88 return m_descriptorIdToObject.contains(descriptorInstanceId); |
| 89 } |
| 90 |
66 void BluetoothAttributeInstanceMap::Clear() { | 91 void BluetoothAttributeInstanceMap::Clear() { |
67 m_serviceIdToObject.clear(); | 92 m_serviceIdToObject.clear(); |
68 m_characteristicIdToObject.clear(); | 93 m_characteristicIdToObject.clear(); |
| 94 m_descriptorIdToObject.clear(); |
69 } | 95 } |
70 | 96 |
71 DEFINE_TRACE(BluetoothAttributeInstanceMap) { | 97 DEFINE_TRACE(BluetoothAttributeInstanceMap) { |
72 visitor->trace(m_device); | 98 visitor->trace(m_device); |
73 visitor->trace(m_serviceIdToObject); | 99 visitor->trace(m_serviceIdToObject); |
74 visitor->trace(m_characteristicIdToObject); | 100 visitor->trace(m_characteristicIdToObject); |
| 101 visitor->trace(m_descriptorIdToObject); |
75 } | 102 } |
76 | 103 |
77 } // namespace blink | 104 } // namespace blink |
OLD | NEW |