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