Chromium Code Reviews| 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 #ifndef BluetoothAttributeInstanceMap_h | 5 #ifndef BluetoothAttributeInstanceMap_h |
| 6 #define BluetoothAttributeInstanceMap_h | 6 #define BluetoothAttributeInstanceMap_h |
| 7 | 7 |
| 8 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" | 8 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" |
| 9 #include "modules/bluetooth/BluetoothRemoteGATTService.h" | 9 #include "modules/bluetooth/BluetoothRemoteGATTService.h" |
| 10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| 11 #include "platform/heap/Heap.h" | 11 #include "platform/heap/Heap.h" |
| 12 #include <memory> | 12 #include <memory> |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 class BluetoothDevice; | 16 class BluetoothDevice; |
| 17 class ExecutionContext; | 17 class ExecutionContext; |
| 18 | 18 |
| 19 struct WebBluetoothRemoteGATTCharacteristicInit; | |
| 20 struct WebBluetoothRemoteGATTService; | |
| 21 | |
| 22 // Map that holds all GATT attributes, i.e. BluetoothRemoteGATTService, | 19 // Map that holds all GATT attributes, i.e. BluetoothRemoteGATTService, |
| 23 // BluetoothRemoteGATTCharacteristic, BluetoothRemoteGATTDescriptor, for | 20 // BluetoothRemoteGATTCharacteristic, BluetoothRemoteGATTDescriptor, for |
| 24 // the BluetoothDevice passed in when constructing the object. | 21 // the BluetoothDevice passed in when constructing the object. |
| 25 // Methods in this map are used to create or retrieve these attributes. | 22 // Methods in this map are used to create or retrieve these attributes. |
| 26 class BluetoothAttributeInstanceMap final | 23 class BluetoothAttributeInstanceMap final |
| 27 : public GarbageCollected<BluetoothAttributeInstanceMap> { | 24 : public GarbageCollected<BluetoothAttributeInstanceMap> { |
| 28 public: | 25 public: |
| 29 BluetoothAttributeInstanceMap(BluetoothDevice*); | 26 BluetoothAttributeInstanceMap(BluetoothDevice*); |
| 30 | 27 |
| 31 // Constructs a new BluetoothRemoteGATTService object if there was | 28 // Constructs a new BluetoothRemoteGATTService object if there was |
| 32 // no service with the same instance id and adds it to the map. | 29 // no service with the same instance id and adds it to the map. |
| 33 // Otherwise returns the BluetoothRemoteGATTService object already | 30 // Otherwise returns the BluetoothRemoteGATTService object already |
| 34 // in the map. | 31 // in the map. |
| 35 BluetoothRemoteGATTService* getOrCreateBluetoothRemoteGATTService( | 32 BluetoothRemoteGATTService* getOrCreateBluetoothRemoteGATTService( |
| 36 std::unique_ptr<WebBluetoothRemoteGATTService>); | 33 const String& serviceInstanceId, |
| 34 const String& uuid, | |
| 35 bool isPrimary, | |
| 36 const String& deviceInstanceId); | |
|
dougt
2016/12/16 00:11:44
I think you can drop the parameter names here. (se
Reilly Grant (use Gerrit)
2016/12/16 01:41:29
I'd prefer we leave the parameter names when they'
| |
| 37 | 37 |
| 38 // Returns true if a BluetoothRemoteGATTService with |serviceInstanceId| | 38 // Returns true if a BluetoothRemoteGATTService with |serviceInstanceId| |
| 39 // is in the map. | 39 // is in the map. |
| 40 bool containsService(const String& serviceInstanceId); | 40 bool containsService(const String& serviceInstanceId); |
| 41 | 41 |
| 42 // Constructs a new BluetoothRemoteGATTCharacteristic object if there was no | 42 // Constructs a new BluetoothRemoteGATTCharacteristic object if there was no |
| 43 // characteristic with the same instance id and adds it to the map. | 43 // characteristic with the same instance id and adds it to the map. |
| 44 // Otherwise returns the BluetoothRemoteGATTCharacteristic object already in | 44 // Otherwise returns the BluetoothRemoteGATTCharacteristic object already in |
| 45 // the map. | 45 // the map. |
| 46 BluetoothRemoteGATTCharacteristic* | 46 BluetoothRemoteGATTCharacteristic* |
| 47 getOrCreateBluetoothRemoteGATTCharacteristic( | 47 getOrCreateBluetoothRemoteGATTCharacteristic( |
| 48 ExecutionContext*, | 48 ExecutionContext*, |
| 49 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit>, | 49 const String& characteristicInstanceId, |
| 50 const String& serviceInstanceId, | |
| 51 const String& uuid, | |
| 52 uint32_t characteristicProperties, | |
| 50 BluetoothRemoteGATTService*); | 53 BluetoothRemoteGATTService*); |
|
dougt
2016/12/16 00:11:44
same.
juncai
2016/12/17 01:18:52
Based on reillyg@'s comment, keep the parameter na
| |
| 51 | 54 |
| 52 // Returns true if a BluetoothRemoteGATTCharacteristic with | 55 // Returns true if a BluetoothRemoteGATTCharacteristic with |
| 53 // |characteristicInstanceId| is in the map. | 56 // |characteristicInstanceId| is in the map. |
| 54 bool containsCharacteristic(const String& characteristicInstanceId); | 57 bool containsCharacteristic(const String& characteristicInstanceId); |
| 55 | 58 |
| 56 // Removes all Attributes from the map. | 59 // Removes all Attributes from the map. |
| 57 // TODO(crbug.com/654950): Remove descriptors when implemented. | 60 // TODO(crbug.com/654950): Remove descriptors when implemented. |
| 58 void Clear(); | 61 void Clear(); |
| 59 | 62 |
| 60 DECLARE_VIRTUAL_TRACE(); | 63 DECLARE_VIRTUAL_TRACE(); |
| 61 | 64 |
| 62 private: | 65 private: |
| 63 // BluetoothDevice that owns this map. | 66 // BluetoothDevice that owns this map. |
| 64 Member<BluetoothDevice> m_device; | 67 Member<BluetoothDevice> m_device; |
| 65 // Map of service instance ids to objects. | 68 // Map of service instance ids to objects. |
| 66 HeapHashMap<String, Member<BluetoothRemoteGATTService>> m_serviceIdToObject; | 69 HeapHashMap<String, Member<BluetoothRemoteGATTService>> m_serviceIdToObject; |
| 67 // Map of characteristic instance ids to objects. | 70 // Map of characteristic instance ids to objects. |
| 68 HeapHashMap<String, Member<BluetoothRemoteGATTCharacteristic>> | 71 HeapHashMap<String, Member<BluetoothRemoteGATTCharacteristic>> |
| 69 m_characteristicIdToObject; | 72 m_characteristicIdToObject; |
| 70 }; | 73 }; |
| 71 | 74 |
| 72 } // namespace blink | 75 } // namespace blink |
| 73 | 76 |
| 74 #endif // BluetoothAttributeInstanceMap_h | 77 #endif // BluetoothAttributeInstanceMap_h |
| OLD | NEW |