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> |
| 9 |
8 #include <vector> | 10 #include <vector> |
9 | 11 |
10 #include "base/basictypes.h" | |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" |
12 #include "device/bluetooth/bluetooth_export.h" | 14 #include "device/bluetooth/bluetooth_export.h" |
13 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 15 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
14 #include "device/bluetooth/bluetooth_uuid.h" | 16 #include "device/bluetooth/bluetooth_uuid.h" |
15 | 17 |
16 namespace device { | 18 namespace device { |
17 | 19 |
18 // BluetoothGattDescriptor represents a local or remote GATT characteristic | 20 // BluetoothGattDescriptor represents a local or remote GATT characteristic |
19 // descriptor. A GATT characteristic descriptor provides further information | 21 // descriptor. A GATT characteristic descriptor provides further information |
20 // about a characteristic's value. They can be used to describe the | 22 // about a characteristic's value. They can be used to describe the |
21 // characteristic's features or to control certain behaviors. | 23 // characteristic's features or to control certain behaviors. |
22 class DEVICE_BLUETOOTH_EXPORT BluetoothGattDescriptor { | 24 class DEVICE_BLUETOOTH_EXPORT BluetoothGattDescriptor { |
23 public: | 25 public: |
24 // The ErrorCallback is used by methods to asynchronously report errors. | 26 // The ErrorCallback is used by methods to asynchronously report errors. |
25 typedef base::Callback<void(BluetoothGattService::GattErrorCode)> | 27 typedef base::Callback<void(BluetoothGattService::GattErrorCode)> |
26 ErrorCallback; | 28 ErrorCallback; |
27 | 29 |
28 // The ValueCallback is used to return the value of a remote characteristic | 30 // The ValueCallback is used to return the value of a remote characteristic |
29 // descriptor upon a read request. | 31 // descriptor upon a read request. |
30 typedef base::Callback<void(const std::vector<uint8>&)> ValueCallback; | 32 typedef base::Callback<void(const std::vector<uint8_t>&)> ValueCallback; |
31 | 33 |
32 // The Bluetooth Specification declares several predefined descriptors that | 34 // The Bluetooth Specification declares several predefined descriptors that |
33 // profiles can use. The following are definitions for the list of UUIDs | 35 // profiles can use. The following are definitions for the list of UUIDs |
34 // and descriptions of the characteristic descriptors that they represent. | 36 // and descriptions of the characteristic descriptors that they represent. |
35 // Possible values for and further information on each descriptor can be found | 37 // Possible values for and further information on each descriptor can be found |
36 // in Core v4.0, Volume 3, Part G, Section 3.3.3. All of these descriptors are | 38 // in Core v4.0, Volume 3, Part G, Section 3.3.3. All of these descriptors are |
37 // optional and may not be present for a given characteristic. | 39 // optional and may not be present for a given characteristic. |
38 | 40 |
39 // The "Characteristic Extended Properties" descriptor. This defines | 41 // The "Characteristic Extended Properties" descriptor. This defines |
40 // additional "Characteristic Properties" which cannot fit into the allocated | 42 // additional "Characteristic Properties" which cannot fit into the allocated |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // an instance of BluetoothGattService::Delegate has been provided to the | 127 // an instance of BluetoothGattService::Delegate has been provided to the |
126 // associated BluetoothGattService instance, in which case the delegate will | 128 // associated BluetoothGattService instance, in which case the delegate will |
127 // handle the read and write requests. | 129 // handle the read and write requests. |
128 // | 130 // |
129 // Currently, only custom UUIDs, |kCharacteristicDescriptionUuid|, and | 131 // Currently, only custom UUIDs, |kCharacteristicDescriptionUuid|, and |
130 // |kCharacteristicPresentationFormat| are supported for locally hosted | 132 // |kCharacteristicPresentationFormat| are supported for locally hosted |
131 // descriptors. This method will return NULL if |uuid| is any one of the | 133 // descriptors. This method will return NULL if |uuid| is any one of the |
132 // unsupported predefined descriptor UUIDs. | 134 // unsupported predefined descriptor UUIDs. |
133 static BluetoothGattDescriptor* Create( | 135 static BluetoothGattDescriptor* Create( |
134 const BluetoothUUID& uuid, | 136 const BluetoothUUID& uuid, |
135 const std::vector<uint8>& value, | 137 const std::vector<uint8_t>& value, |
136 BluetoothGattCharacteristic::Permissions permissions); | 138 BluetoothGattCharacteristic::Permissions permissions); |
137 | 139 |
138 // Identifier used to uniquely identify a GATT descriptor object. This is | 140 // Identifier used to uniquely identify a GATT descriptor object. This is |
139 // different from the descriptor UUID: while multiple descriptors with the | 141 // different from the descriptor UUID: while multiple descriptors with the |
140 // same UUID can exist on a Bluetooth device, the identifier returned from | 142 // same UUID can exist on a Bluetooth device, the identifier returned from |
141 // this method is unique among all descriptors on the adapter. The contents of | 143 // this method is unique among all descriptors on the adapter. The contents of |
142 // the identifier are platform specific. | 144 // the identifier are platform specific. |
143 virtual std::string GetIdentifier() const = 0; | 145 virtual std::string GetIdentifier() const = 0; |
144 | 146 |
145 // The Bluetooth-specific UUID of the characteristic descriptor. | 147 // The Bluetooth-specific UUID of the characteristic descriptor. |
146 virtual BluetoothUUID GetUUID() const = 0; | 148 virtual BluetoothUUID GetUUID() const = 0; |
147 | 149 |
148 // Returns true, if this characteristic descriptor is hosted locally. If | 150 // Returns true, if this characteristic descriptor is hosted locally. If |
149 // false, then this instance represents a remote descriptor. | 151 // false, then this instance represents a remote descriptor. |
150 virtual bool IsLocal() const = 0; | 152 virtual bool IsLocal() const = 0; |
151 | 153 |
152 // Returns the value of the descriptor. For remote descriptors, this is the | 154 // Returns the value of the descriptor. For remote descriptors, this is the |
153 // most recently cached value of the remote descriptor. For local descriptors | 155 // most recently cached value of the remote descriptor. For local descriptors |
154 // this is the most recently updated value or the value retrieved from the | 156 // this is the most recently updated value or the value retrieved from the |
155 // delegate. | 157 // delegate. |
156 virtual const std::vector<uint8>& GetValue() const = 0; | 158 virtual const std::vector<uint8_t>& GetValue() const = 0; |
157 | 159 |
158 // Returns a pointer to the GATT characteristic that this characteristic | 160 // Returns a pointer to the GATT characteristic that this characteristic |
159 // descriptor belongs to. | 161 // descriptor belongs to. |
160 virtual BluetoothGattCharacteristic* GetCharacteristic() const = 0; | 162 virtual BluetoothGattCharacteristic* GetCharacteristic() const = 0; |
161 | 163 |
162 // Returns the bitmask of characteristic descriptor attribute permissions. | 164 // Returns the bitmask of characteristic descriptor attribute permissions. |
163 virtual BluetoothGattCharacteristic::Permissions GetPermissions() const = 0; | 165 virtual BluetoothGattCharacteristic::Permissions GetPermissions() const = 0; |
164 | 166 |
165 // Sends a read request to a remote characteristic descriptor to read its | 167 // Sends a read request to a remote characteristic descriptor to read its |
166 // value. |callback| is called to return the read value on success and | 168 // value. |callback| is called to return the read value on success and |
167 // |error_callback| is called for failures. | 169 // |error_callback| is called for failures. |
168 virtual void ReadRemoteDescriptor(const ValueCallback& callback, | 170 virtual void ReadRemoteDescriptor(const ValueCallback& callback, |
169 const ErrorCallback& error_callback) = 0; | 171 const ErrorCallback& error_callback) = 0; |
170 | 172 |
171 // Sends a write request to a remote characteristic descriptor, to modify the | 173 // Sends a write request to a remote characteristic descriptor, to modify the |
172 // value of the descriptor with the new value |new_value|. |callback| is | 174 // value of the descriptor with the new value |new_value|. |callback| is |
173 // called to signal success and |error_callback| for failures. This method | 175 // called to signal success and |error_callback| for failures. This method |
174 // only applies to remote descriptors and will fail for those that are locally | 176 // only applies to remote descriptors and will fail for those that are locally |
175 // hosted. | 177 // hosted. |
176 virtual void WriteRemoteDescriptor( | 178 virtual void WriteRemoteDescriptor(const std::vector<uint8_t>& new_value, |
177 const std::vector<uint8>& new_value, | 179 const base::Closure& callback, |
178 const base::Closure& callback, | 180 const ErrorCallback& error_callback) = 0; |
179 const ErrorCallback& error_callback) = 0; | |
180 | 181 |
181 protected: | 182 protected: |
182 BluetoothGattDescriptor(); | 183 BluetoothGattDescriptor(); |
183 virtual ~BluetoothGattDescriptor(); | 184 virtual ~BluetoothGattDescriptor(); |
184 | 185 |
185 private: | 186 private: |
186 DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptor); | 187 DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptor); |
187 }; | 188 }; |
188 | 189 |
189 } // namespace device | 190 } // namespace device |
190 | 191 |
191 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_ | 192 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_ |
OLD | NEW |