OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_DEVICE_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "device/bluetooth/bluetooth_uuid.h" | |
15 | 14 |
16 namespace device { | 15 namespace device { |
17 | 16 |
18 class BluetoothProfile; | 17 class BluetoothProfile; |
19 class BluetoothSocket; | 18 class BluetoothSocket; |
20 | 19 |
21 struct BluetoothOutOfBandPairingData; | 20 struct BluetoothOutOfBandPairingData; |
22 | 21 |
23 // BluetoothDevice represents a remote Bluetooth device, both its properties and | 22 // BluetoothDevice represents a remote Bluetooth device, both its properties and |
24 // capabilities as discovered by a local adapter and actions that may be | 23 // capabilities as discovered by a local adapter and actions that may be |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // This method will be called when the Bluetooth daemon requires that a | 162 // This method will be called when the Bluetooth daemon requires that a |
164 // pairing request, usually only incoming, using the just-works model is | 163 // pairing request, usually only incoming, using the just-works model is |
165 // authorized. The delegate should decide whether the user should confirm | 164 // authorized. The delegate should decide whether the user should confirm |
166 // or not, then call ConfirmPairing() on the device to confirm the pairing | 165 // or not, then call ConfirmPairing() on the device to confirm the pairing |
167 // (whether by user action or by default), RejectPairing() on the device to | 166 // (whether by user action or by default), RejectPairing() on the device to |
168 // reject or CancelPairing() on the device to cancel authorization for | 167 // reject or CancelPairing() on the device to cancel authorization for |
169 // any other reason. | 168 // any other reason. |
170 virtual void AuthorizePairing(BluetoothDevice* device) = 0; | 169 virtual void AuthorizePairing(BluetoothDevice* device) = 0; |
171 }; | 170 }; |
172 | 171 |
| 172 // Returns true if uuid is in a a valid canonical format |
| 173 // (see utils::CanonicalUuid). |
| 174 static bool IsUUIDValid(const std::string& uuid); |
| 175 |
173 virtual ~BluetoothDevice(); | 176 virtual ~BluetoothDevice(); |
174 | 177 |
175 // Returns the Bluetooth class of the device, used by GetDeviceType() | 178 // Returns the Bluetooth class of the device, used by GetDeviceType() |
176 // and metrics logging, | 179 // and metrics logging, |
177 virtual uint32 GetBluetoothClass() const = 0; | 180 virtual uint32 GetBluetoothClass() const = 0; |
178 | 181 |
179 // Returns the Bluetooth of address the device. This should be used as | 182 // Returns the Bluetooth of address the device. This should be used as |
180 // a unique key to identify the device and copied where needed. | 183 // a unique key to identify the device and copied where needed. |
181 virtual std::string GetAddress() const = 0; | 184 virtual std::string GetAddress() const = 0; |
182 | 185 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 229 |
227 // Indicates whether there is a call to Connect() ongoing. For this attribute, | 230 // Indicates whether there is a call to Connect() ongoing. For this attribute, |
228 // we consider a call is ongoing if none of the callbacks passed to Connect() | 231 // we consider a call is ongoing if none of the callbacks passed to Connect() |
229 // were called after the corresponding call to Connect(). | 232 // were called after the corresponding call to Connect(). |
230 virtual bool IsConnecting() const = 0; | 233 virtual bool IsConnecting() const = 0; |
231 | 234 |
232 // Returns the set of UUIDs that this device supports. For classic Bluetooth | 235 // Returns the set of UUIDs that this device supports. For classic Bluetooth |
233 // devices this data is collected from both the EIR data and SDP tables, | 236 // devices this data is collected from both the EIR data and SDP tables, |
234 // for Low Energy devices this data is collected from AD and GATT primary | 237 // for Low Energy devices this data is collected from AD and GATT primary |
235 // services, for dual mode devices this may be collected from both./ | 238 // services, for dual mode devices this may be collected from both./ |
236 typedef std::vector<BluetoothUUID> UUIDList; | 239 // |
| 240 // All UUIDs are returned in the canonical 128-bit format. |
| 241 typedef std::vector<std::string> UUIDList; |
237 virtual UUIDList GetUUIDs() const = 0; | 242 virtual UUIDList GetUUIDs() const = 0; |
238 | 243 |
239 // The ErrorCallback is used for methods that can fail in which case it | 244 // The ErrorCallback is used for methods that can fail in which case it |
240 // is called, in the success case the callback is simply not called. | 245 // is called, in the success case the callback is simply not called. |
241 typedef base::Callback<void()> ErrorCallback; | 246 typedef base::Callback<void()> ErrorCallback; |
242 | 247 |
243 // The ConnectErrorCallback is used for methods that can fail with an error, | 248 // The ConnectErrorCallback is used for methods that can fail with an error, |
244 // passed back as an error code argument to this callback. | 249 // passed back as an error code argument to this callback. |
245 // In the success case this callback is not called. | 250 // In the success case this callback is not called. |
246 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; | 251 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // There is no callback for success because this object is often deleted | 326 // There is no callback for success because this object is often deleted |
322 // before that callback would be called. | 327 // before that callback would be called. |
323 virtual void Forget(const ErrorCallback& error_callback) = 0; | 328 virtual void Forget(const ErrorCallback& error_callback) = 0; |
324 | 329 |
325 // Attempts to open a socket to a service matching |uuid| on this device. If | 330 // Attempts to open a socket to a service matching |uuid| on this device. If |
326 // the connection is successful, |callback| is called with a BluetoothSocket. | 331 // the connection is successful, |callback| is called with a BluetoothSocket. |
327 // Otherwise |callback| is called with NULL. The socket is closed as soon as | 332 // Otherwise |callback| is called with NULL. The socket is closed as soon as |
328 // all references to the BluetoothSocket are released. Note that the | 333 // all references to the BluetoothSocket are released. Note that the |
329 // BluetoothSocket object can outlive both this BluetoothDevice and the | 334 // BluetoothSocket object can outlive both this BluetoothDevice and the |
330 // BluetoothAdapter for this device. | 335 // BluetoothAdapter for this device. |
331 virtual void ConnectToService(const BluetoothUUID& service_uuid, | 336 virtual void ConnectToService(const std::string& service_uuid, |
332 const SocketCallback& callback) = 0; | 337 const SocketCallback& callback) = 0; |
333 | 338 |
334 // Attempts to initiate an outgoing connection to this device for the profile | 339 // Attempts to initiate an outgoing connection to this device for the profile |
335 // identified by |profile|, on success the profile's connection callback | 340 // identified by |profile|, on success the profile's connection callback |
336 // will be called as well as |callback|; on failure |error_callback| will be | 341 // will be called as well as |callback|; on failure |error_callback| will be |
337 // called. | 342 // called. |
338 virtual void ConnectToProfile(BluetoothProfile* profile, | 343 virtual void ConnectToProfile(BluetoothProfile* profile, |
339 const base::Closure& callback, | 344 const base::Closure& callback, |
340 const ErrorCallback& error_callback) = 0; | 345 const ErrorCallback& error_callback) = 0; |
341 | 346 |
(...skipping 18 matching lines...) Expand all Loading... |
360 | 365 |
361 private: | 366 private: |
362 // Returns a localized string containing the device's bluetooth address and | 367 // Returns a localized string containing the device's bluetooth address and |
363 // a device type for display when |name_| is empty. | 368 // a device type for display when |name_| is empty. |
364 base::string16 GetAddressWithLocalizedDeviceTypeName() const; | 369 base::string16 GetAddressWithLocalizedDeviceTypeName() const; |
365 }; | 370 }; |
366 | 371 |
367 } // namespace device | 372 } // namespace device |
368 | 373 |
369 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 374 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
OLD | NEW |