Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: device/bluetooth/bluez/bluetooth_device_bluez.h

Issue 2105423003: bluetooth: Update the map of GATT services when services resolve (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Address luiz's comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_DEVICE_BLUEZ_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_DEVICE_BLUEZ_H_
6 #define DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_DEVICE_BLUEZ_H_ 6 #define DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_DEVICE_BLUEZ_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/sequenced_task_runner.h" 16 #include "base/sequenced_task_runner.h"
17 #include "dbus/object_path.h" 17 #include "dbus/object_path.h"
18 #include "device/bluetooth/bluetooth_common.h" 18 #include "device/bluetooth/bluetooth_common.h"
19 #include "device/bluetooth/bluetooth_device.h" 19 #include "device/bluetooth/bluetooth_device.h"
20 #include "device/bluetooth/bluetooth_export.h" 20 #include "device/bluetooth/bluetooth_export.h"
21 #include "device/bluetooth/bluez/bluetooth_service_record_bluez.h" 21 #include "device/bluetooth/bluez/bluetooth_service_record_bluez.h"
22 #include "device/bluetooth/dbus/bluetooth_device_client.h"
23 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" 22 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h"
24 23
25 namespace device { 24 namespace device {
26 class BluetoothSocketThread; 25 class BluetoothSocketThread;
27 } // namespace device 26 } // namespace device
28 27
29 namespace bluez { 28 namespace bluez {
30 29
31 class BluetoothAdapterBlueZ; 30 class BluetoothAdapterBlueZ;
32 class BluetoothPairingBlueZ; 31 class BluetoothPairingBlueZ;
33 32
34 // The BluetoothDeviceBlueZ class implements BluetoothDevice for platforms using 33 // The BluetoothDeviceBlueZ class implements BluetoothDevice for platforms using
35 // BlueZ. 34 // BlueZ.
36 // 35 //
37 // This class is not thread-safe, but is only called from the UI thread. 36 // This class is not thread-safe, but is only called from the UI thread.
38 // 37 //
39 // A socket thread is used to create sockets but posts all callbacks on the UI 38 // A socket thread is used to create sockets but posts all callbacks on the UI
40 // thread. 39 // thread.
41 class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceBlueZ 40 class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceBlueZ
42 : public device::BluetoothDevice, 41 : public device::BluetoothDevice,
43 public bluez::BluetoothDeviceClient::Observer,
44 public bluez::BluetoothGattServiceClient::Observer { 42 public bluez::BluetoothGattServiceClient::Observer {
45 public: 43 public:
46 using GetServiceRecordsCallback = 44 using GetServiceRecordsCallback =
47 base::Callback<void(const std::vector<BluetoothServiceRecordBlueZ>&)>; 45 base::Callback<void(const std::vector<BluetoothServiceRecordBlueZ>&)>;
48 using GetServiceRecordsErrorCallback = 46 using GetServiceRecordsErrorCallback =
49 base::Callback<void(BluetoothServiceRecordBlueZ::ErrorCode)>; 47 base::Callback<void(BluetoothServiceRecordBlueZ::ErrorCode)>;
50 48
51 // BluetoothDevice override 49 // BluetoothDevice override
52 uint32_t GetBluetoothClass() const override; 50 uint32_t GetBluetoothClass() const override;
53 device::BluetoothTransport GetType() const override; 51 device::BluetoothTransport GetType() const override;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 private: 130 private:
133 friend class BluetoothAdapterBlueZ; 131 friend class BluetoothAdapterBlueZ;
134 132
135 BluetoothDeviceBlueZ( 133 BluetoothDeviceBlueZ(
136 BluetoothAdapterBlueZ* adapter, 134 BluetoothAdapterBlueZ* adapter,
137 const dbus::ObjectPath& object_path, 135 const dbus::ObjectPath& object_path,
138 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, 136 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
139 scoped_refptr<device::BluetoothSocketThread> socket_thread); 137 scoped_refptr<device::BluetoothSocketThread> socket_thread);
140 ~BluetoothDeviceBlueZ() override; 138 ~BluetoothDeviceBlueZ() override;
141 139
142 // bluez::BluetoothDeviceClient::Observer overrides
143 void DevicePropertyChanged(const dbus::ObjectPath& object_path,
144 const std::string& property_name) override;
145
146 // bluez::BluetoothGattServiceClient::Observer overrides 140 // bluez::BluetoothGattServiceClient::Observer overrides
147 void GattServiceAdded(const dbus::ObjectPath& object_path) override; 141 void GattServiceAdded(const dbus::ObjectPath& object_path) override;
148 void GattServiceRemoved(const dbus::ObjectPath& object_path) override; 142 void GattServiceRemoved(const dbus::ObjectPath& object_path) override;
149 143
150 // Called by the constructor to initialize the map of GATT services associated 144 // Called once all services have been discovered. Invokes
151 // with this device and to invoke NotifyGattDiscoveryComplete() with each 145 // NotifyGattDiscoveryComplete() for services for which we haven't notified
152 // cached service. 146 // before e.g. if a services is exposed during construction but services
153 void InitializeGattServiceMap(); 147 // haven't been resolved yet..
148 void UpdateGattServices(const dbus::ObjectPath& object_path);
154 149
155 // Called by dbus:: on completion of the D-Bus method call to get the 150 // Called by dbus:: on completion of the D-Bus method call to get the
156 // connection attributes of the current connection to the device. 151 // connection attributes of the current connection to the device.
157 void OnGetConnInfo(const ConnectionInfoCallback& callback, 152 void OnGetConnInfo(const ConnectionInfoCallback& callback,
158 int16_t rssi, 153 int16_t rssi,
159 int16_t transmit_power, 154 int16_t transmit_power,
160 int16_t max_transmit_power); 155 int16_t max_transmit_power);
161 void OnGetConnInfoError(const ConnectionInfoCallback& callback, 156 void OnGetConnInfoError(const ConnectionInfoCallback& callback,
162 const std::string& error_name, 157 const std::string& error_name,
163 const std::string& error_message); 158 const std::string& error_message);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // The dbus object path of the device object. 220 // The dbus object path of the device object.
226 dbus::ObjectPath object_path_; 221 dbus::ObjectPath object_path_;
227 222
228 // Number of ongoing calls to Connect(). 223 // Number of ongoing calls to Connect().
229 int num_connecting_calls_; 224 int num_connecting_calls_;
230 225
231 // True if the connection monitor has been started, tracking the connection 226 // True if the connection monitor has been started, tracking the connection
232 // RSSI and TX power. 227 // RSSI and TX power.
233 bool connection_monitor_started_; 228 bool connection_monitor_started_;
234 229
230 // Keeps track of all services for which we've called
231 // NotifyGattDiscoveryComplete().
232 std::unordered_set<device::BluetoothRemoteGattService*>
233 discovery_complete_notified_;
234
235 // UI thread task runner and socket thread object used to create sockets. 235 // UI thread task runner and socket thread object used to create sockets.
236 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; 236 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
237 scoped_refptr<device::BluetoothSocketThread> socket_thread_; 237 scoped_refptr<device::BluetoothSocketThread> socket_thread_;
238 238
239 // This vector temporarily caches the newly added services for later
240 // notification of discovery complete. Once DevicePropertyChange is invoked
241 // with a toggle of ServicesResolved property, the
242 // NotifyGattDiscoveryComplete() will be called with each service once.
243 std::vector<device::BluetoothRemoteGattService*>
244 newly_discovered_gatt_services_;
245 239
246 // During pairing this is set to an object that we don't own, but on which 240 // During pairing this is set to an object that we don't own, but on which
247 // we can make method calls to request, display or confirm PIN Codes and 241 // we can make method calls to request, display or confirm PIN Codes and
248 // Passkeys. Generally it is the object that owns this one. 242 // Passkeys. Generally it is the object that owns this one.
249 std::unique_ptr<BluetoothPairingBlueZ> pairing_; 243 std::unique_ptr<BluetoothPairingBlueZ> pairing_;
250 244
251 // Note: This should remain the last member so it'll be destroyed and 245 // Note: This should remain the last member so it'll be destroyed and
252 // invalidate its weak pointers before any other members are destroyed. 246 // invalidate its weak pointers before any other members are destroyed.
253 base::WeakPtrFactory<BluetoothDeviceBlueZ> weak_ptr_factory_; 247 base::WeakPtrFactory<BluetoothDeviceBlueZ> weak_ptr_factory_;
254 248
255 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceBlueZ); 249 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceBlueZ);
256 }; 250 };
257 251
258 } // namespace bluez 252 } // namespace bluez
259 253
260 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_DEVICE_BLUEZ_H_ 254 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_DEVICE_BLUEZ_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698