| 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_BLUEZ_BLUETOOTH_DEVICE_BLUEZ_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_DEVICE_BLUEZ_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_DEVICE_BLUEZ_H_ | 6 #define DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_DEVICE_BLUEZ_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
| 17 #include "dbus/object_path.h" | 17 #include "dbus/object_path.h" |
| 18 #include "device/bluetooth/bluetooth_common.h" | 18 #include "device/bluetooth/bluetooth_common.h" |
| 19 #include "device/bluetooth/bluetooth_device.h" | 19 #include "device/bluetooth/bluetooth_device.h" |
| 20 #include "device/bluetooth/bluetooth_export.h" | 20 #include "device/bluetooth/bluetooth_export.h" |
| 21 #include "device/bluetooth/bluez/bluetooth_service_record_bluez.h" |
| 21 #include "device/bluetooth/dbus/bluetooth_device_client.h" | 22 #include "device/bluetooth/dbus/bluetooth_device_client.h" |
| 22 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" | 23 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" |
| 23 | 24 |
| 24 namespace device { | 25 namespace device { |
| 25 class BluetoothSocketThread; | 26 class BluetoothSocketThread; |
| 26 } // namespace device | 27 } // namespace device |
| 27 | 28 |
| 28 namespace bluez { | 29 namespace bluez { |
| 29 | 30 |
| 30 class BluetoothAdapterBlueZ; | 31 class BluetoothAdapterBlueZ; |
| 31 class BluetoothPairingBlueZ; | 32 class BluetoothPairingBlueZ; |
| 32 class BluetoothServiceRecordBlueZ; | |
| 33 | 33 |
| 34 // The BluetoothDeviceBlueZ class implements BluetoothDevice for platforms using | 34 // The BluetoothDeviceBlueZ class implements BluetoothDevice for platforms using |
| 35 // BlueZ. | 35 // BlueZ. |
| 36 // | 36 // |
| 37 // This class is not thread-safe, but is only called from the UI thread. | 37 // This class is not thread-safe, but is only called from the UI thread. |
| 38 // | 38 // |
| 39 // A socket thread is used to create sockets but posts all callbacks on the UI | 39 // A socket thread is used to create sockets but posts all callbacks on the UI |
| 40 // thread. | 40 // thread. |
| 41 class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceBlueZ | 41 class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceBlueZ |
| 42 : public device::BluetoothDevice, | 42 : public device::BluetoothDevice, |
| 43 public bluez::BluetoothDeviceClient::Observer, | 43 public bluez::BluetoothDeviceClient::Observer, |
| 44 public bluez::BluetoothGattServiceClient::Observer { | 44 public bluez::BluetoothGattServiceClient::Observer { |
| 45 public: | 45 public: |
| 46 using GetServiceRecordsCallback = |
| 47 base::Callback<void(const std::vector<BluetoothServiceRecordBlueZ>&)>; |
| 48 using GetServiceRecordsErrorCallback = |
| 49 base::Callback<void(BluetoothServiceRecordBlueZ::ErrorCode)>; |
| 50 |
| 46 // BluetoothDevice override | 51 // BluetoothDevice override |
| 47 uint32_t GetBluetoothClass() const override; | 52 uint32_t GetBluetoothClass() const override; |
| 48 device::BluetoothTransport GetType() const override; | 53 device::BluetoothTransport GetType() const override; |
| 49 std::string GetAddress() const override; | 54 std::string GetAddress() const override; |
| 50 VendorIDSource GetVendorIDSource() const override; | 55 VendorIDSource GetVendorIDSource() const override; |
| 51 uint16_t GetVendorID() const override; | 56 uint16_t GetVendorID() const override; |
| 52 uint16_t GetProductID() const override; | 57 uint16_t GetProductID() const override; |
| 53 uint16_t GetDeviceID() const override; | 58 uint16_t GetDeviceID() const override; |
| 54 uint16_t GetAppearance() const override; | 59 uint16_t GetAppearance() const override; |
| 55 bool IsPaired() const override; | 60 bool IsPaired() const override; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 const ConnectErrorCallback& error_callback) override; | 94 const ConnectErrorCallback& error_callback) override; |
| 90 void SetGattServicesDiscoveryComplete(bool complete) override; | 95 void SetGattServicesDiscoveryComplete(bool complete) override; |
| 91 bool IsGattServicesDiscoveryComplete() const override; | 96 bool IsGattServicesDiscoveryComplete() const override; |
| 92 void Pair(device::BluetoothDevice::PairingDelegate* pairing_delegate, | 97 void Pair(device::BluetoothDevice::PairingDelegate* pairing_delegate, |
| 93 const base::Closure& callback, | 98 const base::Closure& callback, |
| 94 const ConnectErrorCallback& error_callback) override; | 99 const ConnectErrorCallback& error_callback) override; |
| 95 | 100 |
| 96 // Returns the complete list of service records discovered for on this | 101 // Returns the complete list of service records discovered for on this |
| 97 // device via SDP. If called before discovery is complete, it may return | 102 // device via SDP. If called before discovery is complete, it may return |
| 98 // an incomplete list and/or stale cached records. | 103 // an incomplete list and/or stale cached records. |
| 99 std::vector<BluetoothServiceRecordBlueZ*> GetServiceRecords(); | 104 void GetServiceRecords(const GetServiceRecordsCallback& callback, |
| 105 const GetServiceRecordsErrorCallback& error_callback); |
| 100 | 106 |
| 101 // Creates a pairing object with the given delegate |pairing_delegate| and | 107 // Creates a pairing object with the given delegate |pairing_delegate| and |
| 102 // establishes it as the pairing context for this device. All pairing-related | 108 // establishes it as the pairing context for this device. All pairing-related |
| 103 // method calls will be forwarded to this object until it is released. | 109 // method calls will be forwarded to this object until it is released. |
| 104 BluetoothPairingBlueZ* BeginPairing( | 110 BluetoothPairingBlueZ* BeginPairing( |
| 105 BluetoothDevice::PairingDelegate* pairing_delegate); | 111 BluetoothDevice::PairingDelegate* pairing_delegate); |
| 106 | 112 |
| 107 // Releases the current pairing object, any pairing-related method calls will | 113 // Releases the current pairing object, any pairing-related method calls will |
| 108 // be ignored. | 114 // be ignored. |
| 109 void EndPairing(); | 115 void EndPairing(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // Called by dbus:: on completion of the D-Bus method call to get the | 155 // Called by dbus:: on completion of the D-Bus method call to get the |
| 150 // connection attributes of the current connection to the device. | 156 // connection attributes of the current connection to the device. |
| 151 void OnGetConnInfo(const ConnectionInfoCallback& callback, | 157 void OnGetConnInfo(const ConnectionInfoCallback& callback, |
| 152 int16_t rssi, | 158 int16_t rssi, |
| 153 int16_t transmit_power, | 159 int16_t transmit_power, |
| 154 int16_t max_transmit_power); | 160 int16_t max_transmit_power); |
| 155 void OnGetConnInfoError(const ConnectionInfoCallback& callback, | 161 void OnGetConnInfoError(const ConnectionInfoCallback& callback, |
| 156 const std::string& error_name, | 162 const std::string& error_name, |
| 157 const std::string& error_message); | 163 const std::string& error_message); |
| 158 | 164 |
| 165 // Called by dbus:: in case of an error during the GetServiceRecords API call. |
| 166 void OnGetServiceRecordsError( |
| 167 const GetServiceRecordsErrorCallback& error_callback, |
| 168 const std::string& error_name, |
| 169 const std::string& error_message); |
| 170 |
| 159 // Internal method to initiate a connection to this device, and methods called | 171 // Internal method to initiate a connection to this device, and methods called |
| 160 // by dbus:: on completion of the D-Bus method call. | 172 // by dbus:: on completion of the D-Bus method call. |
| 161 void ConnectInternal(bool after_pairing, | 173 void ConnectInternal(bool after_pairing, |
| 162 const base::Closure& callback, | 174 const base::Closure& callback, |
| 163 const ConnectErrorCallback& error_callback); | 175 const ConnectErrorCallback& error_callback); |
| 164 void OnConnect(bool after_pairing, const base::Closure& callback); | 176 void OnConnect(bool after_pairing, const base::Closure& callback); |
| 165 void OnCreateGattConnection(const GattConnectionCallback& callback); | 177 void OnCreateGattConnection(const GattConnectionCallback& callback); |
| 166 void OnConnectError(bool after_pairing, | 178 void OnConnectError(bool after_pairing, |
| 167 const ConnectErrorCallback& error_callback, | 179 const ConnectErrorCallback& error_callback, |
| 168 const std::string& error_name, | 180 const std::string& error_name, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // Note: This should remain the last member so it'll be destroyed and | 251 // Note: This should remain the last member so it'll be destroyed and |
| 240 // invalidate its weak pointers before any other members are destroyed. | 252 // invalidate its weak pointers before any other members are destroyed. |
| 241 base::WeakPtrFactory<BluetoothDeviceBlueZ> weak_ptr_factory_; | 253 base::WeakPtrFactory<BluetoothDeviceBlueZ> weak_ptr_factory_; |
| 242 | 254 |
| 243 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceBlueZ); | 255 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceBlueZ); |
| 244 }; | 256 }; |
| 245 | 257 |
| 246 } // namespace bluez | 258 } // namespace bluez |
| 247 | 259 |
| 248 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_DEVICE_BLUEZ_H_ | 260 #endif // DEVICE_BLUETOOTH_BLUEZ_BLUETOOTH_DEVICE_BLUEZ_H_ |
| OLD | NEW |