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 "bindings/core/v8/ScriptWrappable.h" | 8 #include "bindings/core/v8/ScriptWrappable.h" |
9 #include "core/dom/ContextLifecycleObserver.h" | 9 #include "core/dom/ContextLifecycleObserver.h" |
10 #include "core/dom/DOMArrayPiece.h" | 10 #include "core/dom/DOMArrayPiece.h" |
11 #include "core/dom/DOMDataView.h" | 11 #include "core/dom/DOMDataView.h" |
12 #include "modules/EventTargetModules.h" | 12 #include "modules/EventTargetModules.h" |
13 #include "modules/bluetooth/BluetoothRemoteGATTService.h" | 13 #include "modules/bluetooth/BluetoothRemoteGATTService.h" |
| 14 #include "mojo/public/cpp/bindings/associated_binding.h" |
14 #include "platform/heap/Handle.h" | 15 #include "platform/heap/Handle.h" |
15 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" | 16 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" |
16 #include "wtf/text/WTFString.h" | 17 #include "wtf/text/WTFString.h" |
17 #include <memory> | 18 #include <memory> |
18 | 19 |
19 namespace blink { | 20 namespace blink { |
20 | 21 |
21 class BluetoothCharacteristicProperties; | 22 class BluetoothCharacteristicProperties; |
22 class BluetoothDevice; | 23 class BluetoothDevice; |
23 class ExecutionContext; | 24 class ExecutionContext; |
24 class ScriptPromise; | 25 class ScriptPromise; |
25 class ScriptState; | 26 class ScriptState; |
26 | 27 |
27 // BluetoothRemoteGATTCharacteristic represents a GATT Characteristic, which is | 28 // BluetoothRemoteGATTCharacteristic represents a GATT Characteristic, which is |
28 // a basic data element that provides further information about a peripheral's | 29 // a basic data element that provides further information about a peripheral's |
29 // service. | 30 // service. |
30 // | 31 // |
31 // Callbacks providing WebBluetoothRemoteGATTCharacteristicInit objects are | 32 // Callbacks providing WebBluetoothRemoteGATTCharacteristicInit objects are |
32 // handled by CallbackPromiseAdapter templatized with this class. See this | 33 // handled by CallbackPromiseAdapter templatized with this class. See this |
33 // class's "Interface required by CallbackPromiseAdapter" section and the | 34 // class's "Interface required by CallbackPromiseAdapter" section and the |
34 // CallbackPromiseAdapter class comments. | 35 // CallbackPromiseAdapter class comments. |
35 class BluetoothRemoteGATTCharacteristic final | 36 class BluetoothRemoteGATTCharacteristic final |
36 : public EventTargetWithInlineData, | 37 : public EventTargetWithInlineData, |
37 public ContextLifecycleObserver { | 38 public ContextLifecycleObserver, |
| 39 public mojom::blink::WebBluetoothCharacteristicClient { |
38 USING_PRE_FINALIZER(BluetoothRemoteGATTCharacteristic, dispose); | 40 USING_PRE_FINALIZER(BluetoothRemoteGATTCharacteristic, dispose); |
39 DEFINE_WRAPPERTYPEINFO(); | 41 DEFINE_WRAPPERTYPEINFO(); |
40 USING_GARBAGE_COLLECTED_MIXIN(BluetoothRemoteGATTCharacteristic); | 42 USING_GARBAGE_COLLECTED_MIXIN(BluetoothRemoteGATTCharacteristic); |
41 | 43 |
42 public: | 44 public: |
43 explicit BluetoothRemoteGATTCharacteristic( | 45 explicit BluetoothRemoteGATTCharacteristic( |
44 ExecutionContext*, | 46 ExecutionContext*, |
45 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr, | 47 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr, |
46 BluetoothRemoteGATTService*, | 48 BluetoothRemoteGATTService*, |
47 BluetoothDevice*); | 49 BluetoothDevice*); |
48 | 50 |
49 static BluetoothRemoteGATTCharacteristic* create( | 51 static BluetoothRemoteGATTCharacteristic* create( |
50 ExecutionContext*, | 52 ExecutionContext*, |
51 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr, | 53 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr, |
52 BluetoothRemoteGATTService*, | 54 BluetoothRemoteGATTService*, |
53 BluetoothDevice*); | 55 BluetoothDevice*); |
54 | 56 |
55 // Save value. | 57 // Save value. |
56 void setValue(DOMDataView*); | 58 void setValue(DOMDataView*); |
57 | 59 |
58 void dispatchCharacteristicValueChanged(const Vector<uint8_t>& value); | |
59 | |
60 // ContextLifecycleObserver interface. | 60 // ContextLifecycleObserver interface. |
61 void contextDestroyed(ExecutionContext*) override; | 61 void contextDestroyed(ExecutionContext*) override; |
62 | 62 |
| 63 // mojom::blink::WebBluetoothCharacteristicClient: |
| 64 void RemoteCharacteristicValueChanged( |
| 65 const WTF::Vector<uint8_t>& value) override; |
| 66 |
63 // USING_PRE_FINALIZER interface. | 67 // USING_PRE_FINALIZER interface. |
64 // Called before the object gets garbage collected. | 68 // Called before the object gets garbage collected. |
65 void dispose(); | 69 void dispose(); |
66 | 70 |
67 // Notify our embedder that we should stop any notifications. | 71 // Notify our embedder that we should stop any notifications. |
68 // The function only notifies the embedder once. | 72 // The function only notifies the embedder once. |
69 void notifyCharacteristicObjectRemoved(); | 73 void notifyCharacteristicObjectRemoved(); |
70 | 74 |
71 // EventTarget methods: | 75 // EventTarget methods: |
72 const AtomicString& interfaceName() const override; | 76 const AtomicString& interfaceName() const override; |
(...skipping 30 matching lines...) Expand all Loading... |
103 friend class BluetoothRemoteGATTDescriptor; | 107 friend class BluetoothRemoteGATTDescriptor; |
104 | 108 |
105 BluetoothRemoteGATTServer* getGatt() { return m_service->device()->gatt(); } | 109 BluetoothRemoteGATTServer* getGatt() { return m_service->device()->gatt(); } |
106 | 110 |
107 void ReadValueCallback(ScriptPromiseResolver*, | 111 void ReadValueCallback(ScriptPromiseResolver*, |
108 mojom::blink::WebBluetoothResult, | 112 mojom::blink::WebBluetoothResult, |
109 const Optional<Vector<uint8_t>>& value); | 113 const Optional<Vector<uint8_t>>& value); |
110 void WriteValueCallback(ScriptPromiseResolver*, | 114 void WriteValueCallback(ScriptPromiseResolver*, |
111 const Vector<uint8_t>& value, | 115 const Vector<uint8_t>& value, |
112 mojom::blink::WebBluetoothResult); | 116 mojom::blink::WebBluetoothResult); |
113 void NotificationsCallback(ScriptPromiseResolver*, | 117 void NotificationsCallback( |
114 mojom::blink::WebBluetoothResult); | 118 ScriptPromiseResolver*, |
| 119 mojom::blink::WebBluetoothResult, |
| 120 mojom::blink::WebBluetoothCharacteristicClientAssociatedRequest); |
115 | 121 |
116 ScriptPromise getDescriptorsImpl(ScriptState*, | 122 ScriptPromise getDescriptorsImpl(ScriptState*, |
117 mojom::blink::WebBluetoothGATTQueryQuantity, | 123 mojom::blink::WebBluetoothGATTQueryQuantity, |
118 const String& descriptorUUID = String()); | 124 const String& descriptorUUID = String()); |
119 | 125 |
120 void GetDescriptorsCallback( | 126 void GetDescriptorsCallback( |
121 const String& characteristicInstanceId, | 127 const String& characteristicInstanceId, |
122 mojom::blink::WebBluetoothGATTQueryQuantity, | 128 mojom::blink::WebBluetoothGATTQueryQuantity, |
123 ScriptPromiseResolver*, | 129 ScriptPromiseResolver*, |
124 mojom::blink::WebBluetoothResult, | 130 mojom::blink::WebBluetoothResult, |
125 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>> | 131 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>> |
126 descriptors); | 132 descriptors); |
127 | 133 |
128 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr m_characteristic; | 134 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr m_characteristic; |
129 Member<BluetoothRemoteGATTService> m_service; | 135 Member<BluetoothRemoteGATTService> m_service; |
| 136 mojo::AssociatedBinding<mojom::blink::WebBluetoothCharacteristicClient> |
| 137 m_clientBinding; |
130 bool m_stopped; | 138 bool m_stopped; |
131 Member<BluetoothCharacteristicProperties> m_properties; | 139 Member<BluetoothCharacteristicProperties> m_properties; |
132 Member<DOMDataView> m_value; | 140 Member<DOMDataView> m_value; |
133 Member<BluetoothDevice> m_device; | 141 Member<BluetoothDevice> m_device; |
134 }; | 142 }; |
135 | 143 |
136 } // namespace blink | 144 } // namespace blink |
137 | 145 |
138 #endif // BluetoothRemoteGATTCharacteristic_h | 146 #endif // BluetoothRemoteGATTCharacteristic_h |
OLD | NEW |