bluetooth_advertisement_mac.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADVERTISEMENT_MAC_H_
  5. #define DEVICE_BLUETOOTH_BLUETOOTH_ADVERTISEMENT_MAC_H_
  6. #include "base/memory/raw_ptr.h"
  7. #import <CoreBluetooth/CoreBluetooth.h>
  8. #include <memory>
  9. #include "dbus/object_path.h"
  10. #include "device/bluetooth/bluetooth_adapter.h"
  11. #include "device/bluetooth/bluetooth_advertisement.h"
  12. #include "device/bluetooth/bluetooth_export.h"
  13. namespace device {
  14. class BluetoothLowEnergyAdvertisementManagerMac;
  15. // Simple implementation of BluetoothAdvertisement for Mac. The primary logic is
  16. // currently handled in BluetoothLowEnergyAdvertisementManagerMac.
  17. class DEVICE_BLUETOOTH_EXPORT BluetoothAdvertisementMac
  18. : public BluetoothAdvertisement {
  19. public:
  20. enum Status {
  21. WAITING_FOR_ADAPTER,
  22. ADVERTISEMENT_PENDING,
  23. ADVERTISING,
  24. ERROR_ADVERTISING,
  25. UNREGISTERED,
  26. };
  27. BluetoothAdvertisementMac(
  28. std::unique_ptr<BluetoothAdvertisement::UUIDList> service_uuids,
  29. BluetoothAdapter::CreateAdvertisementCallback callback,
  30. BluetoothAdapter::AdvertisementErrorCallback error_callback,
  31. BluetoothLowEnergyAdvertisementManagerMac* advertisement_manager);
  32. BluetoothAdvertisementMac(const BluetoothAdvertisementMac&) = delete;
  33. BluetoothAdvertisementMac& operator=(const BluetoothAdvertisementMac&) =
  34. delete;
  35. // BluetoothAdvertisement overrides:
  36. void Unregister(SuccessCallback success_callback,
  37. ErrorCallback error_callback) override;
  38. Status status() const { return status_; }
  39. bool is_waiting_for_adapter() { return status_ == WAITING_FOR_ADAPTER; }
  40. bool is_advertising() { return status_ == ADVERTISING; }
  41. bool is_advertisement_pending() { return status_ == ADVERTISEMENT_PENDING; }
  42. BluetoothAdvertisement::UUIDList service_uuids() { return *service_uuids_; }
  43. private:
  44. friend class BluetoothLowEnergyAdvertisementManagerMac;
  45. ~BluetoothAdvertisementMac() override;
  46. // Called by BluetoothLowEnergyAdvertisementManagerMac.
  47. void OnAdvertisementPending();
  48. void OnAdvertisementError(base::SingleThreadTaskRunner* task_runner,
  49. BluetoothAdvertisement::ErrorCode error_code);
  50. void OnAdvertisementSuccess(base::SingleThreadTaskRunner* task_runner);
  51. void OnAdapterReset();
  52. void OnAdvertisementRestarted();
  53. void InvokeSuccessCallback();
  54. std::unique_ptr<BluetoothAdvertisement::UUIDList> service_uuids_;
  55. BluetoothAdapter::CreateAdvertisementCallback success_callback_;
  56. BluetoothAdapter::AdvertisementErrorCallback error_callback_;
  57. raw_ptr<BluetoothLowEnergyAdvertisementManagerMac> advertisement_manager_;
  58. Status status_;
  59. };
  60. } // namespace device
  61. #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADVERTISEMENT_MAC_H_