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 <memory> | |
8 #include "bindings/core/v8/ScriptWrappable.h" | 9 #include "bindings/core/v8/ScriptWrappable.h" |
9 #include "core/dom/ContextLifecycleObserver.h" | 10 #include "core/dom/ContextLifecycleObserver.h" |
10 #include "core/dom/DOMArrayPiece.h" | 11 #include "core/dom/DOMArrayPiece.h" |
11 #include "core/dom/DOMDataView.h" | 12 #include "core/dom/DOMDataView.h" |
12 #include "modules/EventTargetModules.h" | 13 #include "modules/EventTargetModules.h" |
13 #include "modules/bluetooth/BluetoothRemoteGATTService.h" | 14 #include "modules/bluetooth/BluetoothRemoteGATTService.h" |
15 #include "mojo/public/cpp/bindings/associated_binding.h" | |
14 #include "platform/heap/Handle.h" | 16 #include "platform/heap/Handle.h" |
15 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" | 17 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" |
16 #include "wtf/text/WTFString.h" | 18 #include "wtf/text/WTFString.h" |
17 #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( | |
ortuno
2017/03/01 04:52:06
nit: Move this above contextDestroyed so that both
juncai
2017/03/02 03:23:49
Done.
| |
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& requestedDescriptorUUID, | 127 const String& requestedDescriptorUUID, |
122 const String& characteristicInstanceId, | 128 const String& characteristicInstanceId, |
123 mojom::blink::WebBluetoothGATTQueryQuantity, | 129 mojom::blink::WebBluetoothGATTQueryQuantity, |
124 ScriptPromiseResolver*, | 130 ScriptPromiseResolver*, |
125 mojom::blink::WebBluetoothResult, | 131 mojom::blink::WebBluetoothResult, |
126 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>> | 132 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>> |
127 descriptors); | 133 descriptors); |
128 | 134 |
129 DOMException* createInvalidCharacteristicError(); | 135 DOMException* createInvalidCharacteristicError(); |
130 | 136 |
131 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr m_characteristic; | 137 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr m_characteristic; |
132 Member<BluetoothRemoteGATTService> m_service; | 138 Member<BluetoothRemoteGATTService> m_service; |
133 bool m_stopped; | 139 mojo::AssociatedBinding<mojom::blink::WebBluetoothCharacteristicClient> |
ortuno
2017/03/01 04:52:06
nit: move this to the end.
juncai
2017/03/02 03:23:49
Done.
| |
140 m_clientBinding; | |
134 Member<BluetoothCharacteristicProperties> m_properties; | 141 Member<BluetoothCharacteristicProperties> m_properties; |
135 Member<DOMDataView> m_value; | 142 Member<DOMDataView> m_value; |
136 Member<BluetoothDevice> m_device; | 143 Member<BluetoothDevice> m_device; |
137 }; | 144 }; |
138 | 145 |
139 } // namespace blink | 146 } // namespace blink |
140 | 147 |
141 #endif // BluetoothRemoteGATTCharacteristic_h | 148 #endif // BluetoothRemoteGATTCharacteristic_h |
OLD | NEW |