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 <map> | |
9 #include <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
13 #include "base/callback.h" | 14 #include "base/callback.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | |
15 #include "base/string16.h" | 17 #include "base/string16.h" |
16 #include "chrome/browser/chromeos/dbus/bluetooth_agent_service_provider.h" | 18 #include "chrome/browser/chromeos/dbus/bluetooth_agent_service_provider.h" |
17 #include "chrome/browser/chromeos/dbus/bluetooth_device_client.h" | 19 #include "chrome/browser/chromeos/dbus/bluetooth_device_client.h" |
18 #include "dbus/object_path.h" | 20 #include "dbus/object_path.h" |
19 | 21 |
20 namespace chromeos { | 22 namespace chromeos { |
21 | 23 |
22 class BluetoothAdapter; | 24 class BluetoothAdapter; |
25 class BluetoothSocket; | |
23 | 26 |
24 // The BluetoothDevice class represents a remote Bluetooth device, both | 27 // The BluetoothDevice class represents a remote Bluetooth device, both |
25 // its properties and capabilities as discovered by a local adapter and | 28 // its properties and capabilities as discovered by a local adapter and |
26 // 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, |
27 // connection and disconnection. | 30 // connection and disconnection. |
28 // | 31 // |
29 // The class is instantiated and managed by the BluetoothAdapter class | 32 // The class is instantiated and managed by the BluetoothAdapter class |
30 // and pointers should only be obtained from that class and not cached, | 33 // 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. | 34 // instead use the address() method as a unique key for a device. |
32 // | 35 // |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 // If the request fails, |error_callback| will be called. | 234 // If the request fails, |error_callback| will be called. |
232 void Disconnect(ErrorCallback error_callback); | 235 void Disconnect(ErrorCallback error_callback); |
233 | 236 |
234 // Disconnects the device, terminating the low-level ACL connection | 237 // Disconnects the device, terminating the low-level ACL connection |
235 // and any application connections using it, and then discards link keys | 238 // and any application connections using it, and then discards link keys |
236 // and other pairing information. The device object remainds valid until | 239 // and other pairing information. The device object remainds valid until |
237 // returing from the calling function, after which it should be assumed to | 240 // returing from the calling function, after which it should be assumed to |
238 // have been deleted. If the request fails, |error_callback| will be called. | 241 // have been deleted. If the request fails, |error_callback| will be called. |
239 void Forget(ErrorCallback error_callback); | 242 void Forget(ErrorCallback error_callback); |
240 | 243 |
244 // Opens a socket to this device for the given service. | |
245 base::WeakPtr<BluetoothSocket> OpenSocket(const std::string &service_uuid); | |
keybuk
2012/04/16 22:25:36
nit "& " not " &"
Should this be a weak ptr or a
| |
246 | |
247 // Close the socket with the given id. | |
248 void CloseSocket(int socket_id); | |
keybuk
2012/04/16 22:25:36
If BluetoothSocket were refcounted, we could encap
| |
249 | |
241 private: | 250 private: |
242 friend class BluetoothAdapter; | 251 friend class BluetoothAdapter; |
243 | 252 |
244 explicit BluetoothDevice(BluetoothAdapter* adapter); | 253 explicit BluetoothDevice(BluetoothAdapter* adapter); |
245 | 254 |
246 // Sets the dbus object path for the device to |object_path|, indicating | 255 // Sets the dbus object path for the device to |object_path|, indicating |
247 // that the device has gone from being discovered to paired or bonded. | 256 // that the device has gone from being discovered to paired or bonded. |
248 void SetObjectPath(const dbus::ObjectPath& object_path); | 257 void SetObjectPath(const dbus::ObjectPath& object_path); |
249 | 258 |
250 // Updates device information from the properties in |properties|, device | 259 // Updates device information from the properties in |properties|, device |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 const dbus::ObjectPath& object_path, | 435 const dbus::ObjectPath& object_path, |
427 const BluetoothDeviceClient::Properties* properties); | 436 const BluetoothDeviceClient::Properties* properties); |
428 | 437 |
429 // Creates a new BluetoothDevice object not bound to a dbus object path, | 438 // Creates a new BluetoothDevice object not bound to a dbus object path, |
430 // but bound to the adapter |adapter|, representing a discovered or unpaired | 439 // but bound to the adapter |adapter|, representing a discovered or unpaired |
431 // device, with initial properties set from |properties|. | 440 // device, with initial properties set from |properties|. |
432 static BluetoothDevice* CreateUnbound( | 441 static BluetoothDevice* CreateUnbound( |
433 BluetoothAdapter* adapter, | 442 BluetoothAdapter* adapter, |
434 const BluetoothDeviceClient::Properties* properties); | 443 const BluetoothDeviceClient::Properties* properties); |
435 | 444 |
445 // Close all open sockets from this device. | |
446 void CloseAllSockets(); | |
447 | |
436 // Weak pointer factory for generating 'this' pointers that might live longer | 448 // Weak pointer factory for generating 'this' pointers that might live longer |
437 // than we do. | 449 // than we do. |
438 base::WeakPtrFactory<BluetoothDevice> weak_ptr_factory_; | 450 base::WeakPtrFactory<BluetoothDevice> weak_ptr_factory_; |
439 | 451 |
440 // The adapter that owns this device instance. | 452 // The adapter that owns this device instance. |
441 BluetoothAdapter* adapter_; | 453 BluetoothAdapter* adapter_; |
442 | 454 |
443 // The dbus object path of the device, will be empty if the device has only | 455 // The dbus object path of the device, will be empty if the device has only |
444 // been discovered and not yet paired with. | 456 // been discovered and not yet paired with. |
445 dbus::ObjectPath object_path_; | 457 dbus::ObjectPath object_path_; |
(...skipping 25 matching lines...) Expand all Loading... | |
471 // intialized with our own class as its delegate. | 483 // intialized with our own class as its delegate. |
472 scoped_ptr<BluetoothAgentServiceProvider> agent_; | 484 scoped_ptr<BluetoothAgentServiceProvider> agent_; |
473 | 485 |
474 // During pairing these callbacks are set to those provided by method calls | 486 // During pairing these callbacks are set to those provided by method calls |
475 // made on us by |agent_| and are called by our own method calls such as | 487 // made on us by |agent_| and are called by our own method calls such as |
476 // SetPinCode() and SetPasskey(). | 488 // SetPinCode() and SetPasskey(). |
477 PinCodeCallback pincode_callback_; | 489 PinCodeCallback pincode_callback_; |
478 PasskeyCallback passkey_callback_; | 490 PasskeyCallback passkey_callback_; |
479 ConfirmationCallback confirmation_callback_; | 491 ConfirmationCallback confirmation_callback_; |
480 | 492 |
493 typedef std::map<int, BluetoothSocket*> SocketMap; | |
494 SocketMap socket_map_; | |
keybuk
2012/04/16 22:25:36
What's the int here? the fd?
| |
495 | |
481 DISALLOW_COPY_AND_ASSIGN(BluetoothDevice); | 496 DISALLOW_COPY_AND_ASSIGN(BluetoothDevice); |
482 }; | 497 }; |
483 | 498 |
484 } // namespace chromeos | 499 } // namespace chromeos |
485 | 500 |
486 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 501 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
OLD | NEW |