| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 scoped_refptr<device::BluetoothAdvertisement> adv); | 302 scoped_refptr<device::BluetoothAdvertisement> adv); |
| 308 void OnStartLEListenError( | 303 void OnStartLEListenError( |
| 309 const StartLEListenCallback& callback, | 304 const StartLEListenCallback& callback, |
| 310 device::BluetoothAdvertisement::ErrorCode error_code); | 305 device::BluetoothAdvertisement::ErrorCode error_code); |
| 311 | 306 |
| 312 void OnStopLEListenDone(const StopLEListenCallback& callback); | 307 void OnStopLEListenDone(const StopLEListenCallback& callback); |
| 313 void OnStopLEListenError( | 308 void OnStopLEListenError( |
| 314 const StopLEListenCallback& callback, | 309 const StopLEListenCallback& callback, |
| 315 device::BluetoothAdvertisement::ErrorCode error_code); | 310 device::BluetoothAdvertisement::ErrorCode error_code); |
| 316 | 311 |
| 317 using GattReadCallback = base::Callback<void(mojom::BluetoothGattValuePtr)>; | |
| 318 void OnGattReadDone(const GattReadCallback& callback, | |
| 319 const std::vector<uint8_t>& result) const; | |
| 320 void OnGattReadError( | |
| 321 const GattReadCallback& callback, | |
| 322 device::BluetoothGattService::GattErrorCode error_code) const; | |
| 323 | |
| 324 using GattWriteCallback = base::Callback<void(mojom::BluetoothGattStatus)>; | |
| 325 void OnGattWriteDone(const GattWriteCallback& callback) const; | |
| 326 void OnGattWriteError( | |
| 327 const GattWriteCallback& callback, | |
| 328 device::BluetoothGattService::GattErrorCode error_code) const; | |
| 329 | |
| 330 void OnGattNotifyStartDone( | 312 void OnGattNotifyStartDone( |
| 331 const RegisterForGattNotificationCallback& callback, | 313 const RegisterForGattNotificationCallback& callback, |
| 332 const std::string char_string_id, | 314 const std::string char_string_id, |
| 333 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); | 315 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); |
| 334 void OnGattNotifyStartError( | |
| 335 const RegisterForGattNotificationCallback& callback, | |
| 336 device::BluetoothGattService::GattErrorCode error_code) const; | |
| 337 void OnGattNotifyStopDone( | |
| 338 const DeregisterForGattNotificationCallback& callback) const; | |
| 339 | 316 |
| 340 private: | 317 private: |
| 341 mojo::Array<mojom::BluetoothPropertyPtr> GetDeviceProperties( | 318 mojo::Array<mojom::BluetoothPropertyPtr> GetDeviceProperties( |
| 342 mojom::BluetoothPropertyType type, | 319 mojom::BluetoothPropertyType type, |
| 343 device::BluetoothDevice* device) const; | 320 device::BluetoothDevice* device) const; |
| 344 mojo::Array<mojom::BluetoothPropertyPtr> GetAdapterProperties( | 321 mojo::Array<mojom::BluetoothPropertyPtr> GetAdapterProperties( |
| 345 mojom::BluetoothPropertyType type) const; | 322 mojom::BluetoothPropertyType type) const; |
| 346 mojo::Array<mojom::BluetoothAdvertisingDataPtr> GetAdvertisingData( | 323 mojo::Array<mojom::BluetoothAdvertisingDataPtr> GetAdvertisingData( |
| 347 device::BluetoothDevice* device) const; | 324 device::BluetoothDevice* device) const; |
| 348 | 325 |
| 349 void SendCachedDevicesFound() const; | 326 void SendCachedDevicesFound() const; |
| 350 bool HasBluetoothInstance() const; | 327 bool HasBluetoothInstance() const; |
| 351 bool CheckBluetoothInstanceVersion(uint32_t version_need) const; | 328 bool CheckBluetoothInstanceVersion(uint32_t version_need) const; |
| 352 | 329 |
| 353 template <class T> | |
| 354 T* FindGattObjectFromUuid(const std::vector<T*> objs, | |
| 355 const device::BluetoothUUID uuid) const; | |
| 356 device::BluetoothRemoteGattCharacteristic* FindGattCharacteristic( | 330 device::BluetoothRemoteGattCharacteristic* FindGattCharacteristic( |
| 357 mojom::BluetoothAddressPtr remote_addr, | 331 mojom::BluetoothAddressPtr remote_addr, |
| 358 mojom::BluetoothGattServiceIDPtr service_id, | 332 mojom::BluetoothGattServiceIDPtr service_id, |
| 359 mojom::BluetoothGattIDPtr char_id) const; | 333 mojom::BluetoothGattIDPtr char_id) const; |
| 360 | 334 |
| 361 device::BluetoothRemoteGattDescriptor* FindGattDescriptor( | 335 device::BluetoothRemoteGattDescriptor* FindGattDescriptor( |
| 362 mojom::BluetoothAddressPtr remote_addr, | 336 mojom::BluetoothAddressPtr remote_addr, |
| 363 mojom::BluetoothGattServiceIDPtr service_id, | 337 mojom::BluetoothGattServiceIDPtr service_id, |
| 364 mojom::BluetoothGattIDPtr char_id, | 338 mojom::BluetoothGattIDPtr char_id, |
| 365 mojom::BluetoothGattIDPtr desc_id) const; | 339 mojom::BluetoothGattIDPtr desc_id) const; |
| 366 | 340 |
| 367 // Propagates the list of paired device to Android. | 341 // Propagates the list of paired device to Android. |
| 368 void SendCachedPairedDevices() const; | 342 void SendCachedPairedDevices() const; |
| 369 | 343 |
| 344 bool IsGattServerAttributeHandleAvailable(int need); |
| 345 int32_t GetNextGattServerAttributeHandle(); |
| 346 template <class LocalGattAttribute> |
| 347 int32_t CreateGattAttributeHandle(LocalGattAttribute* attribute); |
| 348 |
| 349 bool CalledOnValidThread(); |
| 350 |
| 370 mojo::Binding<mojom::BluetoothHost> binding_; | 351 mojo::Binding<mojom::BluetoothHost> binding_; |
| 371 | 352 |
| 372 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; | 353 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; |
| 373 scoped_refptr<device::BluetoothAdvertisement> advertisment_; | 354 scoped_refptr<device::BluetoothAdvertisement> advertisment_; |
| 374 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; | 355 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; |
| 375 std::map<std::string, std::unique_ptr<device::BluetoothGattNotifySession>> | 356 std::unordered_map<std::string, |
| 357 std::unique_ptr<device::BluetoothGattNotifySession>> |
| 376 notification_session_; | 358 notification_session_; |
| 359 // Map from Android int handle to Chrome (BlueZ) string identifier. |
| 360 std::unordered_map<int32_t, std::string> gatt_identifier_; |
| 361 // Store last GattCharacteristic added to each GattService for GattServer. |
| 362 std::unordered_map<int32_t, int32_t> last_characteristic_; |
| 363 // Monotonically increasing value to use as handle to give to Android side. |
| 364 int32_t gatt_server_attribute_next_handle_ = 0; |
| 365 |
| 366 base::ThreadChecker thread_checker_; |
| 377 | 367 |
| 378 // WeakPtrFactory to use for callbacks. | 368 // WeakPtrFactory to use for callbacks. |
| 379 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; | 369 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; |
| 380 | 370 |
| 381 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); | 371 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); |
| 382 }; | 372 }; |
| 383 | 373 |
| 384 } // namespace arc | 374 } // namespace arc |
| 385 | 375 |
| 386 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ | 376 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ |
| OLD | NEW |