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

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

Issue 2104043002: arc: bluetooth: Implement Gatt Server add/delete/start/stop service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gs1
Patch Set: GattObjectT -> GattAttribute 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 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
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 RemoteGattAttribute>
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 RemoteGattAttribute* gatt_attr) 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
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 RemoteGattAttribute>
353 T* FindGattObjectFromUuid(const std::vector<T*> objs, 349 RemoteGattAttribute* FindGattAttributeFromUuid(
354 const device::BluetoothUUID uuid) const; 350 const std::vector<RemoteGattAttribute*> gatt_attrs,
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 LocalGattAttribute>
367 int32_t CreateGattAttributeHandle(LocalGattAttribute* gatt_attr);
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_;
Luis Héctor Chávez 2016/07/19 01:42:18 can these be std::unordered_map?
puthik_chromium 2016/07/19 22:21:30 Done.
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.
Luis Héctor Chávez 2016/07/19 01:42:18 How about "Monotonically increasing value to use a
puthik_chromium 2016/07/19 22:21:30 Done.
381 int32_t gatt_server_attr_handle = 0;
Luis Héctor Chávez 2016/07/19 01:42:18 gatt_server_attribute_next_handle_?
puthik_chromium 2016/07/19 22:21:30 Done.
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_
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