Index: device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm |
diff --git a/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm b/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7d6f61d15b67ccf17e220bfe89aa8b51b1f4d1cc |
--- /dev/null |
+++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm |
@@ -0,0 +1,144 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h" |
+ |
+#import <CoreBluetooth/CoreBluetooth.h> |
+ |
+#include "device/bluetooth/bluetooth_adapter_mac.h" |
+#include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" |
+ |
+namespace device { |
+ |
+namespace { |
+ |
+static BluetoothGattCharacteristic::Properties |
+CBCharacteristicPropertyToGattCharacteristicProperty( |
scheib
2016/06/10 21:59:31
You can leave this, but FYI:
. Only called from Ge
jlebel
2016/06/10 23:02:45
Done.
|
+ CBCharacteristicProperties cb_property) { |
+ BluetoothGattCharacteristic::Properties result = |
+ BluetoothGattCharacteristic::PROPERTY_NONE; |
+ if (cb_property & CBCharacteristicPropertyBroadcast) { |
+ result |= BluetoothGattCharacteristic::PROPERTY_BROADCAST; |
+ } |
+ if (cb_property & CBCharacteristicPropertyRead) { |
+ result |= BluetoothGattCharacteristic::PROPERTY_READ; |
+ } |
+ if (cb_property & CBCharacteristicPropertyWriteWithoutResponse) { |
+ result |= BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE; |
+ } |
+ if (cb_property & CBCharacteristicPropertyWrite) { |
+ result |= BluetoothGattCharacteristic::PROPERTY_WRITE; |
+ } |
+ if (cb_property & CBCharacteristicPropertyNotify) { |
+ result |= BluetoothGattCharacteristic::PROPERTY_NOTIFY; |
+ } |
+ if (cb_property & CBCharacteristicPropertyIndicate) { |
+ result |= BluetoothGattCharacteristic::PROPERTY_INDICATE; |
+ } |
+ if (cb_property & CBCharacteristicPropertyAuthenticatedSignedWrites) { |
+ result |= BluetoothGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES; |
+ } |
+ if (cb_property & CBCharacteristicPropertyExtendedProperties) { |
+ result |= BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES; |
+ } |
+ if (cb_property & CBCharacteristicPropertyNotifyEncryptionRequired) { |
+ // This should never happens for a remote characteristic |
scheib
2016/06/10 21:59:31
Explain this more here, especially because it is n
jlebel
2016/06/10 23:02:45
Done.
|
+ // (or a CBCharacteristic) |
+ DCHECK(false); |
+ result |= BluetoothGattCharacteristic::PROPERTY_NOTIFY; |
+ } |
+ if (cb_property & CBCharacteristicPropertyIndicateEncryptionRequired) { |
+ // This should never happens for a remote characteristic |
+ // (or a CBCharacteristic) |
+ DCHECK(false); |
+ result |= BluetoothGattCharacteristic::PROPERTY_INDICATE; |
+ } |
+ return result; |
+} |
+} // namespace |
+ |
+BluetoothRemoteGattCharacteristicMac::BluetoothRemoteGattCharacteristicMac( |
+ BluetoothRemoteGattServiceMac* gatt_service, |
+ CBCharacteristic* cb_characteristic) |
+ : gatt_service_(gatt_service), |
+ cb_characteristic_(cb_characteristic, base::scoped_policy::RETAIN) { |
+ uuid_ = BluetoothAdapterMac::BluetoothUUIDWithCBUUID( |
+ [cb_characteristic_.get() UUID]); |
+ identifier_ = |
+ [NSString stringWithFormat:@"%s-%p", uuid_.canonical_value().c_str(), |
+ (void*)cb_characteristic_] |
+ .UTF8String; |
+} |
+ |
+BluetoothRemoteGattCharacteristicMac::~BluetoothRemoteGattCharacteristicMac() {} |
+ |
+std::string BluetoothRemoteGattCharacteristicMac::GetIdentifier() const { |
+ return identifier_; |
+} |
+ |
+BluetoothUUID BluetoothRemoteGattCharacteristicMac::GetUUID() const { |
+ return uuid_; |
+} |
+ |
+BluetoothGattCharacteristic::Properties |
+BluetoothRemoteGattCharacteristicMac::GetProperties() const { |
+ return CBCharacteristicPropertyToGattCharacteristicProperty( |
+ cb_characteristic_.get().properties); |
+} |
+ |
+BluetoothGattCharacteristic::Permissions |
+BluetoothRemoteGattCharacteristicMac::GetPermissions() const { |
+ // Not supported for remote characteristics for CoreBluetooth. |
+ return PERMISSION_NONE; |
scheib
2016/06/10 21:59:30
Use NOTIMPLEMENTED if possible.
jlebel
2016/06/10 23:02:45
Done.
|
+} |
+ |
+const std::vector<uint8_t>& BluetoothRemoteGattCharacteristicMac::GetValue() |
+ const { |
+ std::vector<uint8_t> value; |
+ return const_cast<std::vector<uint8_t>&>(value); |
scheib
2016/06/10 21:59:31
The reference to the local will no longer be valid
jlebel
2016/06/10 23:02:46
Done.
|
+} |
+ |
+BluetoothRemoteGattService* BluetoothRemoteGattCharacteristicMac::GetService() |
+ const { |
+ return static_cast<BluetoothRemoteGattService*>(gatt_service_); |
+} |
+ |
+bool BluetoothRemoteGattCharacteristicMac::IsNotifying() const { |
+ NOTIMPLEMENTED(); |
+ return false; |
+} |
+ |
+std::vector<BluetoothRemoteGattDescriptor*> |
+BluetoothRemoteGattCharacteristicMac::GetDescriptors() const { |
+ return std::vector<BluetoothRemoteGattDescriptor*>(); |
+ NOTIMPLEMENTED(); |
scheib
2016/06/10 21:59:30
swap line order if we intend to run the NOTIMPLEME
jlebel
2016/06/10 23:02:46
Done.
|
+} |
+ |
+BluetoothRemoteGattDescriptor* |
+BluetoothRemoteGattCharacteristicMac::GetDescriptor( |
+ const std::string& identifier) const { |
+ NOTIMPLEMENTED(); |
+ return nullptr; |
+} |
+ |
+void BluetoothRemoteGattCharacteristicMac::StartNotifySession( |
+ const NotifySessionCallback& callback, |
+ const ErrorCallback& error_callback) { |
+ NOTIMPLEMENTED(); |
+} |
+ |
+void BluetoothRemoteGattCharacteristicMac::ReadRemoteCharacteristic( |
+ const ValueCallback& callback, |
+ const ErrorCallback& error_callback) { |
+ NOTIMPLEMENTED(); |
+} |
+ |
+void BluetoothRemoteGattCharacteristicMac::WriteRemoteCharacteristic( |
+ const std::vector<uint8_t>& new_value, |
+ const base::Closure& callback, |
+ const ErrorCallback& error_callback) { |
+ NOTIMPLEMENTED(); |
+} |
+ |
+} // namespace device. |