| 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> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 class ArcBridgeService; | 33 class ArcBridgeService; |
| 34 | 34 |
| 35 class ArcBluetoothBridge | 35 class ArcBluetoothBridge |
| 36 : public ArcService, | 36 : public ArcService, |
| 37 public InstanceHolder<mojom::BluetoothInstance>::Observer, | 37 public InstanceHolder<mojom::BluetoothInstance>::Observer, |
| 38 public device::BluetoothAdapter::Observer, | 38 public device::BluetoothAdapter::Observer, |
| 39 public device::BluetoothAdapterFactory::AdapterCallback, | 39 public device::BluetoothAdapterFactory::AdapterCallback, |
| 40 public device::BluetoothLocalGattService::Delegate, | 40 public device::BluetoothLocalGattService::Delegate, |
| 41 public mojom::BluetoothHost { | 41 public mojom::BluetoothHost { |
| 42 public: | 42 public: |
| 43 using GattStatusCallback = base::Callback<void(mojom::BluetoothGattStatus)>; |
| 44 using GattReadCallback = base::Callback<void(mojom::BluetoothGattValuePtr)>; |
| 45 |
| 43 explicit ArcBluetoothBridge(ArcBridgeService* bridge_service); | 46 explicit ArcBluetoothBridge(ArcBridgeService* bridge_service); |
| 44 ~ArcBluetoothBridge() override; | 47 ~ArcBluetoothBridge() override; |
| 45 | 48 |
| 46 // Overridden from | 49 // Overridden from |
| 47 // InstanceHolder<mojom::BluetoothInstance>::Observer: | 50 // InstanceHolder<mojom::BluetoothInstance>::Observer: |
| 48 void OnInstanceReady() override; | 51 void OnInstanceReady() override; |
| 49 | 52 |
| 50 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); | 53 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); |
| 51 | 54 |
| 52 // Overridden from device::BluetoothAdadpter::Observer | 55 // Overridden from device::BluetoothAdadpter::Observer |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 scoped_refptr<device::BluetoothAdvertisement> adv); | 309 scoped_refptr<device::BluetoothAdvertisement> adv); |
| 307 void OnStartLEListenError( | 310 void OnStartLEListenError( |
| 308 const StartLEListenCallback& callback, | 311 const StartLEListenCallback& callback, |
| 309 device::BluetoothAdvertisement::ErrorCode error_code); | 312 device::BluetoothAdvertisement::ErrorCode error_code); |
| 310 | 313 |
| 311 void OnStopLEListenDone(const StopLEListenCallback& callback); | 314 void OnStopLEListenDone(const StopLEListenCallback& callback); |
| 312 void OnStopLEListenError( | 315 void OnStopLEListenError( |
| 313 const StopLEListenCallback& callback, | 316 const StopLEListenCallback& callback, |
| 314 device::BluetoothAdvertisement::ErrorCode error_code); | 317 device::BluetoothAdvertisement::ErrorCode error_code); |
| 315 | 318 |
| 316 using GattReadCallback = base::Callback<void(mojom::BluetoothGattValuePtr)>; | 319 void OnGattOperationDone(const GattStatusCallback& callback) const; |
| 320 void OnGattOperationError( |
| 321 const GattStatusCallback& callback, |
| 322 device::BluetoothGattService::GattErrorCode error_code) const; |
| 323 |
| 317 void OnGattReadDone(const GattReadCallback& callback, | 324 void OnGattReadDone(const GattReadCallback& callback, |
| 318 const std::vector<uint8_t>& result) const; | 325 const std::vector<uint8_t>& result) const; |
| 319 void OnGattReadError( | 326 void OnGattReadError( |
| 320 const GattReadCallback& callback, | 327 const GattReadCallback& callback, |
| 321 device::BluetoothGattService::GattErrorCode error_code) const; | 328 device::BluetoothGattService::GattErrorCode error_code) const; |
| 322 | 329 |
| 323 using GattWriteCallback = base::Callback<void(mojom::BluetoothGattStatus)>; | |
| 324 void OnGattWriteDone(const GattWriteCallback& callback) const; | |
| 325 void OnGattWriteError( | |
| 326 const GattWriteCallback& callback, | |
| 327 device::BluetoothGattService::GattErrorCode error_code) const; | |
| 328 | |
| 329 void OnGattNotifyStartDone( | 330 void OnGattNotifyStartDone( |
| 330 const RegisterForGattNotificationCallback& callback, | 331 const RegisterForGattNotificationCallback& callback, |
| 331 const std::string char_string_id, | 332 const std::string char_string_id, |
| 332 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); | 333 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); |
| 333 void OnGattNotifyStartError( | |
| 334 const RegisterForGattNotificationCallback& callback, | |
| 335 device::BluetoothGattService::GattErrorCode error_code) const; | |
| 336 void OnGattNotifyStopDone( | |
| 337 const DeregisterForGattNotificationCallback& callback) const; | |
| 338 | 334 |
| 339 private: | 335 private: |
| 340 mojo::Array<mojom::BluetoothPropertyPtr> GetDeviceProperties( | 336 mojo::Array<mojom::BluetoothPropertyPtr> GetDeviceProperties( |
| 341 mojom::BluetoothPropertyType type, | 337 mojom::BluetoothPropertyType type, |
| 342 device::BluetoothDevice* device) const; | 338 device::BluetoothDevice* device) const; |
| 343 mojo::Array<mojom::BluetoothPropertyPtr> GetAdapterProperties( | 339 mojo::Array<mojom::BluetoothPropertyPtr> GetAdapterProperties( |
| 344 mojom::BluetoothPropertyType type) const; | 340 mojom::BluetoothPropertyType type) const; |
| 345 mojo::Array<mojom::BluetoothAdvertisingDataPtr> GetAdvertisingData( | 341 mojo::Array<mojom::BluetoothAdvertisingDataPtr> GetAdvertisingData( |
| 346 device::BluetoothDevice* device) const; | 342 device::BluetoothDevice* device) const; |
| 347 | 343 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 359 | 355 |
| 360 device::BluetoothRemoteGattDescriptor* FindGattDescriptor( | 356 device::BluetoothRemoteGattDescriptor* FindGattDescriptor( |
| 361 mojom::BluetoothAddressPtr remote_addr, | 357 mojom::BluetoothAddressPtr remote_addr, |
| 362 mojom::BluetoothGattServiceIDPtr service_id, | 358 mojom::BluetoothGattServiceIDPtr service_id, |
| 363 mojom::BluetoothGattIDPtr char_id, | 359 mojom::BluetoothGattIDPtr char_id, |
| 364 mojom::BluetoothGattIDPtr desc_id) const; | 360 mojom::BluetoothGattIDPtr desc_id) const; |
| 365 | 361 |
| 366 // Propagates the list of paired device to Android. | 362 // Propagates the list of paired device to Android. |
| 367 void SendCachedPairedDevices() const; | 363 void SendCachedPairedDevices() const; |
| 368 | 364 |
| 365 template <class T> |
| 366 int32_t CreateGattAttributeHandle(T* gatt_obj); |
| 367 |
| 369 mojo::Binding<mojom::BluetoothHost> binding_; | 368 mojo::Binding<mojom::BluetoothHost> binding_; |
| 370 | 369 |
| 371 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; | 370 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; |
| 372 scoped_refptr<device::BluetoothAdvertisement> advertisment_; | 371 scoped_refptr<device::BluetoothAdvertisement> advertisment_; |
| 373 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; | 372 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; |
| 374 std::map<std::string, std::unique_ptr<device::BluetoothGattNotifySession>> | 373 std::map<std::string, std::unique_ptr<device::BluetoothGattNotifySession>> |
| 375 notification_session_; | 374 notification_session_; |
| 375 // Map from android int handle to Chrome (BlueZ) string identifier. |
| 376 std::map<int32_t, std::string> gatt_identifier_; |
| 377 // Store last GattCharacteristic added to each GattService for GattServer. |
| 378 std::map<int32_t, int32_t> last_characteristic_; |
| 379 // Running number for handle to give to Android side. |
| 380 int32_t gatt_server_obj_handle = 0; |
| 376 | 381 |
| 377 // WeakPtrFactory to use for callbacks. | 382 // WeakPtrFactory to use for callbacks. |
| 378 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; | 383 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; |
| 379 | 384 |
| 380 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); | 385 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); |
| 381 }; | 386 }; |
| 382 | 387 |
| 383 } // namespace arc | 388 } // namespace arc |
| 384 | 389 |
| 385 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ | 390 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ |
| OLD | NEW |