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/string16.h" | 16 #include "base/string16.h" |
16 #include "chromeos/dbus/bluetooth_agent_service_provider.h" | 17 #include "chromeos/dbus/bluetooth_agent_service_provider.h" |
17 #include "chromeos/dbus/bluetooth_device_client.h" | 18 #include "chromeos/dbus/bluetooth_device_client.h" |
18 #include "dbus/object_path.h" | 19 #include "dbus/object_path.h" |
19 | 20 |
20 namespace chromeos { | 21 namespace chromeos { |
21 | 22 |
22 class BluetoothAdapter; | 23 class BluetoothAdapter; |
24 class BluetoothSocket; | |
23 | 25 |
24 // The BluetoothDevice class represents a remote Bluetooth device, both | 26 // The BluetoothDevice class represents a remote Bluetooth device, both |
25 // its properties and capabilities as discovered by a local adapter and | 27 // its properties and capabilities as discovered by a local adapter and |
26 // actions that may be performed on the remove device such as pairing, | 28 // actions that may be performed on the remove device such as pairing, |
27 // connection and disconnection. | 29 // connection and disconnection. |
28 // | 30 // |
29 // The class is instantiated and managed by the BluetoothAdapter class | 31 // The class is instantiated and managed by the BluetoothAdapter class |
30 // and pointers should only be obtained from that class and not cached, | 32 // and pointers should only be obtained from that class and not cached, |
31 // instead use the address() method as a unique key for a device. | 33 // instead use the address() method as a unique key for a device. |
32 // | 34 // |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 // If the request fails, |error_callback| will be called. | 244 // If the request fails, |error_callback| will be called. |
243 void Disconnect(ErrorCallback error_callback); | 245 void Disconnect(ErrorCallback error_callback); |
244 | 246 |
245 // Disconnects the device, terminating the low-level ACL connection | 247 // Disconnects the device, terminating the low-level ACL connection |
246 // and any application connections using it, and then discards link keys | 248 // and any application connections using it, and then discards link keys |
247 // and other pairing information. The device object remainds valid until | 249 // and other pairing information. The device object remainds valid until |
248 // returing from the calling function, after which it should be assumed to | 250 // returing from the calling function, after which it should be assumed to |
249 // have been deleted. If the request fails, |error_callback| will be called. | 251 // have been deleted. If the request fails, |error_callback| will be called. |
250 void Forget(ErrorCallback error_callback); | 252 void Forget(ErrorCallback error_callback); |
251 | 253 |
254 // SocketCallback is used by ConnectToService to return a BluetoothSocket | |
255 // to the caller, or NULL if there was an error. The socket will remain open | |
256 // until the last reference to the returned BluetoothSocket is released. | |
257 typedef base::Callback<void(scoped_refptr<BluetoothSocket>)> SocketCallback; | |
258 | |
259 // Attempts to open a socket to a service matching |uuid| on this device. If | |
260 // the connection is successful, |callback| is called with a BluetoothSocket. | |
261 // Otherwise |callback| is called with NULL. The socket is closed as soon as | |
262 // all references to the BluetoothSocket are released. Note that the | |
263 // BluetoothSocket object can outlive both this BluetoothDevice and the | |
264 // BluetoothAdapter for this device. | |
265 void ConnectToService(const std::string& service_uuid, | |
266 SocketCallback callback); | |
267 | |
252 private: | 268 private: |
253 friend class BluetoothAdapter; | 269 friend class BluetoothAdapter; |
254 | 270 |
255 explicit BluetoothDevice(BluetoothAdapter* adapter); | 271 explicit BluetoothDevice(BluetoothAdapter* adapter); |
256 | 272 |
257 // Sets the dbus object path for the device to |object_path|, indicating | 273 // Sets the dbus object path for the device to |object_path|, indicating |
258 // that the device has gone from being discovered to paired or bonded. | 274 // that the device has gone from being discovered to paired or bonded. |
259 void SetObjectPath(const dbus::ObjectPath& object_path); | 275 void SetObjectPath(const dbus::ObjectPath& object_path); |
260 | 276 |
261 // Updates device information from the properties in |properties|, device | 277 // Updates device information from the properties in |properties|, device |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 // called with true if a service with name matching |name| is discovered, or | 336 // called with true if a service with name matching |name| is discovered, or |
321 // with false otherwise. The rest of the parameters are as documented for a | 337 // with false otherwise. The rest of the parameters are as documented for a |
322 // BluetoothDeviceClient::ServicesCallback. | 338 // BluetoothDeviceClient::ServicesCallback. |
323 void SearchServicesForNameCallback( | 339 void SearchServicesForNameCallback( |
324 const std::string& name, | 340 const std::string& name, |
325 ProvidesServiceCallback callback, | 341 ProvidesServiceCallback callback, |
326 const dbus::ObjectPath& object_path, | 342 const dbus::ObjectPath& object_path, |
327 const BluetoothDeviceClient::ServiceMap& service_map, | 343 const BluetoothDeviceClient::ServiceMap& service_map, |
328 bool success); | 344 bool success); |
329 | 345 |
346 // Opens a socket to this device on the provided |channel|. | |
347 scoped_refptr<BluetoothSocket> OpenSocket(const std::string& service_uuid, | |
348 uint8_t channel); | |
keybuk
2012/04/19 23:30:11
OpenSocket is gone now, right?
bryeung
2012/04/20 00:17:56
Oops! Good catch.
| |
349 | |
350 // Called by BluetoothDeviceClient when a call to DiscoverServices() that was | |
351 // initated from ConnectToService completes. The |callback| is called with | |
352 // true iff a connection was successfully established. The rest of the | |
353 // parameters are as documented for a BluetoothDeviceClient::ServicesCallback. | |
354 void ConnectToMatchingService( | |
355 const std::string& service_uuid, | |
356 SocketCallback callback, | |
357 const dbus::ObjectPath& object_path, | |
358 const BluetoothDeviceClient::ServiceMap& service_map, | |
359 bool success); | |
360 | |
330 // BluetoothDeviceClient::Observer override. | 361 // BluetoothDeviceClient::Observer override. |
331 // | 362 // |
332 // Called when the device with object path |object_path| is about | 363 // Called when the device with object path |object_path| is about |
333 // to be disconnected, giving a chance for application layers to | 364 // to be disconnected, giving a chance for application layers to |
334 // shut down cleanly. | 365 // shut down cleanly. |
335 virtual void DisconnectRequested( | 366 virtual void DisconnectRequested( |
336 const dbus::ObjectPath& object_path) OVERRIDE; | 367 const dbus::ObjectPath& object_path) OVERRIDE; |
337 | 368 |
338 // BluetoothAgentServiceProvider::Delegate override. | 369 // BluetoothAgentServiceProvider::Delegate override. |
339 // | 370 // |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 PinCodeCallback pincode_callback_; | 531 PinCodeCallback pincode_callback_; |
501 PasskeyCallback passkey_callback_; | 532 PasskeyCallback passkey_callback_; |
502 ConfirmationCallback confirmation_callback_; | 533 ConfirmationCallback confirmation_callback_; |
503 | 534 |
504 DISALLOW_COPY_AND_ASSIGN(BluetoothDevice); | 535 DISALLOW_COPY_AND_ASSIGN(BluetoothDevice); |
505 }; | 536 }; |
506 | 537 |
507 } // namespace chromeos | 538 } // namespace chromeos |
508 | 539 |
509 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 540 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
OLD | NEW |