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

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h

Issue 1872943002: Add support for local services/characteristics/descriptors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ 6 #define DEVICE_BLUETOOTH_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 10
11 #include <map> 11 #include <map>
12 #include <queue> 12 #include <queue>
13 #include <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "dbus/object_path.h" 19 #include "dbus/object_path.h"
20 #include "device/bluetooth/bluetooth_gatt_characteristic.h" 20 #include "device/bluetooth/bluetooth_gatt_characteristic_bluez.h"
21 #include "device/bluetooth/bluetooth_uuid.h" 21 #include "device/bluetooth/bluetooth_uuid.h"
22 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_client.h" 22 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_client.h"
23 23
24 namespace device { 24 namespace device {
25 25
26 class BluetoothGattDescriptor; 26 class BluetoothGattDescriptor;
27 class BluetoothGattService; 27 class BluetoothGattService;
28 28
29 } // namespace device 29 } // namespace device
30 30
31 namespace bluez { 31 namespace bluez {
32 32
33 class BluetoothRemoteGattDescriptorBlueZ; 33 class BluetoothGattDescriptorBlueZ;
34 class BluetoothRemoteGattServiceBlueZ; 34 class BluetoothRemoteGattServiceBlueZ;
35 35
36 // The BluetoothRemoteGattCharacteristicBlueZ class implements 36 // The BluetoothRemoteGattCharacteristicBlueZ class implements
37 // BluetoothGattCharacteristic for remote GATT characteristics for platforms 37 // BluetoothGattCharacteristic for remote GATT characteristics for platforms
38 // that use BlueZ. 38 // that use BlueZ.
39 class BluetoothRemoteGattCharacteristicBlueZ 39 class BluetoothRemoteGattCharacteristicBlueZ
40 : public device::BluetoothGattCharacteristic, 40 : public BluetoothGattCharacteristicBlueZ,
41 public bluez::BluetoothGattDescriptorClient::Observer { 41 public BluetoothGattDescriptorClient::Observer {
42 public: 42 public:
43 // device::BluetoothGattCharacteristic overrides. 43 // device::BluetoothGattCharacteristic overrides.
44 std::string GetIdentifier() const override;
45 device::BluetoothUUID GetUUID() const override; 44 device::BluetoothUUID GetUUID() const override;
46 bool IsLocal() const override; 45 bool IsLocal() const override;
47 const std::vector<uint8_t>& GetValue() const override; 46 const std::vector<uint8_t>& GetValue() const override;
48 device::BluetoothGattService* GetService() const override;
49 Properties GetProperties() const override; 47 Properties GetProperties() const override;
50 Permissions GetPermissions() const override;
51 bool IsNotifying() const override; 48 bool IsNotifying() const override;
52 std::vector<device::BluetoothGattDescriptor*> GetDescriptors() const override;
53 device::BluetoothGattDescriptor* GetDescriptor(
54 const std::string& identifier) const override;
55 bool AddDescriptor(device::BluetoothGattDescriptor* descriptor) override; 49 bool AddDescriptor(device::BluetoothGattDescriptor* descriptor) override;
56 bool UpdateValue(const std::vector<uint8_t>& value) override; 50 bool UpdateValue(const std::vector<uint8_t>& value) override;
51 void StartNotifySession(const NotifySessionCallback& callback,
52 const ErrorCallback& error_callback) override;
57 void ReadRemoteCharacteristic(const ValueCallback& callback, 53 void ReadRemoteCharacteristic(const ValueCallback& callback,
58 const ErrorCallback& error_callback) override; 54 const ErrorCallback& error_callback) override;
59 void WriteRemoteCharacteristic(const std::vector<uint8_t>& new_value, 55 void WriteRemoteCharacteristic(const std::vector<uint8_t>& new_value,
60 const base::Closure& callback, 56 const base::Closure& callback,
61 const ErrorCallback& error_callback) override; 57 const ErrorCallback& error_callback) override;
62 void StartNotifySession(const NotifySessionCallback& callback,
63 const ErrorCallback& error_callback) override;
64 58
65 // Removes one value update session and invokes |callback| on completion. This 59 // Removes one value update session and invokes |callback| on completion. This
66 // decrements the session reference count by 1 and if the number reaches 0, 60 // decrements the session reference count by 1 and if the number reaches 0,
67 // makes a call to the subsystem to stop notifications from this 61 // makes a call to the subsystem to stop notifications from this
68 // characteristic. 62 // characteristic.
69 void RemoveNotifySession(const base::Closure& callback); 63 void RemoveNotifySession(const base::Closure& callback);
70 64
71 // Object path of the underlying D-Bus characteristic. 65 // Object path of the underlying D-Bus characteristic.
72 const dbus::ObjectPath& object_path() const { return object_path_; } 66 const dbus::ObjectPath& object_path() const { return object_path_; }
73 67
74 private: 68 private:
75 friend class BluetoothRemoteGattServiceBlueZ; 69 friend class BluetoothRemoteGattServiceBlueZ;
76 70
77 typedef std::pair<NotifySessionCallback, ErrorCallback> 71 using PendingStartNotifyCall =
78 PendingStartNotifyCall; 72 std::pair<NotifySessionCallback, ErrorCallback>;
79 73
80 BluetoothRemoteGattCharacteristicBlueZ( 74 BluetoothRemoteGattCharacteristicBlueZ(
81 BluetoothRemoteGattServiceBlueZ* service, 75 BluetoothRemoteGattServiceBlueZ* service,
82 const dbus::ObjectPath& object_path); 76 const dbus::ObjectPath& object_path);
83 ~BluetoothRemoteGattCharacteristicBlueZ() override; 77 ~BluetoothRemoteGattCharacteristicBlueZ() override;
84 78
85 // bluez::BluetoothGattDescriptorClient::Observer overrides. 79 // bluez::BluetoothGattDescriptorClient::Observer overrides.
86 void GattDescriptorAdded(const dbus::ObjectPath& object_path) override; 80 void GattDescriptorAdded(const dbus::ObjectPath& object_path) override;
87 void GattDescriptorRemoved(const dbus::ObjectPath& object_path) override; 81 void GattDescriptorRemoved(const dbus::ObjectPath& object_path) override;
88 void GattDescriptorPropertyChanged(const dbus::ObjectPath& object_path, 82 void GattDescriptorPropertyChanged(const dbus::ObjectPath& object_path,
89 const std::string& property_name) override; 83 const std::string& property_name) override;
90 84
91 // Called by dbus:: on unsuccessful completion of a request to read or write
92 // the characteristic value.
93 void OnError(const ErrorCallback& error_callback,
94 const std::string& error_name,
95 const std::string& error_message);
96
97 // Called by dbus:: on successful completion of a request to start 85 // Called by dbus:: on successful completion of a request to start
98 // notifications. 86 // notifications.
99 void OnStartNotifySuccess(const NotifySessionCallback& callback); 87 void OnStartNotifySuccess(const NotifySessionCallback& callback);
100 88
101 // Called by dbus:: on unsuccessful completion of a request to start 89 // Called by dbus:: on unsuccessful completion of a request to start
102 // notifications. 90 // notifications.
103 void OnStartNotifyError(const ErrorCallback& error_callback, 91 void OnStartNotifyError(const ErrorCallback& error_callback,
104 const std::string& error_name, 92 const std::string& error_name,
105 const std::string& error_message); 93 const std::string& error_message);
106 94
107 // Called by dbus:: on successful completion of a request to stop 95 // Called by dbus:: on successful completion of a request to stop
108 // notifications. 96 // notifications.
109 void OnStopNotifySuccess(const base::Closure& callback); 97 void OnStopNotifySuccess(const base::Closure& callback);
110 98
111 // Called by dbus:: on unsuccessful completion of a request to stop 99 // Called by dbus:: on unsuccessful completion of a request to stop
112 // notifications. 100 // notifications.
113 void OnStopNotifyError(const base::Closure& callback, 101 void OnStopNotifyError(const base::Closure& callback,
114 const std::string& error_name, 102 const std::string& error_name,
115 const std::string& error_message); 103 const std::string& error_message);
116 104
117 // Calls StartNotifySession for each queued request. 105 // Calls StartNotifySession for each queued request.
118 void ProcessStartNotifyQueue(); 106 void ProcessStartNotifyQueue();
119 107
108 // Called by dbus:: on unsuccessful completion of a request to read or write
109 // the characteristic value.
110 void OnError(const ErrorCallback& error_callback,
111 const std::string& error_name,
112 const std::string& error_message);
113
120 // Object path of the D-Bus characteristic object. 114 // Object path of the D-Bus characteristic object.
121 dbus::ObjectPath object_path_; 115 dbus::ObjectPath object_path_;
122 116
123 // The GATT service this GATT characteristic belongs to. 117 // The GATT service this GATT characteristic belongs to.
124 BluetoothRemoteGattServiceBlueZ* service_; 118 BluetoothRemoteGattServiceBlueZ* service_;
125 119
126 // The total number of currently active value update sessions. 120 // The total number of currently active value update sessions.
127 size_t num_notify_sessions_; 121 size_t num_notify_sessions_;
128 122
129 // Calls to StartNotifySession that are pending. This can happen during the 123 // Calls to StartNotifySession that are pending. This can happen during the
130 // first remote call to start notifications. 124 // first remote call to start notifications.
131 std::queue<PendingStartNotifyCall> pending_start_notify_calls_; 125 std::queue<PendingStartNotifyCall> pending_start_notify_calls_;
132 126
133 // 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.
134 bool notify_call_pending_; 128 bool notify_call_pending_;
135 129
136 // Mapping from GATT descriptor object paths to descriptor objects owned by
137 // this characteristic. Since the BlueZ implementation uses object paths
138 // as unique identifiers, we also use this mapping to return descriptors by
139 // identifier.
140 typedef std::map<dbus::ObjectPath, BluetoothRemoteGattDescriptorBlueZ*>
141 DescriptorMap;
142 DescriptorMap descriptors_;
143
144 // Note: This should remain the last member so it'll be destroyed and 130 // Note: This should remain the last member so it'll be destroyed and
145 // invalidate its weak pointers before any other members are destroyed. 131 // invalidate its weak pointers before any other members are destroyed.
146 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicBlueZ> 132 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicBlueZ>
147 weak_ptr_factory_; 133 weak_ptr_factory_;
148 134
149 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicBlueZ); 135 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicBlueZ);
150 }; 136 };
151 137
152 } // namespace bluez 138 } // namespace bluez
153 139
154 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ 140 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698