| 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 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() { | 47 BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() { |
| 48 if (IsGattConnected()) { | 48 if (IsGattConnected()) { |
| 49 GetMacAdapter()->DisconnectGatt(this); | 49 GetMacAdapter()->DisconnectGatt(this); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 void BluetoothLowEnergyDeviceMac::Update(NSDictionary* advertisement_data, | 53 void BluetoothLowEnergyDeviceMac::Update(NSDictionary* advertisement_data, |
| 54 int rssi) { | 54 int rssi) { |
| 55 last_update_time_.reset([[NSDate date] retain]); | 55 UpdateTimestamp(); |
| 56 rssi_ = rssi; | 56 rssi_ = rssi; |
| 57 NSNumber* connectable = | 57 NSNumber* connectable = |
| 58 [advertisement_data objectForKey:CBAdvertisementDataIsConnectable]; | 58 [advertisement_data objectForKey:CBAdvertisementDataIsConnectable]; |
| 59 connectable_ = [connectable boolValue]; | 59 connectable_ = [connectable boolValue]; |
| 60 ClearServiceData(); | 60 ClearServiceData(); |
| 61 NSDictionary* service_data = | 61 NSDictionary* service_data = |
| 62 [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey]; | 62 [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey]; |
| 63 for (CBUUID* uuid in service_data) { | 63 for (CBUUID* uuid in service_data) { |
| 64 NSData* data = [service_data objectForKey:uuid]; | 64 NSData* data = [service_data objectForKey:uuid]; |
| 65 BluetoothUUID service_uuid = BluetoothUUIDWithCBUUID(uuid); | 65 BluetoothUUID service_uuid = BluetoothUUIDWithCBUUID(uuid); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 NOTIMPLEMENTED(); | 216 NOTIMPLEMENTED(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void BluetoothLowEnergyDeviceMac::ConnectToServiceInsecurely( | 219 void BluetoothLowEnergyDeviceMac::ConnectToServiceInsecurely( |
| 220 const device::BluetoothUUID& uuid, | 220 const device::BluetoothUUID& uuid, |
| 221 const ConnectToServiceCallback& callback, | 221 const ConnectToServiceCallback& callback, |
| 222 const ConnectToServiceErrorCallback& error_callback) { | 222 const ConnectToServiceErrorCallback& error_callback) { |
| 223 NOTIMPLEMENTED(); | 223 NOTIMPLEMENTED(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 NSDate* BluetoothLowEnergyDeviceMac::GetLastUpdateTime() const { | |
| 227 return last_update_time_.get(); | |
| 228 } | |
| 229 | |
| 230 std::string BluetoothLowEnergyDeviceMac::GetDeviceName() const { | 226 std::string BluetoothLowEnergyDeviceMac::GetDeviceName() const { |
| 231 return base::SysNSStringToUTF8([peripheral_ name]); | 227 return base::SysNSStringToUTF8([peripheral_ name]); |
| 232 } | 228 } |
| 233 | 229 |
| 234 void BluetoothLowEnergyDeviceMac::CreateGattConnectionImpl() { | 230 void BluetoothLowEnergyDeviceMac::CreateGattConnectionImpl() { |
| 235 if (!IsGattConnected()) { | 231 if (!IsGattConnected()) { |
| 236 GetMacAdapter()->CreateGattConnection(this); | 232 GetMacAdapter()->CreateGattConnection(this); |
| 237 } | 233 } |
| 238 } | 234 } |
| 239 | 235 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 267 |
| 272 void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral( | 268 void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral( |
| 273 BluetoothDevice::ConnectErrorCode error_code) { | 269 BluetoothDevice::ConnectErrorCode error_code) { |
| 274 if (create_gatt_connection_error_callbacks_.empty()) { | 270 if (create_gatt_connection_error_callbacks_.empty()) { |
| 275 // TODO(http://crbug.com/585897): Need to pass the error. | 271 // TODO(http://crbug.com/585897): Need to pass the error. |
| 276 DidDisconnectGatt(); | 272 DidDisconnectGatt(); |
| 277 } else { | 273 } else { |
| 278 DidFailToConnectGatt(error_code); | 274 DidFailToConnectGatt(error_code); |
| 279 } | 275 } |
| 280 } | 276 } |
| OLD | NEW |