OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 |
| 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h" |
| 6 |
| 7 #import <CoreBluetooth/CoreBluetooth.h> |
| 8 |
| 9 #include "device/bluetooth/bluetooth_adapter_mac.h" |
| 10 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" |
| 11 |
| 12 namespace device { |
| 13 |
| 14 namespace { |
| 15 |
| 16 static BluetoothGattCharacteristic::Properties ConvertProperties( |
| 17 CBCharacteristicProperties cb_property) { |
| 18 BluetoothGattCharacteristic::Properties result = |
| 19 BluetoothGattCharacteristic::PROPERTY_NONE; |
| 20 if (cb_property & CBCharacteristicPropertyBroadcast) { |
| 21 result |= BluetoothGattCharacteristic::PROPERTY_BROADCAST; |
| 22 } |
| 23 if (cb_property & CBCharacteristicPropertyRead) { |
| 24 result |= BluetoothGattCharacteristic::PROPERTY_READ; |
| 25 } |
| 26 if (cb_property & CBCharacteristicPropertyWriteWithoutResponse) { |
| 27 result |= BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE; |
| 28 } |
| 29 if (cb_property & CBCharacteristicPropertyWrite) { |
| 30 result |= BluetoothGattCharacteristic::PROPERTY_WRITE; |
| 31 } |
| 32 if (cb_property & CBCharacteristicPropertyNotify) { |
| 33 result |= BluetoothGattCharacteristic::PROPERTY_NOTIFY; |
| 34 } |
| 35 if (cb_property & CBCharacteristicPropertyIndicate) { |
| 36 result |= BluetoothGattCharacteristic::PROPERTY_INDICATE; |
| 37 } |
| 38 if (cb_property & CBCharacteristicPropertyAuthenticatedSignedWrites) { |
| 39 result |= BluetoothGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES; |
| 40 } |
| 41 if (cb_property & CBCharacteristicPropertyExtendedProperties) { |
| 42 result |= BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES; |
| 43 } |
| 44 if (cb_property & CBCharacteristicPropertyNotifyEncryptionRequired) { |
| 45 // This property is used only in CBMutableCharacteristic |
| 46 // (local characteristic). So this value should never appear for |
| 47 // CBCharacteristic (remote characteristic). Apple is not able to send |
| 48 // this value over BLE since it is not part of the spec. |
| 49 DCHECK(false); |
| 50 result |= BluetoothGattCharacteristic::PROPERTY_NOTIFY; |
| 51 } |
| 52 if (cb_property & CBCharacteristicPropertyIndicateEncryptionRequired) { |
| 53 // This property is used only in CBMutableCharacteristic |
| 54 // (local characteristic). So this value should never appear for |
| 55 // CBCharacteristic (remote characteristic). Apple is not able to send |
| 56 // this value over BLE since it is not part of the spec. |
| 57 DCHECK(false); |
| 58 result |= BluetoothGattCharacteristic::PROPERTY_INDICATE; |
| 59 } |
| 60 return result; |
| 61 } |
| 62 } // namespace |
| 63 |
| 64 BluetoothRemoteGattCharacteristicMac::BluetoothRemoteGattCharacteristicMac( |
| 65 BluetoothRemoteGattServiceMac* gatt_service, |
| 66 CBCharacteristic* cb_characteristic) |
| 67 : gatt_service_(gatt_service), |
| 68 cb_characteristic_(cb_characteristic, base::scoped_policy::RETAIN) { |
| 69 uuid_ = BluetoothAdapterMac::BluetoothUUIDWithCBUUID( |
| 70 [cb_characteristic_.get() UUID]); |
| 71 identifier_ = |
| 72 [NSString stringWithFormat:@"%s-%p", uuid_.canonical_value().c_str(), |
| 73 (void*)cb_characteristic_] |
| 74 .UTF8String; |
| 75 } |
| 76 |
| 77 BluetoothRemoteGattCharacteristicMac::~BluetoothRemoteGattCharacteristicMac() {} |
| 78 |
| 79 std::string BluetoothRemoteGattCharacteristicMac::GetIdentifier() const { |
| 80 return identifier_; |
| 81 } |
| 82 |
| 83 BluetoothUUID BluetoothRemoteGattCharacteristicMac::GetUUID() const { |
| 84 return uuid_; |
| 85 } |
| 86 |
| 87 BluetoothGattCharacteristic::Properties |
| 88 BluetoothRemoteGattCharacteristicMac::GetProperties() const { |
| 89 return ConvertProperties(cb_characteristic_.get().properties); |
| 90 } |
| 91 |
| 92 BluetoothGattCharacteristic::Permissions |
| 93 BluetoothRemoteGattCharacteristicMac::GetPermissions() const { |
| 94 // Not supported for remote characteristics for CoreBluetooth. |
| 95 NOTIMPLEMENTED(); |
| 96 return PERMISSION_NONE; |
| 97 } |
| 98 |
| 99 const std::vector<uint8_t>& BluetoothRemoteGattCharacteristicMac::GetValue() |
| 100 const { |
| 101 return value_; |
| 102 } |
| 103 |
| 104 BluetoothRemoteGattService* BluetoothRemoteGattCharacteristicMac::GetService() |
| 105 const { |
| 106 return static_cast<BluetoothRemoteGattService*>(gatt_service_); |
| 107 } |
| 108 |
| 109 bool BluetoothRemoteGattCharacteristicMac::IsNotifying() const { |
| 110 NOTIMPLEMENTED(); |
| 111 return false; |
| 112 } |
| 113 |
| 114 std::vector<BluetoothRemoteGattDescriptor*> |
| 115 BluetoothRemoteGattCharacteristicMac::GetDescriptors() const { |
| 116 NOTIMPLEMENTED(); |
| 117 return std::vector<BluetoothRemoteGattDescriptor*>(); |
| 118 } |
| 119 |
| 120 BluetoothRemoteGattDescriptor* |
| 121 BluetoothRemoteGattCharacteristicMac::GetDescriptor( |
| 122 const std::string& identifier) const { |
| 123 NOTIMPLEMENTED(); |
| 124 return nullptr; |
| 125 } |
| 126 |
| 127 void BluetoothRemoteGattCharacteristicMac::StartNotifySession( |
| 128 const NotifySessionCallback& callback, |
| 129 const ErrorCallback& error_callback) { |
| 130 NOTIMPLEMENTED(); |
| 131 } |
| 132 |
| 133 void BluetoothRemoteGattCharacteristicMac::ReadRemoteCharacteristic( |
| 134 const ValueCallback& callback, |
| 135 const ErrorCallback& error_callback) { |
| 136 NOTIMPLEMENTED(); |
| 137 } |
| 138 |
| 139 void BluetoothRemoteGattCharacteristicMac::WriteRemoteCharacteristic( |
| 140 const std::vector<uint8_t>& new_value, |
| 141 const base::Closure& callback, |
| 142 const ErrorCallback& error_callback) { |
| 143 NOTIMPLEMENTED(); |
| 144 } |
| 145 |
| 146 CBCharacteristic* BluetoothRemoteGattCharacteristicMac::GetCBCharacteristic() |
| 147 const { |
| 148 return cb_characteristic_.get(); |
| 149 } |
| 150 |
| 151 } // namespace device. |
OLD | NEW |