| 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 CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "chromeos/dbus/bluetooth_agent_service_provider.h" | 17 #include "chromeos/dbus/bluetooth_agent_service_provider.h" |
| 18 #include "chromeos/dbus/bluetooth_device_client.h" | 18 #include "chromeos/dbus/bluetooth_device_client.h" |
| 19 #include "chromeos/dbus/bluetooth_out_of_band_client.h" |
| 19 #include "dbus/object_path.h" | 20 #include "dbus/object_path.h" |
| 20 | 21 |
| 21 namespace chromeos { | 22 namespace chromeos { |
| 22 | 23 |
| 23 class BluetoothAdapter; | 24 class BluetoothAdapter; |
| 24 class BluetoothSocket; | 25 class BluetoothSocket; |
| 25 | 26 |
| 26 // The BluetoothDevice class represents a remote Bluetooth device, both | 27 // The BluetoothDevice class represents a remote Bluetooth device, both |
| 27 // its properties and capabilities as discovered by a local adapter and | 28 // its properties and capabilities as discovered by a local adapter and |
| 28 // actions that may be performed on the remove device such as pairing, | 29 // actions that may be performed on the remove device such as pairing, |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // Indicates whether the device is currently pairing and expecting | 198 // Indicates whether the device is currently pairing and expecting |
| 198 // confirmation of a displayed passkey. | 199 // confirmation of a displayed passkey. |
| 199 bool ExpectingConfirmation() const { | 200 bool ExpectingConfirmation() const { |
| 200 return !confirmation_callback_.is_null(); | 201 return !confirmation_callback_.is_null(); |
| 201 } | 202 } |
| 202 | 203 |
| 203 // The ErrorCallback is used for methods that can fail in which case it | 204 // The ErrorCallback is used for methods that can fail in which case it |
| 204 // is called, in the success case the callback is simply not called. | 205 // is called, in the success case the callback is simply not called. |
| 205 typedef base::Callback<void()> ErrorCallback; | 206 typedef base::Callback<void()> ErrorCallback; |
| 206 | 207 |
| 208 // The VoidResultCallback is used for methods that do not return any data, to |
| 209 // indicate that the action requested is complete. |
| 210 typedef base::Callback<void()> VoidResultCallback; |
| 211 |
| 207 // Initiates a connection to the device, pairing first if necessary. | 212 // Initiates a connection to the device, pairing first if necessary. |
| 208 // | 213 // |
| 209 // Method calls will be made on the supplied object |pairing_delegate| | 214 // Method calls will be made on the supplied object |pairing_delegate| |
| 210 // to indicate what display, and in response should make method calls | 215 // to indicate what display, and in response should make method calls |
| 211 // back to the device object. Not all devices require user responses | 216 // back to the device object. Not all devices require user responses |
| 212 // during pairing, so it is normal for |pairing_delegate| to receive no | 217 // during pairing, so it is normal for |pairing_delegate| to receive no |
| 213 // calls. To explicitly force a low-security connection without bonding, | 218 // calls. To explicitly force a low-security connection without bonding, |
| 214 // pass NULL, though this is ignored if the device is already paired. | 219 // pass NULL, though this is ignored if the device is already paired. |
| 215 // | 220 // |
| 216 // If the request fails, |error_callback| will be called; otherwise, | 221 // If the request fails, |error_callback| will be called; otherwise, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 271 |
| 267 // Attempts to open a socket to a service matching |uuid| on this device. If | 272 // Attempts to open a socket to a service matching |uuid| on this device. If |
| 268 // the connection is successful, |callback| is called with a BluetoothSocket. | 273 // the connection is successful, |callback| is called with a BluetoothSocket. |
| 269 // Otherwise |callback| is called with NULL. The socket is closed as soon as | 274 // Otherwise |callback| is called with NULL. The socket is closed as soon as |
| 270 // all references to the BluetoothSocket are released. Note that the | 275 // all references to the BluetoothSocket are released. Note that the |
| 271 // BluetoothSocket object can outlive both this BluetoothDevice and the | 276 // BluetoothSocket object can outlive both this BluetoothDevice and the |
| 272 // BluetoothAdapter for this device. | 277 // BluetoothAdapter for this device. |
| 273 void ConnectToService(const std::string& service_uuid, | 278 void ConnectToService(const std::string& service_uuid, |
| 274 const SocketCallback& callback); | 279 const SocketCallback& callback); |
| 275 | 280 |
| 281 // Sets the Out Of Band pairing data for this device to |data|. Exactly one |
| 282 // of |callback| or |error_callback| will be run. |
| 283 virtual void SetOutOfBandPairingData( |
| 284 const chromeos::BluetoothOutOfBandPairingData& data, |
| 285 const base::Closure& callback, |
| 286 const ErrorCallback& error_callback); |
| 287 |
| 288 // Clears the Out Of Band pairing data for this device. Exactly one of |
| 289 // |callback| or |error_callback| will be run. |
| 290 virtual void ClearOutOfBandPairingData( |
| 291 const base::Closure& callback, |
| 292 const ErrorCallback& error_callback); |
| 293 |
| 276 private: | 294 private: |
| 277 friend class BluetoothAdapter; | 295 friend class BluetoothAdapter; |
| 278 friend class MockBluetoothDevice; | 296 friend class MockBluetoothDevice; |
| 279 | 297 |
| 280 explicit BluetoothDevice(BluetoothAdapter* adapter); | 298 explicit BluetoothDevice(BluetoothAdapter* adapter); |
| 281 | 299 |
| 282 // Sets the dbus object path for the device to |object_path|, indicating | 300 // Sets the dbus object path for the device to |object_path|, indicating |
| 283 // that the device has gone from being discovered to paired or bonded. | 301 // that the device has gone from being discovered to paired or bonded. |
| 284 void SetObjectPath(const dbus::ObjectPath& object_path); | 302 void SetObjectPath(const dbus::ObjectPath& object_path); |
| 285 | 303 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 // initated from ConnectToService completes. The |callback| is called with | 399 // initated from ConnectToService completes. The |callback| is called with |
| 382 // true iff a connection was successfully established. The rest of the | 400 // true iff a connection was successfully established. The rest of the |
| 383 // parameters are as documented for a BluetoothDeviceClient::ServicesCallback. | 401 // parameters are as documented for a BluetoothDeviceClient::ServicesCallback. |
| 384 void ConnectToMatchingService( | 402 void ConnectToMatchingService( |
| 385 const std::string& service_uuid, | 403 const std::string& service_uuid, |
| 386 const SocketCallback& callback, | 404 const SocketCallback& callback, |
| 387 const dbus::ObjectPath& object_path, | 405 const dbus::ObjectPath& object_path, |
| 388 const BluetoothDeviceClient::ServiceMap& service_map, | 406 const BluetoothDeviceClient::ServiceMap& service_map, |
| 389 bool success); | 407 bool success); |
| 390 | 408 |
| 409 // Called by BlueoothDeviceClient in response to the AddRemoteData and |
| 410 // RemoveRemoteData method calls. |
| 411 void OnRemoteDataCallback(const base::Closure& callback, |
| 412 const ErrorCallback& error_callback, |
| 413 bool success); |
| 414 |
| 391 // BluetoothDeviceClient::Observer override. | 415 // BluetoothDeviceClient::Observer override. |
| 392 // | 416 // |
| 393 // Called when the device with object path |object_path| is about | 417 // Called when the device with object path |object_path| is about |
| 394 // to be disconnected, giving a chance for application layers to | 418 // to be disconnected, giving a chance for application layers to |
| 395 // shut down cleanly. | 419 // shut down cleanly. |
| 396 virtual void DisconnectRequested( | 420 virtual void DisconnectRequested( |
| 397 const dbus::ObjectPath& object_path) OVERRIDE; | 421 const dbus::ObjectPath& object_path) OVERRIDE; |
| 398 | 422 |
| 399 // BluetoothAgentServiceProvider::Delegate override. | 423 // BluetoothAgentServiceProvider::Delegate override. |
| 400 // | 424 // |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 | 588 |
| 565 // Used to keep track of pending application connection requests. | 589 // Used to keep track of pending application connection requests. |
| 566 int connecting_applications_counter_; | 590 int connecting_applications_counter_; |
| 567 | 591 |
| 568 DISALLOW_COPY_AND_ASSIGN(BluetoothDevice); | 592 DISALLOW_COPY_AND_ASSIGN(BluetoothDevice); |
| 569 }; | 593 }; |
| 570 | 594 |
| 571 } // namespace chromeos | 595 } // namespace chromeos |
| 572 | 596 |
| 573 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 597 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
| OLD | NEW |