| 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> | |
| 11 #include <memory> | 10 #include <memory> |
| 12 #include <string> | 11 #include <string> |
| 12 #include <unordered_map> |
| 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" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 // Bluetooth Mojo host interface - Bluetooth Gatt Client functions | 185 // Bluetooth Mojo host interface - Bluetooth Gatt Client functions |
| 186 void StartLEScan() override; | 186 void StartLEScan() override; |
| 187 void StopLEScan() override; | 187 void StopLEScan() override; |
| 188 void ConnectLEDevice(mojom::BluetoothAddressPtr remote_addr) override; | 188 void ConnectLEDevice(mojom::BluetoothAddressPtr remote_addr) override; |
| 189 void DisconnectLEDevice(mojom::BluetoothAddressPtr remote_addr) override; | 189 void DisconnectLEDevice(mojom::BluetoothAddressPtr remote_addr) override; |
| 190 void StartLEListen(const StartLEListenCallback& callback) override; | 190 void StartLEListen(const StartLEListenCallback& callback) override; |
| 191 void StopLEListen(const StopLEListenCallback& callback) override; | 191 void StopLEListen(const StopLEListenCallback& callback) override; |
| 192 void SearchService(mojom::BluetoothAddressPtr remote_addr) override; | 192 void SearchService(mojom::BluetoothAddressPtr remote_addr) override; |
| 193 | 193 |
| 194 int ConvertGattIdentifierToId(const std::string identifier) const; | |
| 195 template <class T> | |
| 196 mojom::BluetoothGattDBElementPtr CreateGattDBElement( | |
| 197 const mojom::BluetoothGattDBAttributeType type, | |
| 198 const T* GattObject) const; | |
| 199 void GetGattDB(mojom::BluetoothAddressPtr remote_addr) override; | 194 void GetGattDB(mojom::BluetoothAddressPtr remote_addr) override; |
| 200 void ReadGattCharacteristic( | 195 void ReadGattCharacteristic( |
| 201 mojom::BluetoothAddressPtr remote_addr, | 196 mojom::BluetoothAddressPtr remote_addr, |
| 202 mojom::BluetoothGattServiceIDPtr service_id, | 197 mojom::BluetoothGattServiceIDPtr service_id, |
| 203 mojom::BluetoothGattIDPtr char_id, | 198 mojom::BluetoothGattIDPtr char_id, |
| 204 const ReadGattCharacteristicCallback& callback) override; | 199 const ReadGattCharacteristicCallback& callback) override; |
| 205 void WriteGattCharacteristic( | 200 void WriteGattCharacteristic( |
| 206 mojom::BluetoothAddressPtr remote_addr, | 201 mojom::BluetoothAddressPtr remote_addr, |
| 207 mojom::BluetoothGattServiceIDPtr service_id, | 202 mojom::BluetoothGattServiceIDPtr service_id, |
| 208 mojom::BluetoothGattIDPtr char_id, | 203 mojom::BluetoothGattIDPtr char_id, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 scoped_refptr<device::BluetoothAdvertisement> adv); | 299 scoped_refptr<device::BluetoothAdvertisement> adv); |
| 305 void OnStartLEListenError( | 300 void OnStartLEListenError( |
| 306 const StartLEListenCallback& callback, | 301 const StartLEListenCallback& callback, |
| 307 device::BluetoothAdvertisement::ErrorCode error_code); | 302 device::BluetoothAdvertisement::ErrorCode error_code); |
| 308 | 303 |
| 309 void OnStopLEListenDone(const StopLEListenCallback& callback); | 304 void OnStopLEListenDone(const StopLEListenCallback& callback); |
| 310 void OnStopLEListenError( | 305 void OnStopLEListenError( |
| 311 const StopLEListenCallback& callback, | 306 const StopLEListenCallback& callback, |
| 312 device::BluetoothAdvertisement::ErrorCode error_code); | 307 device::BluetoothAdvertisement::ErrorCode error_code); |
| 313 | 308 |
| 314 using GattReadCallback = base::Callback<void(mojom::BluetoothGattValuePtr)>; | |
| 315 void OnGattReadDone(const GattReadCallback& callback, | |
| 316 const std::vector<uint8_t>& result) const; | |
| 317 void OnGattReadError( | |
| 318 const GattReadCallback& callback, | |
| 319 device::BluetoothGattService::GattErrorCode error_code) const; | |
| 320 | |
| 321 using GattWriteCallback = base::Callback<void(mojom::BluetoothGattStatus)>; | |
| 322 void OnGattWriteDone(const GattWriteCallback& callback) const; | |
| 323 void OnGattWriteError( | |
| 324 const GattWriteCallback& callback, | |
| 325 device::BluetoothGattService::GattErrorCode error_code) const; | |
| 326 | |
| 327 void OnGattNotifyStartDone( | 309 void OnGattNotifyStartDone( |
| 328 const RegisterForGattNotificationCallback& callback, | 310 const RegisterForGattNotificationCallback& callback, |
| 329 const std::string char_string_id, | 311 const std::string char_string_id, |
| 330 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); | 312 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); |
| 331 void OnGattNotifyStartError( | |
| 332 const RegisterForGattNotificationCallback& callback, | |
| 333 device::BluetoothGattService::GattErrorCode error_code) const; | |
| 334 void OnGattNotifyStopDone( | |
| 335 const DeregisterForGattNotificationCallback& callback) const; | |
| 336 | 313 |
| 337 private: | 314 private: |
| 338 mojo::Array<mojom::BluetoothPropertyPtr> GetDeviceProperties( | 315 mojo::Array<mojom::BluetoothPropertyPtr> GetDeviceProperties( |
| 339 mojom::BluetoothPropertyType type, | 316 mojom::BluetoothPropertyType type, |
| 340 device::BluetoothDevice* device) const; | 317 device::BluetoothDevice* device) const; |
| 341 mojo::Array<mojom::BluetoothPropertyPtr> GetAdapterProperties( | 318 mojo::Array<mojom::BluetoothPropertyPtr> GetAdapterProperties( |
| 342 mojom::BluetoothPropertyType type) const; | 319 mojom::BluetoothPropertyType type) const; |
| 343 mojo::Array<mojom::BluetoothAdvertisingDataPtr> GetAdvertisingData( | 320 mojo::Array<mojom::BluetoothAdvertisingDataPtr> GetAdvertisingData( |
| 344 device::BluetoothDevice* device) const; | 321 device::BluetoothDevice* device) const; |
| 345 | 322 |
| 346 void SendCachedDevicesFound() const; | 323 void SendCachedDevicesFound() const; |
| 347 bool HasBluetoothInstance() const; | 324 bool HasBluetoothInstance() const; |
| 348 bool CheckBluetoothInstanceVersion(uint32_t version_need) const; | 325 bool CheckBluetoothInstanceVersion(uint32_t version_need) const; |
| 349 | 326 |
| 350 template <class T> | |
| 351 T* FindGattObjectFromUuid(const std::vector<T*> objs, | |
| 352 const device::BluetoothUUID uuid) const; | |
| 353 device::BluetoothRemoteGattCharacteristic* FindGattCharacteristic( | 327 device::BluetoothRemoteGattCharacteristic* FindGattCharacteristic( |
| 354 mojom::BluetoothAddressPtr remote_addr, | 328 mojom::BluetoothAddressPtr remote_addr, |
| 355 mojom::BluetoothGattServiceIDPtr service_id, | 329 mojom::BluetoothGattServiceIDPtr service_id, |
| 356 mojom::BluetoothGattIDPtr char_id) const; | 330 mojom::BluetoothGattIDPtr char_id) const; |
| 357 | 331 |
| 358 device::BluetoothRemoteGattDescriptor* FindGattDescriptor( | 332 device::BluetoothRemoteGattDescriptor* FindGattDescriptor( |
| 359 mojom::BluetoothAddressPtr remote_addr, | 333 mojom::BluetoothAddressPtr remote_addr, |
| 360 mojom::BluetoothGattServiceIDPtr service_id, | 334 mojom::BluetoothGattServiceIDPtr service_id, |
| 361 mojom::BluetoothGattIDPtr char_id, | 335 mojom::BluetoothGattIDPtr char_id, |
| 362 mojom::BluetoothGattIDPtr desc_id) const; | 336 mojom::BluetoothGattIDPtr desc_id) const; |
| 363 | 337 |
| 364 // Propagates the list of paired device to Android. | 338 // Propagates the list of paired device to Android. |
| 365 void SendCachedPairedDevices() const; | 339 void SendCachedPairedDevices() const; |
| 366 | 340 |
| 341 template <class LocalGattAttribute> |
| 342 int32_t CreateGattAttributeHandle(LocalGattAttribute* gatt_attr); |
| 343 |
| 344 bool CalledOnValidThread(); |
| 345 |
| 346 int32_t next_gatt_server_attribute_handle() { |
| 347 return ++gatt_server_attribute_next_handle; |
| 348 } |
| 349 |
| 367 mojo::Binding<mojom::BluetoothHost> binding_; | 350 mojo::Binding<mojom::BluetoothHost> binding_; |
| 368 | 351 |
| 369 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; | 352 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; |
| 370 scoped_refptr<device::BluetoothAdvertisement> advertisment_; | 353 scoped_refptr<device::BluetoothAdvertisement> advertisment_; |
| 371 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; | 354 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; |
| 372 std::map<std::string, std::unique_ptr<device::BluetoothGattNotifySession>> | 355 std::unordered_map<std::string, |
| 356 std::unique_ptr<device::BluetoothGattNotifySession>> |
| 373 notification_session_; | 357 notification_session_; |
| 358 // Map from android int handle to Chrome (BlueZ) string identifier. |
| 359 std::unordered_map<int32_t, std::string> gatt_identifier_; |
| 360 // Store last GattCharacteristic added to each GattService for GattServer. |
| 361 std::unordered_map<int32_t, int32_t> last_characteristic_; |
| 362 // Monotonically increasing value to use as handle to give to Android side. |
| 363 int32_t gatt_server_attribute_next_handle = 0; |
| 364 |
| 365 base::ThreadChecker thread_checker_; |
| 374 | 366 |
| 375 // WeakPtrFactory to use for callbacks. | 367 // WeakPtrFactory to use for callbacks. |
| 376 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; | 368 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; |
| 377 | 369 |
| 378 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); | 370 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); |
| 379 }; | 371 }; |
| 380 | 372 |
| 381 } // namespace arc | 373 } // namespace arc |
| 382 | 374 |
| 383 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ | 375 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ |
| OLD | NEW |