OLD | NEW |
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_device_mac.h" | 5 #include "device/bluetooth/bluetooth_device_mac.h" |
6 | 6 |
7 #include "device/bluetooth/bluetooth_adapter_mac.h" | 7 #include "device/bluetooth/bluetooth_adapter_mac.h" |
8 | 8 |
9 static NSString* const kErrorDomain = @"ConnectErrorCode"; | 9 static NSString* const kConnectErrorDomain = @"ConnectErrorCode"; |
| 10 static NSString* const kGattErrorDomain = @"GattErrorCode"; |
10 | 11 |
11 namespace device { | 12 namespace device { |
12 | 13 |
13 BluetoothDeviceMac::BluetoothDeviceMac(BluetoothAdapterMac* adapter) | 14 BluetoothDeviceMac::BluetoothDeviceMac(BluetoothAdapterMac* adapter) |
14 : BluetoothDevice(adapter) {} | 15 : BluetoothDevice(adapter) {} |
15 | 16 |
16 BluetoothDeviceMac::~BluetoothDeviceMac() { | 17 BluetoothDeviceMac::~BluetoothDeviceMac() { |
17 } | 18 } |
18 | 19 |
19 NSError* BluetoothDeviceMac::GetNSErrorFromConnectErrorCode( | 20 NSError* BluetoothDeviceMac::GetNSErrorFromConnectErrorCode( |
20 BluetoothDevice::ConnectErrorCode error_code) { | 21 BluetoothDevice::ConnectErrorCode error_code) { |
21 // TODO(http://crbug.com/585894): Need to convert the error. | 22 // TODO(http://crbug.com/585894): Need to convert the error. |
22 return [NSError errorWithDomain:kErrorDomain code:error_code userInfo:nil]; | 23 return [NSError errorWithDomain:kConnectErrorDomain |
| 24 code:error_code |
| 25 userInfo:nil]; |
23 } | 26 } |
24 | 27 |
25 BluetoothDevice::ConnectErrorCode | 28 BluetoothDevice::ConnectErrorCode |
26 BluetoothDeviceMac::GetConnectErrorCodeFromNSError(NSError* error) { | 29 BluetoothDeviceMac::GetConnectErrorCodeFromNSError(NSError* error) { |
27 if ([error.domain isEqualToString:kErrorDomain]) { | 30 if ([error.domain isEqualToString:kConnectErrorDomain]) { |
28 BluetoothDevice::ConnectErrorCode connect_error_code = | 31 BluetoothDevice::ConnectErrorCode connect_error_code = |
29 (BluetoothDevice::ConnectErrorCode)error.code; | 32 (BluetoothDevice::ConnectErrorCode)error.code; |
30 if (connect_error_code >= 0 || | 33 if (connect_error_code >= 0 || |
31 connect_error_code < BluetoothDevice::NUM_CONNECT_ERROR_CODES) { | 34 connect_error_code < BluetoothDevice::NUM_CONNECT_ERROR_CODES) { |
32 return connect_error_code; | 35 return connect_error_code; |
33 } | 36 } |
34 DCHECK(false); | 37 DCHECK(false); |
35 return BluetoothDevice::ERROR_FAILED; | 38 return BluetoothDevice::ERROR_FAILED; |
36 } | 39 } |
37 // TODO(http://crbug.com/585894): Need to convert the error. | 40 // TODO(http://crbug.com/585894): Need to convert the error. |
38 return BluetoothDevice::ERROR_FAILED; | 41 return BluetoothDevice::ERROR_FAILED; |
39 } | 42 } |
40 | 43 |
| 44 NSError* BluetoothDeviceMac::GetNSErrorFromGattErrorCode( |
| 45 BluetoothGattService::GattErrorCode error_code) { |
| 46 // TODO(http://crbug.com/619595): Need to convert the GattErrorCode vale to |
| 47 // a CBError value. |
| 48 return |
| 49 [NSError errorWithDomain:kGattErrorDomain code:error_code userInfo:nil]; |
| 50 } |
| 51 |
| 52 BluetoothGattService::GattErrorCode |
| 53 BluetoothDeviceMac::GetGattErrorCodeFromNSError(NSError* error) { |
| 54 if ([error.domain isEqualToString:kGattErrorDomain]) { |
| 55 BluetoothGattService::GattErrorCode gatt_error_code = |
| 56 (BluetoothGattService::GattErrorCode)error.code; |
| 57 if (gatt_error_code >= 0 || |
| 58 gatt_error_code <= BluetoothGattService::GATT_ERROR_NOT_SUPPORTED) { |
| 59 return gatt_error_code; |
| 60 } |
| 61 NOTREACHED(); |
| 62 return BluetoothGattService::GATT_ERROR_FAILED; |
| 63 } |
| 64 // TODO(http://crbug.com/619595): Need to convert the error code from |
| 65 // CoreBluetooth to a GattErrorCode value. |
| 66 return BluetoothGattService::GATT_ERROR_FAILED; |
| 67 } |
| 68 |
41 } // namespace device | 69 } // namespace device |
OLD | NEW |