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

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

Issue 2595373003: Bluetooth: mac: Working on macOS descriptor implementation. (Closed)
Patch Set: Fixes Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_remote_gatt_service_mac.h" 5 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h"
6 6
7 #import <CoreBluetooth/CoreBluetooth.h> 7 #import <CoreBluetooth/CoreBluetooth.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 for (const auto& iter : gatt_characteristic_macs_) { 88 for (const auto& iter : gatt_characteristic_macs_) {
89 characteristic_identifier_to_remove.insert(iter.first); 89 characteristic_identifier_to_remove.insert(iter.first);
90 } 90 }
91 91
92 for (CBCharacteristic* cb_characteristic in GetService().characteristics) { 92 for (CBCharacteristic* cb_characteristic in GetService().characteristics) {
93 BluetoothRemoteGattCharacteristicMac* gatt_characteristic_mac = 93 BluetoothRemoteGattCharacteristicMac* gatt_characteristic_mac =
94 GetBluetoothRemoteGattCharacteristicMac(cb_characteristic); 94 GetBluetoothRemoteGattCharacteristicMac(cb_characteristic);
95 if (gatt_characteristic_mac) { 95 if (gatt_characteristic_mac) {
96 const std::string& identifier = gatt_characteristic_mac->GetIdentifier(); 96 const std::string& identifier = gatt_characteristic_mac->GetIdentifier();
97 characteristic_identifier_to_remove.erase(identifier); 97 characteristic_identifier_to_remove.erase(identifier);
98 gatt_characteristic_mac->DiscoverDescriptors();
98 continue; 99 continue;
99 } 100 }
100 gatt_characteristic_mac = 101 gatt_characteristic_mac =
101 new BluetoothRemoteGattCharacteristicMac(this, cb_characteristic); 102 new BluetoothRemoteGattCharacteristicMac(this, cb_characteristic);
102 const std::string& identifier = gatt_characteristic_mac->GetIdentifier(); 103 const std::string& identifier = gatt_characteristic_mac->GetIdentifier();
103 auto result_iter = gatt_characteristic_macs_.insert( 104 auto result_iter = gatt_characteristic_macs_.insert(
104 {identifier, base::WrapUnique(gatt_characteristic_mac)}); 105 {identifier, base::WrapUnique(gatt_characteristic_mac)});
105 DCHECK(result_iter.second); 106 DCHECK(result_iter.second);
107 gatt_characteristic_mac->DiscoverDescriptors();
106 GetMacAdapter()->NotifyGattCharacteristicAdded(gatt_characteristic_mac); 108 GetMacAdapter()->NotifyGattCharacteristicAdded(gatt_characteristic_mac);
107 } 109 }
108 110
109 for (const std::string& identifier : characteristic_identifier_to_remove) { 111 for (const std::string& identifier : characteristic_identifier_to_remove) {
110 auto pair_to_remove = gatt_characteristic_macs_.find(identifier); 112 auto pair_to_remove = gatt_characteristic_macs_.find(identifier);
111 std::unique_ptr<BluetoothRemoteGattCharacteristicMac> 113 std::unique_ptr<BluetoothRemoteGattCharacteristicMac>
112 characteristic_to_remove; 114 characteristic_to_remove;
113 pair_to_remove->second.swap(characteristic_to_remove); 115 pair_to_remove->second.swap(characteristic_to_remove);
114 gatt_characteristic_macs_.erase(pair_to_remove); 116 gatt_characteristic_macs_.erase(pair_to_remove);
115 GetMacAdapter()->NotifyGattCharacteristicRemoved( 117 GetMacAdapter()->NotifyGattCharacteristicRemoved(
116 characteristic_to_remove.get()); 118 characteristic_to_remove.get());
117 } 119 }
118 SendNotificationIfComplete(); 120 SendNotificationIfComplete();
119 } 121 }
120 122
123 void BluetoothRemoteGattServiceMac::DidDiscoverDescriptors(
124 CBCharacteristic* characteristic) {
125 DCHECK(!is_discovery_complete_);
126 BluetoothRemoteGattCharacteristicMac* gatt_characteristic =
127 GetBluetoothRemoteGattCharacteristicMac(characteristic);
128 DCHECK(gatt_characteristic);
129 gatt_characteristic->DidDiscoverDescriptors();
130 SendNotificationIfComplete();
131 }
132
121 void BluetoothRemoteGattServiceMac::SendNotificationIfComplete() { 133 void BluetoothRemoteGattServiceMac::SendNotificationIfComplete() {
122 DCHECK(!is_discovery_complete_); 134 DCHECK(!is_discovery_complete_);
123 // Notify when all characteristics have been fully discovered. 135 // Notify when all characteristics have been fully discovered.
124 is_discovery_complete_ = 136 is_discovery_complete_ =
125 std::find_if_not( 137 std::find_if_not(
126 gatt_characteristic_macs_.begin(), gatt_characteristic_macs_.end(), 138 gatt_characteristic_macs_.begin(), gatt_characteristic_macs_.end(),
127 [](const std::pair< 139 [](const std::pair<
128 const std::string, 140 const std::string,
129 std::unique_ptr<BluetoothRemoteGattCharacteristicMac>>& pair) { 141 std::unique_ptr<BluetoothRemoteGattCharacteristicMac>>& pair) {
130 return pair.second->IsDiscoveryComplete(); 142 return pair.second->IsDiscoveryComplete();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 return pair.second->GetCBCharacteristic() == characteristic; 201 return pair.second->GetCBCharacteristic() == characteristic;
190 }); 202 });
191 if (found == gatt_characteristic_macs_.end()) { 203 if (found == gatt_characteristic_macs_.end()) {
192 return nullptr; 204 return nullptr;
193 } else { 205 } else {
194 return found->second.get(); 206 return found->second.get();
195 } 207 }
196 } 208 }
197 209
198 } // namespace device 210 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_service_mac.h ('k') | device/bluetooth/test/bluetooth_test_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698