OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ | |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ | |
7 | |
8 #include <stddef.h> | |
9 #include <stdint.h> | |
10 #include <queue> | |
11 #include <string> | |
12 #include <utility> | |
13 #include <vector> | |
14 | |
15 #include "base/callback_forward.h" | |
16 #include "base/macros.h" | |
17 #include "base/memory/weak_ptr.h" | |
18 #include "dbus/object_path.h" | |
19 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | |
20 #include "device/bluetooth/bluetooth_gatt_characteristic_bluez.h" | |
21 #include "device/bluetooth/bluetooth_uuid.h" | |
22 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_client.h" | |
23 | |
24 namespace device { | |
25 | |
26 class BluetoothGattDescriptor; | |
27 class BluetoothGattService; | |
28 | |
29 } // namespace device | |
30 | |
31 namespace bluez { | |
32 | |
33 class BluetoothGattDescriptorBlueZ; | |
34 class BluetoothRemoteGattServiceBlueZ; | |
35 | |
36 // The BluetoothRemoteGattCharacteristicBlueZ class implements | |
37 // BluetoothGattCharacteristic for remote GATT characteristics for platforms | |
38 // that use BlueZ. | |
39 class BluetoothRemoteGattCharacteristicBlueZ | |
40 : public BluetoothGattCharacteristicBlueZ, | |
41 public BluetoothGattDescriptorClient::Observer { | |
42 public: | |
43 // device::BluetoothGattCharacteristic overrides. | |
44 device::BluetoothUUID GetUUID() const override; | |
45 bool IsLocal() const override; | |
46 const std::vector<uint8_t>& GetValue() const override; | |
47 Properties GetProperties() const override; | |
48 bool IsNotifying() const override; | |
49 bool AddDescriptor(device::BluetoothGattDescriptor* descriptor) override; | |
50 bool UpdateValue(const std::vector<uint8_t>& value) override; | |
51 void StartNotifySession(const NotifySessionCallback& callback, | |
52 const ErrorCallback& error_callback) override; | |
53 void ReadRemoteCharacteristic(const ValueCallback& callback, | |
54 const ErrorCallback& error_callback) override; | |
55 void WriteRemoteCharacteristic(const std::vector<uint8_t>& new_value, | |
56 const base::Closure& callback, | |
57 const ErrorCallback& error_callback) override; | |
58 | |
59 // 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, | |
61 // makes a call to the subsystem to stop notifications from this | |
62 // characteristic. | |
63 void RemoveNotifySession(const base::Closure& callback); | |
64 | |
65 private: | |
66 friend class BluetoothRemoteGattServiceBlueZ; | |
67 | |
68 using PendingStartNotifyCall = | |
69 std::pair<NotifySessionCallback, ErrorCallback>; | |
70 | |
71 BluetoothRemoteGattCharacteristicBlueZ( | |
72 BluetoothRemoteGattServiceBlueZ* service, | |
73 const dbus::ObjectPath& object_path); | |
74 ~BluetoothRemoteGattCharacteristicBlueZ() override; | |
75 | |
76 // bluez::BluetoothGattDescriptorClient::Observer overrides. | |
77 void GattDescriptorAdded(const dbus::ObjectPath& object_path) override; | |
78 void GattDescriptorRemoved(const dbus::ObjectPath& object_path) override; | |
79 void GattDescriptorPropertyChanged(const dbus::ObjectPath& object_path, | |
80 const std::string& property_name) override; | |
81 | |
82 // Called by dbus:: on successful completion of a request to start | |
83 // notifications. | |
84 void OnStartNotifySuccess(const NotifySessionCallback& callback); | |
85 | |
86 // Called by dbus:: on unsuccessful completion of a request to start | |
87 // notifications. | |
88 void OnStartNotifyError(const ErrorCallback& error_callback, | |
89 const std::string& error_name, | |
90 const std::string& error_message); | |
91 | |
92 // Called by dbus:: on successful completion of a request to stop | |
93 // notifications. | |
94 void OnStopNotifySuccess(const base::Closure& callback); | |
95 | |
96 // Called by dbus:: on unsuccessful completion of a request to stop | |
97 // notifications. | |
98 void OnStopNotifyError(const base::Closure& callback, | |
99 const std::string& error_name, | |
100 const std::string& error_message); | |
101 | |
102 // Calls StartNotifySession for each queued request. | |
103 void ProcessStartNotifyQueue(); | |
104 | |
105 // Called by dbus:: on unsuccessful completion of a request to read or write | |
106 // the characteristic value. | |
107 void OnError(const ErrorCallback& error_callback, | |
108 const std::string& error_name, | |
109 const std::string& error_message); | |
110 | |
111 // The total number of currently active value update sessions. | |
112 size_t num_notify_sessions_; | |
113 | |
114 // Calls to StartNotifySession that are pending. This can happen during the | |
115 // first remote call to start notifications. | |
116 std::queue<PendingStartNotifyCall> pending_start_notify_calls_; | |
117 | |
118 // True, if a Start or Stop notify call to bluetoothd is currently pending. | |
119 bool notify_call_pending_; | |
120 | |
121 // Note: This should remain the last member so it'll be destroyed and | |
122 // invalidate its weak pointers before any other members are destroyed. | |
123 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicBlueZ> | |
124 weak_ptr_factory_; | |
125 | |
126 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicBlueZ); | |
127 }; | |
128 | |
129 } // namespace bluez | |
130 | |
131 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ | |
OLD | NEW |