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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ | 6 #define DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <map> |
10 #include <queue> | 11 #include <queue> |
11 #include <string> | 12 #include <string> |
12 #include <utility> | 13 #include <utility> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "base/callback_forward.h" | 16 #include "base/callback_forward.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
18 #include "dbus/object_path.h" | 19 #include "dbus/object_path.h" |
19 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 20 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
20 #include "device/bluetooth/bluetooth_gatt_characteristic_bluez.h" | 21 #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
21 #include "device/bluetooth/bluetooth_uuid.h" | 22 #include "device/bluetooth/bluetooth_uuid.h" |
| 23 #include "device/bluetooth/bluez/bluetooth_gatt_characteristic_bluez.h" |
22 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_client.h" | 24 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_client.h" |
23 | 25 |
24 namespace device { | 26 namespace device { |
25 | 27 |
26 class BluetoothGattDescriptor; | 28 class BluetoothRemoteGattDescriptor; |
27 class BluetoothGattService; | 29 class BluetoothRemoteGattService; |
28 | 30 |
29 } // namespace device | 31 } // namespace device |
30 | 32 |
31 namespace bluez { | 33 namespace bluez { |
32 | 34 |
33 class BluetoothGattDescriptorBlueZ; | 35 class BluetoothRemoteGattDescriptorBlueZ; |
34 class BluetoothRemoteGattServiceBlueZ; | 36 class BluetoothRemoteGattServiceBlueZ; |
35 | 37 |
36 // The BluetoothRemoteGattCharacteristicBlueZ class implements | 38 // The BluetoothRemoteGattCharacteristicBlueZ class implements |
37 // BluetoothGattCharacteristic for remote GATT characteristics for platforms | 39 // BluetoothRemoteGattCharacteristic for remote GATT characteristics for |
| 40 // platforms |
38 // that use BlueZ. | 41 // that use BlueZ. |
39 class BluetoothRemoteGattCharacteristicBlueZ | 42 class BluetoothRemoteGattCharacteristicBlueZ |
40 : public BluetoothGattCharacteristicBlueZ, | 43 : public BluetoothGattCharacteristicBlueZ, |
41 public BluetoothGattDescriptorClient::Observer { | 44 public BluetoothGattDescriptorClient::Observer, |
| 45 public device::BluetoothRemoteGattCharacteristic { |
42 public: | 46 public: |
43 // device::BluetoothGattCharacteristic overrides. | 47 // device::BluetoothGattCharacteristic overrides. |
44 device::BluetoothUUID GetUUID() const override; | 48 device::BluetoothUUID GetUUID() const override; |
45 bool IsLocal() const override; | 49 Properties GetProperties() const override; |
| 50 Permissions GetPermissions() const override; |
| 51 |
| 52 // device::BluetoothRemoteGattCharacteristic overrides. |
46 const std::vector<uint8_t>& GetValue() const override; | 53 const std::vector<uint8_t>& GetValue() const override; |
47 Properties GetProperties() const override; | 54 device::BluetoothRemoteGattService* GetService() const override; |
48 bool IsNotifying() const override; | 55 bool IsNotifying() const override; |
49 bool AddDescriptor(device::BluetoothGattDescriptor* descriptor) override; | 56 std::vector<device::BluetoothRemoteGattDescriptor*> GetDescriptors() |
50 bool UpdateValue(const std::vector<uint8_t>& value) override; | 57 const override; |
| 58 device::BluetoothRemoteGattDescriptor* GetDescriptor( |
| 59 const std::string& identifier) const override; |
51 void StartNotifySession(const NotifySessionCallback& callback, | 60 void StartNotifySession(const NotifySessionCallback& callback, |
52 const ErrorCallback& error_callback) override; | 61 const ErrorCallback& error_callback) override; |
53 void ReadRemoteCharacteristic(const ValueCallback& callback, | 62 void ReadRemoteCharacteristic(const ValueCallback& callback, |
54 const ErrorCallback& error_callback) override; | 63 const ErrorCallback& error_callback) override; |
55 void WriteRemoteCharacteristic(const std::vector<uint8_t>& new_value, | 64 void WriteRemoteCharacteristic(const std::vector<uint8_t>& new_value, |
56 const base::Closure& callback, | 65 const base::Closure& callback, |
57 const ErrorCallback& error_callback) override; | 66 const ErrorCallback& error_callback) override; |
58 | 67 |
59 // Removes one value update session and invokes |callback| on completion. This | 68 // Removes one value update session and invokes |callback| on completion. This |
60 // decrements the session reference count by 1 and if the number reaches 0, | 69 // decrements the session reference count by 1 and if the number reaches 0, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // The total number of currently active value update sessions. | 120 // The total number of currently active value update sessions. |
112 size_t num_notify_sessions_; | 121 size_t num_notify_sessions_; |
113 | 122 |
114 // Calls to StartNotifySession that are pending. This can happen during the | 123 // Calls to StartNotifySession that are pending. This can happen during the |
115 // first remote call to start notifications. | 124 // first remote call to start notifications. |
116 std::queue<PendingStartNotifyCall> pending_start_notify_calls_; | 125 std::queue<PendingStartNotifyCall> pending_start_notify_calls_; |
117 | 126 |
118 // True, if a Start or Stop notify call to bluetoothd is currently pending. | 127 // True, if a Start or Stop notify call to bluetoothd is currently pending. |
119 bool notify_call_pending_; | 128 bool notify_call_pending_; |
120 | 129 |
| 130 // TODO(rkc): Investigate and fix ownership of the descriptor objects in this |
| 131 // map. See crbug.com/604166. |
| 132 using DescriptorMap = |
| 133 std::map<dbus::ObjectPath, BluetoothRemoteGattDescriptorBlueZ*>; |
| 134 |
| 135 // Mapping from GATT descriptor object paths to descriptor objects owned by |
| 136 // this characteristic. Since the BlueZ implementation uses object paths |
| 137 // as unique identifiers, we also use this mapping to return descriptors by |
| 138 // identifier. |
| 139 DescriptorMap descriptors_; |
| 140 |
| 141 // The GATT service this GATT characteristic belongs to. |
| 142 BluetoothRemoteGattServiceBlueZ* service_; |
| 143 |
121 // Note: This should remain the last member so it'll be destroyed and | 144 // Note: This should remain the last member so it'll be destroyed and |
122 // invalidate its weak pointers before any other members are destroyed. | 145 // invalidate its weak pointers before any other members are destroyed. |
123 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicBlueZ> | 146 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicBlueZ> |
124 weak_ptr_factory_; | 147 weak_ptr_factory_; |
125 | 148 |
126 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicBlueZ); | 149 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicBlueZ); |
127 }; | 150 }; |
128 | 151 |
129 } // namespace bluez | 152 } // namespace bluez |
130 | 153 |
131 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ | 154 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ |
OLD | NEW |