| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_chromeos.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" | 9 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" |
| 10 #include "chromeos/dbus/dbus_thread_manager.h" | 10 #include "chromeos/dbus/dbus_thread_manager.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 107 |
| 108 std::vector<device::BluetoothGattDescriptor*> | 108 std::vector<device::BluetoothGattDescriptor*> |
| 109 BluetoothRemoteGattCharacteristicChromeOS::GetDescriptors() const { | 109 BluetoothRemoteGattCharacteristicChromeOS::GetDescriptors() const { |
| 110 std::vector<device::BluetoothGattDescriptor*> descriptors; | 110 std::vector<device::BluetoothGattDescriptor*> descriptors; |
| 111 for (DescriptorMap::const_iterator iter = descriptors_.begin(); | 111 for (DescriptorMap::const_iterator iter = descriptors_.begin(); |
| 112 iter != descriptors_.end(); ++iter) | 112 iter != descriptors_.end(); ++iter) |
| 113 descriptors.push_back(iter->second); | 113 descriptors.push_back(iter->second); |
| 114 return descriptors; | 114 return descriptors; |
| 115 } | 115 } |
| 116 | 116 |
| 117 device::BluetoothGattDescriptor* |
| 118 BluetoothRemoteGattCharacteristicChromeOS::GetDescriptor( |
| 119 const std::string& identifier) const { |
| 120 DescriptorMap::const_iterator iter = |
| 121 descriptors_.find(dbus::ObjectPath(identifier)); |
| 122 if (iter == descriptors_.end()) |
| 123 return NULL; |
| 124 return iter->second; |
| 125 } |
| 126 |
| 117 bool BluetoothRemoteGattCharacteristicChromeOS::AddDescriptor( | 127 bool BluetoothRemoteGattCharacteristicChromeOS::AddDescriptor( |
| 118 device::BluetoothGattDescriptor* descriptor) { | 128 device::BluetoothGattDescriptor* descriptor) { |
| 119 VLOG(1) << "Descriptors cannot be added to a remote GATT characteristic."; | 129 VLOG(1) << "Descriptors cannot be added to a remote GATT characteristic."; |
| 120 return false; | 130 return false; |
| 121 } | 131 } |
| 122 | 132 |
| 123 bool BluetoothRemoteGattCharacteristicChromeOS::UpdateValue( | 133 bool BluetoothRemoteGattCharacteristicChromeOS::UpdateValue( |
| 124 const std::vector<uint8>& value) { | 134 const std::vector<uint8>& value) { |
| 125 VLOG(1) << "Cannot update the value of a remote GATT characteristic."; | 135 VLOG(1) << "Cannot update the value of a remote GATT characteristic."; |
| 126 return false; | 136 return false; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 197 |
| 188 VLOG(1) << "Adding new remote GATT descriptor for GATT characteristic: " | 198 VLOG(1) << "Adding new remote GATT descriptor for GATT characteristic: " |
| 189 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value(); | 199 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value(); |
| 190 | 200 |
| 191 BluetoothRemoteGattDescriptorChromeOS* descriptor = | 201 BluetoothRemoteGattDescriptorChromeOS* descriptor = |
| 192 new BluetoothRemoteGattDescriptorChromeOS(this, object_path); | 202 new BluetoothRemoteGattDescriptorChromeOS(this, object_path); |
| 193 descriptors_[object_path] = descriptor; | 203 descriptors_[object_path] = descriptor; |
| 194 DCHECK(descriptor->GetIdentifier() == object_path.value()); | 204 DCHECK(descriptor->GetIdentifier() == object_path.value()); |
| 195 DCHECK(descriptor->GetUUID().IsValid()); | 205 DCHECK(descriptor->GetUUID().IsValid()); |
| 196 DCHECK(service_); | 206 DCHECK(service_); |
| 207 |
| 208 service_->NotifyDescriptorAddedOrRemoved(this, descriptor, true /* added */); |
| 197 service_->NotifyServiceChanged(); | 209 service_->NotifyServiceChanged(); |
| 198 } | 210 } |
| 199 | 211 |
| 200 void BluetoothRemoteGattCharacteristicChromeOS::GattDescriptorRemoved( | 212 void BluetoothRemoteGattCharacteristicChromeOS::GattDescriptorRemoved( |
| 201 const dbus::ObjectPath& object_path) { | 213 const dbus::ObjectPath& object_path) { |
| 202 DescriptorMap::iterator iter = descriptors_.find(object_path); | 214 DescriptorMap::iterator iter = descriptors_.find(object_path); |
| 203 if (iter == descriptors_.end()) { | 215 if (iter == descriptors_.end()) { |
| 204 VLOG(2) << "Unknown descriptor removed: " << object_path.value(); | 216 VLOG(2) << "Unknown descriptor removed: " << object_path.value(); |
| 205 return; | 217 return; |
| 206 } | 218 } |
| 207 | 219 |
| 208 VLOG(1) << "Removing remote GATT descriptor from characteristic: " | 220 VLOG(1) << "Removing remote GATT descriptor from characteristic: " |
| 209 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value(); | 221 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value(); |
| 210 | 222 |
| 211 BluetoothRemoteGattDescriptorChromeOS* descriptor = iter->second; | 223 BluetoothRemoteGattDescriptorChromeOS* descriptor = iter->second; |
| 212 DCHECK(descriptor->object_path() == object_path); | 224 DCHECK(descriptor->object_path() == object_path); |
| 213 descriptors_.erase(iter); | 225 descriptors_.erase(iter); |
| 226 |
| 227 service_->NotifyDescriptorAddedOrRemoved(this, descriptor, false /* added */); |
| 214 delete descriptor; | 228 delete descriptor; |
| 215 | 229 |
| 216 DCHECK(service_); | 230 DCHECK(service_); |
| 231 |
| 217 service_->NotifyServiceChanged(); | 232 service_->NotifyServiceChanged(); |
| 218 } | 233 } |
| 219 | 234 |
| 220 void BluetoothRemoteGattCharacteristicChromeOS::GattDescriptorPropertyChanged( | 235 void BluetoothRemoteGattCharacteristicChromeOS::GattDescriptorPropertyChanged( |
| 221 const dbus::ObjectPath& object_path, | 236 const dbus::ObjectPath& object_path, |
| 222 const std::string& property_name) { | 237 const std::string& property_name) { |
| 223 DescriptorMap::const_iterator iter = descriptors_.find(object_path); | 238 DescriptorMap::const_iterator iter = descriptors_.find(object_path); |
| 224 if (iter == descriptors_.end()) | 239 if (iter == descriptors_.end()) |
| 225 return; | 240 return; |
| 226 | 241 |
| 242 // Ignore all property changes except for "Value". |
| 243 BluetoothGattDescriptorClient::Properties* properties = |
| 244 DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()-> |
| 245 GetProperties(object_path); |
| 246 DCHECK(properties); |
| 247 if (property_name != properties->value.name()) |
| 248 return; |
| 249 |
| 227 VLOG(1) << "GATT descriptor property changed: " << object_path.value() | 250 VLOG(1) << "GATT descriptor property changed: " << object_path.value() |
| 228 << ", property: " << property_name; | 251 << ", property: " << property_name; |
| 252 |
| 253 DCHECK(service_); |
| 254 |
| 255 service_->NotifyDescriptorValueChanged( |
| 256 this, iter->second, properties->value.value()); |
| 229 } | 257 } |
| 230 | 258 |
| 231 void BluetoothRemoteGattCharacteristicChromeOS::OnGetValue( | 259 void BluetoothRemoteGattCharacteristicChromeOS::OnGetValue( |
| 232 const ValueCallback& callback, | 260 const ValueCallback& callback, |
| 233 const ErrorCallback& error_callback, | 261 const ErrorCallback& error_callback, |
| 234 bool success) { | 262 bool success) { |
| 235 if (!success) { | 263 if (!success) { |
| 236 VLOG(1) << "Failed to read the value from the remote characteristic."; | 264 VLOG(1) << "Failed to read the value from the remote characteristic."; |
| 237 error_callback.Run(); | 265 error_callback.Run(); |
| 238 return; | 266 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 254 VLOG(1) << "Failed to write the value of remote characteristic."; | 282 VLOG(1) << "Failed to write the value of remote characteristic."; |
| 255 error_callback.Run(); | 283 error_callback.Run(); |
| 256 return; | 284 return; |
| 257 } | 285 } |
| 258 | 286 |
| 259 VLOG(1) << "Wrote value of remote characteristic."; | 287 VLOG(1) << "Wrote value of remote characteristic."; |
| 260 callback.Run(); | 288 callback.Run(); |
| 261 } | 289 } |
| 262 | 290 |
| 263 } // namespace chromeos | 291 } // namespace chromeos |
| OLD | NEW |