| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 BluetoothRemoteGATTService_h | 5 #ifndef BluetoothRemoteGATTService_h |
| 6 #define BluetoothRemoteGATTService_h | 6 #define BluetoothRemoteGATTService_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptWrappable.h" | 8 #include "bindings/core/v8/ScriptWrappable.h" |
| 9 #include "bindings/modules/v8/StringOrUnsignedLong.h" | 9 #include "bindings/modules/v8/StringOrUnsignedLong.h" |
| 10 #include "modules/bluetooth/BluetoothDevice.h" | 10 #include "modules/bluetooth/BluetoothDevice.h" |
| 11 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
| 12 #include "platform/heap/Heap.h" | 12 #include "platform/heap/Heap.h" |
| 13 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTService.h" | |
| 14 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" | 13 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" |
| 15 #include "wtf/text/WTFString.h" | 14 #include "wtf/text/WTFString.h" |
| 16 #include <memory> | 15 #include <memory> |
| 17 | 16 |
| 18 namespace blink { | 17 namespace blink { |
| 19 | 18 |
| 20 class ScriptPromise; | 19 class ScriptPromise; |
| 21 class ScriptState; | 20 class ScriptState; |
| 22 | 21 |
| 23 // Represents a GATT Service within a Bluetooth Peripheral, a collection of | 22 // Represents a GATT Service within a Bluetooth Peripheral, a collection of |
| 24 // characteristics and relationships to other services that encapsulate the | 23 // characteristics and relationships to other services that encapsulate the |
| 25 // behavior of part of a device. | 24 // behavior of part of a device. |
| 26 // | 25 // |
| 27 // Callbacks providing WebBluetoothRemoteGATTService objects are handled by | 26 // Callbacks providing WebBluetoothRemoteGATTService objects are handled by |
| 28 // CallbackPromiseAdapter templatized with this class. See this class's | 27 // CallbackPromiseAdapter templatized with this class. See this class's |
| 29 // "Interface required by CallbackPromiseAdapter" section and the | 28 // "Interface required by CallbackPromiseAdapter" section and the |
| 30 // CallbackPromiseAdapter class comments. | 29 // CallbackPromiseAdapter class comments. |
| 31 class BluetoothRemoteGATTService final | 30 class BluetoothRemoteGATTService final |
| 32 : public GarbageCollectedFinalized<BluetoothRemoteGATTService>, | 31 : public GarbageCollectedFinalized<BluetoothRemoteGATTService>, |
| 33 public ScriptWrappable { | 32 public ScriptWrappable { |
| 34 DEFINE_WRAPPERTYPEINFO(); | 33 DEFINE_WRAPPERTYPEINFO(); |
| 35 | 34 |
| 36 public: | 35 public: |
| 37 explicit BluetoothRemoteGATTService( | 36 BluetoothRemoteGATTService(const String& serviceInstanceId, |
| 38 std::unique_ptr<WebBluetoothRemoteGATTService>, | 37 const String& uuid, |
| 39 BluetoothDevice*); | 38 bool isPrimary, |
| 39 const String& deviceInstanceId, |
| 40 BluetoothDevice*); |
| 40 | 41 |
| 41 // Interface required by garbage collection. | 42 // Interface required by garbage collection. |
| 42 DECLARE_VIRTUAL_TRACE(); | 43 DECLARE_VIRTUAL_TRACE(); |
| 43 | 44 |
| 44 // IDL exposed interface: | 45 // IDL exposed interface: |
| 45 String uuid() { return m_webService->uuid; } | 46 String uuid() { return m_uuid; } |
| 46 bool isPrimary() { return m_webService->isPrimary; } | 47 bool isPrimary() { return m_isPrimary; } |
| 47 BluetoothDevice* device() { return m_device; } | 48 BluetoothDevice* device() { return m_device; } |
| 48 ScriptPromise getCharacteristic(ScriptState*, | 49 ScriptPromise getCharacteristic(ScriptState*, |
| 49 const StringOrUnsignedLong& characteristic, | 50 const StringOrUnsignedLong& characteristic, |
| 50 ExceptionState&); | 51 ExceptionState&); |
| 51 ScriptPromise getCharacteristics(ScriptState*, | 52 ScriptPromise getCharacteristics(ScriptState*, |
| 52 const StringOrUnsignedLong& characteristic, | 53 const StringOrUnsignedLong& characteristic, |
| 53 ExceptionState&); | 54 ExceptionState&); |
| 54 ScriptPromise getCharacteristics(ScriptState*, ExceptionState&); | 55 ScriptPromise getCharacteristics(ScriptState*, ExceptionState&); |
| 55 | 56 |
| 56 private: | 57 private: |
| 58 void GetCharacteristicsCallback( |
| 59 const String& serviceInstanceId, |
| 60 mojom::blink::WebBluetoothGATTQueryQuantity, |
| 61 ScriptPromiseResolver*, |
| 62 mojom::blink::WebBluetoothResult, |
| 63 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr>> |
| 64 services); |
| 65 |
| 57 ScriptPromise getCharacteristicsImpl( | 66 ScriptPromise getCharacteristicsImpl( |
| 58 ScriptState*, | 67 ScriptState*, |
| 59 mojom::blink::WebBluetoothGATTQueryQuantity, | 68 mojom::blink::WebBluetoothGATTQueryQuantity, |
| 60 String characteristicUUID = String()); | 69 String characteristicUUID = String()); |
| 61 | 70 |
| 62 std::unique_ptr<WebBluetoothRemoteGATTService> m_webService; | 71 const String m_serviceInstanceId; |
| 72 const String m_uuid; |
| 73 const bool m_isPrimary; |
| 74 const String m_deviceInstanceId; |
| 63 Member<BluetoothDevice> m_device; | 75 Member<BluetoothDevice> m_device; |
| 64 }; | 76 }; |
| 65 | 77 |
| 66 } // namespace blink | 78 } // namespace blink |
| 67 | 79 |
| 68 #endif // BluetoothRemoteGATTService_h | 80 #endif // BluetoothRemoteGATTService_h |
| OLD | NEW |