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

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

Issue 2256003002: components/arc: implement multi advertising (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@plumb-incoming-connections
Patch Set: refactoring interface Created 4 years, 4 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 <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <unordered_map> 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_advertisement.h"
22 #include "device/bluetooth/bluetooth_device.h" 23 #include "device/bluetooth/bluetooth_device.h"
23 #include "device/bluetooth/bluetooth_discovery_session.h" 24 #include "device/bluetooth/bluetooth_discovery_session.h"
24 #include "device/bluetooth/bluetooth_local_gatt_service.h" 25 #include "device/bluetooth/bluetooth_local_gatt_service.h"
25 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" 26 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
26 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" 27 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
27 #include "device/bluetooth/bluetooth_remote_gatt_service.h" 28 #include "device/bluetooth/bluetooth_remote_gatt_service.h"
28 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" 29 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h"
29 #include "mojo/public/cpp/bindings/binding.h" 30 #include "mojo/public/cpp/bindings/binding.h"
30 31
31 namespace arc { 32 namespace arc {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // Delete a local service. 260 // Delete a local service.
260 void DeleteService(int32_t service_handle, 261 void DeleteService(int32_t service_handle,
261 const DeleteServiceCallback& callback) override; 262 const DeleteServiceCallback& callback) override;
262 // Send value indication to a remote device. 263 // Send value indication to a remote device.
263 void SendIndication(int32_t attribute_handle, 264 void SendIndication(int32_t attribute_handle,
264 mojom::BluetoothAddressPtr address, 265 mojom::BluetoothAddressPtr address,
265 bool confirm, 266 bool confirm,
266 mojo::Array<uint8_t> value, 267 mojo::Array<uint8_t> value,
267 const SendIndicationCallback& callback) override; 268 const SendIndicationCallback& callback) override;
268 269
270 // Set up or disable multiple advertising.
271 void ReserveAdvertisementHandle(
272 const ReserveAdvertisementHandleCallback& callback) override;
273 void BroadcastAdvertisement(
274 int32_t adv_handle,
275 mojom::BluetoothAdvertisementPtr advertisement,
276 const BroadcastAdvertisementCallback& callback) override;
277 void ReleaseAdvertisementHandle(
278 int32_t adv_handle,
279 const ReleaseAdvertisementHandleCallback& callback) override;
280
269 // Chrome observer callbacks 281 // Chrome observer callbacks
270 void OnPoweredOn( 282 void OnPoweredOn(
271 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; 283 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const;
272 void OnPoweredOff( 284 void OnPoweredOff(
273 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; 285 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const;
274 void OnPoweredError( 286 void OnPoweredError(
275 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; 287 const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const;
276 void OnDiscoveryStarted( 288 void OnDiscoveryStarted(
277 std::unique_ptr<device::BluetoothDiscoverySession> session); 289 std::unique_ptr<device::BluetoothDiscoverySession> session);
278 void OnDiscoveryStopped(); 290 void OnDiscoveryStopped();
(...skipping 26 matching lines...) Expand all
305 void OnStopLEListenError( 317 void OnStopLEListenError(
306 const StopLEListenCallback& callback, 318 const StopLEListenCallback& callback,
307 device::BluetoothAdvertisement::ErrorCode error_code); 319 device::BluetoothAdvertisement::ErrorCode error_code);
308 320
309 void OnGattNotifyStartDone( 321 void OnGattNotifyStartDone(
310 const RegisterForGattNotificationCallback& callback, 322 const RegisterForGattNotificationCallback& callback,
311 const std::string char_string_id, 323 const std::string char_string_id,
312 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); 324 std::unique_ptr<device::BluetoothGattNotifySession> notify_session);
313 325
314 private: 326 private:
327 // Structure to do bookkeeping for advertisements registered via
328 // multi advertisement across API calls.
329 struct AdvertisementInstance {
330 device::BluetoothAdvertisement::AdvertisementType adv_type;
331 scoped_refptr<device::BluetoothAdvertisement> advertisement;
332 };
333
315 mojo::Array<mojom::BluetoothPropertyPtr> GetDeviceProperties( 334 mojo::Array<mojom::BluetoothPropertyPtr> GetDeviceProperties(
316 mojom::BluetoothPropertyType type, 335 mojom::BluetoothPropertyType type,
317 device::BluetoothDevice* device) const; 336 device::BluetoothDevice* device) const;
318 mojo::Array<mojom::BluetoothPropertyPtr> GetAdapterProperties( 337 mojo::Array<mojom::BluetoothPropertyPtr> GetAdapterProperties(
319 mojom::BluetoothPropertyType type) const; 338 mojom::BluetoothPropertyType type) const;
320 mojo::Array<mojom::BluetoothAdvertisingDataPtr> GetAdvertisingData( 339 mojo::Array<mojom::BluetoothAdvertisingDataPtr> GetAdvertisingData(
321 device::BluetoothDevice* device) const; 340 device::BluetoothDevice* device) const;
322 341
323 void SendCachedDevicesFound() const; 342 void SendCachedDevicesFound() const;
324 bool HasBluetoothInstance() const; 343 bool HasBluetoothInstance() const;
(...skipping 28 matching lines...) Expand all
353 372
354 // Common code for OnCharacteristicWriteRequest and OnDescriptorWriteRequest 373 // Common code for OnCharacteristicWriteRequest and OnDescriptorWriteRequest
355 template <class LocalGattAttribute> 374 template <class LocalGattAttribute>
356 void OnGattAttributeWriteRequest(const device::BluetoothDevice* device, 375 void OnGattAttributeWriteRequest(const device::BluetoothDevice* device,
357 const LocalGattAttribute* attribute, 376 const LocalGattAttribute* attribute,
358 const std::vector<uint8_t>& value, 377 const std::vector<uint8_t>& value,
359 int offset, 378 int offset,
360 const base::Closure& success_callback, 379 const base::Closure& success_callback,
361 const ErrorCallback& error_callback); 380 const ErrorCallback& error_callback);
362 381
382 // Callbacks for managing advertisements registered from the instance.
383
384 // Called when we have an open slot in the advertisement map and want to
385 // register the advertisement given by |data| for handle |adv_handle|.
386 void OnReadyToRegisterAdvertisement(
387 const BroadcastAdvertisementCallback& callback,
388 int32_t adv_handle,
389 std::unique_ptr<device::BluetoothAdvertisement::Data> data);
390 // Called when we've successfully registered a new advertisement for
391 // handle |adv_handle|.
392 void OnRegisterAdvertisementDone(
393 const BroadcastAdvertisementCallback& callback,
394 int32_t adv_handle,
395 scoped_refptr<device::BluetoothAdvertisement> advertisement);
396 // Called when the attempt to register an advertisement for handle
397 // |adv_handle| has failed. |adv_handle| remains reserved, but no
398 // advertisement is associated with it.
399 void OnRegisterAdvertisementError(
400 const BroadcastAdvertisementCallback& callback,
401 int32_t adv_handle,
402 device::BluetoothAdvertisement::ErrorCode error_code);
403 // Both of the following are called after we've tried to unregister
404 // the advertisement for |adv_handle|. Either way, we will no
405 // longer be broadcasting this advertisement, so in either case, the
406 // handle can be released.
407 void OnUnregisterAdvertisementDone(
408 const ReleaseAdvertisementHandleCallback& callback,
409 int32_t adv_handle);
410 void OnUnregisterAdvertisementError(
411 const ReleaseAdvertisementHandleCallback& callback,
412 int32_t adv_handle,
413 device::BluetoothAdvertisement::ErrorCode error_code);
414 // Find the next free advertisement handle and put it in *adv_handle,
415 // or return false if the advertisement map is full.
416 bool GetAdvertisementHandle(int32_t* adv_handle);
417
363 bool CalledOnValidThread(); 418 bool CalledOnValidThread();
364 419
365 mojo::Binding<mojom::BluetoothHost> binding_; 420 mojo::Binding<mojom::BluetoothHost> binding_;
366 421
367 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_; 422 scoped_refptr<bluez::BluetoothAdapterBlueZ> bluetooth_adapter_;
368 scoped_refptr<device::BluetoothAdvertisement> advertisment_; 423 scoped_refptr<device::BluetoothAdvertisement> advertisment_;
369 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; 424 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_;
370 std::unordered_map<std::string, 425 std::unordered_map<std::string,
371 std::unique_ptr<device::BluetoothGattNotifySession>> 426 std::unique_ptr<device::BluetoothGattNotifySession>>
372 notification_session_; 427 notification_session_;
373 // Map from Android int handle to Chrome (BlueZ) string identifier. 428 // Map from Android int handle to Chrome (BlueZ) string identifier.
374 std::unordered_map<int32_t, std::string> gatt_identifier_; 429 std::unordered_map<int32_t, std::string> gatt_identifier_;
375 // Map from Chrome (BlueZ) string identifier to android int handle. 430 // Map from Chrome (BlueZ) string identifier to android int handle.
376 std::unordered_map<std::string, int32_t> gatt_handle_; 431 std::unordered_map<std::string, int32_t> gatt_handle_;
377 // Store last GattCharacteristic added to each GattService for GattServer. 432 // Store last GattCharacteristic added to each GattService for GattServer.
378 std::unordered_map<int32_t, int32_t> last_characteristic_; 433 std::unordered_map<int32_t, int32_t> last_characteristic_;
379 // Monotonically increasing value to use as handle to give to Android side. 434 // Monotonically increasing value to use as handle to give to Android side.
380 int32_t gatt_server_attribute_next_handle_ = 0; 435 int32_t gatt_server_attribute_next_handle_ = 0;
381 // Keeps track of all devices which initiated a GATT connection to us. 436 // Keeps track of all devices which initiated a GATT connection to us.
382 std::unordered_set<std::string> gatt_connection_cache_; 437 std::unordered_set<std::string> gatt_connection_cache_;
383 438
439 // Holds advertising data registered by the instance.
440 static constexpr uint16_t kMaxAdvertisements = 5;
441 std::map<int32_t, scoped_refptr<device::BluetoothAdvertisement>>
442 advertisements_;
443
384 base::ThreadChecker thread_checker_; 444 base::ThreadChecker thread_checker_;
385 445
386 // WeakPtrFactory to use for callbacks. 446 // WeakPtrFactory to use for callbacks.
387 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_; 447 base::WeakPtrFactory<ArcBluetoothBridge> weak_factory_;
388 448
389 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge); 449 DISALLOW_COPY_AND_ASSIGN(ArcBluetoothBridge);
390 }; 450 };
391 451
392 } // namespace arc 452 } // namespace arc
393 453
394 #endif // COMPONENTS_ARC_BLUETOOTH_ARC_BLUETOOTH_BRIDGE_H_ 454 #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