Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: components/arc/bluetooth/arc_bluetooth_bridge.h

Issue 2101283003: arc: bluetooth: Implement Gatt server request to read/write (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gs2
Patch Set: run error_callback if offset < 0 Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 SuccessCallback>
45 struct GattServerCallbacks {
46 GattServerCallbacks() = default;
47 GattServerCallbacks(const SuccessCallback& success_callback,
48 const ErrorCallback& error_callback)
49 : success_callback(success_callback), error_callback(error_callback) {}
50 SuccessCallback 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
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 LocalGattAttribute>
138 void OnGattAttributeReadRequest(const device::BluetoothDevice* device,
139 const LocalGattAttribute* gatt_attr,
140 int offset,
141 const GattServerReadCallbacks& callbacks);
Luis Héctor Chávez 2016/07/19 01:49:17 override?
puthik_chromium 2016/07/19 22:21:47 Function defined in wrong place. Fixed. On{Charact
142
143 template <class LocalGattAttribute>
144 void OnGattAttributeWriteRequest(
145 const device::BluetoothDevice* device,
146 const LocalGattAttribute* gatt_attr,
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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 mojom::BluetoothAddressPtr remote_addr, 385 mojom::BluetoothAddressPtr remote_addr,
359 mojom::BluetoothGattServiceIDPtr service_id, 386 mojom::BluetoothGattServiceIDPtr service_id,
360 mojom::BluetoothGattIDPtr char_id, 387 mojom::BluetoothGattIDPtr char_id,
361 mojom::BluetoothGattIDPtr desc_id) const; 388 mojom::BluetoothGattIDPtr desc_id) const;
362 389
363 // Propagates the list of paired device to Android. 390 // Propagates the list of paired device to Android.
364 void SendCachedPairedDevices() const; 391 void SendCachedPairedDevices() const;
365 392
366 template <class LocalGattAttribute> 393 template <class LocalGattAttribute>
367 int32_t CreateGattAttributeHandle(LocalGattAttribute* gatt_attr); 394 int32_t CreateGattAttributeHandle(LocalGattAttribute* gatt_attr);
395 int32_t CreateGattReadTransaction(const GattServerReadCallbacks& callbacks);
396 int32_t CreateGattWriteTransaction(const GattServerWriteCallbacks& callbacks);
368 397
369 mojo::Binding<mojom::BluetoothHost> binding_; 398 mojo::Binding<mojom::BluetoothHost> binding_;
370 399
371 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; 400 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_;
372 scoped_refptr<device::BluetoothAdvertisement> advertisment_; 401 scoped_refptr<device::BluetoothAdvertisement> advertisment_;
373 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; 402 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_;
374 std::map<std::string, std::unique_ptr<device::BluetoothGattNotifySession>> 403 std::map<std::string, std::unique_ptr<device::BluetoothGattNotifySession>>
375 notification_session_; 404 notification_session_;
376 // Map from android int handle to Chrome (BlueZ) string identifier. 405 // Map from android int handle to Chrome (BlueZ) string identifier.
377 std::map<int32_t, std::string> gatt_identifier_; 406 std::map<int32_t, std::string> gatt_identifier_;
407 // Map from Chrome (BlueZ) string identifier to android int handle.
408 std::map<std::string, int32_t> gatt_handle_;
Luis Héctor Chávez 2016/07/19 01:49:17 std::unordered_map?
puthik_chromium 2016/07/19 22:21:47 Done.
378 // Store last GattCharacteristic added to each GattService for GattServer. 409 // Store last GattCharacteristic added to each GattService for GattServer.
379 std::map<int32_t, int32_t> last_characteristic_; 410 std::map<int32_t, int32_t> last_characteristic_;
380 // Running number for handle to give to Android side. 411 // Running number for handle to give to Android side.
381 int32_t gatt_server_attr_handle = 0; 412 int32_t gatt_server_attr_handle = 0;
413 std::map<int32_t, GattServerReadCallbacks> gatt_server_read_callbacks_;
414 std::map<int32_t, GattServerWriteCallbacks> gatt_server_write_callbacks_;
382 415
383 // WeakPtrFactory to use for callbacks. 416 // WeakPtrFactory to use for callbacks.
384 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; 417 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_;
385 418
386 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); 419 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge);
387 }; 420 };
388 421
389 } // namespace arc 422 } // namespace arc
390 423
391 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ 424 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_
OLDNEW
« no previous file with comments | « no previous file | components/arc/bluetooth/arc_bluetooth_bridge.cc » ('j') | components/arc/bluetooth/arc_bluetooth_bridge.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698