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

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

Issue 1685963003: Adding the last test related with connect/disconnect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@connectdisconnect
Patch Set: Issue to convert no NSError to ConnectErrorCode Created 4 years, 10 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 | « device/bluetooth/bluetooth_adapter_mac.h ('k') | device/bluetooth/bluetooth_device_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_adapter_mac.h" 5 #include "device/bluetooth/bluetooth_adapter_mac.h"
6 6
7 #import <IOBluetooth/objc/IOBluetoothDevice.h> 7 #import <IOBluetooth/objc/IOBluetoothDevice.h>
8 #import <IOBluetooth/objc/IOBluetoothHostController.h> 8 #import <IOBluetooth/objc/IOBluetoothHostController.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 24 matching lines...) Expand all
35 // The frequency with which to poll the adapter for updates. 35 // The frequency with which to poll the adapter for updates.
36 const int kPollIntervalMs = 500; 36 const int kPollIntervalMs = 500;
37 37
38 } // namespace 38 } // namespace
39 39
40 namespace device { 40 namespace device {
41 41
42 // static 42 // static
43 const NSTimeInterval BluetoothAdapterMac::kDiscoveryTimeoutSec = 43 const NSTimeInterval BluetoothAdapterMac::kDiscoveryTimeoutSec =
44 180; // 3 minutes 44 180; // 3 minutes
45 static NSString* const kErrorDomain = @"ConnectErrorCode";
45 46
46 // static 47 // static
47 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( 48 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter(
48 const InitCallback& init_callback) { 49 const InitCallback& init_callback) {
49 return BluetoothAdapterMac::CreateAdapter(); 50 return BluetoothAdapterMac::CreateAdapter();
50 } 51 }
51 52
52 // static 53 // static
53 base::WeakPtr<BluetoothAdapterMac> BluetoothAdapterMac::CreateAdapter() { 54 base::WeakPtr<BluetoothAdapterMac> BluetoothAdapterMac::CreateAdapter() {
54 BluetoothAdapterMac* adapter = new BluetoothAdapterMac(); 55 BluetoothAdapterMac* adapter = new BluetoothAdapterMac();
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 } 567 }
567 568
568 void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral, 569 void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral,
569 NSError* error) { 570 NSError* error) {
570 BluetoothLowEnergyDeviceMac* device_mac = 571 BluetoothLowEnergyDeviceMac* device_mac =
571 GetBluetoothLowEnergyDeviceMac(peripheral); 572 GetBluetoothLowEnergyDeviceMac(peripheral);
572 if (!device_mac) { 573 if (!device_mac) {
573 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; 574 [low_energy_central_manager_ cancelPeripheralConnection:peripheral];
574 return; 575 return;
575 } 576 }
576 // TODO(http://crbug.com/585894): Need to convert the error. 577 BluetoothDevice::ConnectErrorCode error_code =
577 device_mac->DidFailToConnectGatt(BluetoothClassicDeviceMac::ERROR_UNKNOWN); 578 BluetoothAdapterMac::GetConnectErrorCodeFromNSError(error);
579 device_mac->DidFailToConnectGatt(error_code);
578 } 580 }
579 581
580 void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral, 582 void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral,
581 NSError* error) { 583 NSError* error) {
582 BluetoothLowEnergyDeviceMac* device_mac = 584 BluetoothLowEnergyDeviceMac* device_mac =
583 GetBluetoothLowEnergyDeviceMac(peripheral); 585 GetBluetoothLowEnergyDeviceMac(peripheral);
584 if (!device_mac) { 586 if (!device_mac) {
585 [low_energy_central_manager_ cancelPeripheralConnection:peripheral]; 587 [low_energy_central_manager_ cancelPeripheralConnection:peripheral];
586 return; 588 return;
587 } 589 }
588 // TODO(http://crbug.com/585897): Need to pass the error. 590 BluetoothDevice::ConnectErrorCode error_code =
589 device_mac->DidDisconnectPeripheral(); 591 BluetoothAdapterMac::GetConnectErrorCodeFromNSError(error);
592 device_mac->DidDisconnectPeripheral(error_code);
590 } 593 }
591 594
592 BluetoothLowEnergyDeviceMac* 595 BluetoothLowEnergyDeviceMac*
593 BluetoothAdapterMac::GetBluetoothLowEnergyDeviceMac(CBPeripheral* peripheral) { 596 BluetoothAdapterMac::GetBluetoothLowEnergyDeviceMac(CBPeripheral* peripheral) {
594 std::string device_address = 597 std::string device_address =
595 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); 598 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
596 // Try to find device from |devices_| with key |device_address|, 599 // Try to find device from |devices_| with key |device_address|,
597 // if has no entry in the map, disconnect the peripheral. 600 // if has no entry in the map, disconnect the peripheral.
598 DevicesMap::const_iterator iter = devices_.find(device_address); 601 DevicesMap::const_iterator iter = devices_.find(device_address);
599 if (iter == devices_.end()) { 602 if (iter == devices_.end()) {
600 return nil; 603 return nil;
601 } 604 }
602 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); 605 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second);
603 } 606 }
604 607
608 NSError* BluetoothAdapterMac::GetNSErrorFromConnectErrorCode(
609 BluetoothDevice::ConnectErrorCode error_code) {
610 // TODO(http://crbug.com/585894): Need to convert the error.
611 return [NSError errorWithDomain:kErrorDomain code:error_code userInfo:nil];
612 }
613
614 BluetoothDevice::ConnectErrorCode
615 BluetoothAdapterMac::GetConnectErrorCodeFromNSError(NSError* error) {
616 if ([error.domain isEqualToString:kErrorDomain]) {
617 switch ((BluetoothDevice::ConnectErrorCode)error.code) {
scheib 2016/02/10 23:48:16 I don't think this static cast will work. The Blue
jlebel 2016/02/11 00:03:43 I'm not sure to understand. This switch is execute
scheib 2016/03/02 05:33:22 OK, I didn't see or properly understand the NSErro
jlebel 2016/03/02 15:34:32 Yes, of course!
618 case BluetoothDevice::ERROR_ATTRIBUTE_LENGTH_INVALID:
619 return BluetoothDevice::ERROR_ATTRIBUTE_LENGTH_INVALID;
620 case BluetoothDevice::ERROR_AUTH_CANCELED:
621 return BluetoothDevice::ERROR_AUTH_CANCELED;
622 case BluetoothDevice::ERROR_AUTH_FAILED:
623 return BluetoothDevice::ERROR_AUTH_FAILED;
624 case BluetoothDevice::ERROR_AUTH_REJECTED:
625 return BluetoothDevice::ERROR_AUTH_REJECTED;
626 case BluetoothDevice::ERROR_AUTH_TIMEOUT:
627 return BluetoothDevice::ERROR_AUTH_TIMEOUT;
628 case BluetoothDevice::ERROR_CONNECTION_CONGESTED:
629 return BluetoothDevice::ERROR_CONNECTION_CONGESTED;
630 case BluetoothDevice::ERROR_FAILED:
631 return BluetoothDevice::ERROR_FAILED;
632 case BluetoothDevice::ERROR_INPROGRESS:
633 return BluetoothDevice::ERROR_INPROGRESS;
634 case BluetoothDevice::ERROR_INSUFFICIENT_ENCRYPTION:
635 return BluetoothDevice::ERROR_INSUFFICIENT_ENCRYPTION;
636 case BluetoothDevice::ERROR_OFFSET_INVALID:
637 return BluetoothDevice::ERROR_OFFSET_INVALID;
638 case BluetoothDevice::ERROR_READ_NOT_PERMITTED:
639 return BluetoothDevice::ERROR_READ_NOT_PERMITTED;
640 case BluetoothDevice::ERROR_REQUEST_NOT_SUPPORTED:
641 return BluetoothDevice::ERROR_REQUEST_NOT_SUPPORTED;
642 case BluetoothDevice::ERROR_UNKNOWN:
643 return BluetoothDevice::ERROR_UNKNOWN;
644 case BluetoothDevice::ERROR_UNSUPPORTED_DEVICE:
645 return BluetoothDevice::ERROR_UNSUPPORTED_DEVICE;
646 case BluetoothDevice::ERROR_WRITE_NOT_PERMITTED:
647 return BluetoothDevice::ERROR_WRITE_NOT_PERMITTED;
648 case BluetoothDevice::NUM_CONNECT_ERROR_CODES:
649 DCHECK(false);
650 return BluetoothDevice::ERROR_UNKNOWN;
651 }
652 }
653 // TODO(http://crbug.com/585894): Need to convert the error.
654 return BluetoothDevice::ERROR_UNKNOWN;
655 }
656
605 } // namespace device 657 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_mac.h ('k') | device/bluetooth/bluetooth_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698