Automated Commit: Committing new LKGM version 6953.0.0 for chromeos.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_gatt_descriptor.h
blob442a6aeb2c8a4b5100ca153182402151eee38fd4
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
3 // found in the LICENSE file.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "device/bluetooth/bluetooth_export.h"
13 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
14 #include "device/bluetooth/bluetooth_uuid.h"
16 namespace device {
18 // BluetoothGattDescriptor represents a local or remote GATT characteristic
19 // descriptor. A GATT characteristic descriptor provides further information
20 // about a characteristic's value. They can be used to describe the
21 // characteristic's features or to control certain behaviors.
22 class DEVICE_BLUETOOTH_EXPORT BluetoothGattDescriptor {
23 public:
24 // The Bluetooth Specification declares several predefined descriptors that
25 // profiles can use. The following are definitions for the list of UUIDs
26 // and descriptions of the characteristic descriptors that they represent.
27 // Possible values for and further information on each descriptor can be found
28 // in Core v4.0, Volume 3, Part G, Section 3.3.3. All of these descriptors are
29 // optional and may not be present for a given characteristic.
31 // The "Characteristic Extended Properties" descriptor. This defines
32 // additional "Characteristic Properties" which cannot fit into the allocated
33 // single octet property field of a characteristic. The value is a bit field
34 // and the two predefined bits, as per Bluetooth Core Specification v4.0, are:
36 // - Reliable Write: 0x0001
37 // - Writable Auxiliaries: 0x0002
39 static const BluetoothUUID& CharacteristicExtendedPropertiesUuid();
41 // The "Characteristic User Description" descriptor defines a UTF-8 string of
42 // variable size that is a user textual description of the associated
43 // characteristic's value. There can be only one instance of this descriptor
44 // per characteristic. This descriptor can be written to if the "Writable
45 // Auxiliaries" bit of the Characteristic Properties (via the "Characteristic
46 // Extended Properties" descriptor) has been set.
47 static const BluetoothUUID& CharacteristicUserDescriptionUuid();
49 // The "Client Characteristic Configuration" descriptor defines how the
50 // characteristic may be configured by a specific client. A server-side
51 // instance of this descriptor exists for each client that has bonded with
52 // the server and the value can be read and written by that client only. As
53 // of Core v4.0, this descriptor is used by clients to set up notifications
54 // and indications from a characteristic. The value is a bit field and the
55 // predefined bits are:
57 // - Default: 0x0000
58 // - Notification: 0x0001
59 // - Indication: 0x0002
61 static const BluetoothUUID& ClientCharacteristicConfigurationUuid();
63 // The "Server Characteristic Configuration" descriptor defines how the
64 // characteristic may be configured for the server. There is one instance
65 // of this descriptor for all clients and setting the value of this descriptor
66 // affects its configuration for all clients. As of Core v4.0, this descriptor
67 // is used to set up the server to broadcast the characteristic value if
68 // advertising resources are available. The value is a bit field and the
69 // predefined bits are:
71 // - Default: 0x0000
72 // - Broadcast: 0x0001
74 static const BluetoothUUID& ServerCharacteristicConfigurationUuid();
76 // The "Characteristic Presentation Format" declaration defines the format of
77 // the Characteristic Value. The value is composed of 7 octets which are
78 // divided into groups that represent different semantic meanings. For a
79 // detailed description of how the value of this descriptor should be
80 // interpreted, refer to Core v4.0, Volume 3, Part G, Section 3.3.3.5. If more
81 // than one declaration of this descriptor exists for a characteristic, then a
82 // "Characteristic Aggregate Format" descriptor must also exist for that
83 // characteristic.
84 static const BluetoothUUID& CharacteristicPresentationFormatUuid();
86 // The "Characteristic Aggregate Format" descriptor defines the format of an
87 // aggregated characteristic value. In GATT's underlying protocol, ATT, each
88 // attribute is identified by a handle that is unique for the hosting server.
89 // Multiple characteristics can share the same instance(s) of a
90 // "Characteristic Presentation Format" descriptor. The value of the
91 // "Characteristic Aggregate Format" descriptor contains a list of handles
92 // that each refer to a "Characteristic Presentation Format" descriptor that
93 // is used by that characteristic. Hence, exactly one instance of this
94 // descriptor must exist if more than one "Characteristic Presentation Format"
95 // descriptors exist for a characteristic.
97 // Applications that are using the device::Bluetooth API do not have access to
98 // the underlying handles and shouldn't use this descriptor to determine which
99 // "Characteristic Presentation Format" descriptors belong to a
100 // characteristic.
101 // The API will construct a BluetoothGattDescriptor object for each instance
102 // of "Characteristic Presentation Format" descriptor per instance of
103 // BluetoothGattCharacteristic that represents a remote characteristic.
104 // Similarly for local characteristics, implementations DO NOT need to create
105 // an instance of BluetoothGattDescriptor for this descriptor as this will be
106 // handled by the subsystem.
107 static const BluetoothUUID& CharacteristicAggregateFormatUuid();
109 // The ErrorCallback is used by methods to asynchronously report errors.
110 typedef base::Callback<void(BluetoothGattService::GattErrorCode)>
111 ErrorCallback;
113 // The ValueCallback is used to return the value of a remote characteristic
114 // descriptor upon a read request.
115 typedef base::Callback<void(const std::vector<uint8>&)> ValueCallback;
117 // Constructs a BluetoothGattDescriptor that can be associated with a local
118 // GATT characteristic when the adapter is in the peripheral role. To
119 // associate the returned descriptor with a characteristic, add it to a local
120 // characteristic by calling BluetoothGattCharacteristic::AddDescriptor.
122 // This method constructs a characteristic descriptor with UUID |uuid| and the
123 // initial cached value |value|. |value| will be cached and returned for read
124 // requests and automatically modified for write requests by default, unless
125 // an instance of BluetoothGattService::Delegate has been provided to the
126 // associated BluetoothGattService instance, in which case the delegate will
127 // handle the read and write requests.
129 // Currently, only custom UUIDs, |kCharacteristicDescriptionUuid|, and
130 // |kCharacteristicPresentationFormat| are supported for locally hosted
131 // descriptors. This method will return NULL if |uuid| is any one of the
132 // unsupported predefined descriptor UUIDs.
133 static BluetoothGattDescriptor* Create(
134 const BluetoothUUID& uuid,
135 const std::vector<uint8>& value,
136 BluetoothGattCharacteristic::Permissions permissions);
138 // Identifier used to uniquely identify a GATT descriptor object. This is
139 // different from the descriptor UUID: while multiple descriptors with the
140 // same UUID can exist on a Bluetooth device, the identifier returned from
141 // this method is unique among all descriptors of a device. The contents of
142 // the identifier are platform specific.
143 virtual std::string GetIdentifier() const = 0;
145 // The Bluetooth-specific UUID of the characteristic descriptor.
146 virtual BluetoothUUID GetUUID() const = 0;
148 // Returns true, if this characteristic descriptor is hosted locally. If
149 // false, then this instance represents a remote descriptor.
150 virtual bool IsLocal() const = 0;
152 // Returns the value of the descriptor. For remote descriptors, this is the
153 // 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
155 // delegate.
156 virtual const std::vector<uint8>& GetValue() const = 0;
158 // Returns a pointer to the GATT characteristic that this characteristic
159 // descriptor belongs to.
160 virtual BluetoothGattCharacteristic* GetCharacteristic() const = 0;
162 // Returns the bitmask of characteristic descriptor attribute permissions.
163 virtual BluetoothGattCharacteristic::Permissions GetPermissions() const = 0;
165 // 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
167 // |error_callback| is called for failures.
168 virtual void ReadRemoteDescriptor(const ValueCallback& callback,
169 const ErrorCallback& error_callback) = 0;
171 // 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
173 // 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
175 // hosted.
176 virtual void WriteRemoteDescriptor(
177 const std::vector<uint8>& new_value,
178 const base::Closure& callback,
179 const ErrorCallback& error_callback) = 0;
181 protected:
182 BluetoothGattDescriptor();
183 virtual ~BluetoothGattDescriptor();
185 private:
186 DISALLOW_COPY_AND_ASSIGN(BluetoothGattDescriptor);
189 } // namespace device
191 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_DESCRIPTOR_H_