| 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 <memory> | 10 #include <memory> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 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 explicit ArcBluetoothBridge(ArcBridgeService* bridge_service); | 43 explicit ArcBluetoothBridge(ArcBridgeService* bridge_service); |
| 44 ~ArcBluetoothBridge() override; | 44 ~ArcBluetoothBridge() override; |
| 45 | 45 |
| 46 // Overridden from | 46 // Overridden from InstanceHolder<mojom::BluetoothInstance>::Observer: |
| 47 // InstanceHolder<mojom::BluetoothInstance>::Observer: | |
| 48 void OnInstanceReady() override; | 47 void OnInstanceReady() override; |
| 49 | 48 |
| 50 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); | 49 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); |
| 51 | 50 |
| 52 // Overridden from device::BluetoothAdadpter::Observer | 51 // Overridden from device::BluetoothAdadpter::Observer |
| 53 void AdapterPresentChanged(device::BluetoothAdapter* adapter, | 52 void AdapterPresentChanged(device::BluetoothAdapter* adapter, |
| 54 bool present) override; | 53 bool present) override; |
| 55 | 54 |
| 56 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, | 55 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, |
| 57 bool powered) override; | 56 bool powered) override; |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 mojom::BluetoothGattServiceIDPtr service_id, | 333 mojom::BluetoothGattServiceIDPtr service_id, |
| 335 mojom::BluetoothGattIDPtr char_id, | 334 mojom::BluetoothGattIDPtr char_id, |
| 336 mojom::BluetoothGattIDPtr desc_id) const; | 335 mojom::BluetoothGattIDPtr desc_id) const; |
| 337 | 336 |
| 338 // Propagates the list of paired device to Android. | 337 // Propagates the list of paired device to Android. |
| 339 void SendCachedPairedDevices() const; | 338 void SendCachedPairedDevices() const; |
| 340 | 339 |
| 341 template <class LocalGattAttribute> | 340 template <class LocalGattAttribute> |
| 342 int32_t CreateGattAttributeHandle(LocalGattAttribute* gatt_attr); | 341 int32_t CreateGattAttributeHandle(LocalGattAttribute* gatt_attr); |
| 343 | 342 |
| 343 // Common code for OnCharacteristicReadRequest and OnDescriptorReadRequest |
| 344 template <class LocalGattAttribute> |
| 345 void OnGattAttributeReadRequest(const device::BluetoothDevice* device, |
| 346 const LocalGattAttribute* gatt_attr, |
| 347 int offset, |
| 348 const ValueCallback& success_callback, |
| 349 const ErrorCallback& error_callback); |
| 350 |
| 351 // Common code for OnCharacteristicWriteRequest and OnDescriptorWriteRequest |
| 352 template <class LocalGattAttribute> |
| 353 void OnGattAttributeWriteRequest(const device::BluetoothDevice* device, |
| 354 const LocalGattAttribute* gatt_attr, |
| 355 const std::vector<uint8_t>& value, |
| 356 int offset, |
| 357 const base::Closure& success_callback, |
| 358 const ErrorCallback& error_callback); |
| 359 |
| 344 bool CalledOnValidThread(); | 360 bool CalledOnValidThread(); |
| 345 | 361 |
| 346 int32_t next_gatt_server_attribute_handle() { | 362 int32_t next_gatt_server_attribute_handle() { |
| 347 return ++gatt_server_attribute_next_handle; | 363 return ++gatt_server_attribute_next_handle; |
| 348 } | 364 } |
| 349 | 365 |
| 350 mojo::Binding<mojom::BluetoothHost> binding_; | 366 mojo::Binding<mojom::BluetoothHost> binding_; |
| 351 | 367 |
| 352 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; | 368 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; |
| 353 scoped_refptr<device::BluetoothAdvertisement> advertisment_; | 369 scoped_refptr<device::BluetoothAdvertisement> advertisment_; |
| 354 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; | 370 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; |
| 355 std::unordered_map<std::string, | 371 std::unordered_map<std::string, |
| 356 std::unique_ptr<device::BluetoothGattNotifySession>> | 372 std::unique_ptr<device::BluetoothGattNotifySession>> |
| 357 notification_session_; | 373 notification_session_; |
| 358 // Map from android int handle to Chrome (BlueZ) string identifier. | 374 // Map from android int handle to Chrome (BlueZ) string identifier. |
| 359 std::unordered_map<int32_t, std::string> gatt_identifier_; | 375 std::unordered_map<int32_t, std::string> gatt_identifier_; |
| 376 // Map from Chrome (BlueZ) string identifier to android int handle. |
| 377 std::unordered_map<std::string, int32_t> gatt_handle_; |
| 360 // Store last GattCharacteristic added to each GattService for GattServer. | 378 // Store last GattCharacteristic added to each GattService for GattServer. |
| 361 std::unordered_map<int32_t, int32_t> last_characteristic_; | 379 std::unordered_map<int32_t, int32_t> last_characteristic_; |
| 362 // Monotonically increasing value to use as handle to give to Android side. | 380 // Monotonically increasing value to use as handle to give to Android side. |
| 363 int32_t gatt_server_attribute_next_handle = 0; | 381 int32_t gatt_server_attribute_next_handle = 0; |
| 364 | 382 |
| 365 base::ThreadChecker thread_checker_; | 383 base::ThreadChecker thread_checker_; |
| 366 | 384 |
| 367 // WeakPtrFactory to use for callbacks. | 385 // WeakPtrFactory to use for callbacks. |
| 368 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; | 386 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; |
| 369 | 387 |
| 370 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); | 388 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); |
| 371 }; | 389 }; |
| 372 | 390 |
| 373 } // namespace arc | 391 } // namespace arc |
| 374 | 392 |
| 375 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ | 393 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ |
| OLD | NEW |