OLD | NEW |
1 // Copyright 2014 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_service_bluez.h" | |
6 | |
7 #include <iterator> | 5 #include <iterator> |
8 | 6 |
9 #include "base/callback.h" | |
10 #include "base/callback_forward.h" | |
11 #include "base/logging.h" | 7 #include "base/logging.h" |
12 #include "dbus/property.h" | 8 #include "dbus/property.h" |
13 #include "device/bluetooth/bluetooth_adapter_bluez.h" | 9 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" |
14 #include "device/bluetooth/bluetooth_device_bluez.h" | 10 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" |
15 #include "device/bluetooth/bluetooth_gatt_characteristic_bluez.h" | 11 #include "device/bluetooth/bluez/bluetooth_gatt_characteristic_bluez.h" |
16 #include "device/bluetooth/bluetooth_gatt_descriptor_bluez.h" | 12 #include "device/bluetooth/bluez/bluetooth_remote_gatt_characteristic_bluez.h" |
17 #include "device/bluetooth/bluetooth_gatt_service.h" | 13 #include "device/bluetooth/bluez/bluetooth_remote_gatt_descriptor_bluez.h" |
18 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h" | 14 #include "device/bluetooth/bluez/bluetooth_remote_gatt_service_bluez.h" |
19 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 15 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
20 | 16 |
21 namespace bluez { | 17 namespace bluez { |
22 | 18 |
23 BluetoothRemoteGattServiceBlueZ::BluetoothRemoteGattServiceBlueZ( | 19 BluetoothRemoteGattServiceBlueZ::BluetoothRemoteGattServiceBlueZ( |
24 BluetoothAdapterBlueZ* adapter, | 20 BluetoothAdapterBlueZ* adapter, |
25 BluetoothDeviceBlueZ* device, | 21 BluetoothDeviceBlueZ* device, |
26 const dbus::ObjectPath& object_path) | 22 const dbus::ObjectPath& object_path) |
27 : BluetoothGattServiceBlueZ(adapter, object_path), | 23 : BluetoothGattServiceBlueZ(adapter, object_path), |
28 device_(device), | 24 device_(device), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 68 |
73 device::BluetoothUUID BluetoothRemoteGattServiceBlueZ::GetUUID() const { | 69 device::BluetoothUUID BluetoothRemoteGattServiceBlueZ::GetUUID() const { |
74 bluez::BluetoothGattServiceClient::Properties* properties = | 70 bluez::BluetoothGattServiceClient::Properties* properties = |
75 bluez::BluezDBusManager::Get() | 71 bluez::BluezDBusManager::Get() |
76 ->GetBluetoothGattServiceClient() | 72 ->GetBluetoothGattServiceClient() |
77 ->GetProperties(object_path()); | 73 ->GetProperties(object_path()); |
78 DCHECK(properties); | 74 DCHECK(properties); |
79 return device::BluetoothUUID(properties->uuid.value()); | 75 return device::BluetoothUUID(properties->uuid.value()); |
80 } | 76 } |
81 | 77 |
82 bool BluetoothRemoteGattServiceBlueZ::IsLocal() const { | |
83 return false; | |
84 } | |
85 | |
86 bool BluetoothRemoteGattServiceBlueZ::IsPrimary() const { | 78 bool BluetoothRemoteGattServiceBlueZ::IsPrimary() const { |
87 bluez::BluetoothGattServiceClient::Properties* properties = | 79 bluez::BluetoothGattServiceClient::Properties* properties = |
88 bluez::BluezDBusManager::Get() | 80 bluez::BluezDBusManager::Get() |
89 ->GetBluetoothGattServiceClient() | 81 ->GetBluetoothGattServiceClient() |
90 ->GetProperties(object_path()); | 82 ->GetProperties(object_path()); |
91 DCHECK(properties); | 83 DCHECK(properties); |
92 return properties->primary.value(); | 84 return properties->primary.value(); |
93 } | 85 } |
94 | 86 |
95 device::BluetoothDevice* BluetoothRemoteGattServiceBlueZ::GetDevice() const { | 87 device::BluetoothDevice* BluetoothRemoteGattServiceBlueZ::GetDevice() const { |
96 return device_; | 88 return device_; |
97 } | 89 } |
98 | 90 |
99 bool BluetoothRemoteGattServiceBlueZ::AddCharacteristic( | 91 std::vector<device::BluetoothRemoteGattCharacteristic*> |
100 device::BluetoothGattCharacteristic* characteristic) { | 92 BluetoothRemoteGattServiceBlueZ::GetCharacteristics() const { |
101 VLOG(1) << "Characteristics cannot be added to a remote GATT service."; | 93 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics; |
102 return false; | 94 for (CharacteristicMap::const_iterator iter = characteristics_.begin(); |
| 95 iter != characteristics_.end(); ++iter) { |
| 96 characteristics.push_back(iter->second); |
| 97 } |
| 98 return characteristics; |
103 } | 99 } |
104 | 100 |
105 bool BluetoothRemoteGattServiceBlueZ::AddIncludedService( | 101 std::vector<device::BluetoothRemoteGattService*> |
106 device::BluetoothGattService* service) { | 102 BluetoothRemoteGattServiceBlueZ::GetIncludedServices() const { |
107 VLOG(1) << "Included services cannot be added to a remote GATT service."; | 103 // TODO(armansito): Return the actual included services here. |
108 return false; | 104 return std::vector<device::BluetoothRemoteGattService*>(); |
109 } | 105 } |
110 | 106 |
111 void BluetoothRemoteGattServiceBlueZ::Register( | 107 device::BluetoothRemoteGattCharacteristic* |
112 const base::Closure& callback, | 108 BluetoothRemoteGattServiceBlueZ::GetCharacteristic( |
113 const ErrorCallback& error_callback) { | 109 const std::string& identifier) const { |
114 VLOG(1) << "A remote GATT service cannot be registered."; | 110 CharacteristicMap::const_iterator iter = |
115 error_callback.Run(GATT_ERROR_NOT_SUPPORTED); | 111 characteristics_.find(dbus::ObjectPath(identifier)); |
116 } | 112 if (iter == characteristics_.end()) |
117 | 113 return nullptr; |
118 void BluetoothRemoteGattServiceBlueZ::Unregister( | 114 return iter->second; |
119 const base::Closure& callback, | |
120 const ErrorCallback& error_callback) { | |
121 VLOG(1) << "A remote GATT service cannot be unregistered."; | |
122 error_callback.Run(GATT_ERROR_NOT_SUPPORTED); | |
123 } | 115 } |
124 | 116 |
125 void BluetoothRemoteGattServiceBlueZ::NotifyServiceChanged() { | 117 void BluetoothRemoteGattServiceBlueZ::NotifyServiceChanged() { |
126 // Don't send service changed unless we know that all characteristics have | 118 // Don't send service changed unless we know that all characteristics have |
127 // already been discovered. This is to prevent spammy events before sending | 119 // already been discovered. This is to prevent spammy events before sending |
128 // out the first Gatt | 120 // out the first Gatt |
129 if (!discovery_complete_) | 121 if (!discovery_complete_) |
130 return; | 122 return; |
131 | 123 |
132 DCHECK(GetAdapter()); | 124 DCHECK(GetAdapter()); |
133 GetAdapter()->NotifyGattServiceChanged(this); | 125 GetAdapter()->NotifyGattServiceChanged(this); |
134 } | 126 } |
135 | 127 |
136 void BluetoothRemoteGattServiceBlueZ::NotifyDescriptorAddedOrRemoved( | 128 void BluetoothRemoteGattServiceBlueZ::NotifyDescriptorAddedOrRemoved( |
137 BluetoothRemoteGattCharacteristicBlueZ* characteristic, | 129 BluetoothRemoteGattCharacteristicBlueZ* characteristic, |
138 BluetoothGattDescriptorBlueZ* descriptor, | 130 BluetoothRemoteGattDescriptorBlueZ* descriptor, |
139 bool added) { | 131 bool added) { |
140 DCHECK(characteristic->GetService() == this); | 132 DCHECK(characteristic->GetService() == this); |
141 DCHECK(descriptor->GetCharacteristic() == characteristic); | 133 DCHECK(descriptor->GetCharacteristic() == characteristic); |
142 DCHECK(GetAdapter()); | 134 DCHECK(GetAdapter()); |
143 | 135 |
144 if (added) { | 136 if (added) { |
145 GetAdapter()->NotifyGattDescriptorAdded(descriptor); | 137 GetAdapter()->NotifyGattDescriptorAdded(descriptor); |
146 return; | 138 return; |
147 } | 139 } |
148 | 140 |
149 GetAdapter()->NotifyGattDescriptorRemoved(descriptor); | 141 GetAdapter()->NotifyGattDescriptorRemoved(descriptor); |
150 } | 142 } |
151 | 143 |
152 void BluetoothRemoteGattServiceBlueZ::NotifyDescriptorValueChanged( | 144 void BluetoothRemoteGattServiceBlueZ::NotifyDescriptorValueChanged( |
153 BluetoothRemoteGattCharacteristicBlueZ* characteristic, | 145 BluetoothRemoteGattCharacteristicBlueZ* characteristic, |
154 BluetoothGattDescriptorBlueZ* descriptor, | 146 BluetoothRemoteGattDescriptorBlueZ* descriptor, |
155 const std::vector<uint8_t>& value) { | 147 const std::vector<uint8_t>& value) { |
156 DCHECK(characteristic->GetService() == this); | 148 DCHECK(characteristic->GetService() == this); |
157 DCHECK(descriptor->GetCharacteristic() == characteristic); | 149 DCHECK(descriptor->GetCharacteristic() == characteristic); |
158 DCHECK(GetAdapter()); | 150 DCHECK(GetAdapter()); |
159 GetAdapter()->NotifyGattDescriptorValueChanged(descriptor, value); | 151 GetAdapter()->NotifyGattDescriptorValueChanged(descriptor, value); |
160 } | 152 } |
161 | 153 |
162 void BluetoothRemoteGattServiceBlueZ::GattServicePropertyChanged( | 154 void BluetoothRemoteGattServiceBlueZ::GattServicePropertyChanged( |
163 const dbus::ObjectPath& object_path, | 155 const dbus::ObjectPath& object_path, |
164 const std::string& property_name) { | 156 const std::string& property_name) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 const dbus::ObjectPath& object_path) { | 215 const dbus::ObjectPath& object_path) { |
224 CharacteristicMap::iterator iter = characteristics_.find(object_path); | 216 CharacteristicMap::iterator iter = characteristics_.find(object_path); |
225 if (iter == characteristics_.end()) { | 217 if (iter == characteristics_.end()) { |
226 VLOG(2) << "Unknown GATT characteristic removed: " << object_path.value(); | 218 VLOG(2) << "Unknown GATT characteristic removed: " << object_path.value(); |
227 return; | 219 return; |
228 } | 220 } |
229 | 221 |
230 VLOG(1) << "Removing remote GATT characteristic from service: " | 222 VLOG(1) << "Removing remote GATT characteristic from service: " |
231 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value(); | 223 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value(); |
232 | 224 |
233 BluetoothGattCharacteristicBlueZ* characteristic = iter->second; | 225 BluetoothRemoteGattCharacteristicBlueZ* characteristic = iter->second; |
234 DCHECK(characteristic->object_path() == object_path); | 226 DCHECK(characteristic->object_path() == object_path); |
235 characteristics_.erase(iter); | 227 characteristics_.erase(iter); |
236 | 228 |
237 DCHECK(GetAdapter()); | 229 DCHECK(GetAdapter()); |
238 GetAdapter()->NotifyGattCharacteristicRemoved(characteristic); | 230 GetAdapter()->NotifyGattCharacteristicRemoved(characteristic); |
239 | 231 |
240 delete characteristic; | 232 delete characteristic; |
241 } | 233 } |
242 | 234 |
243 void BluetoothRemoteGattServiceBlueZ::GattCharacteristicPropertyChanged( | 235 void BluetoothRemoteGattServiceBlueZ::GattCharacteristicPropertyChanged( |
(...skipping 19 matching lines...) Expand all Loading... |
263 DCHECK(GetAdapter()); | 255 DCHECK(GetAdapter()); |
264 | 256 |
265 if (property_name == properties->flags.name()) | 257 if (property_name == properties->flags.name()) |
266 NotifyServiceChanged(); | 258 NotifyServiceChanged(); |
267 else if (property_name == properties->value.name()) | 259 else if (property_name == properties->value.name()) |
268 GetAdapter()->NotifyGattCharacteristicValueChanged( | 260 GetAdapter()->NotifyGattCharacteristicValueChanged( |
269 iter->second, properties->value.value()); | 261 iter->second, properties->value.value()); |
270 } | 262 } |
271 | 263 |
272 } // namespace bluez | 264 } // namespace bluez |
OLD | NEW |