Chromium Code Reviews| 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 BluetoothRemoteGATTCharacteristic_h | 5 #ifndef BluetoothRemoteGATTCharacteristic_h |
| 6 #define BluetoothRemoteGATTCharacteristic_h | 6 #define BluetoothRemoteGATTCharacteristic_h |
| 7 | 7 |
| 8 #include <list> | |
| 9 #include <memory> | |
| 8 #include "bindings/core/v8/ScriptWrappable.h" | 10 #include "bindings/core/v8/ScriptWrappable.h" |
| 9 #include "core/dom/ContextLifecycleObserver.h" | 11 #include "core/dom/ContextLifecycleObserver.h" |
| 10 #include "core/dom/DOMArrayPiece.h" | 12 #include "core/dom/DOMArrayPiece.h" |
| 11 #include "core/dom/DOMDataView.h" | 13 #include "core/dom/DOMDataView.h" |
| 12 #include "modules/EventTargetModules.h" | 14 #include "modules/EventTargetModules.h" |
| 13 #include "modules/bluetooth/BluetoothRemoteGATTService.h" | 15 #include "modules/bluetooth/BluetoothRemoteGATTService.h" |
| 16 #include "mojo/public/cpp/bindings/associated_binding.h" | |
| 14 #include "platform/heap/Handle.h" | 17 #include "platform/heap/Handle.h" |
| 15 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" | 18 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" |
| 16 #include "wtf/text/WTFString.h" | 19 #include "wtf/text/WTFString.h" |
| 17 #include <memory> | |
| 18 | 20 |
| 19 namespace blink { | 21 namespace blink { |
| 20 | 22 |
| 21 class BluetoothCharacteristicProperties; | 23 class BluetoothCharacteristicProperties; |
| 22 class BluetoothDevice; | 24 class BluetoothDevice; |
| 23 class ExecutionContext; | 25 class ExecutionContext; |
| 24 class ScriptPromise; | 26 class ScriptPromise; |
| 25 class ScriptState; | 27 class ScriptState; |
| 26 | 28 |
| 27 // BluetoothRemoteGATTCharacteristic represents a GATT Characteristic, which is | 29 // BluetoothRemoteGATTCharacteristic represents a GATT Characteristic, which is |
| 28 // a basic data element that provides further information about a peripheral's | 30 // a basic data element that provides further information about a peripheral's |
| 29 // service. | 31 // service. |
| 30 // | 32 // |
| 31 // Callbacks providing WebBluetoothRemoteGATTCharacteristicInit objects are | 33 // Callbacks providing WebBluetoothRemoteGATTCharacteristicInit objects are |
| 32 // handled by CallbackPromiseAdapter templatized with this class. See this | 34 // handled by CallbackPromiseAdapter templatized with this class. See this |
| 33 // class's "Interface required by CallbackPromiseAdapter" section and the | 35 // class's "Interface required by CallbackPromiseAdapter" section and the |
| 34 // CallbackPromiseAdapter class comments. | 36 // CallbackPromiseAdapter class comments. |
| 35 class BluetoothRemoteGATTCharacteristic final | 37 class BluetoothRemoteGATTCharacteristic final |
| 36 : public EventTargetWithInlineData, | 38 : public EventTargetWithInlineData, |
| 37 public ContextLifecycleObserver { | 39 public ContextLifecycleObserver, |
| 40 public mojom::blink::WebBluetoothCharacteristicClient { | |
| 38 USING_PRE_FINALIZER(BluetoothRemoteGATTCharacteristic, Dispose); | 41 USING_PRE_FINALIZER(BluetoothRemoteGATTCharacteristic, Dispose); |
| 39 DEFINE_WRAPPERTYPEINFO(); | 42 DEFINE_WRAPPERTYPEINFO(); |
| 40 USING_GARBAGE_COLLECTED_MIXIN(BluetoothRemoteGATTCharacteristic); | 43 USING_GARBAGE_COLLECTED_MIXIN(BluetoothRemoteGATTCharacteristic); |
| 41 | 44 |
| 42 public: | 45 public: |
| 43 explicit BluetoothRemoteGATTCharacteristic( | 46 explicit BluetoothRemoteGATTCharacteristic( |
| 44 ExecutionContext*, | 47 ExecutionContext*, |
| 45 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr, | 48 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr, |
| 46 BluetoothRemoteGATTService*, | 49 BluetoothRemoteGATTService*, |
| 47 BluetoothDevice*); | 50 BluetoothDevice*); |
| 48 | 51 |
| 49 static BluetoothRemoteGATTCharacteristic* Create( | 52 static BluetoothRemoteGATTCharacteristic* Create( |
| 50 ExecutionContext*, | 53 ExecutionContext*, |
| 51 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr, | 54 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr, |
| 52 BluetoothRemoteGATTService*, | 55 BluetoothRemoteGATTService*, |
| 53 BluetoothDevice*); | 56 BluetoothDevice*); |
| 54 | 57 |
| 55 // Save value. | 58 // Save value. |
| 56 void SetValue(DOMDataView*); | 59 void SetValue(DOMDataView*); |
| 57 | 60 |
| 58 void DispatchCharacteristicValueChanged(const Vector<uint8_t>& value); | 61 // mojom::blink::WebBluetoothCharacteristicClient: |
| 62 void RemoteCharacteristicValueChanged( | |
| 63 const WTF::Vector<uint8_t>& value) override; | |
| 59 | 64 |
| 60 // ContextLifecycleObserver interface. | 65 // ContextLifecycleObserver interface. |
| 61 void contextDestroyed(ExecutionContext*) override; | 66 void contextDestroyed(ExecutionContext*) override; |
| 62 | 67 |
| 63 // USING_PRE_FINALIZER interface. | 68 // USING_PRE_FINALIZER interface. |
| 64 // Called before the object gets garbage collected. | 69 // Called before the object gets garbage collected. |
| 65 void Dispose(); | 70 void Dispose(); |
| 66 | 71 |
| 67 // Notify our embedder that we should stop any notifications. | |
| 68 // The function only notifies the embedder once. | |
| 69 void NotifyCharacteristicObjectRemoved(); | |
| 70 | |
| 71 // EventTarget methods: | 72 // EventTarget methods: |
| 72 const AtomicString& interfaceName() const override; | 73 const AtomicString& interfaceName() const override; |
| 73 ExecutionContext* getExecutionContext() const; | 74 ExecutionContext* getExecutionContext() const; |
| 74 | 75 |
| 75 // Interface required by garbage collection. | 76 // Interface required by garbage collection. |
| 76 DECLARE_VIRTUAL_TRACE(); | 77 DECLARE_VIRTUAL_TRACE(); |
| 77 | 78 |
| 78 // IDL exposed interface: | 79 // IDL exposed interface: |
| 79 BluetoothRemoteGATTService* service() { return m_service; } | 80 BluetoothRemoteGATTService* service() { return m_service; } |
| 80 String uuid() { return m_characteristic->uuid; } | 81 String uuid() { return m_characteristic->uuid; } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 const String& requestedDescriptorUUID, | 122 const String& requestedDescriptorUUID, |
| 122 const String& characteristicInstanceId, | 123 const String& characteristicInstanceId, |
| 123 mojom::blink::WebBluetoothGATTQueryQuantity, | 124 mojom::blink::WebBluetoothGATTQueryQuantity, |
| 124 ScriptPromiseResolver*, | 125 ScriptPromiseResolver*, |
| 125 mojom::blink::WebBluetoothResult, | 126 mojom::blink::WebBluetoothResult, |
| 126 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>> | 127 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>> |
| 127 descriptors); | 128 descriptors); |
| 128 | 129 |
| 129 DOMException* CreateInvalidCharacteristicError(); | 130 DOMException* CreateInvalidCharacteristicError(); |
| 130 | 131 |
| 132 void CloseClientBindings(); | |
| 133 | |
| 131 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr m_characteristic; | 134 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr m_characteristic; |
| 132 Member<BluetoothRemoteGATTService> m_service; | 135 Member<BluetoothRemoteGATTService> m_service; |
| 133 bool m_stopped; | |
| 134 Member<BluetoothCharacteristicProperties> m_properties; | 136 Member<BluetoothCharacteristicProperties> m_properties; |
| 135 Member<DOMDataView> m_value; | 137 Member<DOMDataView> m_value; |
| 136 Member<BluetoothDevice> m_device; | 138 Member<BluetoothDevice> m_device; |
| 139 std::list<std::unique_ptr< | |
| 140 mojo::AssociatedBinding<mojom::blink::WebBluetoothCharacteristicClient>>> | |
|
dcheng
2017/03/23 00:16:57
Can this use AssociatedBindingSet from https://cs.
juncai
2017/03/23 05:34:18
Done.
| |
| 141 m_clientBindings; | |
| 137 }; | 142 }; |
| 138 | 143 |
| 139 } // namespace blink | 144 } // namespace blink |
| 140 | 145 |
| 141 #endif // BluetoothRemoteGATTCharacteristic_h | 146 #endif // BluetoothRemoteGATTCharacteristic_h |
| OLD | NEW |