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" |
11 #include "device/bluetooth/bluetooth_device_chromeos.h" | 11 #include "device/bluetooth/bluetooth_device_chromeos.h" |
12 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" | 12 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" |
13 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h" | 13 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h" |
14 | 14 |
15 namespace chromeos { | 15 namespace chromeos { |
16 | 16 |
17 namespace { | |
18 | |
19 // Stream operator for logging vector<uint8>. | |
20 std::ostream& operator<<(std::ostream& out, const std::vector<uint8> bytes) { | |
21 out << "["; | |
22 for (std::vector<uint8>::const_iterator iter = bytes.begin(); | |
23 iter != bytes.end(); ++iter) { | |
24 out << base::StringPrintf("%02X", *iter); | |
25 } | |
26 return out << "]"; | |
27 } | |
28 | |
29 } // namespace | |
30 | |
31 BluetoothRemoteGattServiceChromeOS::BluetoothRemoteGattServiceChromeOS( | 17 BluetoothRemoteGattServiceChromeOS::BluetoothRemoteGattServiceChromeOS( |
32 BluetoothDeviceChromeOS* device, | 18 BluetoothDeviceChromeOS* device, |
33 const dbus::ObjectPath& object_path) | 19 const dbus::ObjectPath& object_path) |
34 : object_path_(object_path), | 20 : object_path_(object_path), |
35 device_(device), | 21 device_(device), |
36 weak_ptr_factory_(this) { | 22 weak_ptr_factory_(this) { |
37 VLOG(1) << "Creating remote GATT service with identifier: " | 23 VLOG(1) << "Creating remote GATT service with identifier: " |
38 << object_path.value() << ", UUID: " << GetUUID().canonical_value(); | 24 << object_path.value() << ", UUID: " << GetUUID().canonical_value(); |
39 DBusThreadManager::Get()->GetBluetoothGattServiceClient()->AddObserver(this); | 25 DBusThreadManager::Get()->GetBluetoothGattServiceClient()->AddObserver(this); |
40 DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> | 26 DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 const ErrorCallback& error_callback) { | 144 const ErrorCallback& error_callback) { |
159 VLOG(1) << "A remote GATT service cannot be unregistered."; | 145 VLOG(1) << "A remote GATT service cannot be unregistered."; |
160 error_callback.Run(); | 146 error_callback.Run(); |
161 } | 147 } |
162 | 148 |
163 void BluetoothRemoteGattServiceChromeOS::NotifyServiceChanged() { | 149 void BluetoothRemoteGattServiceChromeOS::NotifyServiceChanged() { |
164 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, | 150 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, |
165 GattServiceChanged(this)); | 151 GattServiceChanged(this)); |
166 } | 152 } |
167 | 153 |
| 154 void BluetoothRemoteGattServiceChromeOS::NotifyCharacteristicValueChanged( |
| 155 BluetoothRemoteGattCharacteristicChromeOS* characteristic, |
| 156 const std::vector<uint8>& value) { |
| 157 DCHECK(characteristic->GetService() == this); |
| 158 FOR_EACH_OBSERVER( |
| 159 device::BluetoothGattService::Observer, |
| 160 observers_, |
| 161 GattCharacteristicValueChanged(this, characteristic, value)); |
| 162 } |
| 163 |
168 void BluetoothRemoteGattServiceChromeOS::NotifyDescriptorAddedOrRemoved( | 164 void BluetoothRemoteGattServiceChromeOS::NotifyDescriptorAddedOrRemoved( |
169 BluetoothRemoteGattCharacteristicChromeOS* characteristic, | 165 BluetoothRemoteGattCharacteristicChromeOS* characteristic, |
170 BluetoothRemoteGattDescriptorChromeOS* descriptor, | 166 BluetoothRemoteGattDescriptorChromeOS* descriptor, |
171 bool added) { | 167 bool added) { |
172 DCHECK(characteristic->GetService() == this); | 168 DCHECK(characteristic->GetService() == this); |
173 DCHECK(descriptor->GetCharacteristic() == characteristic); | 169 DCHECK(descriptor->GetCharacteristic() == characteristic); |
174 if (added) { | 170 if (added) { |
175 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, | 171 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, |
176 GattDescriptorAdded(characteristic, descriptor)); | 172 GattDescriptorAdded(characteristic, descriptor)); |
177 return; | 173 return; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 DCHECK(characteristic->object_path() == object_path); | 243 DCHECK(characteristic->object_path() == object_path); |
248 characteristics_.erase(iter); | 244 characteristics_.erase(iter); |
249 | 245 |
250 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, | 246 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, |
251 GattCharacteristicRemoved(this, characteristic)); | 247 GattCharacteristicRemoved(this, characteristic)); |
252 NotifyServiceChanged(); | 248 NotifyServiceChanged(); |
253 | 249 |
254 delete characteristic; | 250 delete characteristic; |
255 } | 251 } |
256 | 252 |
257 void BluetoothRemoteGattServiceChromeOS::GattCharacteristicPropertyChanged( | |
258 const dbus::ObjectPath& object_path, | |
259 const std::string& property_name) { | |
260 CharacteristicMap::iterator iter = characteristics_.find(object_path); | |
261 if (iter == characteristics_.end()) { | |
262 VLOG(2) << "Unknown GATT characteristic property changed: " | |
263 << object_path.value(); | |
264 return; | |
265 } | |
266 | |
267 // Ignore all property changes except for "Value". | |
268 BluetoothGattCharacteristicClient::Properties* properties = | |
269 DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> | |
270 GetProperties(object_path); | |
271 DCHECK(properties); | |
272 if (property_name != properties->value.name()) | |
273 return; | |
274 | |
275 VLOG(1) << "GATT characteristic value has changed: " << object_path.value() | |
276 << ": " << properties->value.value(); | |
277 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, | |
278 GattCharacteristicValueChanged(this, iter->second, | |
279 properties->value.value())); | |
280 } | |
281 | |
282 } // namespace chromeos | 253 } // namespace chromeos |
OLD | NEW |