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 28 matching lines...) Expand all Loading... |
39 } | 39 } |
40 | 40 |
41 BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() { | 41 BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() { |
42 if (IsGattConnected()) { | 42 if (IsGattConnected()) { |
43 GetMacAdapter()->DisconnectGatt(this); | 43 GetMacAdapter()->DisconnectGatt(this); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 void BluetoothLowEnergyDeviceMac::Update(NSDictionary* advertisement_data, | 47 void BluetoothLowEnergyDeviceMac::Update(NSDictionary* advertisement_data, |
48 int rssi) { | 48 int rssi) { |
49 last_update_time_.reset([[NSDate date] retain]); | 49 UpdateTimestamp(); |
50 rssi_ = rssi; | 50 rssi_ = rssi; |
51 NSNumber* connectable = | 51 NSNumber* connectable = |
52 [advertisement_data objectForKey:CBAdvertisementDataIsConnectable]; | 52 [advertisement_data objectForKey:CBAdvertisementDataIsConnectable]; |
53 connectable_ = [connectable boolValue]; | 53 connectable_ = [connectable boolValue]; |
54 ClearServiceData(); | 54 ClearServiceData(); |
55 NSDictionary* service_data = | 55 NSDictionary* service_data = |
56 [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey]; | 56 [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey]; |
57 for (CBUUID* uuid in service_data) { | 57 for (CBUUID* uuid in service_data) { |
58 NSData* data = [service_data objectForKey:uuid]; | 58 NSData* data = [service_data objectForKey:uuid]; |
59 BluetoothUUID service_uuid = | 59 BluetoothUUID service_uuid = |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 NOTIMPLEMENTED(); | 211 NOTIMPLEMENTED(); |
212 } | 212 } |
213 | 213 |
214 void BluetoothLowEnergyDeviceMac::ConnectToServiceInsecurely( | 214 void BluetoothLowEnergyDeviceMac::ConnectToServiceInsecurely( |
215 const device::BluetoothUUID& uuid, | 215 const device::BluetoothUUID& uuid, |
216 const ConnectToServiceCallback& callback, | 216 const ConnectToServiceCallback& callback, |
217 const ConnectToServiceErrorCallback& error_callback) { | 217 const ConnectToServiceErrorCallback& error_callback) { |
218 NOTIMPLEMENTED(); | 218 NOTIMPLEMENTED(); |
219 } | 219 } |
220 | 220 |
221 NSDate* BluetoothLowEnergyDeviceMac::GetLastUpdateTime() const { | |
222 return last_update_time_.get(); | |
223 } | |
224 | |
225 std::string BluetoothLowEnergyDeviceMac::GetDeviceName() const { | 221 std::string BluetoothLowEnergyDeviceMac::GetDeviceName() const { |
226 return base::SysNSStringToUTF8([peripheral_ name]); | 222 return base::SysNSStringToUTF8([peripheral_ name]); |
227 } | 223 } |
228 | 224 |
229 void BluetoothLowEnergyDeviceMac::CreateGattConnectionImpl() { | 225 void BluetoothLowEnergyDeviceMac::CreateGattConnectionImpl() { |
230 if (!IsGattConnected()) { | 226 if (!IsGattConnected()) { |
231 GetMacAdapter()->CreateGattConnection(this); | 227 GetMacAdapter()->CreateGattConnection(this); |
232 } | 228 } |
233 } | 229 } |
234 | 230 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 GattServiceMap gatt_services_swapped; | 358 GattServiceMap gatt_services_swapped; |
363 gatt_services_swapped.swap(gatt_services_); | 359 gatt_services_swapped.swap(gatt_services_); |
364 gatt_services_swapped.clear(); | 360 gatt_services_swapped.clear(); |
365 if (create_gatt_connection_error_callbacks_.empty()) { | 361 if (create_gatt_connection_error_callbacks_.empty()) { |
366 // TODO(http://crbug.com/585897): Need to pass the error. | 362 // TODO(http://crbug.com/585897): Need to pass the error. |
367 DidDisconnectGatt(); | 363 DidDisconnectGatt(); |
368 } else { | 364 } else { |
369 DidFailToConnectGatt(error_code); | 365 DidFailToConnectGatt(error_code); |
370 } | 366 } |
371 } | 367 } |
OLD | NEW |