OLD | NEW |
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_GATT_DESCRIPTOR_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <string> |
9 | |
10 #include <vector> | |
11 | 9 |
12 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/callback_forward.h" |
13 #include "base/macros.h" | 12 #include "base/macros.h" |
14 #include "device/bluetooth/bluetooth_export.h" | 13 #include "device/bluetooth/bluetooth_export.h" |
15 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 14 #include "device/bluetooth/bluetooth_gatt_service.h" |
16 #include "device/bluetooth/bluetooth_uuid.h" | 15 #include "device/bluetooth/bluetooth_uuid.h" |
17 | 16 |
18 namespace device { | 17 namespace device { |
19 | 18 |
20 // BluetoothGattDescriptor represents a local or remote GATT characteristic | 19 // BluetoothGattDescriptor represents a local or remote GATT characteristic |
21 // descriptor. A GATT characteristic descriptor provides further information | 20 // descriptor. A GATT characteristic descriptor provides further information |
22 // about a characteristic's value. They can be used to describe the | 21 // about a characteristic's value. They can be used to describe the |
23 // characteristic's features or to control certain behaviors. | 22 // characteristic's features or to control certain behaviors. |
24 class DEVICE_BLUETOOTH_EXPORT BluetoothGattDescriptor { | 23 class DEVICE_BLUETOOTH_EXPORT BluetoothGattDescriptor { |
25 public: | 24 public: |
26 // The ErrorCallback is used by methods to asynchronously report errors. | 25 // The ErrorCallback is used by methods to asynchronously report errors. |
27 typedef base::Callback<void(BluetoothGattService::GattErrorCode)> | 26 typedef base::Callback<void(BluetoothGattService::GattErrorCode)> |
28 ErrorCallback; | 27 ErrorCallback; |
29 | 28 |
30 // The ValueCallback is used to return the value of a remote characteristic | |
31 // descriptor upon a read request. | |
32 typedef base::Callback<void(const std::vector<uint8_t>&)> ValueCallback; | |
33 | |
34 // The Bluetooth Specification declares several predefined descriptors that | 29 // The Bluetooth Specification declares several predefined descriptors that |
35 // profiles can use. The following are definitions for the list of UUIDs | 30 // profiles can use. The following are definitions for the list of UUIDs |
36 // and descriptions of the characteristic descriptors that they represent. | 31 // and descriptions of the characteristic descriptors that they represent. |
37 // Possible values for and further information on each descriptor can be found | 32 // Possible values for and further information on each descriptor can be found |
38 // in Core v4.0, Volume 3, Part G, Section 3.3.3. All of these descriptors are | 33 // in Core v4.0, Volume 3, Part G, Section 3.3.3. All of these descriptors are |
39 // optional and may not be present for a given characteristic. | 34 // optional and may not be present for a given characteristic. |
40 | 35 |
41 // The "Characteristic Extended Properties" descriptor. This defines | 36 // The "Characteristic Extended Properties" descriptor. This defines |
42 // additional "Characteristic Properties" which cannot fit into the allocated | 37 // additional "Characteristic Properties" which cannot fit into the allocated |
43 // single octet property field of a characteristic. The value is a bit field | 38 // single octet property field of a characteristic. The value is a bit field |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 // is used by that characteristic. Hence, exactly one instance of this | 98 // is used by that characteristic. Hence, exactly one instance of this |
104 // descriptor must exist if more than one "Characteristic Presentation Format" | 99 // descriptor must exist if more than one "Characteristic Presentation Format" |
105 // descriptors exist for a characteristic. | 100 // descriptors exist for a characteristic. |
106 // | 101 // |
107 // Applications that are using the device::Bluetooth API do not have access to | 102 // Applications that are using the device::Bluetooth API do not have access to |
108 // the underlying handles and shouldn't use this descriptor to determine which | 103 // the underlying handles and shouldn't use this descriptor to determine which |
109 // "Characteristic Presentation Format" descriptors belong to a | 104 // "Characteristic Presentation Format" descriptors belong to a |
110 // characteristic. | 105 // characteristic. |
111 // The API will construct a BluetoothGattDescriptor object for each instance | 106 // The API will construct a BluetoothGattDescriptor object for each instance |
112 // of "Characteristic Presentation Format" descriptor per instance of | 107 // of "Characteristic Presentation Format" descriptor per instance of |
113 // BluetoothGattCharacteristic that represents a remote characteristic. | 108 // BluetoothRemoteGattCharacteristic that represents a remote characteristic. |
114 // Similarly for local characteristics, implementations DO NOT need to create | 109 // Similarly for local characteristics, implementations DO NOT need to create |
115 // an instance of BluetoothGattDescriptor for this descriptor as this will be | 110 // an instance of BluetoothGattDescriptor for this descriptor as this will be |
116 // handled by the subsystem. | 111 // handled by the subsystem. |
117 static const BluetoothUUID& CharacteristicAggregateFormatUuid(); | 112 static const BluetoothUUID& CharacteristicAggregateFormatUuid(); |
118 | 113 |
119 // Constructs a BluetoothGattDescriptor that can be associated with a local | |
120 // GATT characteristic when the adapter is in the peripheral role. To | |
121 // associate the returned descriptor with a characteristic, add it to a local | |
122 // characteristic by calling BluetoothGattCharacteristic::AddDescriptor. | |
123 // | |
124 // This method constructs a characteristic descriptor with UUID |uuid| and the | |
125 // initial cached value |value|. |value| will be cached and returned for read | |
126 // requests and automatically modified for write requests by default, unless | |
127 // an instance of BluetoothGattService::Delegate has been provided to the | |
128 // associated BluetoothGattService instance, in which case the delegate will | |
129 // handle the read and write requests. | |
130 // | |
131 // Currently, only custom UUIDs, |kCharacteristicDescriptionUuid|, and | |
132 // |kCharacteristicPresentationFormat| are supported for locally hosted | |
133 // descriptors. This method will return NULL if |uuid| is any one of the | |
134 // unsupported predefined descriptor UUIDs. | |
135 static BluetoothGattDescriptor* Create( | |
136 const BluetoothUUID& uuid, | |
137 const std::vector<uint8_t>& value, | |
138 BluetoothGattCharacteristic::Permissions permissions); | |
139 | |
140 // Identifier used to uniquely identify a GATT descriptor object. This is | 114 // Identifier used to uniquely identify a GATT descriptor object. This is |
141 // different from the descriptor UUID: while multiple descriptors with the | 115 // different from the descriptor UUID: while multiple descriptors with the |
142 // same UUID can exist on a Bluetooth device, the identifier returned from | 116 // same UUID can exist on a Bluetooth device, the identifier returned from |
143 // this method is unique among all descriptors on the adapter. The contents of | 117 // this method is unique among all descriptors on the adapter. The contents of |
144 // the identifier are platform specific. | 118 // the identifier are platform specific. |
145 virtual std::string GetIdentifier() const = 0; | 119 virtual std::string GetIdentifier() const = 0; |
146 | 120 |
147 // The Bluetooth-specific UUID of the characteristic descriptor. | |
148 virtual BluetoothUUID GetUUID() const = 0; | |
149 | |
150 // Returns true, if this characteristic descriptor is hosted locally. If | |
151 // false, then this instance represents a remote descriptor. | |
152 virtual bool IsLocal() const = 0; | |
153 | |
154 // Returns the value of the descriptor. For remote descriptors, this is the | |
155 // most recently cached value of the remote descriptor. For local descriptors | |
156 // this is the most recently updated value or the value retrieved from the | |
157 // delegate. | |
158 virtual const std::vector<uint8_t>& GetValue() const = 0; | |
159 | |
160 // Returns a pointer to the GATT characteristic that this characteristic | |
161 // descriptor belongs to. | |
162 virtual BluetoothGattCharacteristic* GetCharacteristic() const = 0; | |
163 | |
164 // Returns the bitmask of characteristic descriptor attribute permissions. | |
165 virtual BluetoothGattCharacteristic::Permissions GetPermissions() const = 0; | |
166 | |
167 // Sends a read request to a remote characteristic descriptor to read its | |
168 // value. |callback| is called to return the read value on success and | |
169 // |error_callback| is called for failures. | |
170 virtual void ReadRemoteDescriptor(const ValueCallback& callback, | |
171 const ErrorCallback& error_callback) = 0; | |
172 | |
173 // Sends a write request to a remote characteristic descriptor, to modify the | |
174 // value of the descriptor with the new value |new_value|. |callback| is | |
175 // called to signal success and |error_callback| for failures. This method | |
176 // only applies to remote descriptors and will fail for those that are locally | |
177 // hosted. | |
178 virtual void WriteRemoteDescriptor(const std::vector<uint8_t>& new_value, | |
179 const base::Closure& callback, | |
180 const ErrorCallback& error_callback) = 0; | |
181 | |
182 protected: | 121 protected: |
183 BluetoothGattDescriptor(); | 122 BluetoothGattDescriptor(); |
184 virtual ~BluetoothGattDescriptor(); | 123 virtual ~BluetoothGattDescriptor(); |
185 | 124 |
186 private: | 125 private: |
187 DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptor); | 126 DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptor); |
188 }; | 127 }; |
189 | 128 |
190 } // namespace device | 129 } // namespace device |
191 | 130 |
192 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_ | 131 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_ |
OLD | NEW |