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

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>
ortuno 2016/04/14 17:42:36 Please clean up includes.
rkc 2016/04/14 19:27:28 Done. Also cleaned them up in the few places you m
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.
72 const dbus::ObjectPath& object_path() const { return object_path_; }
73
74 private: 65 private:
75 friend class BluetoothRemoteGattServiceBlueZ; 66 friend class BluetoothRemoteGattServiceBlueZ;
76 67
77 typedef std::pair<NotifySessionCallback, ErrorCallback> 68 using PendingStartNotifyCall =
78 PendingStartNotifyCall; 69 std::pair<NotifySessionCallback, ErrorCallback>;
79 70
80 BluetoothRemoteGattCharacteristicBlueZ( 71 BluetoothRemoteGattCharacteristicBlueZ(
81 BluetoothRemoteGattServiceBlueZ* service, 72 BluetoothRemoteGattServiceBlueZ* service,
82 const dbus::ObjectPath& object_path); 73 const dbus::ObjectPath& object_path);
83 ~BluetoothRemoteGattCharacteristicBlueZ() override; 74 ~BluetoothRemoteGattCharacteristicBlueZ() override;
84 75
85 // bluez::BluetoothGattDescriptorClient::Observer overrides. 76 // bluez::BluetoothGattDescriptorClient::Observer overrides.
86 void GattDescriptorAdded(const dbus::ObjectPath& object_path) override; 77 void GattDescriptorAdded(const dbus::ObjectPath& object_path) override;
87 void GattDescriptorRemoved(const dbus::ObjectPath& object_path) override; 78 void GattDescriptorRemoved(const dbus::ObjectPath& object_path) override;
88 void GattDescriptorPropertyChanged(const dbus::ObjectPath& object_path, 79 void GattDescriptorPropertyChanged(const dbus::ObjectPath& object_path,
89 const std::string& property_name) override; 80 const std::string& property_name) override;
90 81
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 82 // Called by dbus:: on successful completion of a request to start
98 // notifications. 83 // notifications.
99 void OnStartNotifySuccess(const NotifySessionCallback& callback); 84 void OnStartNotifySuccess(const NotifySessionCallback& callback);
100 85
101 // Called by dbus:: on unsuccessful completion of a request to start 86 // Called by dbus:: on unsuccessful completion of a request to start
102 // notifications. 87 // notifications.
103 void OnStartNotifyError(const ErrorCallback& error_callback, 88 void OnStartNotifyError(const ErrorCallback& error_callback,
104 const std::string& error_name, 89 const std::string& error_name,
105 const std::string& error_message); 90 const std::string& error_message);
106 91
107 // Called by dbus:: on successful completion of a request to stop 92 // Called by dbus:: on successful completion of a request to stop
108 // notifications. 93 // notifications.
109 void OnStopNotifySuccess(const base::Closure& callback); 94 void OnStopNotifySuccess(const base::Closure& callback);
110 95
111 // Called by dbus:: on unsuccessful completion of a request to stop 96 // Called by dbus:: on unsuccessful completion of a request to stop
112 // notifications. 97 // notifications.
113 void OnStopNotifyError(const base::Closure& callback, 98 void OnStopNotifyError(const base::Closure& callback,
114 const std::string& error_name, 99 const std::string& error_name,
115 const std::string& error_message); 100 const std::string& error_message);
116 101
117 // Calls StartNotifySession for each queued request. 102 // Calls StartNotifySession for each queued request.
118 void ProcessStartNotifyQueue(); 103 void ProcessStartNotifyQueue();
119 104
120 // Object path of the D-Bus characteristic object. 105 // Called by dbus:: on unsuccessful completion of a request to read or write
121 dbus::ObjectPath object_path_; 106 // the characteristic value.
122 107 void OnError(const ErrorCallback& error_callback,
123 // The GATT service this GATT characteristic belongs to. 108 const std::string& error_name,
124 BluetoothRemoteGattServiceBlueZ* service_; 109 const std::string& error_message);
125 110
126 // The total number of currently active value update sessions. 111 // The total number of currently active value update sessions.
127 size_t num_notify_sessions_; 112 size_t num_notify_sessions_;
128 113
129 // Calls to StartNotifySession that are pending. This can happen during the 114 // Calls to StartNotifySession that are pending. This can happen during the
130 // first remote call to start notifications. 115 // first remote call to start notifications.
131 std::queue<PendingStartNotifyCall> pending_start_notify_calls_; 116 std::queue<PendingStartNotifyCall> pending_start_notify_calls_;
132 117
133 // True, if a Start or Stop notify call to bluetoothd is currently pending. 118 // True, if a Start or Stop notify call to bluetoothd is currently pending.
134 bool notify_call_pending_; 119 bool notify_call_pending_;
135 120
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 121 // Note: This should remain the last member so it'll be destroyed and
145 // invalidate its weak pointers before any other members are destroyed. 122 // invalidate its weak pointers before any other members are destroyed.
146 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicBlueZ> 123 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicBlueZ>
147 weak_ptr_factory_; 124 weak_ptr_factory_;
148 125
149 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicBlueZ); 126 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicBlueZ);
150 }; 127 };
151 128
152 } // namespace bluez 129 } // namespace bluez
153 130
154 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ 131 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698