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 | |
17 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.
| |
18 CBCharacteristicProperties cb_property) { | |
19 BluetoothGattCharacteristic::Properties result = | |
20 BluetoothGattCharacteristic::PROPERTY_NONE; | |
21 if (cb_property & CBCharacteristicPropertyBroadcast) { | |
22 result |= BluetoothGattCharacteristic::PROPERTY_BROADCAST; | |
23 } | |
24 if (cb_property & CBCharacteristicPropertyRead) { | |
25 result |= BluetoothGattCharacteristic::PROPERTY_READ; | |
26 } | |
27 if (cb_property & CBCharacteristicPropertyWriteWithoutResponse) { | |
28 result |= BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE; | |
29 } | |
30 if (cb_property & CBCharacteristicPropertyWrite) { | |
31 result |= BluetoothGattCharacteristic::PROPERTY_WRITE; | |
32 } | |
33 if (cb_property & CBCharacteristicPropertyNotify) { | |
34 result |= BluetoothGattCharacteristic::PROPERTY_NOTIFY; | |
35 } | |
36 if (cb_property & CBCharacteristicPropertyIndicate) { | |
37 result |= BluetoothGattCharacteristic::PROPERTY_INDICATE; | |
38 } | |
39 if (cb_property & CBCharacteristicPropertyAuthenticatedSignedWrites) { | |
40 result |= BluetoothGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES; | |
41 } | |
42 if (cb_property & CBCharacteristicPropertyExtendedProperties) { | |
43 result |= BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES; | |
44 } | |
45 if (cb_property & CBCharacteristicPropertyNotifyEncryptionRequired) { | |
46 // 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.
| |
47 // (or a CBCharacteristic) | |
48 DCHECK(false); | |
49 result |= BluetoothGattCharacteristic::PROPERTY_NOTIFY; | |
50 } | |
51 if (cb_property & CBCharacteristicPropertyIndicateEncryptionRequired) { | |
52 // This should never happens for a remote characteristic | |
53 // (or a CBCharacteristic) | |
54 DCHECK(false); | |
55 result |= BluetoothGattCharacteristic::PROPERTY_INDICATE; | |
56 } | |
57 return result; | |
58 } | |
59 } // namespace | |
60 | |
61 BluetoothRemoteGattCharacteristicMac::BluetoothRemoteGattCharacteristicMac( | |
62 BluetoothRemoteGattServiceMac* gatt_service, | |
63 CBCharacteristic* cb_characteristic) | |
64 : gatt_service_(gatt_service), | |
65 cb_characteristic_(cb_characteristic, base::scoped_policy::RETAIN) { | |
66 uuid_ = BluetoothAdapterMac::BluetoothUUIDWithCBUUID( | |
67 [cb_characteristic_.get() UUID]); | |
68 identifier_ = | |
69 [NSString stringWithFormat:@"%s-%p", uuid_.canonical_value().c_str(), | |
70 (void*)cb_characteristic_] | |
71 .UTF8String; | |
72 } | |
73 | |
74 BluetoothRemoteGattCharacteristicMac::~BluetoothRemoteGattCharacteristicMac() {} | |
75 | |
76 std::string BluetoothRemoteGattCharacteristicMac::GetIdentifier() const { | |
77 return identifier_; | |
78 } | |
79 | |
80 BluetoothUUID BluetoothRemoteGattCharacteristicMac::GetUUID() const { | |
81 return uuid_; | |
82 } | |
83 | |
84 BluetoothGattCharacteristic::Properties | |
85 BluetoothRemoteGattCharacteristicMac::GetProperties() const { | |
86 return CBCharacteristicPropertyToGattCharacteristicProperty( | |
87 cb_characteristic_.get().properties); | |
88 } | |
89 | |
90 BluetoothGattCharacteristic::Permissions | |
91 BluetoothRemoteGattCharacteristicMac::GetPermissions() const { | |
92 // Not supported for remote characteristics for CoreBluetooth. | |
93 return PERMISSION_NONE; | |
scheib
2016/06/10 21:59:30
Use NOTIMPLEMENTED if possible.
jlebel
2016/06/10 23:02:45
Done.
| |
94 } | |
95 | |
96 const std::vector<uint8_t>& BluetoothRemoteGattCharacteristicMac::GetValue() | |
97 const { | |
98 std::vector<uint8_t> value; | |
99 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.
| |
100 } | |
101 | |
102 BluetoothRemoteGattService* BluetoothRemoteGattCharacteristicMac::GetService() | |
103 const { | |
104 return static_cast<BluetoothRemoteGattService*>(gatt_service_); | |
105 } | |
106 | |
107 bool BluetoothRemoteGattCharacteristicMac::IsNotifying() const { | |
108 NOTIMPLEMENTED(); | |
109 return false; | |
110 } | |
111 | |
112 std::vector<BluetoothRemoteGattDescriptor*> | |
113 BluetoothRemoteGattCharacteristicMac::GetDescriptors() const { | |
114 return std::vector<BluetoothRemoteGattDescriptor*>(); | |
115 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.
| |
116 } | |
117 | |
118 BluetoothRemoteGattDescriptor* | |
119 BluetoothRemoteGattCharacteristicMac::GetDescriptor( | |
120 const std::string& identifier) const { | |
121 NOTIMPLEMENTED(); | |
122 return nullptr; | |
123 } | |
124 | |
125 void BluetoothRemoteGattCharacteristicMac::StartNotifySession( | |
126 const NotifySessionCallback& callback, | |
127 const ErrorCallback& error_callback) { | |
128 NOTIMPLEMENTED(); | |
129 } | |
130 | |
131 void BluetoothRemoteGattCharacteristicMac::ReadRemoteCharacteristic( | |
132 const ValueCallback& callback, | |
133 const ErrorCallback& error_callback) { | |
134 NOTIMPLEMENTED(); | |
135 } | |
136 | |
137 void BluetoothRemoteGattCharacteristicMac::WriteRemoteCharacteristic( | |
138 const std::vector<uint8_t>& new_value, | |
139 const base::Closure& callback, | |
140 const ErrorCallback& error_callback) { | |
141 NOTIMPLEMENTED(); | |
142 } | |
143 | |
144 } // namespace device. | |
OLD | NEW |