bluetooth_device_mac.mm 2.4 KB

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