| 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_characteristic.h" |
| 15 #include "device/bluetooth/bluetooth_gatt_service.h" |
| 16 #include "device/bluetooth/bluetooth_uuid.h" | 16 #include "device/bluetooth/bluetooth_uuid.h" |
| 17 | 17 |
| 18 namespace device { | 18 namespace device { |
| 19 | 19 |
| 20 // BluetoothGattDescriptor represents a local or remote GATT characteristic | 20 // BluetoothGattDescriptor represents a local or remote GATT characteristic |
| 21 // descriptor. A GATT characteristic descriptor provides further information | 21 // descriptor. A GATT characteristic descriptor provides further information |
| 22 // 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 |
| 23 // characteristic's features or to control certain behaviors. | 23 // characteristic's features or to control certain behaviors. |
| 24 class DEVICE_BLUETOOTH_EXPORT BluetoothGattDescriptor { | 24 class DEVICE_BLUETOOTH_EXPORT BluetoothGattDescriptor { |
| 25 public: | 25 public: |
| 26 // The ErrorCallback is used by methods to asynchronously report errors. | 26 // The ErrorCallback is used by methods to asynchronously report errors. |
| 27 typedef base::Callback<void(BluetoothGattService::GattErrorCode)> | 27 typedef base::Callback<void(BluetoothGattService::GattErrorCode)> |
| 28 ErrorCallback; | 28 ErrorCallback; |
| 29 | 29 |
| 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 | 30 // The Bluetooth Specification declares several predefined descriptors that |
| 35 // profiles can use. The following are definitions for the list of UUIDs | 31 // profiles can use. The following are definitions for the list of UUIDs |
| 36 // and descriptions of the characteristic descriptors that they represent. | 32 // and descriptions of the characteristic descriptors that they represent. |
| 37 // Possible values for and further information on each descriptor can be found | 33 // 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 | 34 // 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. | 35 // optional and may not be present for a given characteristic. |
| 40 | 36 |
| 41 // The "Characteristic Extended Properties" descriptor. This defines | 37 // The "Characteristic Extended Properties" descriptor. This defines |
| 42 // additional "Characteristic Properties" which cannot fit into the allocated | 38 // additional "Characteristic Properties" which cannot fit into the allocated |
| 43 // single octet property field of a characteristic. The value is a bit field | 39 // 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 | 99 // is used by that characteristic. Hence, exactly one instance of this |
| 104 // descriptor must exist if more than one "Characteristic Presentation Format" | 100 // descriptor must exist if more than one "Characteristic Presentation Format" |
| 105 // descriptors exist for a characteristic. | 101 // descriptors exist for a characteristic. |
| 106 // | 102 // |
| 107 // Applications that are using the device::Bluetooth API do not have access to | 103 // 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 | 104 // the underlying handles and shouldn't use this descriptor to determine which |
| 109 // "Characteristic Presentation Format" descriptors belong to a | 105 // "Characteristic Presentation Format" descriptors belong to a |
| 110 // characteristic. | 106 // characteristic. |
| 111 // The API will construct a BluetoothGattDescriptor object for each instance | 107 // The API will construct a BluetoothGattDescriptor object for each instance |
| 112 // of "Characteristic Presentation Format" descriptor per instance of | 108 // of "Characteristic Presentation Format" descriptor per instance of |
| 113 // BluetoothGattCharacteristic that represents a remote characteristic. | 109 // BluetoothRemoteGattCharacteristic that represents a remote characteristic. |
| 114 // Similarly for local characteristics, implementations DO NOT need to create | 110 // Similarly for local characteristics, implementations DO NOT need to create |
| 115 // an instance of BluetoothGattDescriptor for this descriptor as this will be | 111 // an instance of BluetoothGattDescriptor for this descriptor as this will be |
| 116 // handled by the subsystem. | 112 // handled by the subsystem. |
| 117 static const BluetoothUUID& CharacteristicAggregateFormatUuid(); | 113 static const BluetoothUUID& CharacteristicAggregateFormatUuid(); |
| 118 | 114 |
| 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 | 115 // Identifier used to uniquely identify a GATT descriptor object. This is |
| 141 // different from the descriptor UUID: while multiple descriptors with the | 116 // different from the descriptor UUID: while multiple descriptors with the |
| 142 // same UUID can exist on a Bluetooth device, the identifier returned from | 117 // 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 | 118 // this method is unique among all descriptors on the adapter. The contents of |
| 144 // the identifier are platform specific. | 119 // the identifier are platform specific. |
| 145 virtual std::string GetIdentifier() const = 0; | 120 virtual std::string GetIdentifier() const = 0; |
| 146 | 121 |
| 147 // The Bluetooth-specific UUID of the characteristic descriptor. | 122 // The Bluetooth-specific UUID of the characteristic descriptor. |
| 148 virtual BluetoothUUID GetUUID() const = 0; | 123 virtual BluetoothUUID GetUUID() const = 0; |
| 149 | 124 |
| 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. | 125 // Returns the bitmask of characteristic descriptor attribute permissions. |
| 165 virtual BluetoothGattCharacteristic::Permissions GetPermissions() const = 0; | 126 virtual BluetoothGattCharacteristic::Permissions GetPermissions() const = 0; |
| 166 | 127 |
| 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: | 128 protected: |
| 183 BluetoothGattDescriptor(); | 129 BluetoothGattDescriptor(); |
| 184 virtual ~BluetoothGattDescriptor(); | 130 virtual ~BluetoothGattDescriptor(); |
| 185 | 131 |
| 186 private: | 132 private: |
| 187 DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptor); | 133 DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptor); |
| 188 }; | 134 }; |
| 189 | 135 |
| 190 } // namespace device | 136 } // namespace device |
| 191 | 137 |
| 192 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_ | 138 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_ |
| OLD | NEW |