OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ |
6 #define CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ | 6 #define CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 int32_t quantity /* Corresponds to WebBluetoothGATTQueryQuantity in | 57 int32_t quantity /* Corresponds to WebBluetoothGATTQueryQuantity in |
58 web_bluetooth.mojom */, | 58 web_bluetooth.mojom */, |
59 const blink::WebString& services_uuid, | 59 const blink::WebString& services_uuid, |
60 blink::WebBluetoothGetPrimaryServicesCallbacks* callbacks) override; | 60 blink::WebBluetoothGetPrimaryServicesCallbacks* callbacks) override; |
61 void getCharacteristics( | 61 void getCharacteristics( |
62 const blink::WebString& service_instance_id, | 62 const blink::WebString& service_instance_id, |
63 int32_t quantity /* Corresponds to WebBluetoothGATTQueryQuantity in | 63 int32_t quantity /* Corresponds to WebBluetoothGATTQueryQuantity in |
64 web_bluetooth.mojom */, | 64 web_bluetooth.mojom */, |
65 const blink::WebString& characteristics_uuid, | 65 const blink::WebString& characteristics_uuid, |
66 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) override; | 66 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) override; |
67 void readValue(const blink::WebString& characteristic_instance_id, | 67 void characteristicReadValue( |
68 blink::WebBluetoothReadValueCallbacks* callbacks) override; | 68 const blink::WebString& characteristic_instance_id, |
69 void writeValue(const blink::WebString& characteristic_instance_id, | 69 blink::WebBluetoothReadValueCallbacks* callbacks) override; |
70 const blink::WebVector<uint8_t>& value, | 70 void characteristicWriteValue( |
71 blink::WebBluetoothWriteValueCallbacks*) override; | 71 const blink::WebString& characteristic_instance_id, |
72 const blink::WebVector<uint8_t>& value, | |
73 blink::WebBluetoothWriteValueCallbacks*) override; | |
72 void startNotifications( | 74 void startNotifications( |
73 const blink::WebString& characteristic_instance_id, | 75 const blink::WebString& characteristic_instance_id, |
74 blink::WebBluetoothNotificationsCallbacks*) override; | 76 blink::WebBluetoothNotificationsCallbacks*) override; |
75 void stopNotifications( | 77 void stopNotifications( |
76 const blink::WebString& characteristic_instance_id, | 78 const blink::WebString& characteristic_instance_id, |
77 blink::WebBluetoothNotificationsCallbacks*) override; | 79 blink::WebBluetoothNotificationsCallbacks*) override; |
78 void characteristicObjectRemoved( | 80 void characteristicObjectRemoved( |
79 const blink::WebString& characteristic_instance_id, | 81 const blink::WebString& characteristic_instance_id, |
80 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) override; | 82 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) override; |
81 void registerCharacteristicObject( | 83 void registerCharacteristicObject( |
82 const blink::WebString& characteristic_instance_id, | 84 const blink::WebString& characteristic_instance_id, |
83 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) override; | 85 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) override; |
86 void getDescriptors( | |
87 const blink::WebString& characteristic_instance_id, | |
88 int32_t quantity /* Corresponds to WebBluetoothGATTQueryQuantity in | |
89 web_bluetooth.mojom */, | |
90 const blink::WebString& descriptor_uuid, | |
91 blink::WebBluetoothGetDescriptorsCallbacks* callbacks) override; | |
92 void descriptorReadValue( | |
93 const blink::WebString& descriptor_instance_id, | |
94 blink::WebBluetoothReadValueCallbacks* callbacks) override; | |
95 void descriptorWriteValue(const blink::WebString& descriptor_instance_id, | |
96 const blink::WebVector<uint8_t>& value, | |
97 blink::WebBluetoothWriteValueCallbacks*) override; | |
98 void descriptorObjectRemoved( | |
99 const blink::WebString& descriptor_instance_id, | |
100 blink::WebBluetoothRemoteGATTDescriptor* descriptor) override; | |
101 void registerDescriptorObject( | |
ortuno
2016/11/21 03:34:08
Per comment in web_bluetooth.mojom, no need for th
| |
102 const blink::WebString& descriptor_instance_id, | |
103 blink::WebBluetoothRemoteGATTDescriptor* descriptor) override; | |
84 | 104 |
85 private: | 105 private: |
86 struct GetCharacteristicsCallback; | 106 struct GetCharacteristicsCallback; |
87 // WebBluetoothServiceClient methods: | 107 // WebBluetoothServiceClient methods: |
88 void RemoteCharacteristicValueChanged( | 108 void RemoteCharacteristicValueChanged( |
89 const mojo::String& characteristic_instance_id, | 109 const mojo::String& characteristic_instance_id, |
90 mojo::Array<uint8_t> value) override; | 110 mojo::Array<uint8_t> value) override; |
111 void RemoteDescriptorValueChanged(const mojo::String& descriptor_instance_id, | |
112 mojo::Array<uint8_t> value) override; | |
91 void GattServerDisconnected(const WebBluetoothDeviceId& device_id) override; | 113 void GattServerDisconnected(const WebBluetoothDeviceId& device_id) override; |
92 | 114 |
93 // Callbacks for WebBluetoothService calls: | 115 // Callbacks for WebBluetoothService calls: |
94 void OnRequestDeviceComplete( | 116 void OnRequestDeviceComplete( |
95 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, | 117 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, |
96 const blink::mojom::WebBluetoothResult result, | 118 const blink::mojom::WebBluetoothResult result, |
97 blink::mojom::WebBluetoothDevicePtr device); | 119 blink::mojom::WebBluetoothDevicePtr device); |
98 void OnConnectComplete( | 120 void OnConnectComplete( |
99 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> | 121 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> |
100 callbacks, | 122 callbacks, |
101 blink::mojom::WebBluetoothResult result); | 123 blink::mojom::WebBluetoothResult result); |
102 void OnGetPrimaryServicesComplete( | 124 void OnGetPrimaryServicesComplete( |
103 const blink::WebString& device_id, | 125 const blink::WebString& device_id, |
104 std::unique_ptr<blink::WebBluetoothGetPrimaryServicesCallbacks> callbacks, | 126 std::unique_ptr<blink::WebBluetoothGetPrimaryServicesCallbacks> callbacks, |
105 blink::mojom::WebBluetoothResult result, | 127 blink::mojom::WebBluetoothResult result, |
106 mojo::Array<blink::mojom::WebBluetoothRemoteGATTServicePtr> services); | 128 mojo::Array<blink::mojom::WebBluetoothRemoteGATTServicePtr> services); |
107 void OnGetCharacteristicsComplete( | 129 void OnGetCharacteristicsComplete( |
108 const blink::WebString& service_instance_id, | 130 const blink::WebString& characteristic_instance_id, |
109 std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks, | 131 std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks, |
110 blink::mojom::WebBluetoothResult result, | 132 blink::mojom::WebBluetoothResult result, |
111 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> | 133 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> |
112 characteristics); | 134 characteristics); |
113 void OnReadValueComplete( | 135 void OnReadValueComplete( |
114 std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks, | 136 std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks, |
115 blink::mojom::WebBluetoothResult result, | 137 blink::mojom::WebBluetoothResult result, |
116 mojo::Array<uint8_t> value); | 138 mojo::Array<uint8_t> value); |
117 void OnWriteValueComplete( | 139 void OnWriteValueComplete( |
118 const blink::WebVector<uint8_t>& value, | 140 const blink::WebVector<uint8_t>& value, |
119 std::unique_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks, | 141 std::unique_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks, |
120 blink::mojom::WebBluetoothResult result); | 142 blink::mojom::WebBluetoothResult result); |
121 void OnStartNotificationsComplete( | 143 void OnStartNotificationsComplete( |
122 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks, | 144 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks, |
123 blink::mojom::WebBluetoothResult result); | 145 blink::mojom::WebBluetoothResult result); |
124 void OnStopNotificationsComplete( | 146 void OnStopNotificationsComplete( |
125 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks); | 147 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks); |
126 | 148 void OnGetDescriptorsComplete( |
149 const blink::WebString& service_instance_id, | |
150 std::unique_ptr<blink::WebBluetoothGetDescriptorsCallbacks> callbacks, | |
151 blink::mojom::WebBluetoothResult result, | |
152 mojo::Array<blink::mojom::WebBluetoothRemoteGATTDescriptorPtr> | |
153 characteristics); | |
127 void DispatchCharacteristicValueChanged( | 154 void DispatchCharacteristicValueChanged( |
128 const std::string& characteristic_instance_id, | 155 const std::string& characteristic_instance_id, |
129 const std::vector<uint8_t>& value); | 156 const std::vector<uint8_t>& value); |
157 void DispatchDescriptorValueChanged(const std::string& descriptor_instance_id, | |
158 const std::vector<uint8_t>& value); | |
130 | 159 |
131 blink::mojom::WebBluetoothService& GetWebBluetoothService(); | 160 blink::mojom::WebBluetoothService& GetWebBluetoothService(); |
132 service_manager::InterfaceProvider* const remote_interfaces_; | 161 service_manager::InterfaceProvider* const remote_interfaces_; |
133 blink::mojom::WebBluetoothServicePtr web_bluetooth_service_; | 162 blink::mojom::WebBluetoothServicePtr web_bluetooth_service_; |
134 | 163 |
135 // Map of characteristic_instance_ids to | 164 // Map of characteristic_instance_ids to |
136 // WebBluetoothRemoteGATTCharacteristics. When characteristicObjectRemoved is | 165 // WebBluetoothRemoteGATTCharacteristics. When characteristicObjectRemoved is |
137 // called the characteristic should be removed from the map. | 166 // called the characteristic should be removed from the map. |
138 // Keeps track of what characteristics have listeners. | 167 // Keeps track of what characteristics have listeners. |
139 std::unordered_map<std::string, blink::WebBluetoothRemoteGATTCharacteristic*> | 168 std::unordered_map<std::string, blink::WebBluetoothRemoteGATTCharacteristic*> |
140 active_characteristics_; | 169 active_characteristics_; |
141 | 170 |
171 // Map of descriptor_instance_ids to | |
172 // WebBluetoothRemoteGATTDescriptors. When descriptorObjectRemoved is | |
173 // called the descriptor should be removed from the map. | |
174 // Keeps track of what descriptors have listeners. | |
175 std::unordered_map<std::string, blink::WebBluetoothRemoteGATTDescriptor*> | |
176 active_descriptors_; | |
177 | |
142 // Map of device_ids to WebBluetoothDevices. Added in connect() and removed in | 178 // Map of device_ids to WebBluetoothDevices. Added in connect() and removed in |
143 // disconnect(). This means a device may not actually be connected while in | 179 // disconnect(). This means a device may not actually be connected while in |
144 // this map, but that it will definitely be removed when the page navigates. | 180 // this map, but that it will definitely be removed when the page navigates. |
145 std::unordered_map<WebBluetoothDeviceId, | 181 std::unordered_map<WebBluetoothDeviceId, |
146 blink::WebBluetoothDevice*, | 182 blink::WebBluetoothDevice*, |
147 WebBluetoothDeviceIdHash> | 183 WebBluetoothDeviceIdHash> |
148 connected_devices_; | 184 connected_devices_; |
149 | 185 |
150 // Binding associated with |web_bluetooth_service_|. | 186 // Binding associated with |web_bluetooth_service_|. |
151 mojo::AssociatedBinding<blink::mojom::WebBluetoothServiceClient> binding_; | 187 mojo::AssociatedBinding<blink::mojom::WebBluetoothServiceClient> binding_; |
152 | 188 |
153 DISALLOW_COPY_AND_ASSIGN(WebBluetoothImpl); | 189 DISALLOW_COPY_AND_ASSIGN(WebBluetoothImpl); |
154 }; | 190 }; |
155 | 191 |
156 } // namespace content | 192 } // namespace content |
157 | 193 |
158 #endif // CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ | 194 #endif // CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_ |
OLD | NEW |