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

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

Issue 2767813002: Bluetooth: macOS: Implementing read/write for descriptors (Closed)
Patch Set: NSString/NSNumber type for descriptor value 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"
11 #include "base/mac/scoped_cftyperef.h" 11 #include "base/mac/scoped_cftyperef.h"
12 #include "base/mac/sdk_forward_declarations.h" 12 #include "base/mac/sdk_forward_declarations.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/sys_string_conversions.h" 15 #include "base/strings/sys_string_conversions.h"
16 #include "device/bluetooth/bluetooth_adapter_mac.h" 16 #include "device/bluetooth/bluetooth_adapter_mac.h"
17 #include "device/bluetooth/bluetooth_device.h" 17 #include "device/bluetooth/bluetooth_device.h"
18 #include "device/bluetooth/bluetooth_low_energy_peripheral_delegate.h" 18 #include "device/bluetooth/bluetooth_low_energy_peripheral_delegate.h"
19 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h"
20 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_mac.h"
19 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" 21 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h"
20 22
21 using device::BluetoothDevice; 23 using device::BluetoothDevice;
22 using device::BluetoothLowEnergyDeviceMac; 24 using device::BluetoothLowEnergyDeviceMac;
23 25
24 BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac( 26 BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac(
25 BluetoothAdapterMac* adapter, 27 BluetoothAdapterMac* adapter,
26 CBPeripheral* peripheral) 28 CBPeripheral* peripheral)
27 : BluetoothDeviceMac(adapter), 29 : BluetoothDeviceMac(adapter),
28 peripheral_(peripheral, base::scoped_policy::RETAIN), 30 peripheral_(peripheral, base::scoped_policy::RETAIN),
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // Don't discover descriptors if the device disconnected. 327 // Don't discover descriptors if the device disconnected.
326 return; 328 return;
327 } 329 }
328 BluetoothRemoteGattServiceMac* gatt_service = 330 BluetoothRemoteGattServiceMac* gatt_service =
329 GetBluetoothRemoteGattService(cb_characteristic.service); 331 GetBluetoothRemoteGattService(cb_characteristic.service);
330 DCHECK(gatt_service); 332 DCHECK(gatt_service);
331 gatt_service->DidDiscoverDescriptors(cb_characteristic); 333 gatt_service->DidDiscoverDescriptors(cb_characteristic);
332 SendNotificationIfDiscoveryComplete(); 334 SendNotificationIfDiscoveryComplete();
333 } 335 }
334 336
337 void BluetoothLowEnergyDeviceMac::DidUpdateValueForDescriptor(
338 CBDescriptor* cb_descriptor,
339 NSError* error) {
340 BluetoothRemoteGattDescriptorMac* gatt_descriptor =
341 GetBluetoothRemoteGattDescriptor(cb_descriptor);
342 DCHECK(gatt_descriptor);
343 gatt_descriptor->DidUpdateValueForDescriptor(error);
344 }
345
346 void BluetoothLowEnergyDeviceMac::DidWriteValueForDescriptor(
347 CBDescriptor* cb_descriptor,
348 NSError* error) {
349 BluetoothRemoteGattDescriptorMac* gatt_descriptor =
350 GetBluetoothRemoteGattDescriptor(cb_descriptor);
351 DCHECK(gatt_descriptor);
352 gatt_descriptor->DidWriteValueForDescriptor(error);
353 }
354
335 // static 355 // static
336 std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier( 356 std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(
337 CBPeripheral* peripheral) { 357 CBPeripheral* peripheral) {
338 DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable()); 358 DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable());
339 NSUUID* uuid = [peripheral identifier]; 359 NSUUID* uuid = [peripheral identifier];
340 NSString* uuidString = [uuid UUIDString]; 360 NSString* uuidString = [uuid UUIDString];
341 return base::SysNSStringToUTF8(uuidString); 361 return base::SysNSStringToUTF8(uuidString);
342 } 362 }
343 363
344 // static 364 // static
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 for (auto it = gatt_services_.begin(); it != gatt_services_.end(); ++it) { 413 for (auto it = gatt_services_.begin(); it != gatt_services_.end(); ++it) {
394 device::BluetoothRemoteGattService* gatt_service = it->second.get(); 414 device::BluetoothRemoteGattService* gatt_service = it->second.get();
395 device::BluetoothRemoteGattServiceMac* gatt_service_mac = 415 device::BluetoothRemoteGattServiceMac* gatt_service_mac =
396 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service); 416 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service);
397 if (gatt_service_mac->GetService() == cb_service) 417 if (gatt_service_mac->GetService() == cb_service)
398 return gatt_service_mac; 418 return gatt_service_mac;
399 } 419 }
400 return nullptr; 420 return nullptr;
401 } 421 }
402 422
423 device::BluetoothRemoteGattDescriptorMac*
424 BluetoothLowEnergyDeviceMac::GetBluetoothRemoteGattDescriptor(
425 CBDescriptor* cb_descriptor) const {
426 CBCharacteristic* cb_characteristic = cb_descriptor.characteristic;
427 device::BluetoothRemoteGattServiceMac* gatt_service =
428 GetBluetoothRemoteGattService(cb_characteristic.service);
429 DCHECK(gatt_service);
430 device::BluetoothRemoteGattCharacteristicMac* gatt_characteristic =
431 gatt_service->GetBluetoothRemoteGattCharacteristicMac(cb_characteristic);
432 DCHECK(gatt_characteristic);
433 return gatt_characteristic->GetBluetoothRemoteGattDescriptorMac(
ortuno 2017/04/04 23:39:43 optional: Is GetBluetoothRemoteGattDescriptorMac a
jlebel 2017/04/06 17:48:49 crbug.com/709100
434 cb_descriptor);
435 }
436
403 void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral(NSError* error) { 437 void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral(NSError* error) {
404 VLOG(1) << *this << ": Disconnected from peripheral."; 438 VLOG(1) << *this << ": Disconnected from peripheral.";
405 if (error) { 439 if (error) {
406 VLOG(1) << *this 440 VLOG(1) << *this
407 << ": Bluetooth error: " << BluetoothAdapterMac::String(error); 441 << ": Bluetooth error: " << BluetoothAdapterMac::String(error);
408 } 442 }
409 SetGattServicesDiscoveryComplete(false); 443 SetGattServicesDiscoveryComplete(false);
410 // Removing all services at once to ensure that calling GetGattService on 444 // Removing all services at once to ensure that calling GetGattService on
411 // removed service in GattServiceRemoved returns null. 445 // removed service in GattServiceRemoved returns null.
412 GattServiceMap gatt_services_swapped; 446 GattServiceMap gatt_services_swapped;
(...skipping 19 matching lines...) Expand all
432 std::ostream& operator<<(std::ostream& out, 466 std::ostream& operator<<(std::ostream& out,
433 const BluetoothLowEnergyDeviceMac& device) { 467 const BluetoothLowEnergyDeviceMac& device) {
434 // TODO(crbug.com/703878): Should use 468 // TODO(crbug.com/703878): Should use
435 // BluetoothLowEnergyDeviceMac::GetNameForDisplay() instead. 469 // BluetoothLowEnergyDeviceMac::GetNameForDisplay() instead.
436 base::Optional<std::string> name = device.GetName(); 470 base::Optional<std::string> name = device.GetName();
437 const char* name_cstr = name ? name->c_str() : ""; 471 const char* name_cstr = name ? name->c_str() : "";
438 return out << "<BluetoothLowEnergyDeviceMac " << device.GetAddress() << "/" 472 return out << "<BluetoothLowEnergyDeviceMac " << device.GetAddress() << "/"
439 << &device << ", \"" << name_cstr << "\">"; 473 << &device << ", \"" << name_cstr << "\">";
440 } 474 }
441 } // namespace device 475 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698