| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 void BluetoothLowEnergyDeviceMac::DidDiscoverPrimaryServices(NSError* error) { | 185 void BluetoothLowEnergyDeviceMac::DidDiscoverPrimaryServices(NSError* error) { |
| 186 if (error) { | 186 if (error) { |
| 187 // TODO(http://crbug.com/609320): Need to pass the error. | 187 // TODO(http://crbug.com/609320): Need to pass the error. |
| 188 // TODO(http://crbug.com/609844): Decide what to do if discover failed | 188 // TODO(http://crbug.com/609844): Decide what to do if discover failed |
| 189 // a device services. | 189 // a device services. |
| 190 VLOG(1) << "Can't discover primary services: " | 190 VLOG(1) << "Can't discover primary services: " |
| 191 << error.localizedDescription.UTF8String << " (" << error.domain | 191 << error.localizedDescription.UTF8String << " (" << error.domain |
| 192 << ": " << error.code << ")"; | 192 << ": " << error.code << ")"; |
| 193 return; | 193 return; |
| 194 } | 194 } |
| 195 VLOG(1) << "DidDiscoverPrimaryServices."; |
| 195 | 196 |
| 196 if (!IsGattConnected()) { | 197 if (!IsGattConnected()) { |
| 197 // Don't create services if the device disconnected. | 198 // Don't create services if the device disconnected. |
| 198 return; | 199 return; |
| 199 } | 200 } |
| 200 | 201 |
| 201 for (CBService* cb_service in GetPeripheral().services) { | 202 for (CBService* cb_service in GetPeripheral().services) { |
| 202 BluetoothRemoteGattServiceMac* gatt_service = | 203 BluetoothRemoteGattServiceMac* gatt_service = |
| 203 GetBluetoothRemoteGattService(cb_service); | 204 GetBluetoothRemoteGattService(cb_service); |
| 204 if (!gatt_service) { | 205 if (!gatt_service) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 223 CBService* cb_service, | 224 CBService* cb_service, |
| 224 NSError* error) { | 225 NSError* error) { |
| 225 if (error) { | 226 if (error) { |
| 226 // TODO(http://crbug.com/609320): Need to pass the error. | 227 // TODO(http://crbug.com/609320): Need to pass the error. |
| 227 // TODO(http://crbug.com/609844): Decide what to do if discover failed | 228 // TODO(http://crbug.com/609844): Decide what to do if discover failed |
| 228 VLOG(1) << "Can't discover characteristics: " | 229 VLOG(1) << "Can't discover characteristics: " |
| 229 << error.localizedDescription.UTF8String << " (" << error.domain | 230 << error.localizedDescription.UTF8String << " (" << error.domain |
| 230 << ": " << error.code << ")"; | 231 << ": " << error.code << ")"; |
| 231 return; | 232 return; |
| 232 } | 233 } |
| 234 VLOG(1) << "DidDiscoverCharacteristics."; |
| 233 | 235 |
| 234 if (!IsGattConnected()) { | 236 if (!IsGattConnected()) { |
| 235 // Don't create characteristics if the device disconnected. | 237 // Don't create characteristics if the device disconnected. |
| 236 return; | 238 return; |
| 237 } | 239 } |
| 238 | 240 |
| 239 BluetoothRemoteGattServiceMac* gatt_service = | 241 BluetoothRemoteGattServiceMac* gatt_service = |
| 240 GetBluetoothRemoteGattService(cb_service); | 242 GetBluetoothRemoteGattService(cb_service); |
| 241 DCHECK(gatt_service); | 243 DCHECK(gatt_service); |
| 242 gatt_service->DidDiscoverCharacteristics(); | 244 gatt_service->DidDiscoverCharacteristics(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 253 if (discovery_complete) { | 255 if (discovery_complete) { |
| 254 device_uuids_.ReplaceServiceUUIDs(gatt_services_); | 256 device_uuids_.ReplaceServiceUUIDs(gatt_services_); |
| 255 SetGattServicesDiscoveryComplete(true); | 257 SetGattServicesDiscoveryComplete(true); |
| 256 adapter_->NotifyGattServicesDiscovered(this); | 258 adapter_->NotifyGattServicesDiscovered(this); |
| 257 adapter_->NotifyDeviceChanged(this); | 259 adapter_->NotifyDeviceChanged(this); |
| 258 } | 260 } |
| 259 } | 261 } |
| 260 | 262 |
| 261 void BluetoothLowEnergyDeviceMac::DidModifyServices( | 263 void BluetoothLowEnergyDeviceMac::DidModifyServices( |
| 262 NSArray* invalidatedServices) { | 264 NSArray* invalidatedServices) { |
| 265 VLOG(1) << "DidModifyServices: "; |
| 263 for (CBService* cb_service in invalidatedServices) { | 266 for (CBService* cb_service in invalidatedServices) { |
| 264 BluetoothRemoteGattServiceMac* gatt_service = | 267 BluetoothRemoteGattServiceMac* gatt_service = |
| 265 GetBluetoothRemoteGattService(cb_service); | 268 GetBluetoothRemoteGattService(cb_service); |
| 266 DCHECK(gatt_service); | 269 DCHECK(gatt_service); |
| 270 VLOG(1) << gatt_service->GetUUID().canonical_value(); |
| 267 std::unique_ptr<BluetoothRemoteGattService> scoped_service = | 271 std::unique_ptr<BluetoothRemoteGattService> scoped_service = |
| 268 gatt_services_.take_and_erase(gatt_service->GetIdentifier()); | 272 gatt_services_.take_and_erase(gatt_service->GetIdentifier()); |
| 269 adapter_->NotifyGattServiceRemoved(scoped_service.get()); | 273 adapter_->NotifyGattServiceRemoved(scoped_service.get()); |
| 270 } | 274 } |
| 271 device_uuids_.ClearServiceUUIDs(); | 275 device_uuids_.ClearServiceUUIDs(); |
| 272 SetGattServicesDiscoveryComplete(false); | 276 SetGattServicesDiscoveryComplete(false); |
| 273 adapter_->NotifyDeviceChanged(this); | 277 adapter_->NotifyDeviceChanged(this); |
| 274 [GetPeripheral() discoverServices:nil]; | 278 [GetPeripheral() discoverServices:nil]; |
| 275 } | 279 } |
| 276 | 280 |
| 277 void BluetoothLowEnergyDeviceMac::DidUpdateValue( | 281 void BluetoothLowEnergyDeviceMac::DidUpdateValue( |
| 278 CBCharacteristic* characteristic, | 282 CBCharacteristic* characteristic, |
| 279 NSError* error) { | 283 NSError* error) { |
| 284 VLOG(1) << "DidUpdateValue."; |
| 280 BluetoothRemoteGattServiceMac* gatt_service = | 285 BluetoothRemoteGattServiceMac* gatt_service = |
| 281 GetBluetoothRemoteGattService(characteristic.service); | 286 GetBluetoothRemoteGattService(characteristic.service); |
| 282 DCHECK(gatt_service); | 287 DCHECK(gatt_service); |
| 283 gatt_service->DidUpdateValue(characteristic, error); | 288 gatt_service->DidUpdateValue(characteristic, error); |
| 284 } | 289 } |
| 285 | 290 |
| 286 void BluetoothLowEnergyDeviceMac::DidWriteValue( | 291 void BluetoothLowEnergyDeviceMac::DidWriteValue( |
| 287 CBCharacteristic* characteristic, | 292 CBCharacteristic* characteristic, |
| 288 NSError* error) { | 293 NSError* error) { |
| 294 VLOG(1) << "DidWriteValue."; |
| 289 BluetoothRemoteGattServiceMac* gatt_service = | 295 BluetoothRemoteGattServiceMac* gatt_service = |
| 290 GetBluetoothRemoteGattService(characteristic.service); | 296 GetBluetoothRemoteGattService(characteristic.service); |
| 291 DCHECK(gatt_service); | 297 DCHECK(gatt_service); |
| 292 gatt_service->DidWriteValue(characteristic, error); | 298 gatt_service->DidWriteValue(characteristic, error); |
| 293 } | 299 } |
| 294 | 300 |
| 295 void BluetoothLowEnergyDeviceMac::DidUpdateNotificationState( | 301 void BluetoothLowEnergyDeviceMac::DidUpdateNotificationState( |
| 296 CBCharacteristic* characteristic, | 302 CBCharacteristic* characteristic, |
| 297 NSError* error) { | 303 NSError* error) { |
| 304 VLOG(1) << "DidUpdateNotificationState"; |
| 298 BluetoothRemoteGattServiceMac* gatt_service = | 305 BluetoothRemoteGattServiceMac* gatt_service = |
| 299 GetBluetoothRemoteGattService(characteristic.service); | 306 GetBluetoothRemoteGattService(characteristic.service); |
| 300 DCHECK(gatt_service); | 307 DCHECK(gatt_service); |
| 301 gatt_service->DidUpdateNotificationState(characteristic, error); | 308 gatt_service->DidUpdateNotificationState(characteristic, error); |
| 302 } | 309 } |
| 303 | 310 |
| 304 // static | 311 // static |
| 305 std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier( | 312 std::string BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier( |
| 306 CBPeripheral* peripheral) { | 313 CBPeripheral* peripheral) { |
| 307 DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable()); | 314 DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 // 2. When we cancel a pending connection request. | 364 // 2. When we cancel a pending connection request. |
| 358 if (create_gatt_connection_error_callbacks_.empty()) { | 365 if (create_gatt_connection_error_callbacks_.empty()) { |
| 359 // If there are no pending callbacks then the connection broke (#1). | 366 // If there are no pending callbacks then the connection broke (#1). |
| 360 DidDisconnectGatt(); | 367 DidDisconnectGatt(); |
| 361 return; | 368 return; |
| 362 } | 369 } |
| 363 // Else we canceled the connection request (#2). | 370 // Else we canceled the connection request (#2). |
| 364 // TODO(http://crbug.com/585897): Need to pass the error. | 371 // TODO(http://crbug.com/585897): Need to pass the error. |
| 365 DidFailToConnectGatt(BluetoothDevice::ConnectErrorCode::ERROR_FAILED); | 372 DidFailToConnectGatt(BluetoothDevice::ConnectErrorCode::ERROR_FAILED); |
| 366 } | 373 } |
| OLD | NEW |