Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: device/bluetooth/bluetooth_low_energy_device_mac.mm

Issue 2205693003: bluetooth: Replace old advertised uuids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Mac test and docs Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 =
60 BluetoothAdapterMac::BluetoothUUIDWithCBUUID(uuid); 60 BluetoothAdapterMac::BluetoothUUIDWithCBUUID(uuid);
61 SetServiceData(service_uuid, static_cast<const char*>([data bytes]), 61 SetServiceData(service_uuid, static_cast<const char*>([data bytes]),
62 [data length]); 62 [data length]);
63 } 63 }
64
65 std::unordered_set<BluetoothUUID, BluetoothUUIDHash> uuid_set;
64 NSArray* service_uuids = 66 NSArray* service_uuids =
65 [advertisement_data objectForKey:CBAdvertisementDataServiceUUIDsKey]; 67 [advertisement_data objectForKey:CBAdvertisementDataServiceUUIDsKey];
66 for (CBUUID* uuid in service_uuids) { 68 for (CBUUID* uuid in service_uuids) {
67 advertised_uuids_.insert( 69 uuid_set.emplace([[uuid UUIDString] UTF8String]);
68 BluetoothUUID(std::string([[uuid UUIDString] UTF8String])));
69 } 70 }
70 NSArray* overflow_service_uuids = [advertisement_data 71 NSArray* overflow_service_uuids = [advertisement_data
71 objectForKey:CBAdvertisementDataOverflowServiceUUIDsKey]; 72 objectForKey:CBAdvertisementDataOverflowServiceUUIDsKey];
72 for (CBUUID* uuid in overflow_service_uuids) { 73 for (CBUUID* uuid in overflow_service_uuids) {
73 advertised_uuids_.insert( 74 uuid_set.emplace([[uuid UUIDString] UTF8String]);
74 BluetoothUUID(std::string([[uuid UUIDString] UTF8String])));
75 } 75 }
76
77 advertised_uuids_ = UUIDList(uuid_set.begin(), uuid_set.end());
76 } 78 }
77 79
78 std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const { 80 std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const {
79 return identifier_; 81 return identifier_;
80 } 82 }
81 83
82 uint32_t BluetoothLowEnergyDeviceMac::GetBluetoothClass() const { 84 uint32_t BluetoothLowEnergyDeviceMac::GetBluetoothClass() const {
83 return 0x1F00; // Unspecified Device Class 85 return 0x1F00; // Unspecified Device Class
84 } 86 }
85 87
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 136 }
135 137
136 bool BluetoothLowEnergyDeviceMac::IsConnectable() const { 138 bool BluetoothLowEnergyDeviceMac::IsConnectable() const {
137 return connectable_; 139 return connectable_;
138 } 140 }
139 141
140 bool BluetoothLowEnergyDeviceMac::IsConnecting() const { 142 bool BluetoothLowEnergyDeviceMac::IsConnecting() const {
141 return ([peripheral_ state] == CBPeripheralStateConnecting); 143 return ([peripheral_ state] == CBPeripheralStateConnecting);
142 } 144 }
143 145
144 BluetoothDevice::UUIDList BluetoothLowEnergyDeviceMac::GetUUIDs() const {
145 return BluetoothDevice::UUIDList(advertised_uuids_.begin(),
146 advertised_uuids_.end());
147 }
148
149 int16_t BluetoothLowEnergyDeviceMac::GetInquiryRSSI() const { 146 int16_t BluetoothLowEnergyDeviceMac::GetInquiryRSSI() const {
150 return kUnknownPower; 147 return kUnknownPower;
151 } 148 }
152 149
153 int16_t BluetoothLowEnergyDeviceMac::GetInquiryTxPower() const { 150 int16_t BluetoothLowEnergyDeviceMac::GetInquiryTxPower() const {
154 NOTIMPLEMENTED(); 151 NOTIMPLEMENTED();
155 return kUnknownPower; 152 return kUnknownPower;
156 } 153 }
157 154
158 bool BluetoothLowEnergyDeviceMac::ExpectingPinCode() const { 155 bool BluetoothLowEnergyDeviceMac::ExpectingPinCode() const {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // Notify when all services have been discovered. 293 // Notify when all services have been discovered.
297 bool discovery_complete = 294 bool discovery_complete =
298 std::find_if_not( 295 std::find_if_not(
299 gatt_services_.begin(), gatt_services_.end(), 296 gatt_services_.begin(), gatt_services_.end(),
300 [](std::pair<std::string, BluetoothRemoteGattService*> pair) { 297 [](std::pair<std::string, BluetoothRemoteGattService*> pair) {
301 BluetoothRemoteGattService* gatt_service = pair.second; 298 BluetoothRemoteGattService* gatt_service = pair.second;
302 return static_cast<BluetoothRemoteGattServiceMac*>(gatt_service) 299 return static_cast<BluetoothRemoteGattServiceMac*>(gatt_service)
303 ->IsDiscoveryComplete(); 300 ->IsDiscoveryComplete();
304 }) == gatt_services_.end(); 301 }) == gatt_services_.end();
305 if (discovery_complete) { 302 if (discovery_complete) {
303 UpdateServiceUUIDs();
306 SetGattServicesDiscoveryComplete(true); 304 SetGattServicesDiscoveryComplete(true);
307 adapter_->NotifyGattServicesDiscovered(this); 305 adapter_->NotifyGattServicesDiscovered(this);
308 } 306 }
309 } 307 }
310 308
311 void BluetoothLowEnergyDeviceMac::DidModifyServices( 309 void BluetoothLowEnergyDeviceMac::DidModifyServices(
312 NSArray* invalidatedServices) { 310 NSArray* invalidatedServices) {
313 for (CBService* cb_service in invalidatedServices) { 311 for (CBService* cb_service in invalidatedServices) {
314 BluetoothRemoteGattServiceMac* gatt_service = 312 BluetoothRemoteGattServiceMac* gatt_service =
315 GetBluetoothRemoteGattService(cb_service); 313 GetBluetoothRemoteGattService(cb_service);
316 DCHECK(gatt_service); 314 DCHECK(gatt_service);
317 std::unique_ptr<BluetoothRemoteGattService> scoped_service = 315 std::unique_ptr<BluetoothRemoteGattService> scoped_service =
318 gatt_services_.take_and_erase(gatt_service->GetIdentifier()); 316 gatt_services_.take_and_erase(gatt_service->GetIdentifier());
319 adapter_->NotifyGattServiceRemoved(scoped_service.get()); 317 adapter_->NotifyGattServiceRemoved(scoped_service.get());
320 } 318 }
319 service_uuids_.clear();
321 SetGattServicesDiscoveryComplete(false); 320 SetGattServicesDiscoveryComplete(false);
322 [GetPeripheral() discoverServices:nil]; 321 [GetPeripheral() discoverServices:nil];
323 } 322 }
324 323
325 void BluetoothLowEnergyDeviceMac::DidUpdateValue( 324 void BluetoothLowEnergyDeviceMac::DidUpdateValue(
326 CBCharacteristic* characteristic, 325 CBCharacteristic* characteristic,
327 NSError* error) { 326 NSError* error) {
328 BluetoothRemoteGattServiceMac* gatt_service = 327 BluetoothRemoteGattServiceMac* gatt_service =
329 GetBluetoothRemoteGattService(characteristic.service); 328 GetBluetoothRemoteGattService(characteristic.service);
330 DCHECK(gatt_service); 329 DCHECK(gatt_service);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 GattServiceMap gatt_services_swapped; 398 GattServiceMap gatt_services_swapped;
400 gatt_services_swapped.swap(gatt_services_); 399 gatt_services_swapped.swap(gatt_services_);
401 gatt_services_swapped.clear(); 400 gatt_services_swapped.clear();
402 if (create_gatt_connection_error_callbacks_.empty()) { 401 if (create_gatt_connection_error_callbacks_.empty()) {
403 // TODO(http://crbug.com/585897): Need to pass the error. 402 // TODO(http://crbug.com/585897): Need to pass the error.
404 DidDisconnectGatt(); 403 DidDisconnectGatt();
405 } else { 404 } else {
406 DidFailToConnectGatt(error_code); 405 DidFailToConnectGatt(error_code);
407 } 406 }
408 } 407 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698