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

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;
46 bool IsLocal() const override; 44 bool IsLocal() const override;
47 const std::vector<uint8_t>& GetValue() const override;
48 device::BluetoothGattService* GetService() const override;
49 Properties GetProperties() const override;
50 Permissions GetPermissions() const override;
51 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; 45 bool AddDescriptor(device::BluetoothGattDescriptor* descriptor) override;
56 bool UpdateValue(const std::vector<uint8_t>& value) override; 46 bool UpdateValue(const std::vector<uint8_t>& value) override;
57 void ReadRemoteCharacteristic(const ValueCallback& callback,
58 const ErrorCallback& error_callback) override;
59 void WriteRemoteCharacteristic(const std::vector<uint8_t>& new_value,
60 const base::Closure& callback,
61 const ErrorCallback& error_callback) override;
62 void StartNotifySession(const NotifySessionCallback& callback, 47 void StartNotifySession(const NotifySessionCallback& callback,
63 const ErrorCallback& error_callback) override; 48 const ErrorCallback& error_callback) override;
64 49
65 // Removes one value update session and invokes |callback| on completion. This 50 // 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, 51 // 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 52 // makes a call to the subsystem to stop notifications from this
68 // characteristic. 53 // characteristic.
69 void RemoveNotifySession(const base::Closure& callback); 54 void RemoveNotifySession(const base::Closure& callback);
70 55
71 // Object path of the underlying D-Bus characteristic. 56 // Object path of the underlying D-Bus characteristic.
72 const dbus::ObjectPath& object_path() const { return object_path_; } 57 const dbus::ObjectPath& object_path() const { return object_path_; }
73 58
74 private: 59 private:
75 friend class BluetoothRemoteGattServiceBlueZ; 60 friend class BluetoothRemoteGattServiceBlueZ;
76 61
77 typedef std::pair<NotifySessionCallback, ErrorCallback> 62 typedef std::pair<NotifySessionCallback, ErrorCallback>
78 PendingStartNotifyCall; 63 PendingStartNotifyCall;
79 64
80 BluetoothRemoteGattCharacteristicBlueZ( 65 BluetoothRemoteGattCharacteristicBlueZ(
81 BluetoothRemoteGattServiceBlueZ* service, 66 BluetoothRemoteGattServiceBlueZ* service,
82 const dbus::ObjectPath& object_path); 67 const dbus::ObjectPath& object_path);
83 ~BluetoothRemoteGattCharacteristicBlueZ() override; 68 ~BluetoothRemoteGattCharacteristicBlueZ() override;
84 69
85 // bluez::BluetoothGattDescriptorClient::Observer overrides. 70 // bluez::BluetoothGattDescriptorClient::Observer overrides.
86 void GattDescriptorAdded(const dbus::ObjectPath& object_path) override; 71 void GattDescriptorAdded(const dbus::ObjectPath& object_path) override;
87 void GattDescriptorRemoved(const dbus::ObjectPath& object_path) override; 72 void GattDescriptorRemoved(const dbus::ObjectPath& object_path) override;
88 void GattDescriptorPropertyChanged(const dbus::ObjectPath& object_path, 73 void GattDescriptorPropertyChanged(const dbus::ObjectPath& object_path,
89 const std::string& property_name) override; 74 const std::string& property_name) override;
90 75
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 76 // Called by dbus:: on successful completion of a request to start
98 // notifications. 77 // notifications.
99 void OnStartNotifySuccess(const NotifySessionCallback& callback); 78 void OnStartNotifySuccess(const NotifySessionCallback& callback);
100 79
101 // Called by dbus:: on unsuccessful completion of a request to start 80 // Called by dbus:: on unsuccessful completion of a request to start
102 // notifications. 81 // notifications.
103 void OnStartNotifyError(const ErrorCallback& error_callback, 82 void OnStartNotifyError(const ErrorCallback& error_callback,
104 const std::string& error_name, 83 const std::string& error_name,
105 const std::string& error_message); 84 const std::string& error_message);
106 85
(...skipping 23 matching lines...) Expand all
130 // first remote call to start notifications. 109 // first remote call to start notifications.
131 std::queue<PendingStartNotifyCall> pending_start_notify_calls_; 110 std::queue<PendingStartNotifyCall> pending_start_notify_calls_;
132 111
133 // True, if a Start or Stop notify call to bluetoothd is currently pending. 112 // True, if a Start or Stop notify call to bluetoothd is currently pending.
134 bool notify_call_pending_; 113 bool notify_call_pending_;
135 114
136 // Mapping from GATT descriptor object paths to descriptor objects owned by 115 // Mapping from GATT descriptor object paths to descriptor objects owned by
137 // this characteristic. Since the BlueZ implementation uses object paths 116 // this characteristic. Since the BlueZ implementation uses object paths
138 // as unique identifiers, we also use this mapping to return descriptors by 117 // as unique identifiers, we also use this mapping to return descriptors by
139 // identifier. 118 // identifier.
140 typedef std::map<dbus::ObjectPath, BluetoothRemoteGattDescriptorBlueZ*> 119 typedef std::map<dbus::ObjectPath, BluetoothGattDescriptorBlueZ*>
141 DescriptorMap; 120 DescriptorMap;
142 DescriptorMap descriptors_; 121 DescriptorMap descriptors_;
143 122
144 // Note: This should remain the last member so it'll be destroyed and 123 // Note: This should remain the last member so it'll be destroyed and
145 // invalidate its weak pointers before any other members are destroyed. 124 // invalidate its weak pointers before any other members are destroyed.
146 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicBlueZ> 125 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicBlueZ>
147 weak_ptr_factory_; 126 weak_ptr_factory_;
148 127
149 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicBlueZ); 128 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicBlueZ);
150 }; 129 };
151 130
152 } // namespace bluez 131 } // namespace bluez
153 132
154 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_ 133 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_BLUEZ_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698