Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: device/bluetooth/bluetooth_gatt_characteristic.h

Issue 1542163002: Switch to standard integer types in device/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_CHARACTERISTIC_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_GATT_CHARACTERISTIC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_CHARACTERISTIC_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_CHARACTERISTIC_H_
7 7
8 #include <stdint.h>
9
8 #include <string> 10 #include <string>
9 #include <vector> 11 #include <vector>
10 12
11 #include "base/basictypes.h"
12 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
14 #include "device/bluetooth/bluetooth_export.h" 16 #include "device/bluetooth/bluetooth_export.h"
15 #include "device/bluetooth/bluetooth_gatt_service.h" 17 #include "device/bluetooth/bluetooth_gatt_service.h"
16 #include "device/bluetooth/bluetooth_uuid.h" 18 #include "device/bluetooth/bluetooth_uuid.h"
17 19
18 namespace device { 20 namespace device {
19 21
20 class BluetoothGattDescriptor; 22 class BluetoothGattDescriptor;
21 class BluetoothGattNotifySession; 23 class BluetoothGattNotifySession;
22 24
(...skipping 26 matching lines...) Expand all
49 PROPERTY_READ = 1 << 1, 51 PROPERTY_READ = 1 << 1,
50 PROPERTY_WRITE_WITHOUT_RESPONSE = 1 << 2, 52 PROPERTY_WRITE_WITHOUT_RESPONSE = 1 << 2,
51 PROPERTY_WRITE = 1 << 3, 53 PROPERTY_WRITE = 1 << 3,
52 PROPERTY_NOTIFY = 1 << 4, 54 PROPERTY_NOTIFY = 1 << 4,
53 PROPERTY_INDICATE = 1 << 5, 55 PROPERTY_INDICATE = 1 << 5,
54 PROPERTY_AUTHENTICATED_SIGNED_WRITES = 1 << 6, 56 PROPERTY_AUTHENTICATED_SIGNED_WRITES = 1 << 6,
55 PROPERTY_EXTENDED_PROPERTIES = 1 << 7, 57 PROPERTY_EXTENDED_PROPERTIES = 1 << 7,
56 PROPERTY_RELIABLE_WRITE = 1 << 8, 58 PROPERTY_RELIABLE_WRITE = 1 << 8,
57 PROPERTY_WRITABLE_AUXILIARIES = 1 << 9 59 PROPERTY_WRITABLE_AUXILIARIES = 1 << 9
58 }; 60 };
59 typedef uint32 Properties; 61 typedef uint32_t Properties;
60 62
61 // Values representing read, write, and encryption permissions for a 63 // Values representing read, write, and encryption permissions for a
62 // characteristic's value. While attribute permissions for all GATT 64 // characteristic's value. While attribute permissions for all GATT
63 // definitions have been set by the Bluetooth specification, characteristic 65 // definitions have been set by the Bluetooth specification, characteristic
64 // value permissions are left up to the higher-level profile. 66 // value permissions are left up to the higher-level profile.
65 // 67 //
66 // Attribute permissions are distinct from the characteristic properties. For 68 // Attribute permissions are distinct from the characteristic properties. For
67 // example, a characteristic may have the property |PROPERTY_READ| to make 69 // example, a characteristic may have the property |PROPERTY_READ| to make
68 // clients know that it is possible to read the characteristic value and have 70 // clients know that it is possible to read the characteristic value and have
69 // the permission |PERMISSION_READ_ENCRYPTED| to require a secure connection. 71 // the permission |PERMISSION_READ_ENCRYPTED| to require a secure connection.
70 // It is up to the application to properly specify the permissions and 72 // It is up to the application to properly specify the permissions and
71 // properties for a local characteristic. 73 // properties for a local characteristic.
72 enum Permission { 74 enum Permission {
73 PERMISSION_NONE = 0, 75 PERMISSION_NONE = 0,
74 PERMISSION_READ = 1 << 0, 76 PERMISSION_READ = 1 << 0,
75 PERMISSION_WRITE = 1 << 1, 77 PERMISSION_WRITE = 1 << 1,
76 PERMISSION_READ_ENCRYPTED = 1 << 2, 78 PERMISSION_READ_ENCRYPTED = 1 << 2,
77 PERMISSION_WRITE_ENCRYPTED = 1 << 3 79 PERMISSION_WRITE_ENCRYPTED = 1 << 3
78 }; 80 };
79 typedef uint32 Permissions; 81 typedef uint32_t Permissions;
80 82
81 // The ErrorCallback is used by methods to asynchronously report errors. 83 // The ErrorCallback is used by methods to asynchronously report errors.
82 typedef base::Callback<void(BluetoothGattService::GattErrorCode)> 84 typedef base::Callback<void(BluetoothGattService::GattErrorCode)>
83 ErrorCallback; 85 ErrorCallback;
84 86
85 // The ValueCallback is used to return the value of a remote characteristic 87 // The ValueCallback is used to return the value of a remote characteristic
86 // upon a read request. 88 // upon a read request.
87 typedef base::Callback<void(const std::vector<uint8>&)> ValueCallback; 89 typedef base::Callback<void(const std::vector<uint8_t>&)> ValueCallback;
88 90
89 // The NotifySessionCallback is used to return sessions after they have 91 // The NotifySessionCallback is used to return sessions after they have
90 // been successfully started. 92 // been successfully started.
91 typedef base::Callback<void(scoped_ptr<BluetoothGattNotifySession>)> 93 typedef base::Callback<void(scoped_ptr<BluetoothGattNotifySession>)>
92 NotifySessionCallback; 94 NotifySessionCallback;
93 95
94 // Constructs a BluetoothGattCharacteristic that can be associated with a 96 // Constructs a BluetoothGattCharacteristic that can be associated with a
95 // local GATT service when the adapter is in the peripheral role. To 97 // local GATT service when the adapter is in the peripheral role. To
96 // associate the returned characteristic with a service, add it to a local 98 // associate the returned characteristic with a service, add it to a local
97 // service by calling BluetoothGattService::AddCharacteristic. 99 // service by calling BluetoothGattService::AddCharacteristic.
98 // 100 //
99 // This method constructs a characteristic with UUID |uuid|, initial cached 101 // This method constructs a characteristic with UUID |uuid|, initial cached
100 // value |value|, properties |properties|, and permissions |permissions|. 102 // value |value|, properties |properties|, and permissions |permissions|.
101 // |value| will be cached and returned for read requests and automatically set 103 // |value| will be cached and returned for read requests and automatically set
102 // for write requests by default, unless an instance of 104 // for write requests by default, unless an instance of
103 // BluetoothGattService::Delegate has been provided to the associated 105 // BluetoothGattService::Delegate has been provided to the associated
104 // BluetoothGattService instance, in which case the delegate will handle read 106 // BluetoothGattService instance, in which case the delegate will handle read
105 // and write requests. 107 // and write requests.
106 // 108 //
107 // NOTE: Don't explicitly set |PROPERTY_EXTENDED_PROPERTIES| in |properties|. 109 // NOTE: Don't explicitly set |PROPERTY_EXTENDED_PROPERTIES| in |properties|.
108 // Instead, create and add a BluetoothGattDescriptor that represents the 110 // Instead, create and add a BluetoothGattDescriptor that represents the
109 // "Characteristic Extended Properties" descriptor and this will automatically 111 // "Characteristic Extended Properties" descriptor and this will automatically
110 // set the correspoding bit in the characteristic's properties field. If 112 // set the correspoding bit in the characteristic's properties field. If
111 // |properties| has |PROPERTY_EXTENDED_PROPERTIES| set, it will be ignored. 113 // |properties| has |PROPERTY_EXTENDED_PROPERTIES| set, it will be ignored.
112 static BluetoothGattCharacteristic* Create(const BluetoothUUID& uuid, 114 static BluetoothGattCharacteristic* Create(const BluetoothUUID& uuid,
113 const std::vector<uint8>& value, 115 const std::vector<uint8_t>& value,
114 Properties properties, 116 Properties properties,
115 Permissions permissions); 117 Permissions permissions);
116 118
117 // Identifier used to uniquely identify a GATT characteristic object. This is 119 // Identifier used to uniquely identify a GATT characteristic object. This is
118 // different from the characteristic UUID: while multiple characteristics with 120 // different from the characteristic UUID: while multiple characteristics with
119 // the same UUID can exist on a Bluetooth device, the identifier returned from 121 // the same UUID can exist on a Bluetooth device, the identifier returned from
120 // this method is unique among all characteristics on the adapter. The 122 // this method is unique among all characteristics on the adapter. The
121 // contents of the identifier are platform specific. 123 // contents of the identifier are platform specific.
122 virtual std::string GetIdentifier() const = 0; 124 virtual std::string GetIdentifier() const = 0;
123 125
124 // The Bluetooth-specific UUID of the characteristic. 126 // The Bluetooth-specific UUID of the characteristic.
125 virtual BluetoothUUID GetUUID() const = 0; 127 virtual BluetoothUUID GetUUID() const = 0;
126 128
127 // Returns true, if this characteristic is hosted locally. If false, then this 129 // Returns true, if this characteristic is hosted locally. If false, then this
128 // instance represents a remote GATT characteristic. 130 // instance represents a remote GATT characteristic.
129 virtual bool IsLocal() const = 0; 131 virtual bool IsLocal() const = 0;
130 132
131 // Returns the value of the characteristic. For remote characteristics, this 133 // Returns the value of the characteristic. For remote characteristics, this
132 // is the most recently cached value. For local characteristics, this is the 134 // is the most recently cached value. For local characteristics, this is the
133 // most recently updated value or the value retrieved from the delegate. 135 // most recently updated value or the value retrieved from the delegate.
134 virtual const std::vector<uint8>& GetValue() const = 0; 136 virtual const std::vector<uint8_t>& GetValue() const = 0;
135 137
136 // Returns a pointer to the GATT service this characteristic belongs to. 138 // Returns a pointer to the GATT service this characteristic belongs to.
137 virtual BluetoothGattService* GetService() const = 0; 139 virtual BluetoothGattService* GetService() const = 0;
138 140
139 // Returns the bitmask of characteristic properties. 141 // Returns the bitmask of characteristic properties.
140 virtual Properties GetProperties() const = 0; 142 virtual Properties GetProperties() const = 0;
141 143
142 // Returns the bitmask of characteristic attribute permissions. 144 // Returns the bitmask of characteristic attribute permissions.
143 virtual Permissions GetPermissions() const = 0; 145 virtual Permissions GetPermissions() const = 0;
144 146
(...skipping 21 matching lines...) Expand all
166 // For locally hosted characteristics, updates the characteristic's value. 168 // For locally hosted characteristics, updates the characteristic's value.
167 // This will update the value that is visible to remote devices and send out 169 // This will update the value that is visible to remote devices and send out
168 // any notifications and indications that have been configured. This method 170 // any notifications and indications that have been configured. This method
169 // can be used in place of, and in conjunction with, 171 // can be used in place of, and in conjunction with,
170 // BluetoothGattService::Delegate methods to send updates to remote devices, 172 // BluetoothGattService::Delegate methods to send updates to remote devices,
171 // or simply to set update the cached value for read requests without having 173 // or simply to set update the cached value for read requests without having
172 // to implement the delegate methods. 174 // to implement the delegate methods.
173 // 175 //
174 // This method only makes sense for local characteristics and does nothing and 176 // This method only makes sense for local characteristics and does nothing and
175 // returns false if this instance represents a remote characteristic. 177 // returns false if this instance represents a remote characteristic.
176 virtual bool UpdateValue(const std::vector<uint8>& value) = 0; 178 virtual bool UpdateValue(const std::vector<uint8_t>& value) = 0;
177 179
178 // Starts a notify session for the remote characteristic, if it supports 180 // Starts a notify session for the remote characteristic, if it supports
179 // notifications/indications. On success, the characteristic starts sending 181 // notifications/indications. On success, the characteristic starts sending
180 // value notifications and |callback| is called with a session object whose 182 // value notifications and |callback| is called with a session object whose
181 // ownership belongs to the caller. |error_callback| is called on errors. 183 // ownership belongs to the caller. |error_callback| is called on errors.
182 virtual void StartNotifySession(const NotifySessionCallback& callback, 184 virtual void StartNotifySession(const NotifySessionCallback& callback,
183 const ErrorCallback& error_callback) = 0; 185 const ErrorCallback& error_callback) = 0;
184 186
185 // Sends a read request to a remote characteristic to read its value. 187 // Sends a read request to a remote characteristic to read its value.
186 // |callback| is called to return the read value on success and 188 // |callback| is called to return the read value on success and
187 // |error_callback| is called for failures. 189 // |error_callback| is called for failures.
188 virtual void ReadRemoteCharacteristic( 190 virtual void ReadRemoteCharacteristic(
189 const ValueCallback& callback, 191 const ValueCallback& callback,
190 const ErrorCallback& error_callback) = 0; 192 const ErrorCallback& error_callback) = 0;
191 193
192 // Sends a write request to a remote characteristic, to modify the 194 // Sends a write request to a remote characteristic, to modify the
193 // characteristic's value with the new value |new_value|. |callback| is 195 // characteristic's value with the new value |new_value|. |callback| is
194 // called to signal success and |error_callback| for failures. This method 196 // called to signal success and |error_callback| for failures. This method
195 // only applies to remote characteristics and will fail for those that are 197 // only applies to remote characteristics and will fail for those that are
196 // locally hosted. 198 // locally hosted.
197 virtual void WriteRemoteCharacteristic( 199 virtual void WriteRemoteCharacteristic(
198 const std::vector<uint8>& new_value, 200 const std::vector<uint8_t>& new_value,
199 const base::Closure& callback, 201 const base::Closure& callback,
200 const ErrorCallback& error_callback) = 0; 202 const ErrorCallback& error_callback) = 0;
201 203
202 protected: 204 protected:
203 BluetoothGattCharacteristic(); 205 BluetoothGattCharacteristic();
204 virtual ~BluetoothGattCharacteristic(); 206 virtual ~BluetoothGattCharacteristic();
205 207
206 private: 208 private:
207 DISALLOW_COPY_AND_ASSIGN(BluetoothGattCharacteristic); 209 DISALLOW_COPY_AND_ASSIGN(BluetoothGattCharacteristic);
208 }; 210 };
209 211
210 } // namespace device 212 } // namespace device
211 213
212 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_CHARACTERISTIC_H_ 214 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_CHARACTERISTIC_H_
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_gatt_bluez_unittest.cc ('k') | device/bluetooth/bluetooth_gatt_characteristic.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698