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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 GetBluetoothRemoteGattService(cb_service); | 251 GetBluetoothRemoteGattService(cb_service); |
252 if (!gatt_service) { | 252 if (!gatt_service) { |
253 gatt_service = new BluetoothRemoteGattServiceMac(this, cb_service, | 253 gatt_service = new BluetoothRemoteGattServiceMac(this, cb_service, |
254 true /* is_primary */); | 254 true /* is_primary */); |
255 auto result_iter = gatt_services_.add(gatt_service->GetIdentifier(), | 255 auto result_iter = gatt_services_.add(gatt_service->GetIdentifier(), |
256 base::WrapUnique(gatt_service)); | 256 base::WrapUnique(gatt_service)); |
257 DCHECK(result_iter.second); | 257 DCHECK(result_iter.second); |
258 adapter_->NotifyGattServiceAdded(gatt_service); | 258 adapter_->NotifyGattServiceAdded(gatt_service); |
259 } | 259 } |
260 } | 260 } |
261 // TODO(http://crbug.com/609064): Services are fully discovered once all | 261 for (GattServiceMap::const_iterator it = gatt_services_.begin(); |
262 // characteristics have been found. | 262 it != gatt_services_.end(); ++it) { |
263 SetGattServicesDiscoveryComplete(true); | 263 device::BluetoothRemoteGattService* gatt_service = it->second; |
264 adapter_->NotifyGattServicesDiscovered(this); | 264 device::BluetoothRemoteGattServiceMac* gatt_service_mac = |
265 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service); | |
266 [GetPeripheral() discoverCharacteristics:nil | |
267 forService:gatt_service_mac->GetService()]; | |
268 } | |
269 } | |
270 | |
271 void BluetoothLowEnergyDeviceMac::DidDiscoverCharacteristics( | |
272 CBService* cb_service, | |
273 NSError* error) { | |
274 if (error) { | |
275 // TODO(http://crbug.com/609320): Need to pass the error. | |
276 // TODO(http://crbug.com/609844): Decide what to do if we fail to discover | |
277 // a device services. | |
278 VLOG(1) << "Can't discover characteristics: " | |
279 << error.localizedDescription.UTF8String << " (" << error.domain | |
280 << ": " << error.code << ")"; | |
281 return; | |
282 } | |
283 BluetoothRemoteGattServiceMac* gatt_service = | |
284 GetBluetoothRemoteGattService(cb_service); | |
285 DCHECK(gatt_service); | |
286 gatt_service->DidDiscoverCharacteristics(); | |
287 // Does all services have been discovered? | |
scheib
2016/06/10 21:59:30
blank line, then
"Notify when all services have be
jlebel
2016/06/10 23:02:45
Done.
| |
288 bool discovery_complete = true; | |
289 for (GattServiceMap::const_iterator it = gatt_services_.begin(); | |
290 it != gatt_services_.end(); ++it) { | |
291 device::BluetoothRemoteGattService* gatt_service = it->second; | |
292 device::BluetoothRemoteGattServiceMac* gatt_service_mac = | |
293 static_cast<BluetoothRemoteGattServiceMac*>(gatt_service); | |
294 discovery_complete = gatt_service_mac->IsDiscoveryComplete(); | |
295 if (!discovery_complete) { | |
296 break; | |
297 } | |
298 } | |
299 if (discovery_complete) { | |
300 SetGattServicesDiscoveryComplete(true); | |
301 adapter_->NotifyGattServicesDiscovered(this); | |
302 } | |
265 } | 303 } |
266 | 304 |
267 void BluetoothLowEnergyDeviceMac::DidModifyServices( | 305 void BluetoothLowEnergyDeviceMac::DidModifyServices( |
268 NSArray* invalidatedServices) { | 306 NSArray* invalidatedServices) { |
269 for (CBService* cb_service in invalidatedServices) { | 307 for (CBService* cb_service in invalidatedServices) { |
270 BluetoothRemoteGattServiceMac* gatt_service = | 308 BluetoothRemoteGattServiceMac* gatt_service = |
271 GetBluetoothRemoteGattService(cb_service); | 309 GetBluetoothRemoteGattService(cb_service); |
272 DCHECK(gatt_service); | 310 DCHECK(gatt_service); |
273 std::unique_ptr<BluetoothRemoteGattService> scoped_service = | 311 std::unique_ptr<BluetoothRemoteGattService> scoped_service = |
274 gatt_services_.take_and_erase(gatt_service->GetIdentifier()); | 312 gatt_services_.take_and_erase(gatt_service->GetIdentifier()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 GattServiceMap gatt_services_swapped; | 366 GattServiceMap gatt_services_swapped; |
329 gatt_services_swapped.swap(gatt_services_); | 367 gatt_services_swapped.swap(gatt_services_); |
330 gatt_services_swapped.clear(); | 368 gatt_services_swapped.clear(); |
331 if (create_gatt_connection_error_callbacks_.empty()) { | 369 if (create_gatt_connection_error_callbacks_.empty()) { |
332 // TODO(http://crbug.com/585897): Need to pass the error. | 370 // TODO(http://crbug.com/585897): Need to pass the error. |
333 DidDisconnectGatt(); | 371 DidDisconnectGatt(); |
334 } else { | 372 } else { |
335 DidFailToConnectGatt(error_code); | 373 DidFailToConnectGatt(error_code); |
336 } | 374 } |
337 } | 375 } |
OLD | NEW |