Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_characteristic_mac.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 return nullptr; | 145 return nullptr; |
| 146 } | 146 } |
| 147 return static_cast<BluetoothRemoteGattDescriptor*>( | 147 return static_cast<BluetoothRemoteGattDescriptor*>( |
| 148 searched_pair->second.get()); | 148 searched_pair->second.get()); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void BluetoothRemoteGattCharacteristicMac::ReadRemoteCharacteristic( | 151 void BluetoothRemoteGattCharacteristicMac::ReadRemoteCharacteristic( |
| 152 const ValueCallback& callback, | 152 const ValueCallback& callback, |
| 153 const ErrorCallback& error_callback) { | 153 const ErrorCallback& error_callback) { |
| 154 if (!IsReadable()) { | 154 if (!IsReadable()) { |
| 155 VLOG(1) << ToString() << ": Characteristic not readable."; | |
| 155 base::ThreadTaskRunnerHandle::Get()->PostTask( | 156 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 156 FROM_HERE, | 157 FROM_HERE, |
| 157 base::Bind(error_callback, | 158 base::Bind(error_callback, |
| 158 BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); | 159 BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); |
| 159 return; | 160 return; |
| 160 } | 161 } |
| 161 if (characteristic_value_read_or_write_in_progress_) { | 162 if (characteristic_value_read_or_write_in_progress_) { |
| 163 VLOG(1) << ToString() << ": Characteristic read already in progress."; | |
| 162 base::ThreadTaskRunnerHandle::Get()->PostTask( | 164 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 163 FROM_HERE, | 165 FROM_HERE, |
| 164 base::Bind(error_callback, | 166 base::Bind(error_callback, |
| 165 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS)); | 167 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS)); |
| 166 return; | 168 return; |
| 167 } | 169 } |
| 170 VLOG(1) << ToString() << ": Read characteristic."; | |
| 168 characteristic_value_read_or_write_in_progress_ = true; | 171 characteristic_value_read_or_write_in_progress_ = true; |
| 169 read_characteristic_value_callbacks_ = | 172 read_characteristic_value_callbacks_ = |
| 170 std::make_pair(callback, error_callback); | 173 std::make_pair(callback, error_callback); |
| 171 [GetCBPeripheral() readValueForCharacteristic:cb_characteristic_]; | 174 [GetCBPeripheral() readValueForCharacteristic:cb_characteristic_]; |
| 172 } | 175 } |
| 173 | 176 |
| 174 void BluetoothRemoteGattCharacteristicMac::WriteRemoteCharacteristic( | 177 void BluetoothRemoteGattCharacteristicMac::WriteRemoteCharacteristic( |
| 175 const std::vector<uint8_t>& value, | 178 const std::vector<uint8_t>& value, |
| 176 const base::Closure& callback, | 179 const base::Closure& callback, |
| 177 const ErrorCallback& error_callback) { | 180 const ErrorCallback& error_callback) { |
| 178 if (!IsWritable()) { | 181 if (!IsWritable()) { |
| 182 VLOG(1) << ToString() << ": Characteristic not writable."; | |
| 179 base::ThreadTaskRunnerHandle::Get()->PostTask( | 183 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 180 FROM_HERE, | 184 FROM_HERE, |
| 181 base::Bind(error_callback, | 185 base::Bind(error_callback, |
| 182 BluetoothRemoteGattService::GATT_ERROR_NOT_PERMITTED)); | 186 BluetoothRemoteGattService::GATT_ERROR_NOT_PERMITTED)); |
| 183 return; | 187 return; |
| 184 } | 188 } |
| 185 if (characteristic_value_read_or_write_in_progress_) { | 189 if (characteristic_value_read_or_write_in_progress_) { |
| 190 VLOG(1) << ToString() << ": Characteristic write already in progress."; | |
| 186 base::ThreadTaskRunnerHandle::Get()->PostTask( | 191 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 187 FROM_HERE, | 192 FROM_HERE, |
| 188 base::Bind(error_callback, | 193 base::Bind(error_callback, |
| 189 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS)); | 194 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS)); |
| 190 return; | 195 return; |
| 191 } | 196 } |
| 197 VLOG(1) << ToString() << ": Write characteristic."; | |
| 192 characteristic_value_read_or_write_in_progress_ = true; | 198 characteristic_value_read_or_write_in_progress_ = true; |
| 193 write_characteristic_value_callbacks_ = | 199 write_characteristic_value_callbacks_ = |
| 194 std::make_pair(callback, error_callback); | 200 std::make_pair(callback, error_callback); |
| 195 base::scoped_nsobject<NSData> nsdata_value( | 201 base::scoped_nsobject<NSData> nsdata_value( |
| 196 [[NSData alloc] initWithBytes:value.data() length:value.size()]); | 202 [[NSData alloc] initWithBytes:value.data() length:value.size()]); |
| 197 CBCharacteristicWriteType write_type = GetCBWriteType(); | 203 CBCharacteristicWriteType write_type = GetCBWriteType(); |
| 198 [GetCBPeripheral() writeValue:nsdata_value | 204 [GetCBPeripheral() writeValue:nsdata_value |
| 199 forCharacteristic:cb_characteristic_ | 205 forCharacteristic:cb_characteristic_ |
| 200 type:write_type]; | 206 type:write_type]; |
| 201 if (write_type == CBCharacteristicWriteWithoutResponse) { | 207 if (write_type == CBCharacteristicWriteWithoutResponse) { |
| 202 base::ThreadTaskRunnerHandle::Get()->PostTask( | 208 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 203 FROM_HERE, | 209 FROM_HERE, |
| 204 base::Bind(&BluetoothRemoteGattCharacteristicMac::DidWriteValue, | 210 base::Bind(&BluetoothRemoteGattCharacteristicMac::DidWriteValue, |
| 205 base::Unretained(this), nil)); | 211 base::Unretained(this), nil)); |
| 206 } | 212 } |
| 207 } | 213 } |
| 208 | 214 |
| 209 void BluetoothRemoteGattCharacteristicMac::SubscribeToNotifications( | 215 void BluetoothRemoteGattCharacteristicMac::SubscribeToNotifications( |
| 210 BluetoothRemoteGattDescriptor* ccc_descriptor, | 216 BluetoothRemoteGattDescriptor* ccc_descriptor, |
| 211 const base::Closure& callback, | 217 const base::Closure& callback, |
| 212 const ErrorCallback& error_callback) { | 218 const ErrorCallback& error_callback) { |
| 219 VLOG(1) << ToString() << ": Subscribe to characteristic."; | |
| 213 DCHECK(subscribe_to_notification_callbacks_.first.is_null()); | 220 DCHECK(subscribe_to_notification_callbacks_.first.is_null()); |
| 214 DCHECK(subscribe_to_notification_callbacks_.second.is_null()); | 221 DCHECK(subscribe_to_notification_callbacks_.second.is_null()); |
| 215 DCHECK(unsubscribe_from_notification_callbacks_.first.is_null()); | 222 DCHECK(unsubscribe_from_notification_callbacks_.first.is_null()); |
| 216 DCHECK(unsubscribe_from_notification_callbacks_.second.is_null()); | 223 DCHECK(unsubscribe_from_notification_callbacks_.second.is_null()); |
| 217 subscribe_to_notification_callbacks_ = | 224 subscribe_to_notification_callbacks_ = |
| 218 std::make_pair(callback, error_callback); | 225 std::make_pair(callback, error_callback); |
| 219 [GetCBPeripheral() setNotifyValue:YES | 226 [GetCBPeripheral() setNotifyValue:YES |
| 220 forCharacteristic:cb_characteristic_.get()]; | 227 forCharacteristic:cb_characteristic_.get()]; |
| 221 } | 228 } |
| 222 | 229 |
| 223 void BluetoothRemoteGattCharacteristicMac::UnsubscribeFromNotifications( | 230 void BluetoothRemoteGattCharacteristicMac::UnsubscribeFromNotifications( |
| 224 BluetoothRemoteGattDescriptor* ccc_descriptor, | 231 BluetoothRemoteGattDescriptor* ccc_descriptor, |
| 225 const base::Closure& callback, | 232 const base::Closure& callback, |
| 226 const ErrorCallback& error_callback) { | 233 const ErrorCallback& error_callback) { |
| 234 VLOG(1) << ToString() << ": Unsubscribe to characteristic."; | |
|
ortuno
2017/03/14 00:34:33
Unsubscribe from characteristic.
jlebel
2017/03/15 01:08:40
Done.
| |
| 227 DCHECK(subscribe_to_notification_callbacks_.first.is_null()); | 235 DCHECK(subscribe_to_notification_callbacks_.first.is_null()); |
| 228 DCHECK(subscribe_to_notification_callbacks_.second.is_null()); | 236 DCHECK(subscribe_to_notification_callbacks_.second.is_null()); |
| 229 DCHECK(unsubscribe_from_notification_callbacks_.first.is_null()); | 237 DCHECK(unsubscribe_from_notification_callbacks_.first.is_null()); |
| 230 DCHECK(unsubscribe_from_notification_callbacks_.second.is_null()); | 238 DCHECK(unsubscribe_from_notification_callbacks_.second.is_null()); |
| 231 unsubscribe_from_notification_callbacks_ = | 239 unsubscribe_from_notification_callbacks_ = |
| 232 std::make_pair(callback, error_callback); | 240 std::make_pair(callback, error_callback); |
| 233 [GetCBPeripheral() setNotifyValue:NO | 241 [GetCBPeripheral() setNotifyValue:NO |
| 234 forCharacteristic:cb_characteristic_.get()]; | 242 forCharacteristic:cb_characteristic_.get()]; |
| 235 } | 243 } |
| 236 | 244 |
| 237 void BluetoothRemoteGattCharacteristicMac::DiscoverDescriptors() { | 245 void BluetoothRemoteGattCharacteristicMac::DiscoverDescriptors() { |
| 246 VLOG(1) << ToString() << ": Discover descriptors."; | |
| 238 is_discovery_complete_ = false; | 247 is_discovery_complete_ = false; |
| 239 [GetCBPeripheral() | 248 [GetCBPeripheral() |
| 240 discoverDescriptorsForCharacteristic:cb_characteristic_.get()]; | 249 discoverDescriptorsForCharacteristic:cb_characteristic_.get()]; |
| 241 } | 250 } |
| 242 | 251 |
| 243 void BluetoothRemoteGattCharacteristicMac::DidUpdateValue(NSError* error) { | 252 void BluetoothRemoteGattCharacteristicMac::DidUpdateValue(NSError* error) { |
| 244 CHECK_EQ(GetCBPeripheral().state, CBPeripheralStateConnected); | 253 CHECK_EQ(GetCBPeripheral().state, CBPeripheralStateConnected); |
| 245 // This method is called when the characteristic is read and when a | 254 // This method is called when the characteristic is read and when a |
| 246 // notification is received. | 255 // notification is received. |
| 247 if (characteristic_value_read_or_write_in_progress_) { | 256 if (characteristic_value_read_or_write_in_progress_) { |
| 257 VLOG(1) << ToString() << ": Update value."; | |
|
ortuno
2017/03/14 00:34:33
I would get rid of this one and log each case sepa
jlebel
2017/03/15 01:08:40
Done.
| |
| 248 std::pair<ValueCallback, ErrorCallback> callbacks; | 258 std::pair<ValueCallback, ErrorCallback> callbacks; |
| 249 callbacks.swap(read_characteristic_value_callbacks_); | 259 callbacks.swap(read_characteristic_value_callbacks_); |
| 250 characteristic_value_read_or_write_in_progress_ = false; | 260 characteristic_value_read_or_write_in_progress_ = false; |
| 251 if (error) { | 261 if (error) { |
| 252 VLOG(1) << "Bluetooth error while reading for characteristic, domain: " | 262 VLOG(1) << ToString() |
| 263 << ": Bluetooth error while reading for characteristic, domain: " | |
| 253 << base::SysNSStringToUTF8(error.domain) | 264 << base::SysNSStringToUTF8(error.domain) |
| 254 << ", error code: " << error.code; | 265 << ", error code: " << error.code; |
| 255 BluetoothGattService::GattErrorCode error_code = | 266 BluetoothGattService::GattErrorCode error_code = |
| 256 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | 267 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); |
| 257 callbacks.second.Run(error_code); | 268 callbacks.second.Run(error_code); |
| 258 return; | 269 return; |
| 259 } | 270 } |
| 260 UpdateValue(); | 271 UpdateValue(); |
|
ortuno
2017/03/14 00:34:33
Read request arrived.
jlebel
2017/03/15 01:08:40
Done.
| |
| 261 callbacks.first.Run(value_); | 272 callbacks.first.Run(value_); |
| 262 } else if (IsNotifying()) { | 273 } else if (IsNotifying()) { |
| 263 UpdateValue(); | 274 UpdateValue(); |
|
ortuno
2017/03/14 00:34:33
Notification arrived.
jlebel
2017/03/15 01:08:40
Done.
| |
| 264 gatt_service_->GetMacAdapter()->NotifyGattCharacteristicValueChanged( | 275 gatt_service_->GetMacAdapter()->NotifyGattCharacteristicValueChanged( |
| 265 this, value_); | 276 this, value_); |
| 266 } else { | 277 } else { |
| 267 // In case of buggy device, nothing should be done if receiving extra | 278 // In case of buggy device, nothing should be done if receiving extra |
| 268 // read confirmation. | 279 // read confirmation. |
| 269 VLOG(1) << "Characteristic value updated while having no pending read nor " | 280 VLOG(1) |
| 270 "notification."; | 281 << ToString() |
| 282 << ": Characteristic value updated while having no pending read nor " | |
| 283 "notification."; | |
| 271 } | 284 } |
| 272 } | 285 } |
| 273 | 286 |
| 274 void BluetoothRemoteGattCharacteristicMac::UpdateValue() { | 287 void BluetoothRemoteGattCharacteristicMac::UpdateValue() { |
| 288 VLOG(1) << ToString() << ": Update value."; | |
|
ortuno
2017/03/14 00:34:33
This seems a bit unnecessary. We are already loggi
jlebel
2017/03/15 01:08:40
Done.
| |
| 275 NSData* nsdata_value = cb_characteristic_.get().value; | 289 NSData* nsdata_value = cb_characteristic_.get().value; |
| 276 const uint8_t* buffer = static_cast<const uint8_t*>(nsdata_value.bytes); | 290 const uint8_t* buffer = static_cast<const uint8_t*>(nsdata_value.bytes); |
| 277 value_.assign(buffer, buffer + nsdata_value.length); | 291 value_.assign(buffer, buffer + nsdata_value.length); |
| 278 } | 292 } |
| 279 | 293 |
| 280 void BluetoothRemoteGattCharacteristicMac::DidWriteValue(NSError* error) { | 294 void BluetoothRemoteGattCharacteristicMac::DidWriteValue(NSError* error) { |
| 281 CHECK_EQ(GetCBPeripheral().state, CBPeripheralStateConnected); | 295 CHECK_EQ(GetCBPeripheral().state, CBPeripheralStateConnected); |
| 282 if (!characteristic_value_read_or_write_in_progress_) { | 296 if (!characteristic_value_read_or_write_in_progress_) { |
| 283 // In case of buggy device, nothing should be done if receiving extra | 297 // In case of buggy device, nothing should be done if receiving extra |
| 284 // write confirmation. | 298 // write confirmation. |
| 285 VLOG(1) << "Write notification while no write operation pending."; | 299 VLOG(1) << ToString() |
| 300 << ": Write notification while no write operation pending."; | |
| 286 return; | 301 return; |
| 287 } | 302 } |
| 303 VLOG(1) << ToString() << ": Write value."; | |
|
ortuno
2017/03/14 00:34:33
Move this all the way down and change it to: "Writ
jlebel
2017/03/15 01:08:40
Done.
| |
| 288 std::pair<base::Closure, ErrorCallback> callbacks; | 304 std::pair<base::Closure, ErrorCallback> callbacks; |
| 289 callbacks.swap(write_characteristic_value_callbacks_); | 305 callbacks.swap(write_characteristic_value_callbacks_); |
| 290 characteristic_value_read_or_write_in_progress_ = false; | 306 characteristic_value_read_or_write_in_progress_ = false; |
| 291 if (error) { | 307 if (error) { |
| 292 VLOG(1) << "Bluetooth error while writing for characteristic, domain: " | 308 VLOG(1) << ToString() |
| 309 << ": Bluetooth error while writing for characteristic, domain: " | |
| 293 << base::SysNSStringToUTF8(error.domain) | 310 << base::SysNSStringToUTF8(error.domain) |
| 294 << ", error code: " << error.code; | 311 << ", error code: " << error.code; |
| 295 BluetoothGattService::GattErrorCode error_code = | 312 BluetoothGattService::GattErrorCode error_code = |
| 296 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | 313 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); |
| 297 callbacks.second.Run(error_code); | 314 callbacks.second.Run(error_code); |
| 298 return; | 315 return; |
| 299 } | 316 } |
| 300 callbacks.first.Run(); | 317 callbacks.first.Run(); |
| 301 } | 318 } |
| 302 | 319 |
| 303 void BluetoothRemoteGattCharacteristicMac::DidUpdateNotificationState( | 320 void BluetoothRemoteGattCharacteristicMac::DidUpdateNotificationState( |
| 304 NSError* error) { | 321 NSError* error) { |
| 305 PendingNotifyCallbacks reentrant_safe_callbacks; | 322 PendingNotifyCallbacks reentrant_safe_callbacks; |
| 306 if (!subscribe_to_notification_callbacks_.first.is_null()) { | 323 if (!subscribe_to_notification_callbacks_.first.is_null()) { |
| 307 DCHECK([GetCBCharacteristic() isNotifying] || error); | 324 DCHECK([GetCBCharacteristic() isNotifying] || error); |
| 308 reentrant_safe_callbacks.swap(subscribe_to_notification_callbacks_); | 325 reentrant_safe_callbacks.swap(subscribe_to_notification_callbacks_); |
| 309 } else if (!unsubscribe_from_notification_callbacks_.first.is_null()) { | 326 } else if (!unsubscribe_from_notification_callbacks_.first.is_null()) { |
| 310 DCHECK(![GetCBCharacteristic() isNotifying] || error); | 327 DCHECK(![GetCBCharacteristic() isNotifying] || error); |
| 311 reentrant_safe_callbacks.swap(unsubscribe_from_notification_callbacks_); | 328 reentrant_safe_callbacks.swap(unsubscribe_from_notification_callbacks_); |
| 312 } else { | 329 } else { |
| 313 VLOG(1) << "No pending notification update for characteristic " | 330 VLOG(1) << ToString() |
| 314 << GetUUID().value(); | 331 << ": No pending notification update for characteristic."; |
| 315 return; | 332 return; |
| 316 } | 333 } |
| 317 if (error) { | 334 if (error) { |
| 318 VLOG(1) << "Bluetooth error while modifying notification state for " | 335 VLOG(1) << ToString() |
| 336 << ": Bluetooth error while modifying notification state for " | |
| 319 "characteristic, domain: " | 337 "characteristic, domain: " |
| 320 << base::SysNSStringToUTF8(error.domain) | 338 << base::SysNSStringToUTF8(error.domain) |
| 321 << ", error code: " << error.code << ", localized description: " | 339 << ", error code: " << error.code << ", localized description: " |
| 322 << base::SysNSStringToUTF8(error.localizedDescription); | 340 << base::SysNSStringToUTF8(error.localizedDescription); |
| 323 BluetoothGattService::GattErrorCode error_code = | 341 BluetoothGattService::GattErrorCode error_code = |
| 324 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); | 342 BluetoothDeviceMac::GetGattErrorCodeFromNSError(error); |
| 325 reentrant_safe_callbacks.second.Run(error_code); | 343 reentrant_safe_callbacks.second.Run(error_code); |
| 326 return; | 344 return; |
| 327 } | 345 } |
| 328 reentrant_safe_callbacks.first.Run(); | 346 reentrant_safe_callbacks.first.Run(); |
| 329 } | 347 } |
| 330 | 348 |
| 331 void BluetoothRemoteGattCharacteristicMac::DidDiscoverDescriptors() { | 349 void BluetoothRemoteGattCharacteristicMac::DidDiscoverDescriptors() { |
| 332 DCHECK(!is_discovery_complete_); | 350 DCHECK(!is_discovery_complete_); |
| 351 VLOG(1) << ToString() << "Did discover descriptors."; | |
| 333 std::unordered_set<std::string> descriptor_identifier_to_remove; | 352 std::unordered_set<std::string> descriptor_identifier_to_remove; |
| 334 for (const auto& iter : gatt_descriptor_macs_) { | 353 for (const auto& iter : gatt_descriptor_macs_) { |
| 335 descriptor_identifier_to_remove.insert(iter.first); | 354 descriptor_identifier_to_remove.insert(iter.first); |
| 336 } | 355 } |
| 337 | 356 |
| 338 for (CBDescriptor* cb_descriptor in cb_characteristic_.get().descriptors) { | 357 for (CBDescriptor* cb_descriptor in cb_characteristic_.get().descriptors) { |
| 339 BluetoothRemoteGattDescriptorMac* gatt_descriptor_mac = | 358 BluetoothRemoteGattDescriptorMac* gatt_descriptor_mac = |
| 340 GetBluetoothRemoteGattDescriptorMac(cb_descriptor); | 359 GetBluetoothRemoteGattDescriptorMac(cb_descriptor); |
| 341 if (gatt_descriptor_mac) { | 360 if (gatt_descriptor_mac) { |
| 361 VLOG(1) << gatt_descriptor_mac->ToString() << ": Known descriptor."; | |
| 342 const std::string& identifier = gatt_descriptor_mac->GetIdentifier(); | 362 const std::string& identifier = gatt_descriptor_mac->GetIdentifier(); |
| 343 descriptor_identifier_to_remove.erase(identifier); | 363 descriptor_identifier_to_remove.erase(identifier); |
| 344 continue; | 364 continue; |
| 345 } | 365 } |
| 346 gatt_descriptor_mac = | 366 gatt_descriptor_mac = |
| 347 new BluetoothRemoteGattDescriptorMac(this, cb_descriptor); | 367 new BluetoothRemoteGattDescriptorMac(this, cb_descriptor); |
| 348 const std::string& identifier = gatt_descriptor_mac->GetIdentifier(); | 368 const std::string& identifier = gatt_descriptor_mac->GetIdentifier(); |
| 349 auto result_iter = gatt_descriptor_macs_.insert( | 369 auto result_iter = gatt_descriptor_macs_.insert( |
| 350 {identifier, base::WrapUnique(gatt_descriptor_mac)}); | 370 {identifier, base::WrapUnique(gatt_descriptor_mac)}); |
| 351 DCHECK(result_iter.second); | 371 DCHECK(result_iter.second); |
| 352 GetMacAdapter()->NotifyGattDescriptorAdded(gatt_descriptor_mac); | 372 GetMacAdapter()->NotifyGattDescriptorAdded(gatt_descriptor_mac); |
| 373 VLOG(1) << gatt_descriptor_mac->ToString() << ": New descriptor."; | |
| 353 } | 374 } |
| 354 | 375 |
| 355 for (const std::string& identifier : descriptor_identifier_to_remove) { | 376 for (const std::string& identifier : descriptor_identifier_to_remove) { |
| 356 auto pair_to_remove = gatt_descriptor_macs_.find(identifier); | 377 auto pair_to_remove = gatt_descriptor_macs_.find(identifier); |
| 357 std::unique_ptr<BluetoothRemoteGattDescriptorMac> descriptor_to_remove; | 378 std::unique_ptr<BluetoothRemoteGattDescriptorMac> descriptor_to_remove; |
| 379 VLOG(1) << descriptor_to_remove->ToString() << ": Removed descriptor."; | |
| 358 pair_to_remove->second.swap(descriptor_to_remove); | 380 pair_to_remove->second.swap(descriptor_to_remove); |
| 359 gatt_descriptor_macs_.erase(pair_to_remove); | 381 gatt_descriptor_macs_.erase(pair_to_remove); |
| 360 GetMacAdapter()->NotifyGattDescriptorRemoved(descriptor_to_remove.get()); | 382 GetMacAdapter()->NotifyGattDescriptorRemoved(descriptor_to_remove.get()); |
| 361 } | 383 } |
| 362 is_discovery_complete_ = true; | 384 is_discovery_complete_ = true; |
| 363 } | 385 } |
| 364 | 386 |
| 365 bool BluetoothRemoteGattCharacteristicMac::IsReadable() const { | 387 bool BluetoothRemoteGattCharacteristicMac::IsReadable() const { |
| 366 return GetProperties() & BluetoothGattCharacteristic::PROPERTY_READ; | 388 return GetProperties() & BluetoothGattCharacteristic::PROPERTY_READ; |
| 367 } | 389 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 std::unique_ptr<BluetoothRemoteGattDescriptorMac>>& | 435 std::unique_ptr<BluetoothRemoteGattDescriptorMac>>& |
| 414 pair) { | 436 pair) { |
| 415 return pair.second->GetCBDescriptor() == cb_descriptor; | 437 return pair.second->GetCBDescriptor() == cb_descriptor; |
| 416 }); | 438 }); |
| 417 if (found == gatt_descriptor_macs_.end()) { | 439 if (found == gatt_descriptor_macs_.end()) { |
| 418 return nullptr; | 440 return nullptr; |
| 419 } else { | 441 } else { |
| 420 return found->second.get(); | 442 return found->second.get(); |
| 421 } | 443 } |
| 422 } | 444 } |
| 445 | |
| 446 std::string BluetoothRemoteGattCharacteristicMac::ToString() const { | |
| 447 return std::string("<BluetoothRemoteGattCharacteristicMac ") + | |
| 448 GetIdentifier() + ", service " + gatt_service_->GetIdentifier() + ">"; | |
|
ortuno
2017/03/14 00:34:33
A UUID is more useful than the identifier.
jlebel
2017/03/15 01:08:40
The identifier contains the uuid and the memory ad
scheib
2017/03/21 21:43:31
I think GetIdentifier is OK as jlebel states - no
jlebel
2017/03/21 23:57:59
Done.
| |
| 449 } | |
| 423 } // namespace device. | 450 } // namespace device. |
| OLD | NEW |