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

Side by Side Diff: device/bluetooth/bluetooth_low_energy_device_mac.mm

Issue 2784373003: bluetooth: macOS: Adding explicit function to log NSError (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
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 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" 5 #include "device/bluetooth/bluetooth_low_energy_device_mac.h"
6 6
7 #import <CoreFoundation/CoreFoundation.h> 7 #import <CoreFoundation/CoreFoundation.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 VLOG(1) << *this 194 VLOG(1) << *this
195 << ": BluetoothLowEnergyDeviceMac::discovery_pending_count_ " 195 << ": BluetoothLowEnergyDeviceMac::discovery_pending_count_ "
196 << discovery_pending_count_; 196 << discovery_pending_count_;
197 discovery_pending_count_ = 0; 197 discovery_pending_count_ = 0;
198 return; 198 return;
199 } 199 }
200 if (error) { 200 if (error) {
201 // TODO(http://crbug.com/609320): Need to pass the error. 201 // TODO(http://crbug.com/609320): Need to pass the error.
202 // TODO(http://crbug.com/609844): Decide what to do if discover failed 202 // TODO(http://crbug.com/609844): Decide what to do if discover failed
203 // a device services. 203 // a device services.
204 VLOG(1) << *this << ": Can't discover primary services: " << error; 204 VLOG(1) << *this << ": Can't discover primary services: "
205 << BluetoothAdapterMac::String(error);
205 return; 206 return;
206 } 207 }
207 208
208 if (!IsGattConnected()) { 209 if (!IsGattConnected()) {
209 // Don't create services if the device disconnected. 210 // Don't create services if the device disconnected.
210 VLOG(1) << *this << ": DidDiscoverPrimaryServices, gatt not connected."; 211 VLOG(1) << *this << ": DidDiscoverPrimaryServices, gatt not connected.";
211 return; 212 return;
212 } 213 }
213 VLOG(1) << *this << ": DidDiscoverPrimaryServices, pending count: " 214 VLOG(1) << *this << ": DidDiscoverPrimaryServices, pending count: "
214 << discovery_pending_count_; 215 << discovery_pending_count_;
(...skipping 23 matching lines...) Expand all
238 SendNotificationIfDiscoveryComplete(); 239 SendNotificationIfDiscoveryComplete();
239 } 240 }
240 } 241 }
241 242
242 void BluetoothLowEnergyDeviceMac::DidDiscoverCharacteristics( 243 void BluetoothLowEnergyDeviceMac::DidDiscoverCharacteristics(
243 CBService* cb_service, 244 CBService* cb_service,
244 NSError* error) { 245 NSError* error) {
245 if (error) { 246 if (error) {
246 // TODO(http://crbug.com/609320): Need to pass the error. 247 // TODO(http://crbug.com/609320): Need to pass the error.
247 // TODO(http://crbug.com/609844): Decide what to do if discover failed 248 // TODO(http://crbug.com/609844): Decide what to do if discover failed
248 VLOG(1) << *this << ": Can't discover characteristics: " << error; 249 VLOG(1) << *this << ": Can't discover characteristics: "
250 << BluetoothAdapterMac::String(error);
249 return; 251 return;
250 } 252 }
251 253
252 if (!IsGattConnected()) { 254 if (!IsGattConnected()) {
253 VLOG(1) << *this << ": DidDiscoverCharacteristics, gatt disconnected."; 255 VLOG(1) << *this << ": DidDiscoverCharacteristics, gatt disconnected.";
254 // Don't create characteristics if the device disconnected. 256 // Don't create characteristics if the device disconnected.
255 return; 257 return;
256 } 258 }
257 259
258 BluetoothRemoteGattServiceMac* gatt_service = 260 BluetoothRemoteGattServiceMac* gatt_service =
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 DCHECK(gatt_service); 311 DCHECK(gatt_service);
310 gatt_service->DidUpdateNotificationState(characteristic, error); 312 gatt_service->DidUpdateNotificationState(characteristic, error);
311 } 313 }
312 314
313 void BluetoothLowEnergyDeviceMac::DidDiscoverDescriptors( 315 void BluetoothLowEnergyDeviceMac::DidDiscoverDescriptors(
314 CBCharacteristic* cb_characteristic, 316 CBCharacteristic* cb_characteristic,
315 NSError* error) { 317 NSError* error) {
316 if (error) { 318 if (error) {
317 // TODO(http://crbug.com/609320): Need to pass the error. 319 // TODO(http://crbug.com/609320): Need to pass the error.
318 // TODO(http://crbug.com/609844): Decide what to do if discover failed 320 // TODO(http://crbug.com/609844): Decide what to do if discover failed
319 VLOG(1) << *this << ": Can't discover descriptors: " << error; 321 VLOG(1) << *this << ": Can't discover descriptors: "
322 << BluetoothAdapterMac::String(error);
320 return; 323 return;
321 } 324 }
322 if (!IsGattConnected()) { 325 if (!IsGattConnected()) {
323 VLOG(1) << *this << ": DidDiscoverDescriptors, disconnected."; 326 VLOG(1) << *this << ": DidDiscoverDescriptors, disconnected.";
324 // Don't discover descriptors if the device disconnected. 327 // Don't discover descriptors if the device disconnected.
325 return; 328 return;
326 } 329 }
327 BluetoothRemoteGattServiceMac* gatt_service = 330 BluetoothRemoteGattServiceMac* gatt_service =
328 GetBluetoothRemoteGattService(cb_characteristic.service); 331 GetBluetoothRemoteGattService(cb_characteristic.service);
329 DCHECK(gatt_service); 332 DCHECK(gatt_service);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service); 398 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service);
396 if (gatt_service_mac->GetService() == cb_service) 399 if (gatt_service_mac->GetService() == cb_service)
397 return gatt_service_mac; 400 return gatt_service_mac;
398 } 401 }
399 return nullptr; 402 return nullptr;
400 } 403 }
401 404
402 void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral(NSError* error) { 405 void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral(NSError* error) {
403 VLOG(1) << *this << ": Disconnected from peripheral."; 406 VLOG(1) << *this << ": Disconnected from peripheral.";
404 if (error) { 407 if (error) {
405 VLOG(1) << *this << ": Bluetooth error: " << error; 408 VLOG(1) << *this
409 << ": Bluetooth error: " << BluetoothAdapterMac::String(error);
406 } 410 }
407 SetGattServicesDiscoveryComplete(false); 411 SetGattServicesDiscoveryComplete(false);
408 // Removing all services at once to ensure that calling GetGattService on 412 // Removing all services at once to ensure that calling GetGattService on
409 // removed service in GattServiceRemoved returns null. 413 // removed service in GattServiceRemoved returns null.
410 GattServiceMap gatt_services_swapped; 414 GattServiceMap gatt_services_swapped;
411 gatt_services_swapped.swap(gatt_services_); 415 gatt_services_swapped.swap(gatt_services_);
412 gatt_services_swapped.clear(); 416 gatt_services_swapped.clear();
413 device_uuids_.ClearServiceUUIDs(); 417 device_uuids_.ClearServiceUUIDs();
414 // There are two cases in which this function will be called: 418 // There are two cases in which this function will be called:
415 // 1. When the connection to the device breaks (either because 419 // 1. When the connection to the device breaks (either because
(...skipping 14 matching lines...) Expand all
430 std::ostream& operator<<(std::ostream& out, 434 std::ostream& operator<<(std::ostream& out,
431 const BluetoothLowEnergyDeviceMac& device) { 435 const BluetoothLowEnergyDeviceMac& device) {
432 // TODO(crbug.com/703878): Should use 436 // TODO(crbug.com/703878): Should use
433 // BluetoothLowEnergyDeviceMac::GetNameForDisplay() instead. 437 // BluetoothLowEnergyDeviceMac::GetNameForDisplay() instead.
434 base::Optional<std::string> name = device.GetName(); 438 base::Optional<std::string> name = device.GetName();
435 const char* name_cstr = name ? name->c_str() : ""; 439 const char* name_cstr = name ? name->c_str() : "";
436 return out << "<BluetoothLowEnergyDeviceMac " << device.GetAddress() << "/" 440 return out << "<BluetoothLowEnergyDeviceMac " << device.GetAddress() << "/"
437 << &device << ", \"" << name_cstr << "\">"; 441 << &device << ", \"" << name_cstr << "\">";
438 } 442 }
439 } // namespace device 443 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_mac.mm ('k') | device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698