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_DEVICE_H_ | 5 #ifndef DEVICE_BLUETOOTH_DEVICE_H_ |
6 #define DEVICE_BLUETOOTH_DEVICE_H_ | 6 #define DEVICE_BLUETOOTH_DEVICE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" |
14 #include "device/bluetooth/bluetooth_adapter.h" | 15 #include "device/bluetooth/bluetooth_adapter.h" |
15 #include "device/bluetooth/bluetooth_device.h" | 16 #include "device/bluetooth/bluetooth_device.h" |
16 #include "device/bluetooth/bluetooth_gatt_connection.h" | 17 #include "device/bluetooth/bluetooth_gatt_connection.h" |
17 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 18 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
18 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" | 19 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" |
19 #include "device/bluetooth/bluetooth_remote_gatt_service.h" | 20 #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
20 #include "device/bluetooth/public/interfaces/device.mojom.h" | 21 #include "device/bluetooth/public/interfaces/device.mojom.h" |
21 #include "mojo/public/cpp/bindings/strong_binding.h" | 22 #include "mojo/public/cpp/bindings/strong_binding.h" |
22 | 23 |
23 namespace bluetooth { | 24 namespace bluetooth { |
(...skipping 23 matching lines...) Expand all Loading... |
47 device::BluetoothDevice* device) override; | 48 device::BluetoothDevice* device) override; |
48 void GattServicesDiscovered(device::BluetoothAdapter* adapter, | 49 void GattServicesDiscovered(device::BluetoothAdapter* adapter, |
49 device::BluetoothDevice* device) override; | 50 device::BluetoothDevice* device) override; |
50 | 51 |
51 // mojom::Device overrides: | 52 // mojom::Device overrides: |
52 void Disconnect() override; | 53 void Disconnect() override; |
53 void GetInfo(const GetInfoCallback& callback) override; | 54 void GetInfo(const GetInfoCallback& callback) override; |
54 void GetServices(const GetServicesCallback& callback) override; | 55 void GetServices(const GetServicesCallback& callback) override; |
55 void GetCharacteristics(const std::string& service_id, | 56 void GetCharacteristics(const std::string& service_id, |
56 const GetCharacteristicsCallback& callback) override; | 57 const GetCharacteristicsCallback& callback) override; |
| 58 void ReadValueForCharacteristic( |
| 59 const std::string& service_id, |
| 60 const std::string& characteristic_id, |
| 61 const ReadValueForCharacteristicCallback& callback) override; |
| 62 void WriteValueForCharacteristic( |
| 63 const std::string& service_id, |
| 64 const std::string& characteristic_id, |
| 65 const std::vector<uint8_t>& value, |
| 66 const WriteValueForCharacteristicCallback& callback) override; |
57 void GetDescriptors(const std::string& service_id, | 67 void GetDescriptors(const std::string& service_id, |
58 const std::string& characteristic_id, | 68 const std::string& characteristic_id, |
59 const GetDescriptorsCallback& callback) override; | 69 const GetDescriptorsCallback& callback) override; |
60 | 70 |
61 private: | 71 private: |
62 Device(scoped_refptr<device::BluetoothAdapter> adapter, | 72 Device(scoped_refptr<device::BluetoothAdapter> adapter, |
63 std::unique_ptr<device::BluetoothGattConnection> connection); | 73 std::unique_ptr<device::BluetoothGattConnection> connection); |
64 | 74 |
65 void GetServicesImpl(const GetServicesCallback& callback); | 75 void GetServicesImpl(const GetServicesCallback& callback); |
66 | 76 |
67 mojom::ServiceInfoPtr ConstructServiceInfoStruct( | 77 mojom::ServiceInfoPtr ConstructServiceInfoStruct( |
68 const device::BluetoothRemoteGattService& service); | 78 const device::BluetoothRemoteGattService& service); |
69 | 79 |
| 80 void OnReadRemoteCharacteristic( |
| 81 const ReadValueForCharacteristicCallback& callback, |
| 82 const std::vector<uint8_t>& value); |
| 83 |
| 84 void OnReadRemoteCharacteristicError( |
| 85 const ReadValueForCharacteristicCallback& callback, |
| 86 device::BluetoothGattService::GattErrorCode error_code); |
| 87 |
| 88 void OnWriteRemoteCharacteristic( |
| 89 const WriteValueForCharacteristicCallback& callback); |
| 90 |
| 91 void OnWriteRemoteCharacteristicError( |
| 92 const WriteValueForCharacteristicCallback& callback, |
| 93 device::BluetoothGattService::GattErrorCode error_code); |
| 94 |
70 const std::string& GetAddress(); | 95 const std::string& GetAddress(); |
71 | 96 |
72 // The current BluetoothAdapter. | 97 // The current BluetoothAdapter. |
73 scoped_refptr<device::BluetoothAdapter> adapter_; | 98 scoped_refptr<device::BluetoothAdapter> adapter_; |
74 | 99 |
75 // The GATT connection to this device. | 100 // The GATT connection to this device. |
76 std::unique_ptr<device::BluetoothGattConnection> connection_; | 101 std::unique_ptr<device::BluetoothGattConnection> connection_; |
77 | 102 |
78 mojo::StrongBindingPtr<mojom::Device> binding_; | 103 mojo::StrongBindingPtr<mojom::Device> binding_; |
79 | 104 |
80 // The services request queue which holds callbacks that are waiting for | 105 // The services request queue which holds callbacks that are waiting for |
81 // services to be discovered for this device. | 106 // services to be discovered for this device. |
82 std::vector<base::Closure> pending_services_requests_; | 107 std::vector<base::Closure> pending_services_requests_; |
83 | 108 |
| 109 base::WeakPtrFactory<Device> weak_ptr_factory_; |
| 110 |
84 DISALLOW_COPY_AND_ASSIGN(Device); | 111 DISALLOW_COPY_AND_ASSIGN(Device); |
85 }; | 112 }; |
86 | 113 |
87 } // namespace bluetooth | 114 } // namespace bluetooth |
88 | 115 |
89 #endif // DEVICE_BLUETOOTH_DEVICE_H_ | 116 #endif // DEVICE_BLUETOOTH_DEVICE_H_ |
OLD | NEW |