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

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

Issue 2745983003: Bluetooth: macOS: Adding logs (Closed)
Patch Set: Last fix about GetIdentifier() Created 3 years, 9 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 const std::string& identifier) const { 71 const std::string& identifier) const {
72 auto searched_pair = gatt_characteristic_macs_.find(identifier); 72 auto searched_pair = gatt_characteristic_macs_.find(identifier);
73 if (searched_pair == gatt_characteristic_macs_.end()) { 73 if (searched_pair == gatt_characteristic_macs_.end()) {
74 return nullptr; 74 return nullptr;
75 } 75 }
76 return static_cast<BluetoothRemoteGattCharacteristic*>( 76 return static_cast<BluetoothRemoteGattCharacteristic*>(
77 searched_pair->second.get()); 77 searched_pair->second.get());
78 } 78 }
79 79
80 void BluetoothRemoteGattServiceMac::DiscoverCharacteristics() { 80 void BluetoothRemoteGattServiceMac::DiscoverCharacteristics() {
81 VLOG(1) << ToString() << ": DiscoverCharacteristics.";
81 is_discovery_complete_ = false; 82 is_discovery_complete_ = false;
82 [GetCBPeripheral() discoverCharacteristics:nil forService:GetService()]; 83 [GetCBPeripheral() discoverCharacteristics:nil forService:GetService()];
83 } 84 }
84 85
85 void BluetoothRemoteGattServiceMac::DidDiscoverCharacteristics() { 86 void BluetoothRemoteGattServiceMac::DidDiscoverCharacteristics() {
86 DCHECK(!is_discovery_complete_); 87 DCHECK(!is_discovery_complete_);
88 VLOG(1) << ToString() << ": DidDiscoverCharacteristics.";
87 std::unordered_set<std::string> characteristic_identifier_to_remove; 89 std::unordered_set<std::string> characteristic_identifier_to_remove;
88 for (const auto& iter : gatt_characteristic_macs_) { 90 for (const auto& iter : gatt_characteristic_macs_) {
89 characteristic_identifier_to_remove.insert(iter.first); 91 characteristic_identifier_to_remove.insert(iter.first);
90 } 92 }
91 93
92 for (CBCharacteristic* cb_characteristic in GetService().characteristics) { 94 for (CBCharacteristic* cb_characteristic in GetService().characteristics) {
93 BluetoothRemoteGattCharacteristicMac* gatt_characteristic_mac = 95 BluetoothRemoteGattCharacteristicMac* gatt_characteristic_mac =
94 GetBluetoothRemoteGattCharacteristicMac(cb_characteristic); 96 GetBluetoothRemoteGattCharacteristicMac(cb_characteristic);
95 if (gatt_characteristic_mac) { 97 if (gatt_characteristic_mac) {
98 VLOG(1) << gatt_characteristic_mac->ToString()
99 << ": Known characteristic, properties "
100 << gatt_characteristic_mac->GetProperties();
96 const std::string& identifier = gatt_characteristic_mac->GetIdentifier(); 101 const std::string& identifier = gatt_characteristic_mac->GetIdentifier();
97 characteristic_identifier_to_remove.erase(identifier); 102 characteristic_identifier_to_remove.erase(identifier);
98 gatt_characteristic_mac->DiscoverDescriptors(); 103 gatt_characteristic_mac->DiscoverDescriptors();
99 continue; 104 continue;
100 } 105 }
101 gatt_characteristic_mac = 106 gatt_characteristic_mac =
102 new BluetoothRemoteGattCharacteristicMac(this, cb_characteristic); 107 new BluetoothRemoteGattCharacteristicMac(this, cb_characteristic);
103 const std::string& identifier = gatt_characteristic_mac->GetIdentifier(); 108 const std::string& identifier = gatt_characteristic_mac->GetIdentifier();
104 auto result_iter = gatt_characteristic_macs_.insert( 109 auto result_iter = gatt_characteristic_macs_.insert(
105 {identifier, base::WrapUnique(gatt_characteristic_mac)}); 110 {identifier, base::WrapUnique(gatt_characteristic_mac)});
106 DCHECK(result_iter.second); 111 DCHECK(result_iter.second);
112 VLOG(1) << gatt_characteristic_mac->ToString()
113 << ": New characteristic, properties "
114 << gatt_characteristic_mac->GetProperties();
107 gatt_characteristic_mac->DiscoverDescriptors(); 115 gatt_characteristic_mac->DiscoverDescriptors();
108 GetMacAdapter()->NotifyGattCharacteristicAdded(gatt_characteristic_mac); 116 GetMacAdapter()->NotifyGattCharacteristicAdded(gatt_characteristic_mac);
109 } 117 }
110 118
111 for (const std::string& identifier : characteristic_identifier_to_remove) { 119 for (const std::string& identifier : characteristic_identifier_to_remove) {
112 auto pair_to_remove = gatt_characteristic_macs_.find(identifier); 120 auto pair_to_remove = gatt_characteristic_macs_.find(identifier);
113 std::unique_ptr<BluetoothRemoteGattCharacteristicMac> 121 std::unique_ptr<BluetoothRemoteGattCharacteristicMac>
114 characteristic_to_remove; 122 characteristic_to_remove;
123 VLOG(1) << characteristic_to_remove->ToString()
124 << ": Removed characteristic.";
115 pair_to_remove->second.swap(characteristic_to_remove); 125 pair_to_remove->second.swap(characteristic_to_remove);
116 gatt_characteristic_macs_.erase(pair_to_remove); 126 gatt_characteristic_macs_.erase(pair_to_remove);
117 GetMacAdapter()->NotifyGattCharacteristicRemoved( 127 GetMacAdapter()->NotifyGattCharacteristicRemoved(
118 characteristic_to_remove.get()); 128 characteristic_to_remove.get());
119 } 129 }
120 SendNotificationIfComplete(); 130 SendNotificationIfComplete();
121 } 131 }
122 132
123 void BluetoothRemoteGattServiceMac::DidDiscoverDescriptors( 133 void BluetoothRemoteGattServiceMac::DidDiscoverDescriptors(
124 CBCharacteristic* characteristic) { 134 CBCharacteristic* characteristic) {
(...skipping 10 matching lines...) Expand all
135 // Notify when all characteristics have been fully discovered. 145 // Notify when all characteristics have been fully discovered.
136 is_discovery_complete_ = 146 is_discovery_complete_ =
137 std::find_if_not( 147 std::find_if_not(
138 gatt_characteristic_macs_.begin(), gatt_characteristic_macs_.end(), 148 gatt_characteristic_macs_.begin(), gatt_characteristic_macs_.end(),
139 [](const std::pair< 149 [](const std::pair<
140 const std::string, 150 const std::string,
141 std::unique_ptr<BluetoothRemoteGattCharacteristicMac>>& pair) { 151 std::unique_ptr<BluetoothRemoteGattCharacteristicMac>>& pair) {
142 return pair.second->IsDiscoveryComplete(); 152 return pair.second->IsDiscoveryComplete();
143 }) == gatt_characteristic_macs_.end(); 153 }) == gatt_characteristic_macs_.end();
144 if (is_discovery_complete_) { 154 if (is_discovery_complete_) {
155 VLOG(1) << ToString() << ": Discovery complete.";
145 GetMacAdapter()->NotifyGattServiceChanged(this); 156 GetMacAdapter()->NotifyGattServiceChanged(this);
146 } 157 }
147 } 158 }
148 159
149 void BluetoothRemoteGattServiceMac::DidUpdateValue( 160 void BluetoothRemoteGattServiceMac::DidUpdateValue(
150 CBCharacteristic* characteristic, 161 CBCharacteristic* characteristic,
151 NSError* error) { 162 NSError* error) {
152 BluetoothRemoteGattCharacteristicMac* gatt_characteristic = 163 BluetoothRemoteGattCharacteristicMac* gatt_characteristic =
153 GetBluetoothRemoteGattCharacteristicMac(characteristic); 164 GetBluetoothRemoteGattCharacteristicMac(characteristic);
154 DCHECK(gatt_characteristic); 165 DCHECK(gatt_characteristic);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 std::unique_ptr<BluetoothRemoteGattCharacteristicMac>>& pair) { 211 std::unique_ptr<BluetoothRemoteGattCharacteristicMac>>& pair) {
201 return pair.second->GetCBCharacteristic() == characteristic; 212 return pair.second->GetCBCharacteristic() == characteristic;
202 }); 213 });
203 if (found == gatt_characteristic_macs_.end()) { 214 if (found == gatt_characteristic_macs_.end()) {
204 return nullptr; 215 return nullptr;
205 } else { 216 } else {
206 return found->second.get(); 217 return found->second.get();
207 } 218 }
208 } 219 }
209 220
221 std::string BluetoothRemoteGattServiceMac::ToString() const {
222 return std::string("<BluetoothRemoteGattServiceMac ") + GetIdentifier() +
223 ", device " + bluetooth_device_mac_->GetIdentifier() + ">";
ortuno 2017/03/14 00:34:33 Same here: UUID might be more useful.
224 }
225
210 } // namespace device 226 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698