| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_ADAPTER_H_ | 5 #ifndef DEVICE_BLUETOOTH_ADAPTER_H_ |
| 6 #define DEVICE_BLUETOOTH_ADAPTER_H_ | 6 #define DEVICE_BLUETOOTH_ADAPTER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "device/bluetooth/bluetooth_adapter.h" | 12 #include "device/bluetooth/bluetooth_adapter.h" |
| 13 #include "device/bluetooth/bluetooth_gatt_connection.h" |
| 13 #include "device/bluetooth/public/interfaces/adapter.mojom.h" | 14 #include "device/bluetooth/public/interfaces/adapter.mojom.h" |
| 14 #include "device/bluetooth/public/interfaces/device.mojom.h" | 15 #include "device/bluetooth/public/interfaces/device.mojom.h" |
| 15 | 16 |
| 16 namespace bluetooth { | 17 namespace bluetooth { |
| 17 | 18 |
| 18 // Implementation of Mojo Adapter located in | 19 // Implementation of Mojo Adapter located in |
| 19 // device/bluetooth/public/interfaces/adapter.mojom. | 20 // device/bluetooth/public/interfaces/adapter.mojom. |
| 20 // It handles requests for Bluetooth adapter capabilities | 21 // It handles requests for Bluetooth adapter capabilities |
| 21 // and devices and uses the platform abstraction of device/bluetooth. | 22 // and devices and uses the platform abstraction of device/bluetooth. |
| 22 class Adapter : public mojom::Adapter, | 23 class Adapter : public mojom::Adapter, |
| 23 public device::BluetoothAdapter::Observer { | 24 public device::BluetoothAdapter::Observer { |
| 24 public: | 25 public: |
| 25 explicit Adapter(scoped_refptr<device::BluetoothAdapter> adapter); | 26 explicit Adapter(scoped_refptr<device::BluetoothAdapter> adapter); |
| 26 ~Adapter() override; | 27 ~Adapter() override; |
| 27 | 28 |
| 28 // mojom::Adapter overrides: | 29 // mojom::Adapter overrides: |
| 29 void GetInfo(const GetInfoCallback& callback) override; | 30 void GetInfo(const GetInfoCallback& callback) override; |
| 30 void GetDevice(const std::string& address, | 31 void ConnectToDevice(const std::string& address, |
| 31 const GetDeviceCallback& callback) override; | 32 const ConnectToDeviceCallback& callback) override; |
| 32 void GetDevices(const GetDevicesCallback& callback) override; | 33 void GetDevices(const GetDevicesCallback& callback) override; |
| 33 void SetClient(mojom::AdapterClientPtr client) override; | 34 void SetClient(mojom::AdapterClientPtr client) override; |
| 34 | 35 |
| 35 // device::BluetoothAdapter::Observer overrides: | 36 // device::BluetoothAdapter::Observer overrides: |
| 36 void DeviceAdded(device::BluetoothAdapter* adapter, | 37 void DeviceAdded(device::BluetoothAdapter* adapter, |
| 37 device::BluetoothDevice* device) override; | 38 device::BluetoothDevice* device) override; |
| 38 void DeviceRemoved(device::BluetoothAdapter* adapter, | 39 void DeviceRemoved(device::BluetoothAdapter* adapter, |
| 39 device::BluetoothDevice* device) override; | 40 device::BluetoothDevice* device) override; |
| 40 void DeviceChanged(device::BluetoothAdapter* adapter, | 41 void DeviceChanged(device::BluetoothAdapter* adapter, |
| 41 device::BluetoothDevice* device) override; | 42 device::BluetoothDevice* device) override; |
| 42 | 43 |
| 43 private: | 44 private: |
| 45 void OnGattConnected( |
| 46 const ConnectToDeviceCallback& callback, |
| 47 std::unique_ptr<device::BluetoothGattConnection> connection); |
| 48 |
| 49 void OnConnectError(const ConnectToDeviceCallback& callback, |
| 50 device::BluetoothDevice::ConnectErrorCode error_code); |
| 51 |
| 44 // The current Bluetooth adapter. | 52 // The current Bluetooth adapter. |
| 45 scoped_refptr<device::BluetoothAdapter> adapter_; | 53 scoped_refptr<device::BluetoothAdapter> adapter_; |
| 46 | 54 |
| 47 // The adapter client that listens to this service. | 55 // The adapter client that listens to this service. |
| 48 mojom::AdapterClientPtr client_; | 56 mojom::AdapterClientPtr client_; |
| 49 | 57 |
| 50 base::WeakPtrFactory<Adapter> weak_ptr_factory_; | 58 base::WeakPtrFactory<Adapter> weak_ptr_factory_; |
| 51 | 59 |
| 52 DISALLOW_COPY_AND_ASSIGN(Adapter); | 60 DISALLOW_COPY_AND_ASSIGN(Adapter); |
| 53 }; | 61 }; |
| 54 | 62 |
| 55 } // namespace bluetooth | 63 } // namespace bluetooth |
| 56 | 64 |
| 57 #endif // DEVICE_BLUETOOTH_ADAPTER_H_ | 65 #endif // DEVICE_BLUETOOTH_ADAPTER_H_ |
| OLD | NEW |