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 | 14 |
14 namespace chromeos { | 15 namespace chromeos { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // Stream operator for logging vector<uint8>. | 19 // Stream operator for logging vector<uint8>. |
19 std::ostream& operator<<(std::ostream& out, const std::vector<uint8> bytes) { | 20 std::ostream& operator<<(std::ostream& out, const std::vector<uint8> bytes) { |
20 out << "["; | 21 out << "["; |
21 for (std::vector<uint8>::const_iterator iter = bytes.begin(); | 22 for (std::vector<uint8>::const_iterator iter = bytes.begin(); |
22 iter != bytes.end(); ++iter) { | 23 iter != bytes.end(); ++iter) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 const ErrorCallback& error_callback) { | 158 const ErrorCallback& error_callback) { |
158 VLOG(1) << "A remote GATT service cannot be unregistered."; | 159 VLOG(1) << "A remote GATT service cannot be unregistered."; |
159 error_callback.Run(); | 160 error_callback.Run(); |
160 } | 161 } |
161 | 162 |
162 void BluetoothRemoteGattServiceChromeOS::NotifyServiceChanged() { | 163 void BluetoothRemoteGattServiceChromeOS::NotifyServiceChanged() { |
163 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, | 164 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, |
164 GattServiceChanged(this)); | 165 GattServiceChanged(this)); |
165 } | 166 } |
166 | 167 |
| 168 void BluetoothRemoteGattServiceChromeOS::NotifyDescriptorAddedOrRemoved( |
| 169 BluetoothRemoteGattCharacteristicChromeOS* characteristic, |
| 170 BluetoothRemoteGattDescriptorChromeOS* descriptor, |
| 171 bool added) { |
| 172 DCHECK(characteristic->GetService() == this); |
| 173 DCHECK(descriptor->GetCharacteristic() == characteristic); |
| 174 if (added) { |
| 175 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, |
| 176 GattDescriptorAdded(characteristic, descriptor)); |
| 177 return; |
| 178 } |
| 179 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, |
| 180 GattDescriptorRemoved(characteristic, descriptor)); |
| 181 } |
| 182 |
| 183 void BluetoothRemoteGattServiceChromeOS::NotifyDescriptorValueChanged( |
| 184 BluetoothRemoteGattCharacteristicChromeOS* characteristic, |
| 185 BluetoothRemoteGattDescriptorChromeOS* descriptor, |
| 186 const std::vector<uint8>& value) { |
| 187 DCHECK(characteristic->GetService() == this); |
| 188 DCHECK(descriptor->GetCharacteristic() == characteristic); |
| 189 FOR_EACH_OBSERVER( |
| 190 device::BluetoothGattService::Observer, observers_, |
| 191 GattDescriptorValueChanged(characteristic, descriptor, value)); |
| 192 } |
| 193 |
167 void BluetoothRemoteGattServiceChromeOS::GattServicePropertyChanged( | 194 void BluetoothRemoteGattServiceChromeOS::GattServicePropertyChanged( |
168 const dbus::ObjectPath& object_path, | 195 const dbus::ObjectPath& object_path, |
169 const std::string& property_name){ | 196 const std::string& property_name){ |
170 NotifyServiceChanged(); | 197 NotifyServiceChanged(); |
171 } | 198 } |
172 | 199 |
173 void BluetoothRemoteGattServiceChromeOS::GattCharacteristicAdded( | 200 void BluetoothRemoteGattServiceChromeOS::GattCharacteristicAdded( |
174 const dbus::ObjectPath& object_path) { | 201 const dbus::ObjectPath& object_path) { |
175 if (characteristics_.find(object_path) != characteristics_.end()) { | 202 if (characteristics_.find(object_path) != characteristics_.end()) { |
176 VLOG(1) << "Remote GATT characteristic already exists: " | 203 VLOG(1) << "Remote GATT characteristic already exists: " |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 return; | 269 return; |
243 | 270 |
244 VLOG(1) << "GATT characteristic value has changed: " << object_path.value() | 271 VLOG(1) << "GATT characteristic value has changed: " << object_path.value() |
245 << ": " << properties->value.value(); | 272 << ": " << properties->value.value(); |
246 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, | 273 FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, |
247 GattCharacteristicValueChanged(this, iter->second, | 274 GattCharacteristicValueChanged(this, iter->second, |
248 properties->value.value())); | 275 properties->value.value())); |
249 } | 276 } |
250 | 277 |
251 } // namespace chromeos | 278 } // namespace chromeos |
OLD | NEW |