Chromium Code Reviews| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 // Bluetooth Mojo host interface - Bluetooth Gatt Client functions | 188 // Bluetooth Mojo host interface - Bluetooth Gatt Client functions |
| 186 void StartLEScan() override; | 189 void StartLEScan() override; |
| 187 void StopLEScan() override; | 190 void StopLEScan() override; |
| 188 void ConnectLEDevice(mojom::BluetoothAddressPtr remote_addr) override; | 191 void ConnectLEDevice(mojom::BluetoothAddressPtr remote_addr) override; |
| 189 void DisconnectLEDevice(mojom::BluetoothAddressPtr remote_addr) override; | 192 void DisconnectLEDevice(mojom::BluetoothAddressPtr remote_addr) override; |
| 190 void StartLEListen(const StartLEListenCallback& callback) override; | 193 void StartLEListen(const StartLEListenCallback& callback) override; |
| 191 void StopLEListen(const StopLEListenCallback& callback) override; | 194 void StopLEListen(const StopLEListenCallback& callback) override; |
| 192 void SearchService(mojom::BluetoothAddressPtr remote_addr) override; | 195 void SearchService(mojom::BluetoothAddressPtr remote_addr) override; |
| 193 | 196 |
| 194 int ConvertGattIdentifierToId(const std::string identifier) const; | 197 int ConvertGattIdentifierToId(const std::string identifier) const; |
| 195 template <class T> | 198 template <class RemoteGattObjectT> |
|
rkc
2016/07/16 00:37:29
Gatt Objects are collectively called Attributes. W
rkc
2016/07/18 21:48:16
Unaddressed?
Please rename "GattObject" and simil
puthik_chromium
2016/07/18 22:45:23
Missed this comment.
Done
| |
| 196 mojom::BluetoothGattDBElementPtr CreateGattDBElement( | 199 mojom::BluetoothGattDBElementPtr CreateGattDBElement( |
| 197 const mojom::BluetoothGattDBAttributeType type, | 200 const mojom::BluetoothGattDBAttributeType type, |
| 198 const T* GattObject) const; | 201 const RemoteGattObjectT* GattObject) const; |
| 199 void GetGattDB(mojom::BluetoothAddressPtr remote_addr) override; | 202 void GetGattDB(mojom::BluetoothAddressPtr remote_addr) override; |
| 200 void ReadGattCharacteristic( | 203 void ReadGattCharacteristic( |
| 201 mojom::BluetoothAddressPtr remote_addr, | 204 mojom::BluetoothAddressPtr remote_addr, |
| 202 mojom::BluetoothGattServiceIDPtr service_id, | 205 mojom::BluetoothGattServiceIDPtr service_id, |
| 203 mojom::BluetoothGattIDPtr char_id, | 206 mojom::BluetoothGattIDPtr char_id, |
| 204 const ReadGattCharacteristicCallback& callback) override; | 207 const ReadGattCharacteristicCallback& callback) override; |
| 205 void WriteGattCharacteristic( | 208 void WriteGattCharacteristic( |
| 206 mojom::BluetoothAddressPtr remote_addr, | 209 mojom::BluetoothAddressPtr remote_addr, |
| 207 mojom::BluetoothGattServiceIDPtr service_id, | 210 mojom::BluetoothGattServiceIDPtr service_id, |
| 208 mojom::BluetoothGattIDPtr char_id, | 211 mojom::BluetoothGattIDPtr char_id, |
| (...skipping 97 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 |
| 348 void SendCachedDevicesFound() const; | 344 void SendCachedDevicesFound() const; |
| 349 bool HasBluetoothInstance() const; | 345 bool HasBluetoothInstance() const; |
| 350 bool CheckBluetoothInstanceVersion(uint32_t version_need) const; | 346 bool CheckBluetoothInstanceVersion(uint32_t version_need) const; |
| 351 | 347 |
| 352 template <class T> | 348 template <class RemoteGattObjectT> |
| 353 T* FindGattObjectFromUuid(const std::vector<T*> objs, | 349 RemoteGattObjectT* FindGattObjectFromUuid( |
| 354 const device::BluetoothUUID uuid) const; | 350 const std::vector<RemoteGattObjectT*> objs, |
| 351 const device::BluetoothUUID uuid) const; | |
| 355 device::BluetoothRemoteGattCharacteristic* FindGattCharacteristic( | 352 device::BluetoothRemoteGattCharacteristic* FindGattCharacteristic( |
| 356 mojom::BluetoothAddressPtr remote_addr, | 353 mojom::BluetoothAddressPtr remote_addr, |
| 357 mojom::BluetoothGattServiceIDPtr service_id, | 354 mojom::BluetoothGattServiceIDPtr service_id, |
| 358 mojom::BluetoothGattIDPtr char_id) const; | 355 mojom::BluetoothGattIDPtr char_id) const; |
| 359 | 356 |
| 360 device::BluetoothRemoteGattDescriptor* FindGattDescriptor( | 357 device::BluetoothRemoteGattDescriptor* FindGattDescriptor( |
| 361 mojom::BluetoothAddressPtr remote_addr, | 358 mojom::BluetoothAddressPtr remote_addr, |
| 362 mojom::BluetoothGattServiceIDPtr service_id, | 359 mojom::BluetoothGattServiceIDPtr service_id, |
| 363 mojom::BluetoothGattIDPtr char_id, | 360 mojom::BluetoothGattIDPtr char_id, |
| 364 mojom::BluetoothGattIDPtr desc_id) const; | 361 mojom::BluetoothGattIDPtr desc_id) const; |
| 365 | 362 |
| 366 // Propagates the list of paired device to Android. | 363 // Propagates the list of paired device to Android. |
| 367 void SendCachedPairedDevices() const; | 364 void SendCachedPairedDevices() const; |
| 368 | 365 |
| 366 template <class LocalGattObjectT> | |
| 367 int32_t CreateGattAttributeHandle(LocalGattObjectT* gatt_obj); | |
| 368 | |
| 369 mojo::Binding<mojom::BluetoothHost> binding_; | 369 mojo::Binding<mojom::BluetoothHost> binding_; |
| 370 | 370 |
| 371 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; | 371 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; |
| 372 scoped_refptr<device::BluetoothAdvertisement> advertisment_; | 372 scoped_refptr<device::BluetoothAdvertisement> advertisment_; |
| 373 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; | 373 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; |
| 374 std::map<std::string, std::unique_ptr<device::BluetoothGattNotifySession>> | 374 std::map<std::string, std::unique_ptr<device::BluetoothGattNotifySession>> |
| 375 notification_session_; | 375 notification_session_; |
| 376 // Map from android int handle to Chrome (BlueZ) string identifier. | |
| 377 std::map<int32_t, std::string> gatt_identifier_; | |
| 378 // Store last GattCharacteristic added to each GattService for GattServer. | |
| 379 std::map<int32_t, int32_t> last_characteristic_; | |
| 380 // Running number for handle to give to Android side. | |
| 381 int32_t gatt_server_obj_handle = 0; | |
| 376 | 382 |
| 377 // WeakPtrFactory to use for callbacks. | 383 // WeakPtrFactory to use for callbacks. |
| 378 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; | 384 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; |
| 379 | 385 |
| 380 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); | 386 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); |
| 381 }; | 387 }; |
| 382 | 388 |
| 383 } // namespace arc | 389 } // namespace arc |
| 384 | 390 |
| 385 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ | 391 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ |
| OLD | NEW |