Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_characteristic.cc

Issue 2613473002: bluetooth: bluez: Implement BluetoothRemoteGattCharacteristicBluez::SubscribeToNotifications and Un… (Closed)
Patch Set: Also include Chrome OS as it uses Bluez. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 return; 140 return;
141 } 141 }
142 142
143 // After we migrate each platform to the new way of starting and stopping 143 // After we migrate each platform to the new way of starting and stopping
144 // notifications, we can remove them from this #if check. The goal is to get 144 // notifications, we can remove them from this #if check. The goal is to get
145 // rid of the entire check, and run SubscribeToNotifications on all 145 // rid of the entire check, and run SubscribeToNotifications on all
146 // platforms. 146 // platforms.
147 // 147 //
148 // TODO(http://crbug.com/633191): Remove OS_MACOSX from this check. 148 // TODO(http://crbug.com/633191): Remove OS_MACOSX from this check.
149 // TODO(http://crbug.com/636270): Remove OS_WIN from this check. 149 // TODO(http://crbug.com/636270): Remove OS_WIN from this check.
150 // TODO(http://crbug.com/636275): Remove OS_CHROMEOS and OS_LINUX from this 150 #if defined(OS_MACOSX) || defined(OS_WIN)
151 // check.
152 #if defined(OS_CHROMEOS) || defined(OS_LINUX) || defined(OS_MACOSX) || \
153 defined(OS_WIN)
154 base::ThreadTaskRunnerHandle::Get()->PostTask( 151 base::ThreadTaskRunnerHandle::Get()->PostTask(
155 FROM_HERE, 152 FROM_HERE,
156 base::Bind(&BluetoothRemoteGattCharacteristic::OnStartNotifySessionError, 153 base::Bind(&BluetoothRemoteGattCharacteristic::OnStartNotifySessionError,
157 GetWeakPtr(), error_callback, 154 GetWeakPtr(), error_callback,
158 BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); 155 BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED));
159 #else // !(defined(OS_CHROMEOS) || defined(OS_LINUX) || defined(OS_MACOSX) || 156 #else // !(defined(OS_MACOSX) || defined(OS_WIN))
160 // defined(OS_WIN))
161 // Find the Client Characteristic Configuration descriptor. 157 // Find the Client Characteristic Configuration descriptor.
162 std::vector<BluetoothRemoteGattDescriptor*> ccc_descriptor = 158 std::vector<BluetoothRemoteGattDescriptor*> ccc_descriptor =
163 GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: 159 GetDescriptorsByUUID(BluetoothRemoteGattDescriptor::
164 ClientCharacteristicConfigurationUuid()); 160 ClientCharacteristicConfigurationUuid());
165 161
166 if (ccc_descriptor.size() != 1u) { 162 if (ccc_descriptor.size() != 1u) {
167 LOG(ERROR) << "Found " << ccc_descriptor.size() 163 LOG(ERROR) << "Found " << ccc_descriptor.size()
168 << " client characteristic configuration descriptors."; 164 << " client characteristic configuration descriptors.";
169 base::ThreadTaskRunnerHandle::Get()->PostTask( 165 base::ThreadTaskRunnerHandle::Get()->PostTask(
170 FROM_HERE, 166 FROM_HERE,
171 base::Bind( 167 base::Bind(
172 &BluetoothRemoteGattCharacteristic::OnStartNotifySessionError, 168 &BluetoothRemoteGattCharacteristic::OnStartNotifySessionError,
173 GetWeakPtr(), error_callback, 169 GetWeakPtr(), error_callback,
174 (ccc_descriptor.size() == 0) 170 (ccc_descriptor.size() == 0)
175 ? BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED 171 ? BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED
176 : BluetoothRemoteGattService::GATT_ERROR_FAILED)); 172 : BluetoothRemoteGattService::GATT_ERROR_FAILED));
177 return; 173 return;
178 } 174 }
179 175
180 // Pass the Client Characteristic Configuration descriptor to 176 // Pass the Client Characteristic Configuration descriptor to
181 // SubscribetoNotifications, which will write the correct value to it, and 177 // SubscribetoNotifications, which will write the correct value to it, and
182 // do whatever else is needed to get the notifications flowing. 178 // do whatever else is needed to get the notifications flowing.
183 SubscribeToNotifications( 179 SubscribeToNotifications(
184 ccc_descriptor[0], 180 ccc_descriptor[0],
185 base::Bind( 181 base::Bind(
186 &BluetoothRemoteGattCharacteristic::OnStartNotifySessionSuccess, 182 &BluetoothRemoteGattCharacteristic::OnStartNotifySessionSuccess,
187 GetWeakPtr(), callback), 183 GetWeakPtr(), callback),
188 base::Bind(&BluetoothRemoteGattCharacteristic::OnStartNotifySessionError, 184 base::Bind(&BluetoothRemoteGattCharacteristic::OnStartNotifySessionError,
189 GetWeakPtr(), error_callback)); 185 GetWeakPtr(), error_callback));
190 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) || defined(OS_MACOSX) || 186 #endif // defined(OS_MACOSX) || defined(OS_WIN)
191 // defined(OS_WIN)
192 } 187 }
193 188
194 void BluetoothRemoteGattCharacteristic::CancelStartNotifySession( 189 void BluetoothRemoteGattCharacteristic::CancelStartNotifySession(
195 base::Closure callback) { 190 base::Closure callback) {
196 std::unique_ptr<NotifySessionCommand> command = 191 std::unique_ptr<NotifySessionCommand> command =
197 std::move(pending_notify_commands_.front()); 192 std::move(pending_notify_commands_.front());
198 pending_notify_commands_.pop(); 193 pending_notify_commands_.pop();
199 callback.Run(); 194 callback.Run();
200 } 195 }
201 196
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 return; 273 return;
279 } 274 }
280 275
281 // After we migrate each platform to the new way of starting and stopping 276 // After we migrate each platform to the new way of starting and stopping
282 // notifications, we can remove them from this #if check. The goal is to get 277 // notifications, we can remove them from this #if check. The goal is to get
283 // rid of the entire check, and run SubscribeToNotifications on all 278 // rid of the entire check, and run SubscribeToNotifications on all
284 // platforms. 279 // platforms.
285 // 280 //
286 // TODO(http://crbug.com/633191): Remove OS_MACOSX from this check. 281 // TODO(http://crbug.com/633191): Remove OS_MACOSX from this check.
287 // TODO(http://crbug.com/636270): Remove OS_WIN from this check. 282 // TODO(http://crbug.com/636270): Remove OS_WIN from this check.
288 // TODO(http://crbug.com/636275): Remove OS_CHROMEOS and OS_LINUX from this 283 #if defined(OS_MACOSX) || defined(OS_WIN)
289 // check.
290 #if defined(OS_CHROMEOS) || defined(OS_LINUX) || defined(OS_MACOSX) || \
291 defined(OS_WIN)
292 base::ThreadTaskRunnerHandle::Get()->PostTask( 284 base::ThreadTaskRunnerHandle::Get()->PostTask(
293 FROM_HERE, 285 FROM_HERE,
294 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionError, 286 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionError,
295 GetWeakPtr(), session, callback, 287 GetWeakPtr(), session, callback,
296 BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); 288 BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED));
297 #else // !(defined(OS_CHROMEOS) || defined(OS_LINUX) || defined(OS_MACOSX) || 289 #else // !(defined(OS_MACOSX) || defined(OS_WIN))
298 // defined(OS_WIN))
299 // Find the Client Characteristic Configuration descriptor. 290 // Find the Client Characteristic Configuration descriptor.
300 std::vector<BluetoothRemoteGattDescriptor*> ccc_descriptor = 291 std::vector<BluetoothRemoteGattDescriptor*> ccc_descriptor =
301 GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: 292 GetDescriptorsByUUID(BluetoothRemoteGattDescriptor::
302 ClientCharacteristicConfigurationUuid()); 293 ClientCharacteristicConfigurationUuid());
303 294
304 if (ccc_descriptor.size() != 1u) { 295 if (ccc_descriptor.size() != 1u) {
305 LOG(ERROR) << "Found " << ccc_descriptor.size() 296 LOG(ERROR) << "Found " << ccc_descriptor.size()
306 << " client characteristic configuration descriptors."; 297 << " client characteristic configuration descriptors.";
307 base::ThreadTaskRunnerHandle::Get()->PostTask( 298 base::ThreadTaskRunnerHandle::Get()->PostTask(
308 FROM_HERE, 299 FROM_HERE,
309 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionError, 300 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionError,
310 GetWeakPtr(), session, callback, 301 GetWeakPtr(), session, callback,
311 BluetoothRemoteGattService::GATT_ERROR_FAILED)); 302 BluetoothRemoteGattService::GATT_ERROR_FAILED));
312 return; 303 return;
313 } 304 }
314 305
315 UnsubscribeFromNotifications( 306 UnsubscribeFromNotifications(
316 ccc_descriptor[0], 307 ccc_descriptor[0],
317 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionSuccess, 308 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionSuccess,
318 GetWeakPtr(), session, callback), 309 GetWeakPtr(), session, callback),
319 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionError, 310 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionError,
320 GetWeakPtr(), session, callback)); 311 GetWeakPtr(), session, callback));
321 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) || defined(OS_MACOSX) || 312 #endif // defined(OS_MACOSX) || defined(OS_WIN)
322 // defined(OS_WIN)
323 } 313 }
324 314
325 void BluetoothRemoteGattCharacteristic::CancelStopNotifySession( 315 void BluetoothRemoteGattCharacteristic::CancelStopNotifySession(
326 base::Closure callback) { 316 base::Closure callback) {
327 std::unique_ptr<NotifySessionCommand> command = 317 std::unique_ptr<NotifySessionCommand> command =
328 std::move(pending_notify_commands_.front()); 318 std::move(pending_notify_commands_.front());
329 pending_notify_commands_.pop(); 319 pending_notify_commands_.pop();
330 callback.Run(); 320 callback.Run();
331 } 321 }
332 322
(...skipping 29 matching lines...) Expand all
362 352
363 pending_notify_commands_.pop(); 353 pending_notify_commands_.pop();
364 if (!pending_notify_commands_.empty()) { 354 if (!pending_notify_commands_.empty()) {
365 pending_notify_commands_.front()->Execute( 355 pending_notify_commands_.front()->Execute(
366 NotifySessionCommand::COMMAND_STOP, NotifySessionCommand::RESULT_ERROR, 356 NotifySessionCommand::COMMAND_STOP, NotifySessionCommand::RESULT_ERROR,
367 error); 357 error);
368 } 358 }
369 } 359 }
370 360
371 } // namespace device 361 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698