OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CHROMEOS_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_BLUEZ_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_BLUEZ_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
14 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
15 #include "device/bluetooth/bluetooth_device.h" | 16 #include "device/bluetooth/bluetooth_device.h" |
16 #include "device/bluetooth/bluetooth_export.h" | 17 #include "device/bluetooth/bluetooth_export.h" |
17 #include "device/bluetooth/dbus/bluetooth_device_client.h" | 18 #include "device/bluetooth/dbus/bluetooth_device_client.h" |
18 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" | 19 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" |
19 | 20 |
20 namespace device { | 21 namespace device { |
21 class BluetoothSocketThread; | 22 class BluetoothSocketThread; |
22 } // namespace device | 23 } // namespace device |
23 | 24 |
24 namespace chromeos { | 25 namespace bluez { |
25 | 26 |
26 class BluetoothAdapterChromeOS; | 27 class BluetoothAdapterBlueZ; |
27 class BluetoothPairingChromeOS; | 28 class BluetoothPairingBlueZ; |
28 | 29 |
29 // The BluetoothDeviceChromeOS class implements BluetoothDevice for the | 30 // The BluetoothDeviceBlueZ class implements BluetoothDevice for the |
30 // Chrome OS platform. | 31 // Chrome OS platform. |
31 // | 32 // |
32 // This class is not thread-safe, but is only called from the UI thread. | 33 // This class is not thread-safe, but is only called from the UI thread. |
33 // | 34 // |
34 // A socket thread is used to create sockets but posts all callbacks on the UI | 35 // A socket thread is used to create sockets but posts all callbacks on the UI |
35 // thread. | 36 // thread. |
36 class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceChromeOS | 37 class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceBlueZ |
37 : public device::BluetoothDevice, | 38 : public device::BluetoothDevice, |
38 public bluez::BluetoothGattServiceClient::Observer { | 39 public bluez::BluetoothGattServiceClient::Observer { |
39 public: | 40 public: |
40 // BluetoothDevice override | 41 // BluetoothDevice override |
41 uint32 GetBluetoothClass() const override; | 42 uint32 GetBluetoothClass() const override; |
42 std::string GetAddress() const override; | 43 std::string GetAddress() const override; |
43 VendorIDSource GetVendorIDSource() const override; | 44 VendorIDSource GetVendorIDSource() const override; |
44 uint16 GetVendorID() const override; | 45 uint16 GetVendorID() const override; |
45 uint16 GetProductID() const override; | 46 uint16 GetProductID() const override; |
46 uint16 GetDeviceID() const override; | 47 uint16 GetDeviceID() const override; |
47 bool IsPaired() const override; | 48 bool IsPaired() const override; |
48 bool IsConnected() const override; | 49 bool IsConnected() const override; |
49 bool IsGattConnected() const override; | 50 bool IsGattConnected() const override; |
50 bool IsConnectable() const override; | 51 bool IsConnectable() const override; |
51 bool IsConnecting() const override; | 52 bool IsConnecting() const override; |
52 UUIDList GetUUIDs() const override; | 53 UUIDList GetUUIDs() const override; |
53 int16 GetInquiryRSSI() const override; | 54 int16 GetInquiryRSSI() const override; |
54 int16 GetInquiryTxPower() const override; | 55 int16 GetInquiryTxPower() const override; |
55 bool ExpectingPinCode() const override; | 56 bool ExpectingPinCode() const override; |
56 bool ExpectingPasskey() const override; | 57 bool ExpectingPasskey() const override; |
57 bool ExpectingConfirmation() const override; | 58 bool ExpectingConfirmation() const override; |
58 void GetConnectionInfo( | 59 void GetConnectionInfo(const ConnectionInfoCallback& callback) override; |
59 const ConnectionInfoCallback& callback) override; | |
60 void Connect(device::BluetoothDevice::PairingDelegate* pairing_delegate, | 60 void Connect(device::BluetoothDevice::PairingDelegate* pairing_delegate, |
61 const base::Closure& callback, | 61 const base::Closure& callback, |
62 const ConnectErrorCallback& error_callback) override; | 62 const ConnectErrorCallback& error_callback) override; |
63 void SetPinCode(const std::string& pincode) override; | 63 void SetPinCode(const std::string& pincode) override; |
64 void SetPasskey(uint32 passkey) override; | 64 void SetPasskey(uint32 passkey) override; |
65 void ConfirmPairing() override; | 65 void ConfirmPairing() override; |
66 void RejectPairing() override; | 66 void RejectPairing() override; |
67 void CancelPairing() override; | 67 void CancelPairing() override; |
68 void Disconnect(const base::Closure& callback, | 68 void Disconnect(const base::Closure& callback, |
69 const ErrorCallback& error_callback) override; | 69 const ErrorCallback& error_callback) override; |
70 void Forget(const ErrorCallback& error_callback) override; | 70 void Forget(const ErrorCallback& error_callback) override; |
71 void ConnectToService( | 71 void ConnectToService( |
72 const device::BluetoothUUID& uuid, | 72 const device::BluetoothUUID& uuid, |
73 const ConnectToServiceCallback& callback, | 73 const ConnectToServiceCallback& callback, |
74 const ConnectToServiceErrorCallback& error_callback) override; | 74 const ConnectToServiceErrorCallback& error_callback) override; |
75 void ConnectToServiceInsecurely( | 75 void ConnectToServiceInsecurely( |
76 const device::BluetoothUUID& uuid, | 76 const device::BluetoothUUID& uuid, |
77 const ConnectToServiceCallback& callback, | 77 const ConnectToServiceCallback& callback, |
78 const ConnectToServiceErrorCallback& error_callback) override; | 78 const ConnectToServiceErrorCallback& error_callback) override; |
79 void CreateGattConnection( | 79 void CreateGattConnection( |
80 const GattConnectionCallback& callback, | 80 const GattConnectionCallback& callback, |
81 const ConnectErrorCallback& error_callback) override; | 81 const ConnectErrorCallback& error_callback) override; |
82 void Pair(device::BluetoothDevice::PairingDelegate* pairing_delegate, | 82 void Pair(device::BluetoothDevice::PairingDelegate* pairing_delegate, |
83 const base::Closure& callback, | 83 const base::Closure& callback, |
84 const ConnectErrorCallback& error_callback) override; | 84 const ConnectErrorCallback& error_callback) override; |
85 | 85 |
86 // Creates a pairing object with the given delegate |pairing_delegate| and | 86 // Creates a pairing object with the given delegate |pairing_delegate| and |
87 // establishes it as the pairing context for this device. All pairing-related | 87 // establishes it as the pairing context for this device. All pairing-related |
88 // method calls will be forwarded to this object until it is released. | 88 // method calls will be forwarded to this object until it is released. |
89 BluetoothPairingChromeOS* BeginPairing( | 89 BluetoothPairingBlueZ* BeginPairing( |
90 BluetoothDevice::PairingDelegate* pairing_delegate); | 90 BluetoothDevice::PairingDelegate* pairing_delegate); |
91 | 91 |
92 // Releases the current pairing object, any pairing-related method calls will | 92 // Releases the current pairing object, any pairing-related method calls will |
93 // be ignored. | 93 // be ignored. |
94 void EndPairing(); | 94 void EndPairing(); |
95 | 95 |
96 // Returns the current pairing object or NULL if no pairing is in progress. | 96 // Returns the current pairing object or NULL if no pairing is in progress. |
97 BluetoothPairingChromeOS* GetPairing() const; | 97 BluetoothPairingBlueZ* GetPairing() const; |
98 | 98 |
99 // Returns the object path of the device. | 99 // Returns the object path of the device. |
100 const dbus::ObjectPath& object_path() const { return object_path_; } | 100 const dbus::ObjectPath& object_path() const { return object_path_; } |
101 | 101 |
102 // Returns the adapter which owns this device instance. | 102 // Returns the adapter which owns this device instance. |
103 BluetoothAdapterChromeOS* adapter() const; | 103 BluetoothAdapterBlueZ* adapter() const; |
104 | 104 |
105 protected: | 105 protected: |
106 // BluetoothDevice override | 106 // BluetoothDevice override |
107 std::string GetDeviceName() const override; | 107 std::string GetDeviceName() const override; |
108 void CreateGattConnectionImpl() override; | 108 void CreateGattConnectionImpl() override; |
109 void DisconnectGatt() override; | 109 void DisconnectGatt() override; |
110 | 110 |
111 private: | 111 private: |
112 friend class BluetoothAdapterChromeOS; | 112 friend class BluetoothAdapterBlueZ; |
113 | 113 |
114 BluetoothDeviceChromeOS( | 114 BluetoothDeviceBlueZ( |
115 BluetoothAdapterChromeOS* adapter, | 115 BluetoothAdapterBlueZ* adapter, |
116 const dbus::ObjectPath& object_path, | 116 const dbus::ObjectPath& object_path, |
117 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 117 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
118 scoped_refptr<device::BluetoothSocketThread> socket_thread); | 118 scoped_refptr<device::BluetoothSocketThread> socket_thread); |
119 ~BluetoothDeviceChromeOS() override; | 119 ~BluetoothDeviceBlueZ() override; |
120 | 120 |
121 // bluez::BluetoothGattServiceClient::Observer overrides. | 121 // bluez::BluetoothGattServiceClient::Observer overrides. |
122 void GattServiceAdded(const dbus::ObjectPath& object_path) override; | 122 void GattServiceAdded(const dbus::ObjectPath& object_path) override; |
123 void GattServiceRemoved(const dbus::ObjectPath& object_path) override; | 123 void GattServiceRemoved(const dbus::ObjectPath& object_path) override; |
124 | 124 |
125 // Called by dbus:: on completion of the D-Bus method call to get the | 125 // Called by dbus:: on completion of the D-Bus method call to get the |
126 // connection attributes of the current connection to the device. | 126 // connection attributes of the current connection to the device. |
127 void OnGetConnInfo(const ConnectionInfoCallback& callback, | 127 void OnGetConnInfo(const ConnectionInfoCallback& callback, |
128 int16 rssi, | 128 int16 rssi, |
129 int16 transmit_power, | 129 int16 transmit_power, |
130 int16 max_transmit_power); | 130 int16 max_transmit_power); |
131 void OnGetConnInfoError(const ConnectionInfoCallback& callback, | 131 void OnGetConnInfoError(const ConnectionInfoCallback& callback, |
132 const std::string& error_name, | 132 const std::string& error_name, |
133 const std::string& error_message); | 133 const std::string& error_message); |
134 | 134 |
135 // Internal method to initiate a connection to this device, and methods called | 135 // Internal method to initiate a connection to this device, and methods called |
136 // by dbus:: on completion of the D-Bus method call. | 136 // by dbus:: on completion of the D-Bus method call. |
137 void ConnectInternal(bool after_pairing, | 137 void ConnectInternal(bool after_pairing, |
138 const base::Closure& callback, | 138 const base::Closure& callback, |
139 const ConnectErrorCallback& error_callback); | 139 const ConnectErrorCallback& error_callback); |
140 void OnConnect(bool after_pairing, | 140 void OnConnect(bool after_pairing, const base::Closure& callback); |
141 const base::Closure& callback); | |
142 void OnCreateGattConnection(const GattConnectionCallback& callback); | 141 void OnCreateGattConnection(const GattConnectionCallback& callback); |
143 void OnConnectError(bool after_pairing, | 142 void OnConnectError(bool after_pairing, |
144 const ConnectErrorCallback& error_callback, | 143 const ConnectErrorCallback& error_callback, |
145 const std::string& error_name, | 144 const std::string& error_name, |
146 const std::string& error_message); | 145 const std::string& error_message); |
147 | 146 |
148 // Called by dbus:: on completion of the D-Bus method call to pair the device, | 147 // Called by dbus:: on completion of the D-Bus method call to pair the device, |
149 // made inside |Connect()|. | 148 // made inside |Connect()|. |
150 void OnPairDuringConnect(const base::Closure& callback, | 149 void OnPairDuringConnect(const base::Closure& callback, |
151 const ConnectErrorCallback& error_callback); | 150 const ConnectErrorCallback& error_callback); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // RSSI and TX power. | 196 // RSSI and TX power. |
198 bool connection_monitor_started_; | 197 bool connection_monitor_started_; |
199 | 198 |
200 // UI thread task runner and socket thread object used to create sockets. | 199 // UI thread task runner and socket thread object used to create sockets. |
201 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 200 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
202 scoped_refptr<device::BluetoothSocketThread> socket_thread_; | 201 scoped_refptr<device::BluetoothSocketThread> socket_thread_; |
203 | 202 |
204 // During pairing this is set to an object that we don't own, but on which | 203 // During pairing this is set to an object that we don't own, but on which |
205 // we can make method calls to request, display or confirm PIN Codes and | 204 // we can make method calls to request, display or confirm PIN Codes and |
206 // Passkeys. Generally it is the object that owns this one. | 205 // Passkeys. Generally it is the object that owns this one. |
207 scoped_ptr<BluetoothPairingChromeOS> pairing_; | 206 scoped_ptr<BluetoothPairingBlueZ> pairing_; |
208 | 207 |
209 // Note: This should remain the last member so it'll be destroyed and | 208 // Note: This should remain the last member so it'll be destroyed and |
210 // invalidate its weak pointers before any other members are destroyed. | 209 // invalidate its weak pointers before any other members are destroyed. |
211 base::WeakPtrFactory<BluetoothDeviceChromeOS> weak_ptr_factory_; | 210 base::WeakPtrFactory<BluetoothDeviceBlueZ> weak_ptr_factory_; |
212 | 211 |
213 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceChromeOS); | 212 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceBlueZ); |
214 }; | 213 }; |
215 | 214 |
216 } // namespace chromeos | 215 } // namespace bluez |
217 | 216 |
218 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_ | 217 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_BLUEZ_H_ |
OLD | NEW |