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 // Store callback functions for Gatt Server request read / write | |
| 44 template <class T> | |
|
rkc
2016/07/14 23:28:12
Use more descriptive template arguments. Here and
puthik_chromium
2016/07/15 21:49:59
Done.
| |
| 45 struct GattServerCallbacks { | |
| 46 GattServerCallbacks() = default; | |
| 47 GattServerCallbacks(const T& success_callback, | |
| 48 const ErrorCallback& error_callback) | |
| 49 : success_callback(success_callback), error_callback(error_callback) {} | |
| 50 T success_callback; | |
| 51 ErrorCallback error_callback; | |
| 52 }; | |
| 53 | |
| 43 using GattStatusCallback = base::Callback<void(mojom::BluetoothGattStatus)>; | 54 using GattStatusCallback = base::Callback<void(mojom::BluetoothGattStatus)>; |
| 44 using GattReadCallback = base::Callback<void(mojom::BluetoothGattValuePtr)>; | 55 using GattReadCallback = base::Callback<void(mojom::BluetoothGattValuePtr)>; |
| 56 using GattServerReadCallbacks = GattServerCallbacks<ValueCallback>; | |
| 57 using GattServerWriteCallbacks = GattServerCallbacks<base::Closure>; | |
| 45 | 58 |
| 46 explicit ArcBluetoothBridge(ArcBridgeService* bridge_service); | 59 explicit ArcBluetoothBridge(ArcBridgeService* bridge_service); |
| 47 ~ArcBluetoothBridge() override; | 60 ~ArcBluetoothBridge() override; |
| 48 | 61 |
| 49 // Overridden from | 62 // Overridden from |
| 50 // InstanceHolder<mojom::BluetoothInstance>::Observer: | 63 // InstanceHolder<mojom::BluetoothInstance>::Observer: |
| 51 void OnInstanceReady() override; | 64 void OnInstanceReady() override; |
| 52 | 65 |
| 53 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); | 66 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); |
| 54 | 67 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 device::BluetoothAdapter* adapter, | 127 device::BluetoothAdapter* adapter, |
| 115 device::BluetoothRemoteGattCharacteristic* characteristic, | 128 device::BluetoothRemoteGattCharacteristic* characteristic, |
| 116 const std::vector<uint8_t>& value) override; | 129 const std::vector<uint8_t>& value) override; |
| 117 | 130 |
| 118 void GattDescriptorValueChanged( | 131 void GattDescriptorValueChanged( |
| 119 device::BluetoothAdapter* adapter, | 132 device::BluetoothAdapter* adapter, |
| 120 device::BluetoothRemoteGattDescriptor* descriptor, | 133 device::BluetoothRemoteGattDescriptor* descriptor, |
| 121 const std::vector<uint8_t>& value) override; | 134 const std::vector<uint8_t>& value) override; |
| 122 | 135 |
| 123 // Overridden from device::BluetoothLocalGattService::Delegate | 136 // Overridden from device::BluetoothLocalGattService::Delegate |
| 137 template <class T> | |
| 138 void OnGattAttributeReadRequest(const device::BluetoothDevice* device, | |
| 139 const T* gatt_obj, | |
| 140 int offset, | |
| 141 const GattServerReadCallbacks& callbacks); | |
| 142 | |
| 143 template <class T> | |
| 144 void OnGattAttributeWriteRequest( | |
| 145 const device::BluetoothDevice* device, | |
| 146 const T* gatt_obj, | |
| 147 const std::vector<uint8_t>& value, | |
| 148 int offset, | |
| 149 const GattServerWriteCallbacks& callbacks) override; | |
| 150 | |
| 124 void OnCharacteristicReadRequest( | 151 void OnCharacteristicReadRequest( |
| 125 const device::BluetoothDevice* device, | 152 const device::BluetoothDevice* device, |
| 126 const device::BluetoothLocalGattCharacteristic* characteristic, | 153 const device::BluetoothLocalGattCharacteristic* characteristic, |
| 127 int offset, | 154 int offset, |
| 128 const ValueCallback& callback, | 155 const ValueCallback& callback, |
| 129 const ErrorCallback& error_callback) override; | 156 const ErrorCallback& error_callback) override; |
| 130 | 157 |
| 131 void OnCharacteristicWriteRequest( | 158 void OnCharacteristicWriteRequest( |
| 132 const device::BluetoothDevice* device, | 159 const device::BluetoothDevice* device, |
| 133 const device::BluetoothLocalGattCharacteristic* characteristic, | 160 const device::BluetoothLocalGattCharacteristic* characteristic, |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 mojom::BluetoothAddressPtr remote_addr, | 384 mojom::BluetoothAddressPtr remote_addr, |
| 358 mojom::BluetoothGattServiceIDPtr service_id, | 385 mojom::BluetoothGattServiceIDPtr service_id, |
| 359 mojom::BluetoothGattIDPtr char_id, | 386 mojom::BluetoothGattIDPtr char_id, |
| 360 mojom::BluetoothGattIDPtr desc_id) const; | 387 mojom::BluetoothGattIDPtr desc_id) const; |
| 361 | 388 |
| 362 // Propagates the list of paired device to Android. | 389 // Propagates the list of paired device to Android. |
| 363 void SendCachedPairedDevices() const; | 390 void SendCachedPairedDevices() const; |
| 364 | 391 |
| 365 template <class T> | 392 template <class T> |
| 366 int32_t CreateGattAttributeHandle(T* gatt_obj); | 393 int32_t CreateGattAttributeHandle(T* gatt_obj); |
| 394 int32_t CreateGattReadTransaction(const GattServerReadCallbacks& callbacks); | |
| 395 int32_t CreateGattWriteTransaction(const GattServerWriteCallbacks& callbacks); | |
| 367 | 396 |
| 368 mojo::Binding<mojom::BluetoothHost> binding_; | 397 mojo::Binding<mojom::BluetoothHost> binding_; |
| 369 | 398 |
| 370 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; | 399 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; |
| 371 scoped_refptr<device::BluetoothAdvertisement> advertisment_; | 400 scoped_refptr<device::BluetoothAdvertisement> advertisment_; |
| 372 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; | 401 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; |
| 373 std::map<std::string, std::unique_ptr<device::BluetoothGattNotifySession>> | 402 std::map<std::string, std::unique_ptr<device::BluetoothGattNotifySession>> |
| 374 notification_session_; | 403 notification_session_; |
| 375 // Map from android int handle to Chrome (BlueZ) string identifier. | 404 // Map from android int handle to Chrome (BlueZ) string identifier. |
| 376 std::map<int32_t, std::string> gatt_identifier_; | 405 std::map<int32_t, std::string> gatt_identifier_; |
| 377 // Store last GattCharacteristic added to each GattService for GattServer. | 406 // Store last GattCharacteristic added to each GattService for GattServer. |
| 378 std::map<int32_t, int32_t> last_characteristic_; | 407 std::map<int32_t, int32_t> last_characteristic_; |
| 379 // Running number for handle to give to Android side. | 408 // Running number for handle to give to Android side. |
| 380 int32_t gatt_server_obj_handle = 0; | 409 int32_t gatt_server_obj_handle = 0; |
| 410 std::map<int32_t, GattServerReadCallbacks> gatt_server_read_callbacks_; | |
| 411 std::map<int32_t, GattServerWriteCallbacks> gatt_server_write_callbacks_; | |
| 381 | 412 |
| 382 // WeakPtrFactory to use for callbacks. | 413 // WeakPtrFactory to use for callbacks. |
| 383 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; | 414 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; |
| 384 | 415 |
| 385 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); | 416 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); |
| 386 }; | 417 }; |
| 387 | 418 |
| 388 } // namespace arc | 419 } // namespace arc |
| 389 | 420 |
| 390 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ | 421 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ |
| OLD | NEW |