| 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 COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ | 5 #ifndef COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ |
| 6 #define COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ | 6 #define COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "components/arc/arc_bridge_service.h" | 16 #include "components/arc/arc_bridge_service.h" |
| 17 #include "components/arc/arc_service.h" | 17 #include "components/arc/arc_service.h" |
| 18 #include "components/arc/common/bluetooth.mojom.h" | 18 #include "components/arc/common/bluetooth.mojom.h" |
| 19 #include "components/arc/instance_holder.h" | 19 #include "components/arc/instance_holder.h" |
| 20 #include "device/bluetooth/bluetooth_adapter.h" | 20 #include "device/bluetooth/bluetooth_adapter.h" |
| 21 #include "device/bluetooth/bluetooth_adapter_factory.h" | 21 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 22 #include "device/bluetooth/bluetooth_device.h" | 22 #include "device/bluetooth/bluetooth_device.h" |
| 23 #include "device/bluetooth/bluetooth_discovery_session.h" | 23 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 24 #include "device/bluetooth/bluetooth_local_gatt_service.h" |
| 24 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 25 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 25 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" | 26 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" |
| 26 #include "device/bluetooth/bluetooth_remote_gatt_service.h" | 27 #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
| 27 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" | 28 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" |
| 28 #include "mojo/public/cpp/bindings/binding.h" | 29 #include "mojo/public/cpp/bindings/binding.h" |
| 29 | 30 |
| 30 namespace arc { | 31 namespace arc { |
| 31 | 32 |
| 32 class ArcBridgeService; | 33 class ArcBridgeService; |
| 33 | 34 |
| 34 class ArcBluetoothBridge | 35 class ArcBluetoothBridge |
| 35 : public ArcService, | 36 : public ArcService, |
| 36 public InstanceHolder<mojom::BluetoothInstance>::Observer, | 37 public InstanceHolder<mojom::BluetoothInstance>::Observer, |
| 37 public device::BluetoothAdapter::Observer, | 38 public device::BluetoothAdapter::Observer, |
| 38 public device::BluetoothAdapterFactory::AdapterCallback, | 39 public device::BluetoothAdapterFactory::AdapterCallback, |
| 40 public device::BluetoothLocalGattService::Delegate, |
| 39 public mojom::BluetoothHost { | 41 public mojom::BluetoothHost { |
| 40 public: | 42 public: |
| 41 explicit ArcBluetoothBridge(ArcBridgeService* bridge_service); | 43 explicit ArcBluetoothBridge(ArcBridgeService* bridge_service); |
| 42 ~ArcBluetoothBridge() override; | 44 ~ArcBluetoothBridge() override; |
| 43 | 45 |
| 44 // Overridden from | 46 // Overridden from |
| 45 // InstanceHolder<mojom::BluetoothInstance>::Observer: | 47 // InstanceHolder<mojom::BluetoothInstance>::Observer: |
| 46 void OnInstanceReady() override; | 48 void OnInstanceReady() override; |
| 47 | 49 |
| 48 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); | 50 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 void GattCharacteristicValueChanged( | 110 void GattCharacteristicValueChanged( |
| 109 device::BluetoothAdapter* adapter, | 111 device::BluetoothAdapter* adapter, |
| 110 device::BluetoothRemoteGattCharacteristic* characteristic, | 112 device::BluetoothRemoteGattCharacteristic* characteristic, |
| 111 const std::vector<uint8_t>& value) override; | 113 const std::vector<uint8_t>& value) override; |
| 112 | 114 |
| 113 void GattDescriptorValueChanged( | 115 void GattDescriptorValueChanged( |
| 114 device::BluetoothAdapter* adapter, | 116 device::BluetoothAdapter* adapter, |
| 115 device::BluetoothRemoteGattDescriptor* descriptor, | 117 device::BluetoothRemoteGattDescriptor* descriptor, |
| 116 const std::vector<uint8_t>& value) override; | 118 const std::vector<uint8_t>& value) override; |
| 117 | 119 |
| 120 // Overridden from device::BluetoothLocalGattService::Delegate |
| 121 void OnCharacteristicReadRequest( |
| 122 const device::BluetoothDevice* device, |
| 123 const device::BluetoothLocalGattCharacteristic* characteristic, |
| 124 int offset, |
| 125 const ValueCallback& callback, |
| 126 const ErrorCallback& error_callback) override; |
| 127 |
| 128 void OnCharacteristicWriteRequest( |
| 129 const device::BluetoothDevice* device, |
| 130 const device::BluetoothLocalGattCharacteristic* characteristic, |
| 131 const std::vector<uint8_t>& value, |
| 132 int offset, |
| 133 const base::Closure& callback, |
| 134 const ErrorCallback& error_callback) override; |
| 135 |
| 136 void OnDescriptorReadRequest( |
| 137 const device::BluetoothDevice* device, |
| 138 const device::BluetoothLocalGattDescriptor* descriptor, |
| 139 int offset, |
| 140 const ValueCallback& callback, |
| 141 const ErrorCallback& error_callback) override; |
| 142 |
| 143 void OnDescriptorWriteRequest( |
| 144 const device::BluetoothDevice* device, |
| 145 const device::BluetoothLocalGattDescriptor* descriptor, |
| 146 const std::vector<uint8_t>& value, |
| 147 int offset, |
| 148 const base::Closure& callback, |
| 149 const ErrorCallback& error_callback) override; |
| 150 |
| 151 void OnNotificationsStart( |
| 152 const device::BluetoothDevice* device, |
| 153 const device::BluetoothLocalGattCharacteristic* characteristic) override; |
| 154 |
| 155 void OnNotificationsStop( |
| 156 const device::BluetoothDevice* device, |
| 157 const device::BluetoothLocalGattCharacteristic* characteristic) override; |
| 158 |
| 118 // Bluetooth Mojo host interface | 159 // Bluetooth Mojo host interface |
| 119 void EnableAdapter(const EnableAdapterCallback& callback) override; | 160 void EnableAdapter(const EnableAdapterCallback& callback) override; |
| 120 void DisableAdapter(const DisableAdapterCallback& callback) override; | 161 void DisableAdapter(const DisableAdapterCallback& callback) override; |
| 121 | 162 |
| 122 void GetAdapterProperty(mojom::BluetoothPropertyType type) override; | 163 void GetAdapterProperty(mojom::BluetoothPropertyType type) override; |
| 123 void SetAdapterProperty(mojom::BluetoothPropertyPtr property) override; | 164 void SetAdapterProperty(mojom::BluetoothPropertyPtr property) override; |
| 124 | 165 |
| 125 void GetRemoteDeviceProperty(mojom::BluetoothAddressPtr remote_addr, | 166 void GetRemoteDeviceProperty(mojom::BluetoothAddressPtr remote_addr, |
| 126 mojom::BluetoothPropertyType type) override; | 167 mojom::BluetoothPropertyType type) override; |
| 127 void SetRemoteDeviceProperty(mojom::BluetoothAddressPtr remote_addr, | 168 void SetRemoteDeviceProperty(mojom::BluetoothAddressPtr remote_addr, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 mojom::BluetoothAddressPtr remote_addr, | 229 mojom::BluetoothAddressPtr remote_addr, |
| 189 mojom::BluetoothGattServiceIDPtr service_id, | 230 mojom::BluetoothGattServiceIDPtr service_id, |
| 190 mojom::BluetoothGattIDPtr char_id, | 231 mojom::BluetoothGattIDPtr char_id, |
| 191 const DeregisterForGattNotificationCallback& callback) override; | 232 const DeregisterForGattNotificationCallback& callback) override; |
| 192 void ReadRemoteRssi(mojom::BluetoothAddressPtr remote_addr, | 233 void ReadRemoteRssi(mojom::BluetoothAddressPtr remote_addr, |
| 193 const ReadRemoteRssiCallback& callback) override; | 234 const ReadRemoteRssiCallback& callback) override; |
| 194 | 235 |
| 195 void OpenBluetoothSocket( | 236 void OpenBluetoothSocket( |
| 196 const OpenBluetoothSocketCallback& callback) override; | 237 const OpenBluetoothSocketCallback& callback) override; |
| 197 | 238 |
| 239 // Bluetooth Mojo host interface - Bluetooth Gatt Server functions |
| 240 // Android counterpart link: |
| 241 // https://source.android.com/devices/halref/bt__gatt__server_8h.html |
| 242 // Create a new service. Chrome will create an integer service handle based on |
| 243 // that BlueZ identifier that will pass back to Android in the callback. |
| 244 // num_handles: number of handle for characteristic / descriptor that will be |
| 245 // created in this service |
| 246 void AddService(mojom::BluetoothGattServiceIDPtr service_id, |
| 247 int32_t num_handles, |
| 248 const AddServiceCallback& callback) override; |
| 249 // Add a characteristic to a service and pass the characteristic handle back. |
| 250 void AddCharacteristic(int32_t service_handle, |
| 251 mojom::BluetoothUUIDPtr uuid, |
| 252 int32_t properties, |
| 253 int32_t permissions, |
| 254 const AddCharacteristicCallback& callback) override; |
| 255 // Add a descriptor to the last characteristic added to the given service |
| 256 // and pass the descriptor handle back. |
| 257 void AddDescriptor(int32_t service_handle, |
| 258 mojom::BluetoothUUIDPtr uuid, |
| 259 int32_t permissions, |
| 260 const AddDescriptorCallback& callback) override; |
| 261 // Start a local service. |
| 262 void StartService(int32_t service_handle, |
| 263 const StartServiceCallback& callback) override; |
| 264 // Stop a local service. |
| 265 void StopService(int32_t service_handle, |
| 266 const StopServiceCallback& callback) override; |
| 267 // Delete a local service. |
| 268 void DeleteService(int32_t service_handle, |
| 269 const DeleteServiceCallback& callback) override; |
| 270 // Send value indication to a remote device. |
| 271 void SendIndication(int32_t attribute_handle, |
| 272 mojom::BluetoothAddressPtr address, |
| 273 bool confirm, |
| 274 mojo::Array<uint8_t> value, |
| 275 const SendIndicationCallback& callback) override; |
| 276 |
| 198 // Chrome observer callbacks | 277 // Chrome observer callbacks |
| 199 void OnPoweredOn( | 278 void OnPoweredOn( |
| 200 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; | 279 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; |
| 201 void OnPoweredOff( | 280 void OnPoweredOff( |
| 202 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; | 281 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; |
| 203 void OnPoweredError( | 282 void OnPoweredError( |
| 204 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; | 283 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; |
| 205 void OnDiscoveryStarted( | 284 void OnDiscoveryStarted( |
| 206 std::unique_ptr<device::BluetoothDiscoverySession> session); | 285 std::unique_ptr<device::BluetoothDiscoverySession> session); |
| 207 void OnDiscoveryStopped(); | 286 void OnDiscoveryStopped(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 377 |
| 299 // WeakPtrFactory to use for callbacks. | 378 // WeakPtrFactory to use for callbacks. |
| 300 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; | 379 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; |
| 301 | 380 |
| 302 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); | 381 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); |
| 303 }; | 382 }; |
| 304 | 383 |
| 305 } // namespace arc | 384 } // namespace arc |
| 306 | 385 |
| 307 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ | 386 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ |
| OLD | NEW |