| 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" | |
| 10 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTService.h" | |
| 11 #include <memory> | 9 #include <memory> |
| 12 #include <utility> | 10 #include <utility> |
| 13 | 11 |
| 14 namespace blink { | 12 namespace blink { |
| 15 | 13 |
| 16 BluetoothAttributeInstanceMap::BluetoothAttributeInstanceMap( | 14 BluetoothAttributeInstanceMap::BluetoothAttributeInstanceMap( |
| 17 BluetoothDevice* device) | 15 BluetoothDevice* device) |
| 18 : m_device(device) {} | 16 : m_device(device) {} |
| 19 | 17 |
| 20 BluetoothRemoteGATTService* | 18 BluetoothRemoteGATTService* |
| 21 BluetoothAttributeInstanceMap::getOrCreateBluetoothRemoteGATTService( | 19 BluetoothAttributeInstanceMap::getOrCreateBluetoothRemoteGATTService( |
| 22 std::unique_ptr<WebBluetoothRemoteGATTService> webService) { | 20 const String& serviceInstanceId, |
| 23 String serviceInstanceId = webService->serviceInstanceID; | 21 const String& uuid, |
| 24 | 22 bool isPrimary, |
| 23 const String& deviceInstanceId) { |
| 25 BluetoothRemoteGATTService* service = | 24 BluetoothRemoteGATTService* service = |
| 26 m_serviceIdToObject.get(serviceInstanceId); | 25 m_serviceIdToObject.get(serviceInstanceId); |
| 27 | 26 |
| 28 if (!service) { | 27 if (!service) { |
| 29 service = | 28 service = new BluetoothRemoteGATTService(serviceInstanceId, uuid, isPrimary, |
| 30 new BluetoothRemoteGATTService(std::move(webService), m_device.get()); | 29 deviceInstanceId, m_device); |
| 31 m_serviceIdToObject.add(serviceInstanceId, service); | 30 m_serviceIdToObject.add(serviceInstanceId, service); |
| 32 } | 31 } |
| 33 | 32 |
| 34 return service; | 33 return service; |
| 35 } | 34 } |
| 36 | 35 |
| 37 bool BluetoothAttributeInstanceMap::containsService( | 36 bool BluetoothAttributeInstanceMap::containsService( |
| 38 const String& serviceInstanceId) { | 37 const String& serviceInstanceId) { |
| 39 return m_serviceIdToObject.contains(serviceInstanceId); | 38 return m_serviceIdToObject.contains(serviceInstanceId); |
| 40 } | 39 } |
| 41 | 40 |
| 42 BluetoothRemoteGATTCharacteristic* | 41 BluetoothRemoteGATTCharacteristic* |
| 43 BluetoothAttributeInstanceMap::getOrCreateBluetoothRemoteGATTCharacteristic( | 42 BluetoothAttributeInstanceMap::getOrCreateBluetoothRemoteGATTCharacteristic( |
| 44 ExecutionContext* context, | 43 ExecutionContext* context, |
| 45 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit> webCharacteristic, | 44 const String& characteristicInstanceId, |
| 45 const String& serviceInstanceId, |
| 46 const String& uuid, |
| 47 uint32_t characteristicProperties, |
| 46 BluetoothRemoteGATTService* service) { | 48 BluetoothRemoteGATTService* service) { |
| 47 String characteristicInstanceId = webCharacteristic->characteristicInstanceID; | |
| 48 | |
| 49 BluetoothRemoteGATTCharacteristic* characteristic = | 49 BluetoothRemoteGATTCharacteristic* characteristic = |
| 50 m_characteristicIdToObject.get(characteristicInstanceId); | 50 m_characteristicIdToObject.get(characteristicInstanceId); |
| 51 | 51 |
| 52 if (!characteristic) { | 52 if (!characteristic) { |
| 53 characteristic = BluetoothRemoteGATTCharacteristic::create( | 53 characteristic = BluetoothRemoteGATTCharacteristic::create( |
| 54 context, std::move(webCharacteristic), service); | 54 context, characteristicInstanceId, serviceInstanceId, uuid, |
| 55 characteristicProperties, service, m_device); |
| 55 m_characteristicIdToObject.add(characteristicInstanceId, characteristic); | 56 m_characteristicIdToObject.add(characteristicInstanceId, characteristic); |
| 56 } | 57 } |
| 57 | 58 |
| 58 return characteristic; | 59 return characteristic; |
| 59 } | 60 } |
| 60 | 61 |
| 61 bool BluetoothAttributeInstanceMap::containsCharacteristic( | 62 bool BluetoothAttributeInstanceMap::containsCharacteristic( |
| 62 const String& characteristicInstanceId) { | 63 const String& characteristicInstanceId) { |
| 63 return m_characteristicIdToObject.contains(characteristicInstanceId); | 64 return m_characteristicIdToObject.contains(characteristicInstanceId); |
| 64 } | 65 } |
| 65 | 66 |
| 66 void BluetoothAttributeInstanceMap::Clear() { | 67 void BluetoothAttributeInstanceMap::Clear() { |
| 67 m_serviceIdToObject.clear(); | 68 m_serviceIdToObject.clear(); |
| 68 m_characteristicIdToObject.clear(); | 69 m_characteristicIdToObject.clear(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 DEFINE_TRACE(BluetoothAttributeInstanceMap) { | 72 DEFINE_TRACE(BluetoothAttributeInstanceMap) { |
| 72 visitor->trace(m_device); | 73 visitor->trace(m_device); |
| 73 visitor->trace(m_serviceIdToObject); | 74 visitor->trace(m_serviceIdToObject); |
| 74 visitor->trace(m_characteristicIdToObject); | 75 visitor->trace(m_characteristicIdToObject); |
| 75 } | 76 } |
| 76 | 77 |
| 77 } // namespace blink | 78 } // namespace blink |
| OLD | NEW |