Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_low_energy_device_mac.h" | 5 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" |
| 6 | 6 |
| 7 #import <CoreFoundation/CoreFoundation.h> | 7 #import <CoreFoundation/CoreFoundation.h> |
| 8 | 8 |
| 9 #include "base/mac/scoped_cftyperef.h" | 9 #include "base/mac/scoped_cftyperef.h" |
| 10 #include "base/mac/sdk_forward_declarations.h" | 10 #include "base/mac/sdk_forward_declarations.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 std::string uuid_c_string = base::SysNSStringToUTF8(uuidString); | 59 std::string uuid_c_string = base::SysNSStringToUTF8(uuidString); |
| 60 return device::BluetoothUUID(uuid_c_string); | 60 return device::BluetoothUUID(uuid_c_string); |
| 61 } | 61 } |
| 62 | 62 |
| 63 } // namespace | 63 } // namespace |
| 64 | 64 |
| 65 BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac( | 65 BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac( |
| 66 CBPeripheral* peripheral, | 66 CBPeripheral* peripheral, |
| 67 NSDictionary* advertisementData, | 67 NSDictionary* advertisementData, |
| 68 int rssi) { | 68 int rssi) { |
| 69 supports_low_energy_ = true; | |
| 70 supports_classic_ = false; | |
| 69 Update(peripheral, advertisementData, rssi); | 71 Update(peripheral, advertisementData, rssi); |
| 70 } | 72 } |
| 71 | 73 |
| 72 BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() { | 74 BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() { |
| 73 } | 75 } |
| 74 | 76 |
| 75 void BluetoothLowEnergyDeviceMac::Update(CBPeripheral* peripheral, | 77 void BluetoothLowEnergyDeviceMac::Update(CBPeripheral* peripheral, |
| 76 NSDictionary* advertisementData, | 78 NSDictionary* advertisementData, |
| 77 int rssi) { | 79 int rssi) { |
| 80 last_call_to_update_ = [NSDate date]; | |
| 78 peripheral_.reset([peripheral retain]); | 81 peripheral_.reset([peripheral retain]); |
| 79 rssi_ = rssi; | 82 rssi_ = rssi; |
| 80 ClearServiceData(); | 83 ClearServiceData(); |
| 81 NSNumber* nbConnectable = | 84 NSNumber* nbConnectable = |
| 82 [advertisementData objectForKey:CBAdvertisementDataIsConnectable]; | 85 [advertisementData objectForKey:CBAdvertisementDataIsConnectable]; |
| 83 connectable_ = [nbConnectable boolValue]; | 86 connectable_ = [nbConnectable boolValue]; |
| 84 NSDictionary* serviceData = | 87 NSDictionary* serviceData = |
| 85 [advertisementData objectForKey:CBAdvertisementDataServiceDataKey]; | 88 [advertisementData objectForKey:CBAdvertisementDataServiceDataKey]; |
| 86 for (CBUUID* uuid in serviceData) { | 89 for (CBUUID* uuid in serviceData) { |
| 87 NSData* data = [serviceData objectForKey:uuid]; | 90 NSData* data = [serviceData objectForKey:uuid]; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 | 124 |
| 122 int BluetoothLowEnergyDeviceMac::GetRSSI() const { | 125 int BluetoothLowEnergyDeviceMac::GetRSSI() const { |
| 123 return rssi_; | 126 return rssi_; |
| 124 } | 127 } |
| 125 | 128 |
| 126 bool BluetoothLowEnergyDeviceMac::IsPaired() const { | 129 bool BluetoothLowEnergyDeviceMac::IsPaired() const { |
| 127 return false; | 130 return false; |
| 128 } | 131 } |
| 129 | 132 |
| 130 bool BluetoothLowEnergyDeviceMac::IsConnected() const { | 133 bool BluetoothLowEnergyDeviceMac::IsConnected() const { |
| 134 // TODO(krstnmnlsn): Remove check once we move to OSX SDK >= 10.9. | |
|
scheib
2015/06/29 20:44:24
This block seems out of place for this patch. Is i
krstnmnlsn
2015/06/30 00:50:35
Oh alright..
| |
| 135 if ([peripheral_ respondsToSelector:@selector(state)]) { | |
| 136 return ([peripheral_ state] == CBPeripheralStateConnected); | |
| 137 } | |
| 131 return [peripheral_ isConnected]; | 138 return [peripheral_ isConnected]; |
| 132 } | 139 } |
| 133 | 140 |
| 134 bool BluetoothLowEnergyDeviceMac::IsConnectable() const { | 141 bool BluetoothLowEnergyDeviceMac::IsConnectable() const { |
| 135 return connectable_; | 142 return connectable_; |
| 136 } | 143 } |
| 137 | 144 |
| 138 bool BluetoothLowEnergyDeviceMac::IsConnecting() const { | 145 bool BluetoothLowEnergyDeviceMac::IsConnecting() const { |
| 139 return false; | 146 return false; |
| 140 } | 147 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 const ConnectToServiceErrorCallback& error_callback) { | 226 const ConnectToServiceErrorCallback& error_callback) { |
| 220 NOTIMPLEMENTED(); | 227 NOTIMPLEMENTED(); |
| 221 } | 228 } |
| 222 | 229 |
| 223 void BluetoothLowEnergyDeviceMac::CreateGattConnection( | 230 void BluetoothLowEnergyDeviceMac::CreateGattConnection( |
| 224 const GattConnectionCallback& callback, | 231 const GattConnectionCallback& callback, |
| 225 const ConnectErrorCallback& error_callback) { | 232 const ConnectErrorCallback& error_callback) { |
| 226 NOTIMPLEMENTED(); | 233 NOTIMPLEMENTED(); |
| 227 } | 234 } |
| 228 | 235 |
| 236 NSDate* BluetoothLowEnergyDeviceMac::GetLastCallToUpdate() { | |
| 237 return last_call_to_update_; | |
| 238 } | |
| 239 | |
| 229 std::string BluetoothLowEnergyDeviceMac::GetDeviceName() const { | 240 std::string BluetoothLowEnergyDeviceMac::GetDeviceName() const { |
| 230 return base::SysNSStringToUTF8([peripheral_ name]); | 241 return base::SysNSStringToUTF8([peripheral_ name]); |
| 231 } | 242 } |
| 232 | 243 |
| 233 std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier( | 244 std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier( |
| 234 CBPeripheral* peripheral) { | 245 CBPeripheral* peripheral) { |
| 235 // TODO(dvh): Remove this once we moved to OSX SDK >= 10.9. | 246 // TODO(dvh): Remove this once we moved to OSX SDK >= 10.9. |
| 236 if ([peripheral respondsToSelector:@selector(identifier)]) { | 247 if ([peripheral respondsToSelector:@selector(identifier)]) { |
| 237 // When -[CBPeripheral identifier] is available. | 248 // When -[CBPeripheral identifier] is available. |
| 238 NSUUID* uuid = [peripheral identifier]; | 249 NSUUID* uuid = [peripheral identifier]; |
| 239 NSString* uuidString = [uuid UUIDString]; | 250 NSString* uuidString = [uuid UUIDString]; |
| 240 return base::SysNSStringToUTF8(uuidString); | 251 return base::SysNSStringToUTF8(uuidString); |
| 241 } | 252 } |
| 242 | 253 |
| 243 base::ScopedCFTypeRef<CFStringRef> str( | 254 base::ScopedCFTypeRef<CFStringRef> str( |
| 244 CFUUIDCreateString(NULL, [peripheral UUID])); | 255 CFUUIDCreateString(NULL, [peripheral UUID])); |
| 245 return SysCFStringRefToUTF8(str); | 256 return SysCFStringRefToUTF8(str); |
| 246 } | 257 } |
| OLD | NEW |