OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_REMOTE_GATT_DESCRIPTOR_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_DESCRIPTOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | |
10 #include <vector> | 9 #include <vector> |
11 | 10 |
12 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/callback_forward.h" | |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "device/bluetooth/bluetooth_export.h" | 14 #include "device/bluetooth/bluetooth_export.h" |
15 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 15 #include "device/bluetooth/bluetooth_gatt_descriptor.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 class BluetoothRemoteGattCharacteristic; |
21 // descriptor. A GATT characteristic descriptor provides further information | 21 |
22 // about a characteristic's value. They can be used to describe the | 22 // BluetoothRemoteGattDescriptor represents a remote GATT characteristic |
23 // characteristic's features or to control certain behaviors. | 23 // descriptor. |
scheib
2016/04/20 01:23:30
Might as well keep the "A GATT characteristic desc
rkc
2016/04/20 16:31:54
Its there in the comment for the base class. I am
| |
24 class DEVICE_BLUETOOTH_EXPORT BluetoothGattDescriptor { | 24 // |
25 // Note: We use virtual inheritance on the GATT descriptor since it will be | |
26 // inherited by platform specific versions of the GATT descriptor classes also. | |
27 // The platform specific remote GATT descriptor classes will inherit both this | |
28 // class and their GATT descriptor class, hence causing an inheritance diamond. | |
29 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattDescriptor | |
30 : public virtual BluetoothGattDescriptor { | |
25 public: | 31 public: |
26 // The ErrorCallback is used by methods to asynchronously report errors. | |
27 typedef base::Callback<void(BluetoothGattService::GattErrorCode)> | |
28 ErrorCallback; | |
29 | |
30 // The ValueCallback is used to return the value of a remote characteristic | 32 // The ValueCallback is used to return the value of a remote characteristic |
31 // descriptor upon a read request. | 33 // descriptor upon a read request. |
32 typedef base::Callback<void(const std::vector<uint8_t>&)> ValueCallback; | 34 typedef base::Callback<void(const std::vector<uint8_t>&)> ValueCallback; |
33 | 35 |
34 // The Bluetooth Specification declares several predefined descriptors that | |
35 // profiles can use. The following are definitions for the list of UUIDs | |
36 // and descriptions of the characteristic descriptors that they represent. | |
37 // 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 | |
39 // optional and may not be present for a given characteristic. | |
40 | |
41 // The "Characteristic Extended Properties" descriptor. This defines | |
42 // additional "Characteristic Properties" which cannot fit into the allocated | |
43 // single octet property field of a characteristic. The value is a bit field | |
44 // and the two predefined bits, as per Bluetooth Core Specification v4.0, are: | |
45 // | |
46 // - Reliable Write: 0x0001 | |
47 // - Writable Auxiliaries: 0x0002 | |
48 // | |
49 static const BluetoothUUID& CharacteristicExtendedPropertiesUuid(); | |
50 | |
51 // The "Characteristic User Description" descriptor defines a UTF-8 string of | |
52 // variable size that is a user textual description of the associated | |
53 // characteristic's value. There can be only one instance of this descriptor | |
54 // per characteristic. This descriptor can be written to if the "Writable | |
55 // Auxiliaries" bit of the Characteristic Properties (via the "Characteristic | |
56 // Extended Properties" descriptor) has been set. | |
57 static const BluetoothUUID& CharacteristicUserDescriptionUuid(); | |
58 | |
59 // The "Client Characteristic Configuration" descriptor defines how the | |
60 // characteristic may be configured by a specific client. A server-side | |
61 // instance of this descriptor exists for each client that has bonded with | |
62 // the server and the value can be read and written by that client only. As | |
63 // of Core v4.0, this descriptor is used by clients to set up notifications | |
64 // and indications from a characteristic. The value is a bit field and the | |
65 // predefined bits are: | |
66 // | |
67 // - Default: 0x0000 | |
68 // - Notification: 0x0001 | |
69 // - Indication: 0x0002 | |
70 // | |
71 static const BluetoothUUID& ClientCharacteristicConfigurationUuid(); | |
72 | |
73 // The "Server Characteristic Configuration" descriptor defines how the | |
74 // characteristic may be configured for the server. There is one instance | |
75 // of this descriptor for all clients and setting the value of this descriptor | |
76 // affects its configuration for all clients. As of Core v4.0, this descriptor | |
77 // is used to set up the server to broadcast the characteristic value if | |
78 // advertising resources are available. The value is a bit field and the | |
79 // predefined bits are: | |
80 // | |
81 // - Default: 0x0000 | |
82 // - Broadcast: 0x0001 | |
83 // | |
84 static const BluetoothUUID& ServerCharacteristicConfigurationUuid(); | |
85 | |
86 // The "Characteristic Presentation Format" declaration defines the format of | |
87 // the Characteristic Value. The value is composed of 7 octets which are | |
88 // divided into groups that represent different semantic meanings. For a | |
89 // detailed description of how the value of this descriptor should be | |
90 // interpreted, refer to Core v4.0, Volume 3, Part G, Section 3.3.3.5. If more | |
91 // than one declaration of this descriptor exists for a characteristic, then a | |
92 // "Characteristic Aggregate Format" descriptor must also exist for that | |
93 // characteristic. | |
94 static const BluetoothUUID& CharacteristicPresentationFormatUuid(); | |
95 | |
96 // The "Characteristic Aggregate Format" descriptor defines the format of an | |
97 // aggregated characteristic value. In GATT's underlying protocol, ATT, each | |
98 // attribute is identified by a handle that is unique for the hosting server. | |
99 // Multiple characteristics can share the same instance(s) of a | |
100 // "Characteristic Presentation Format" descriptor. The value of the | |
101 // "Characteristic Aggregate Format" descriptor contains a list of handles | |
102 // that each refer to a "Characteristic Presentation Format" descriptor that | |
103 // is used by that characteristic. Hence, exactly one instance of this | |
104 // descriptor must exist if more than one "Characteristic Presentation Format" | |
105 // descriptors exist for a characteristic. | |
106 // | |
107 // 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 | |
109 // "Characteristic Presentation Format" descriptors belong to a | |
110 // characteristic. | |
111 // The API will construct a BluetoothGattDescriptor object for each instance | |
112 // of "Characteristic Presentation Format" descriptor per instance of | |
113 // BluetoothGattCharacteristic that represents a remote characteristic. | |
114 // Similarly for local characteristics, implementations DO NOT need to create | |
115 // an instance of BluetoothGattDescriptor for this descriptor as this will be | |
116 // handled by the subsystem. | |
117 static const BluetoothUUID& CharacteristicAggregateFormatUuid(); | |
118 | |
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 | |
141 // different from the descriptor UUID: while multiple descriptors with the | |
142 // 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 | |
144 // the identifier are platform specific. | |
145 virtual std::string GetIdentifier() const = 0; | |
146 | |
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 | 36 // Returns the value of the descriptor. For remote descriptors, this is the |
155 // most recently cached value of the remote descriptor. For local descriptors | 37 // 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 | 38 // this is the most recently updated value or the value retrieved from the |
157 // delegate. | 39 // delegate. |
158 virtual const std::vector<uint8_t>& GetValue() const = 0; | 40 virtual const std::vector<uint8_t>& GetValue() const = 0; |
159 | 41 |
160 // Returns a pointer to the GATT characteristic that this characteristic | 42 // Returns a pointer to the GATT characteristic that this characteristic |
161 // descriptor belongs to. | 43 // descriptor belongs to. |
162 virtual BluetoothGattCharacteristic* GetCharacteristic() const = 0; | 44 virtual BluetoothRemoteGattCharacteristic* GetCharacteristic() const = 0; |
163 | |
164 // Returns the bitmask of characteristic descriptor attribute permissions. | |
165 virtual BluetoothGattCharacteristic::Permissions GetPermissions() const = 0; | |
166 | 45 |
167 // Sends a read request to a remote characteristic descriptor to read its | 46 // 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 | 47 // value. |callback| is called to return the read value on success and |
169 // |error_callback| is called for failures. | 48 // |error_callback| is called for failures. |
170 virtual void ReadRemoteDescriptor(const ValueCallback& callback, | 49 virtual void ReadRemoteDescriptor(const ValueCallback& callback, |
171 const ErrorCallback& error_callback) = 0; | 50 const ErrorCallback& error_callback) = 0; |
172 | 51 |
173 // Sends a write request to a remote characteristic descriptor, to modify the | 52 // 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 | 53 // value of the descriptor with the new value |new_value|. |callback| is |
175 // called to signal success and |error_callback| for failures. This method | 54 // 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 | 55 // only applies to remote descriptors and will fail for those that are locally |
177 // hosted. | 56 // hosted. |
178 virtual void WriteRemoteDescriptor(const std::vector<uint8_t>& new_value, | 57 virtual void WriteRemoteDescriptor(const std::vector<uint8_t>& new_value, |
179 const base::Closure& callback, | 58 const base::Closure& callback, |
180 const ErrorCallback& error_callback) = 0; | 59 const ErrorCallback& error_callback) = 0; |
181 | 60 |
182 protected: | 61 protected: |
183 BluetoothGattDescriptor(); | 62 BluetoothRemoteGattDescriptor(); |
184 virtual ~BluetoothGattDescriptor(); | 63 ~BluetoothRemoteGattDescriptor() override; |
185 | 64 |
186 private: | 65 private: |
187 DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptor); | 66 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattDescriptor); |
188 }; | 67 }; |
189 | 68 |
190 } // namespace device | 69 } // namespace device |
191 | 70 |
192 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_ | 71 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_DESCRIPTOR_H_ |
OLD | NEW |