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_service_chromeos.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_service_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_service_client.h" | 9 #include "chromeos/dbus/bluetooth_gatt_service_client.h" |
10 #include "chromeos/dbus/dbus_thread_manager.h" | 10 #include "chromeos/dbus/dbus_thread_manager.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 const ErrorCallback& error_callback) { | 158 const ErrorCallback& error_callback) { |
159 VLOG(1) << "A remote GATT service cannot be unregistered."; | 159 VLOG(1) << "A remote GATT service cannot be unregistered."; |
160 error_callback.Run(); | 160 error_callback.Run(); |
161 } | 161 } |
162 | 162 |
163 void BluetoothRemoteGattServiceChromeOS::NotifyServiceChanged() { | 163 void BluetoothRemoteGattServiceChromeOS::NotifyServiceChanged() { |
164 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, | 164 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, |
165 GattServiceChanged(this)); | 165 GattServiceChanged(this)); |
166 } | 166 } |
167 | 167 |
| 168 void BluetoothRemoteGattServiceChromeOS::NotifyCharacteristicValueChanged( |
| 169 BluetoothRemoteGattCharacteristicChromeOS* characteristic, |
| 170 const std::vector<uint8>& value) { |
| 171 DCHECK(characteristic->GetService() == this); |
| 172 FOR_EACH_OBSERVER( |
| 173 device::BluetoothGattService::Observer, |
| 174 observers_, |
| 175 GattCharacteristicValueChanged(this, characteristic, value)); |
| 176 } |
| 177 |
168 void BluetoothRemoteGattServiceChromeOS::NotifyDescriptorAddedOrRemoved( | 178 void BluetoothRemoteGattServiceChromeOS::NotifyDescriptorAddedOrRemoved( |
169 BluetoothRemoteGattCharacteristicChromeOS* characteristic, | 179 BluetoothRemoteGattCharacteristicChromeOS* characteristic, |
170 BluetoothRemoteGattDescriptorChromeOS* descriptor, | 180 BluetoothRemoteGattDescriptorChromeOS* descriptor, |
171 bool added) { | 181 bool added) { |
172 DCHECK(characteristic->GetService() == this); | 182 DCHECK(characteristic->GetService() == this); |
173 DCHECK(descriptor->GetCharacteristic() == characteristic); | 183 DCHECK(descriptor->GetCharacteristic() == characteristic); |
174 if (added) { | 184 if (added) { |
175 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, | 185 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, |
176 GattDescriptorAdded(characteristic, descriptor)); | 186 GattDescriptorAdded(characteristic, descriptor)); |
177 return; | 187 return; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 DCHECK(characteristic->object_path() == object_path); | 253 DCHECK(characteristic->object_path() == object_path); |
244 characteristics_.erase(iter); | 254 characteristics_.erase(iter); |
245 | 255 |
246 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, | 256 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, |
247 GattCharacteristicRemoved(this, characteristic)); | 257 GattCharacteristicRemoved(this, characteristic)); |
248 NotifyServiceChanged(); | 258 NotifyServiceChanged(); |
249 | 259 |
250 delete characteristic; | 260 delete characteristic; |
251 } | 261 } |
252 | 262 |
253 void BluetoothRemoteGattServiceChromeOS::GattCharacteristicPropertyChanged( | |
254 const dbus::ObjectPath& object_path, | |
255 const std::string& property_name) { | |
256 CharacteristicMap::iterator iter = characteristics_.find(object_path); | |
257 if (iter == characteristics_.end()) { | |
258 VLOG(2) << "Unknown GATT characteristic property changed: " | |
259 << object_path.value(); | |
260 return; | |
261 } | |
262 | |
263 // Ignore all property changes except for "Value". | |
264 BluetoothGattCharacteristicClient::Properties* properties = | |
265 DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> | |
266 GetProperties(object_path); | |
267 DCHECK(properties); | |
268 if (property_name != properties->value.name()) | |
269 return; | |
270 | |
271 VLOG(1) << "GATT characteristic value has changed: " << object_path.value() | |
272 << ": " << properties->value.value(); | |
273 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, | |
274 GattCharacteristicValueChanged(this, iter->second, | |
275 properties->value.value())); | |
276 } | |
277 | |
278 } // namespace chromeos | 263 } // namespace chromeos |
OLD | NEW |