OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_classic_device_mac.h" | 5 #include "device/bluetooth/bluetooth_classic_device_mac.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/hash.h" | 10 #include "base/hash.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 if ([service_class_data getTypeDescriptor] == | 138 if ([service_class_data getTypeDescriptor] == |
139 kBluetoothSDPDataElementTypeDataElementSequence) { | 139 kBluetoothSDPDataElementTypeDataElementSequence) { |
140 BluetoothUUID uuid = ExtractUuid(service_class_data); | 140 BluetoothUUID uuid = ExtractUuid(service_class_data); |
141 if (uuid.IsValid()) | 141 if (uuid.IsValid()) |
142 uuids.push_back(uuid); | 142 uuids.push_back(uuid); |
143 } | 143 } |
144 } | 144 } |
145 return uuids; | 145 return uuids; |
146 } | 146 } |
147 | 147 |
148 int16_t BluetoothClassicDeviceMac::GetInquiryRSSI() const { | 148 base::Optional<int8_t> BluetoothClassicDeviceMac::GetInquiryRSSI() const { |
149 return kUnknownPower; | 149 return base::Optional<int8_t>(); |
scheib
2016/05/07 02:06:52
return nullopt;
| |
150 } | 150 } |
151 | 151 |
152 int16_t BluetoothClassicDeviceMac::GetInquiryTxPower() const { | 152 base::Optional<int8_t> BluetoothClassicDeviceMac::GetInquiryTxPower() const { |
153 NOTIMPLEMENTED(); | 153 NOTIMPLEMENTED(); |
154 return kUnknownPower; | 154 return base::Optional<int8_t>(); |
155 } | 155 } |
156 | 156 |
157 bool BluetoothClassicDeviceMac::ExpectingPinCode() const { | 157 bool BluetoothClassicDeviceMac::ExpectingPinCode() const { |
158 NOTIMPLEMENTED(); | 158 NOTIMPLEMENTED(); |
159 return false; | 159 return false; |
160 } | 160 } |
161 | 161 |
162 bool BluetoothClassicDeviceMac::ExpectingPasskey() const { | 162 bool BluetoothClassicDeviceMac::ExpectingPasskey() const { |
163 NOTIMPLEMENTED(); | 163 NOTIMPLEMENTED(); |
164 return false; | 164 return false; |
165 } | 165 } |
166 | 166 |
167 bool BluetoothClassicDeviceMac::ExpectingConfirmation() const { | 167 bool BluetoothClassicDeviceMac::ExpectingConfirmation() const { |
168 NOTIMPLEMENTED(); | 168 NOTIMPLEMENTED(); |
169 return false; | 169 return false; |
170 } | 170 } |
171 | 171 |
172 void BluetoothClassicDeviceMac::GetConnectionInfo( | 172 void BluetoothClassicDeviceMac::GetConnectionInfo( |
173 const ConnectionInfoCallback& callback) { | 173 const ConnectionInfoCallback& callback) { |
174 ConnectionInfo connection_info; | 174 ConnectionInfo connection_info; |
175 if (![device_ isConnected]) { | 175 if (![device_ isConnected]) { |
176 callback.Run(connection_info); | 176 callback.Run(connection_info); |
177 return; | 177 return; |
178 } | 178 } |
179 | 179 |
180 connection_info.rssi = [device_ rawRSSI]; | 180 BluetoothHCIRSSIValue rssi = [device_ rawRSSI]; |
181 | |
181 // The API guarantees that +127 is returned in case the RSSI is not readable: | 182 // The API guarantees that +127 is returned in case the RSSI is not readable: |
182 // http://goo.gl/bpURYv | 183 // http://goo.gl/bpURYv |
183 if (connection_info.rssi == 127) | 184 if (rssi == 127) |
184 connection_info.rssi = kUnknownPower; | 185 connection_info.rssi = base::make_optional(rssi); |
scheib
2016/05/07 02:06:52
In the event rssi is 127 we want to use nullopt, e
| |
185 | 186 |
186 connection_info.transmit_power = | 187 connection_info.transmit_power = |
187 GetHostTransmitPower(kReadCurrentTransmitPowerLevel); | 188 GetHostTransmitPower(kReadCurrentTransmitPowerLevel); |
188 connection_info.max_transmit_power = | 189 connection_info.max_transmit_power = |
189 GetHostTransmitPower(kReadMaximumTransmitPowerLevel); | 190 GetHostTransmitPower(kReadMaximumTransmitPowerLevel); |
190 | 191 |
191 callback.Run(connection_info); | 192 callback.Run(connection_info); |
192 } | 193 } |
193 | 194 |
194 void BluetoothClassicDeviceMac::Connect( | 195 void BluetoothClassicDeviceMac::Connect( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 const GattConnectionCallback& callback, | 250 const GattConnectionCallback& callback, |
250 const ConnectErrorCallback& error_callback) { | 251 const ConnectErrorCallback& error_callback) { |
251 // TODO(armansito): Implement. | 252 // TODO(armansito): Implement. |
252 error_callback.Run(ERROR_UNSUPPORTED_DEVICE); | 253 error_callback.Run(ERROR_UNSUPPORTED_DEVICE); |
253 } | 254 } |
254 | 255 |
255 NSDate* BluetoothClassicDeviceMac::GetLastUpdateTime() const { | 256 NSDate* BluetoothClassicDeviceMac::GetLastUpdateTime() const { |
256 return [device_ getLastInquiryUpdate]; | 257 return [device_ getLastInquiryUpdate]; |
257 } | 258 } |
258 | 259 |
259 int BluetoothClassicDeviceMac::GetHostTransmitPower( | 260 base::Optional<int8_t> BluetoothClassicDeviceMac::GetHostTransmitPower( |
260 BluetoothHCITransmitPowerLevelType power_level_type) const { | 261 BluetoothHCITransmitPowerLevelType power_level_type) const { |
261 IOBluetoothHostController* controller = | 262 IOBluetoothHostController* controller = |
262 [IOBluetoothHostController defaultController]; | 263 [IOBluetoothHostController defaultController]; |
263 | 264 |
264 // Bail if the undocumented API is unavailable on this machine. | 265 // Bail if the undocumented API is unavailable on this machine. |
265 SEL selector = @selector(BluetoothHCIReadTransmitPowerLevel: | 266 SEL selector = @selector(BluetoothHCIReadTransmitPowerLevel: |
266 inType: | 267 inType: |
267 outTransmitPowerLevel:); | 268 outTransmitPowerLevel:); |
268 if (![controller respondsToSelector:selector]) | 269 if (![controller respondsToSelector:selector]) |
269 return kUnknownPower; | 270 return base::nullopt; |
270 | 271 |
271 BluetoothHCITransmitPowerLevel power_level; | 272 BluetoothHCITransmitPowerLevel power_level; |
272 IOReturn result = | 273 IOReturn result = |
273 [controller BluetoothHCIReadTransmitPowerLevel:[device_ connectionHandle] | 274 [controller BluetoothHCIReadTransmitPowerLevel:[device_ connectionHandle] |
274 inType:power_level_type | 275 inType:power_level_type |
275 outTransmitPowerLevel:&power_level]; | 276 outTransmitPowerLevel:&power_level]; |
276 if (result != kIOReturnSuccess) | 277 if (result != kIOReturnSuccess) |
277 return kUnknownPower; | 278 return base::nullopt; |
278 | 279 |
279 return power_level; | 280 return base::make_optional(power_level); |
280 } | 281 } |
281 | 282 |
282 // static | 283 // static |
283 std::string BluetoothClassicDeviceMac::GetDeviceAddress( | 284 std::string BluetoothClassicDeviceMac::GetDeviceAddress( |
284 IOBluetoothDevice* device) { | 285 IOBluetoothDevice* device) { |
285 return CanonicalizeAddress(base::SysNSStringToUTF8([device addressString])); | 286 return CanonicalizeAddress(base::SysNSStringToUTF8([device addressString])); |
286 } | 287 } |
287 | 288 |
288 } // namespace device | 289 } // namespace device |
OLD | NEW |