| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 68     int rssi) { | 68     int rssi) { | 
| 69   Update(peripheral, advertisementData, rssi); | 69   Update(peripheral, advertisementData, rssi); | 
| 70 } | 70 } | 
| 71 | 71 | 
| 72 BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() { | 72 BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() { | 
| 73 } | 73 } | 
| 74 | 74 | 
| 75 void BluetoothLowEnergyDeviceMac::Update(CBPeripheral* peripheral, | 75 void BluetoothLowEnergyDeviceMac::Update(CBPeripheral* peripheral, | 
| 76                                          NSDictionary* advertisementData, | 76                                          NSDictionary* advertisementData, | 
| 77                                          int rssi) { | 77                                          int rssi) { | 
|  | 78   last_update_time_.reset([[NSDate date] retain]); | 
| 78   peripheral_.reset([peripheral retain]); | 79   peripheral_.reset([peripheral retain]); | 
| 79   rssi_ = rssi; | 80   rssi_ = rssi; | 
| 80   ClearServiceData(); | 81   ClearServiceData(); | 
| 81   NSNumber* nbConnectable = | 82   NSNumber* nbConnectable = | 
| 82       [advertisementData objectForKey:CBAdvertisementDataIsConnectable]; | 83       [advertisementData objectForKey:CBAdvertisementDataIsConnectable]; | 
| 83   connectable_ = [nbConnectable boolValue]; | 84   connectable_ = [nbConnectable boolValue]; | 
| 84   NSDictionary* serviceData = | 85   NSDictionary* serviceData = | 
| 85       [advertisementData objectForKey:CBAdvertisementDataServiceDataKey]; | 86       [advertisementData objectForKey:CBAdvertisementDataServiceDataKey]; | 
| 86   for (CBUUID* uuid in serviceData) { | 87   for (CBUUID* uuid in serviceData) { | 
| 87     NSData* data = [serviceData objectForKey:uuid]; | 88     NSData* data = [serviceData objectForKey:uuid]; | 
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 219     const ConnectToServiceErrorCallback& error_callback) { | 220     const ConnectToServiceErrorCallback& error_callback) { | 
| 220   NOTIMPLEMENTED(); | 221   NOTIMPLEMENTED(); | 
| 221 } | 222 } | 
| 222 | 223 | 
| 223 void BluetoothLowEnergyDeviceMac::CreateGattConnection( | 224 void BluetoothLowEnergyDeviceMac::CreateGattConnection( | 
| 224     const GattConnectionCallback& callback, | 225     const GattConnectionCallback& callback, | 
| 225     const ConnectErrorCallback& error_callback) { | 226     const ConnectErrorCallback& error_callback) { | 
| 226   NOTIMPLEMENTED(); | 227   NOTIMPLEMENTED(); | 
| 227 } | 228 } | 
| 228 | 229 | 
|  | 230 NSDate* BluetoothLowEnergyDeviceMac::GetLastUpdateTime() const { | 
|  | 231   return last_update_time_.get(); | 
|  | 232 } | 
|  | 233 | 
| 229 std::string BluetoothLowEnergyDeviceMac::GetDeviceName() const { | 234 std::string BluetoothLowEnergyDeviceMac::GetDeviceName() const { | 
| 230   return base::SysNSStringToUTF8([peripheral_ name]); | 235   return base::SysNSStringToUTF8([peripheral_ name]); | 
| 231 } | 236 } | 
| 232 | 237 | 
| 233 std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier( | 238 std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier( | 
| 234     CBPeripheral* peripheral) { | 239     CBPeripheral* peripheral) { | 
| 235   // TODO(dvh): Remove this once we moved to OSX SDK >= 10.9. | 240   // TODO(dvh): Remove this once we moved to OSX SDK >= 10.9. | 
| 236   if ([peripheral respondsToSelector:@selector(identifier)]) { | 241   if ([peripheral respondsToSelector:@selector(identifier)]) { | 
| 237     // When -[CBPeripheral identifier] is available. | 242     // When -[CBPeripheral identifier] is available. | 
| 238     NSUUID* uuid = [peripheral identifier]; | 243     NSUUID* uuid = [peripheral identifier]; | 
| 239     NSString* uuidString = [uuid UUIDString]; | 244     NSString* uuidString = [uuid UUIDString]; | 
| 240     return base::SysNSStringToUTF8(uuidString); | 245     return base::SysNSStringToUTF8(uuidString); | 
| 241   } | 246   } | 
| 242 | 247 | 
| 243   base::ScopedCFTypeRef<CFStringRef> str( | 248   base::ScopedCFTypeRef<CFStringRef> str( | 
| 244       CFUUIDCreateString(NULL, [peripheral UUID])); | 249       CFUUIDCreateString(NULL, [peripheral UUID])); | 
| 245   return SysCFStringRefToUTF8(str); | 250   return SysCFStringRefToUTF8(str); | 
| 246 } | 251 } | 
| OLD | NEW | 
|---|