bluetooth_discovery_manager_mac.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2014 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_DISCOVERY_MANAGER_MAC_H_
  5. #define DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_MANAGER_MAC_H_
  6. #include "base/memory/raw_ptr.h"
  7. @class IOBluetoothDevice;
  8. namespace device {
  9. // Class used by BluetoothAdapterMac to manage classic and LE device discovery.
  10. // For Bluetooth Classic, this class is responsible for keeping device inquiry
  11. // running if device discovery is initiated.
  12. class BluetoothDiscoveryManagerMac {
  13. public:
  14. // Interface for being notified of events during a device discovery session.
  15. class Observer {
  16. public:
  17. // Called when |this| manager has found a device through classic device
  18. // inquiry in the form of an IOBluetoothDevice.
  19. virtual void ClassicDeviceFound(IOBluetoothDevice* device) = 0;
  20. // Called when device discovery is no longer running, due to either a call
  21. // to BluetoothDiscoveryManagerMac::StopDiscovery or an unexpected reason,
  22. // such as when a user disables the controller, in which case the value of
  23. // |unexpected| will be true.
  24. virtual void ClassicDiscoveryStopped(bool unexpected) = 0;
  25. protected:
  26. virtual ~Observer() {}
  27. };
  28. BluetoothDiscoveryManagerMac(const BluetoothDiscoveryManagerMac&) = delete;
  29. BluetoothDiscoveryManagerMac& operator=(const BluetoothDiscoveryManagerMac&) =
  30. delete;
  31. virtual ~BluetoothDiscoveryManagerMac();
  32. // Returns true, if discovery is currently being performed.
  33. virtual bool IsDiscovering() const = 0;
  34. // Initiates a discovery session. Returns true on success or if discovery
  35. // is already running. Returns false on failure.
  36. virtual bool StartDiscovery() = 0;
  37. // Stops a discovery session. Returns true on success or if discovery is
  38. // already not running. Returns false on failure.
  39. virtual bool StopDiscovery() = 0;
  40. // Creates a discovery manager for Bluetooth Classic device discovery with
  41. // observer |observer|. Note that the life-time of |observer| should not
  42. // end before that of the returned BluetoothDiscoveryManager, as that may
  43. // lead to use after free errors.
  44. static BluetoothDiscoveryManagerMac* CreateClassic(Observer* observer);
  45. protected:
  46. explicit BluetoothDiscoveryManagerMac(Observer* observer);
  47. // Observer interested in notifications from us.
  48. raw_ptr<Observer> observer_;
  49. };
  50. } // namespace device
  51. #endif // DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_MANAGER_MAC_H_