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

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

Issue 2613473002: bluetooth: bluez: Implement BluetoothRemoteGattCharacteristicBluez::SubscribeToNotifications and Un… (Closed)
Patch Set: Also include Chrome OS as it uses Bluez. Created 3 years, 11 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 2016 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_BLUEZ_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_
6 #define DEVICE_BLUETOOTH_BLUEZ_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 <map>
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 Permissions GetPermissions() const override; 50 Permissions GetPermissions() const override;
51 51
52 // device::BluetoothRemoteGattCharacteristic overrides. 52 // device::BluetoothRemoteGattCharacteristic overrides.
53 const std::vector<uint8_t>& GetValue() const override; 53 const std::vector<uint8_t>& GetValue() const override;
54 device::BluetoothRemoteGattService* GetService() const override; 54 device::BluetoothRemoteGattService* GetService() const override;
55 bool IsNotifying() const override; 55 bool IsNotifying() const override;
56 std::vector<device::BluetoothRemoteGattDescriptor*> GetDescriptors() 56 std::vector<device::BluetoothRemoteGattDescriptor*> GetDescriptors()
57 const override; 57 const override;
58 device::BluetoothRemoteGattDescriptor* GetDescriptor( 58 device::BluetoothRemoteGattDescriptor* GetDescriptor(
59 const std::string& identifier) const override; 59 const std::string& identifier) const override;
60 void StartNotifySession(const NotifySessionCallback& callback,
61 const ErrorCallback& error_callback) override;
62 // Removes one value update session and invokes |callback| on completion. This
63 // decrements the session reference count by 1 and if the number reaches 0,
64 // makes a call to the subsystem to stop notifications from this
65 // characteristic.
66 void StopNotifySession(device::BluetoothGattNotifySession* session,
67 const base::Closure& callback) override;
68 void ReadRemoteCharacteristic(const ValueCallback& callback, 60 void ReadRemoteCharacteristic(const ValueCallback& callback,
69 const ErrorCallback& error_callback) override; 61 const ErrorCallback& error_callback) override;
70 void WriteRemoteCharacteristic(const std::vector<uint8_t>& value, 62 void WriteRemoteCharacteristic(const std::vector<uint8_t>& value,
71 const base::Closure& callback, 63 const base::Closure& callback,
72 const ErrorCallback& error_callback) override; 64 const ErrorCallback& error_callback) override;
73 65
74 protected: 66 protected:
75 void SubscribeToNotifications( 67 void SubscribeToNotifications(
76 device::BluetoothRemoteGattDescriptor* ccc_descriptor, 68 device::BluetoothRemoteGattDescriptor* ccc_descriptor,
77 const base::Closure& callback, 69 const base::Closure& callback,
(...skipping 15 matching lines...) Expand all
93 ~BluetoothRemoteGattCharacteristicBlueZ() override; 85 ~BluetoothRemoteGattCharacteristicBlueZ() override;
94 86
95 // bluez::BluetoothGattDescriptorClient::Observer overrides. 87 // bluez::BluetoothGattDescriptorClient::Observer overrides.
96 void GattDescriptorAdded(const dbus::ObjectPath& object_path) override; 88 void GattDescriptorAdded(const dbus::ObjectPath& object_path) override;
97 void GattDescriptorRemoved(const dbus::ObjectPath& object_path) override; 89 void GattDescriptorRemoved(const dbus::ObjectPath& object_path) override;
98 void GattDescriptorPropertyChanged(const dbus::ObjectPath& object_path, 90 void GattDescriptorPropertyChanged(const dbus::ObjectPath& object_path,
99 const std::string& property_name) override; 91 const std::string& property_name) override;
100 92
101 // Called by dbus:: on successful completion of a request to start 93 // Called by dbus:: on successful completion of a request to start
102 // notifications. 94 // notifications.
103 void OnStartNotifySuccess(const NotifySessionCallback& callback); 95 void OnStartNotifySuccess(const base::Closure& callback);
104 96
105 // Called by dbus:: on unsuccessful completion of a request to start 97 // Called by dbus:: on unsuccessful completion of a request to start
106 // notifications. 98 // notifications.
107 void OnStartNotifyError(const ErrorCallback& error_callback, 99 void OnStartNotifyError(const ErrorCallback& error_callback,
108 const std::string& error_name, 100 const std::string& error_name,
109 const std::string& error_message); 101 const std::string& error_message);
110 102
111 // Called by dbus:: on successful completion of a request to stop 103 // Called by dbus:: on successful completion of a request to stop
112 // notifications. 104 // notifications.
113 void OnStopNotifySuccess(const base::Closure& callback); 105 void OnStopNotifySuccess(const base::Closure& callback);
114 106
115 // Called by dbus:: on unsuccessful completion of a request to stop 107 // Called by dbus:: on unsuccessful completion of a request to stop
116 // notifications. 108 // notifications.
117 void OnStopNotifyError(const base::Closure& callback, 109 void OnStopNotifyError(const base::Closure& callback,
118 const std::string& error_name, 110 const std::string& error_name,
119 const std::string& error_message); 111 const std::string& error_message);
120 112
121 // Calls StartNotifySession for each queued request.
122 void ProcessStartNotifyQueue();
123
124 // Called by dbus:: on unsuccessful completion of a request to read or write 113 // Called by dbus:: on unsuccessful completion of a request to read or write
125 // the characteristic value. 114 // the characteristic value.
126 void OnError(const ErrorCallback& error_callback, 115 void OnError(const ErrorCallback& error_callback,
127 const std::string& error_name, 116 const std::string& error_name,
128 const std::string& error_message); 117 const std::string& error_message);
129 118
130 // The total number of currently active value update sessions. 119 // True, if there exists a Bluez notify session.
131 size_t num_notify_sessions_; 120 bool has_notify_session_;
132
133 // Calls to StartNotifySession that are pending. This can happen during the
134 // first remote call to start notifications.
135 std::queue<PendingStartNotifyCall> pending_start_notify_calls_;
136
137 // True, if a Start or Stop notify call to bluetoothd is currently pending.
138 bool notify_call_pending_;
139 121
140 // TODO(rkc): Investigate and fix ownership of the descriptor objects in this 122 // TODO(rkc): Investigate and fix ownership of the descriptor objects in this
141 // map. See crbug.com/604166. 123 // map. See crbug.com/604166.
142 using DescriptorMap = 124 using DescriptorMap =
143 std::map<dbus::ObjectPath, BluetoothRemoteGattDescriptorBlueZ*>; 125 std::map<dbus::ObjectPath, BluetoothRemoteGattDescriptorBlueZ*>;
144 126
145 // Mapping from GATT descriptor object paths to descriptor objects owned by 127 // Mapping from GATT descriptor object paths to descriptor objects owned by
146 // this characteristic. Since the BlueZ implementation uses object paths 128 // this characteristic. Since the BlueZ implementation uses object paths
147 // as unique identifiers, we also use this mapping to return descriptors by 129 // as unique identifiers, we also use this mapping to return descriptors by
148 // identifier. 130 // identifier.
149 DescriptorMap descriptors_; 131 DescriptorMap descriptors_;
150 132
151 // The GATT service this GATT characteristic belongs to. 133 // The GATT service this GATT characteristic belongs to.
152 BluetoothRemoteGattServiceBlueZ* service_; 134 BluetoothRemoteGattServiceBlueZ* service_;
153 135
154 // Note: This should remain the last member so it'll be destroyed and 136 // Note: This should remain the last member so it'll be destroyed and
155 // invalidate its weak pointers before any other members are destroyed. 137 // invalidate its weak pointers before any other members are destroyed.
156 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicBlueZ> 138 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicBlueZ>
157 weak_ptr_factory_; 139 weak_ptr_factory_;
158 140
159 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicBlueZ); 141 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicBlueZ);
160 }; 142 };
161 143
162 } // namespace bluez 144 } // namespace bluez
163 145
164 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ 146 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698