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 "platform/heap/Handle.h" | 14 #include "platform/heap/Handle.h" |
15 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristic
.h" | 15 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" |
16 #include "public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristic
Init.h" | |
17 #include "wtf/text/WTFString.h" | 16 #include "wtf/text/WTFString.h" |
18 #include <memory> | 17 #include <memory> |
19 | 18 |
20 namespace blink { | 19 namespace blink { |
21 | 20 |
22 class BluetoothCharacteristicProperties; | 21 class BluetoothCharacteristicProperties; |
| 22 class BluetoothDevice; |
23 class ExecutionContext; | 23 class ExecutionContext; |
24 class ScriptPromise; | 24 class ScriptPromise; |
25 class ScriptState; | 25 class ScriptState; |
26 | 26 |
27 // BluetoothRemoteGATTCharacteristic represents a GATT Characteristic, which is | 27 // BluetoothRemoteGATTCharacteristic represents a GATT Characteristic, which is |
28 // a basic data element that provides further information about a peripheral's | 28 // a basic data element that provides further information about a peripheral's |
29 // service. | 29 // service. |
30 // | 30 // |
31 // Callbacks providing WebBluetoothRemoteGATTCharacteristicInit objects are | 31 // Callbacks providing WebBluetoothRemoteGATTCharacteristicInit objects are |
32 // handled by CallbackPromiseAdapter templatized with this class. See this | 32 // handled by CallbackPromiseAdapter templatized with this class. See this |
33 // class's "Interface required by CallbackPromiseAdapter" section and the | 33 // class's "Interface required by CallbackPromiseAdapter" section and the |
34 // CallbackPromiseAdapter class comments. | 34 // CallbackPromiseAdapter class comments. |
35 class BluetoothRemoteGATTCharacteristic final | 35 class BluetoothRemoteGATTCharacteristic final |
36 : public EventTargetWithInlineData, | 36 : public EventTargetWithInlineData, |
37 public ContextLifecycleObserver, | 37 public ContextLifecycleObserver { |
38 public WebBluetoothRemoteGATTCharacteristic { | |
39 USING_PRE_FINALIZER(BluetoothRemoteGATTCharacteristic, dispose); | 38 USING_PRE_FINALIZER(BluetoothRemoteGATTCharacteristic, dispose); |
40 DEFINE_WRAPPERTYPEINFO(); | 39 DEFINE_WRAPPERTYPEINFO(); |
41 USING_GARBAGE_COLLECTED_MIXIN(BluetoothRemoteGATTCharacteristic); | 40 USING_GARBAGE_COLLECTED_MIXIN(BluetoothRemoteGATTCharacteristic); |
42 | 41 |
43 public: | 42 public: |
44 explicit BluetoothRemoteGATTCharacteristic( | 43 explicit BluetoothRemoteGATTCharacteristic( |
45 ExecutionContext*, | 44 ExecutionContext*, |
46 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit>, | 45 const String& characteristicInstanceId, |
47 BluetoothRemoteGATTService*); | 46 const String& serviceInstanceId, |
| 47 const String& uuid, |
| 48 uint32_t characteristicProperties, |
| 49 BluetoothRemoteGATTService*, |
| 50 BluetoothDevice*); |
48 | 51 |
49 static BluetoothRemoteGATTCharacteristic* create( | 52 static BluetoothRemoteGATTCharacteristic* create( |
50 ExecutionContext*, | 53 ExecutionContext*, |
51 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit>, | 54 const String& characteristicInstanceId, |
52 BluetoothRemoteGATTService*); | 55 const String& serviceInstanceId, |
| 56 const String& uuid, |
| 57 uint32_t characteristicProperties, |
| 58 BluetoothRemoteGATTService*, |
| 59 BluetoothDevice*); |
53 | 60 |
54 // Save value. | 61 // Save value. |
55 void setValue(DOMDataView*); | 62 void setValue(DOMDataView*); |
56 | 63 |
57 // WebBluetoothRemoteGATTCharacteristic interface: | 64 void dispatchCharacteristicValueChanged(const Vector<uint8_t>& value); |
58 void dispatchCharacteristicValueChanged(const WebVector<uint8_t>&) override; | |
59 | 65 |
60 // ContextLifecycleObserver interface. | 66 // ContextLifecycleObserver interface. |
61 void contextDestroyed() override; | 67 void contextDestroyed() override; |
62 | 68 |
63 // USING_PRE_FINALIZER interface. | 69 // USING_PRE_FINALIZER interface. |
64 // Called before the object gets garbage collected. | 70 // Called before the object gets garbage collected. |
65 void dispose(); | 71 void dispose(); |
66 | 72 |
67 // Notify our embedder that we should stop any notifications. | 73 // Notify our embedder that we should stop any notifications. |
68 // The function only notifies the embedder once. | 74 // The function only notifies the embedder once. |
69 void notifyCharacteristicObjectRemoved(); | 75 void notifyCharacteristicObjectRemoved(); |
70 | 76 |
71 // EventTarget methods: | 77 // EventTarget methods: |
72 const AtomicString& interfaceName() const override; | 78 const AtomicString& interfaceName() const override; |
73 ExecutionContext* getExecutionContext() const; | 79 ExecutionContext* getExecutionContext() const; |
74 | 80 |
75 // Interface required by garbage collection. | 81 // Interface required by garbage collection. |
76 DECLARE_VIRTUAL_TRACE(); | 82 DECLARE_VIRTUAL_TRACE(); |
77 | 83 |
78 // IDL exposed interface: | 84 // IDL exposed interface: |
79 BluetoothRemoteGATTService* service() { return m_service; } | 85 BluetoothRemoteGATTService* service() { return m_service; } |
80 String uuid() { return m_webCharacteristic->uuid; } | 86 String uuid() { return m_uuid; } |
81 BluetoothCharacteristicProperties* properties() { return m_properties; } | 87 BluetoothCharacteristicProperties* properties() { return m_properties; } |
82 DOMDataView* value() const { return m_value; } | 88 DOMDataView* value() const { return m_value; } |
83 ScriptPromise readValue(ScriptState*); | 89 ScriptPromise readValue(ScriptState*); |
84 ScriptPromise writeValue(ScriptState*, const DOMArrayPiece&); | 90 ScriptPromise writeValue(ScriptState*, const DOMArrayPiece&); |
85 ScriptPromise startNotifications(ScriptState*); | 91 ScriptPromise startNotifications(ScriptState*); |
86 ScriptPromise stopNotifications(ScriptState*); | 92 ScriptPromise stopNotifications(ScriptState*); |
87 | 93 |
88 DEFINE_ATTRIBUTE_EVENT_LISTENER(characteristicvaluechanged); | 94 DEFINE_ATTRIBUTE_EVENT_LISTENER(characteristicvaluechanged); |
89 | 95 |
90 protected: | 96 protected: |
91 // EventTarget overrides. | 97 // EventTarget overrides. |
92 void addedEventListener(const AtomicString& eventType, | 98 void addedEventListener(const AtomicString& eventType, |
93 RegisteredEventListener&) override; | 99 RegisteredEventListener&) override; |
94 | 100 |
95 private: | 101 private: |
96 friend class ReadValueCallback; | |
97 friend class WriteValueCallback; | |
98 friend class NotificationsCallback; | |
99 | |
100 BluetoothRemoteGATTServer* gatt() { return m_service->device()->gatt(); } | 102 BluetoothRemoteGATTServer* gatt() { return m_service->device()->gatt(); } |
101 | 103 |
102 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit> m_webCharacteristic; | 104 void ReadValueCallback(ScriptPromiseResolver*, |
| 105 mojom::blink::WebBluetoothResult, |
| 106 const Optional<Vector<uint8_t>>& value); |
| 107 void WriteValueCallback(ScriptPromiseResolver*, |
| 108 const Vector<uint8_t>& value, |
| 109 mojom::blink::WebBluetoothResult); |
| 110 void NotificationsCallback(ScriptPromiseResolver*, |
| 111 mojom::blink::WebBluetoothResult); |
| 112 |
| 113 const String m_characteristicInstanceId; |
| 114 const String m_serviceInstanceId; |
| 115 const String m_uuid; |
| 116 const uint32_t m_characteristicProperties; |
103 Member<BluetoothRemoteGATTService> m_service; | 117 Member<BluetoothRemoteGATTService> m_service; |
104 bool m_stopped; | 118 bool m_stopped; |
105 Member<BluetoothCharacteristicProperties> m_properties; | 119 Member<BluetoothCharacteristicProperties> m_properties; |
106 Member<DOMDataView> m_value; | 120 Member<DOMDataView> m_value; |
| 121 Member<BluetoothDevice> m_device; |
107 }; | 122 }; |
108 | 123 |
109 } // namespace blink | 124 } // namespace blink |
110 | 125 |
111 #endif // BluetoothRemoteGATTCharacteristic_h | 126 #endif // BluetoothRemoteGATTCharacteristic_h |
OLD | NEW |