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