bluetooth_advertisement_monitor_service_provider.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2021 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_DBUS_BLUETOOTH_ADVERTISEMENT_MONITOR_SERVICE_PROVIDER_H_
  5. #define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_ADVERTISEMENT_MONITOR_SERVICE_PROVIDER_H_
  6. #include "base/memory/weak_ptr.h"
  7. #include "dbus/bus.h"
  8. #include "dbus/message.h"
  9. #include "dbus/object_path.h"
  10. #include "device/bluetooth/bluetooth_export.h"
  11. #include "device/bluetooth/bluetooth_low_energy_scan_filter.h"
  12. namespace bluez {
  13. // BluetoothAdvertisementMonitorServiceProvider is used to provide a D-Bus
  14. // object that the Bluetooth daemon can communicate with to register
  15. // Advertisement Monitor service hierarchies.
  16. class DEVICE_BLUETOOTH_EXPORT BluetoothAdvertisementMonitorServiceProvider {
  17. public:
  18. // Interface for reacting to BluetoothAdvertisementMonitorServiceProvider
  19. // events.
  20. class Delegate {
  21. public:
  22. virtual ~Delegate() = default;
  23. // Called when the advertisement monitor is successfully activated and
  24. // ready to start receiving device found or device lost events.
  25. virtual void OnActivate() = 0;
  26. // Called when the advertisement monitor is invalidated. The advertisement
  27. // monitor cannot recover from this state.
  28. virtual void OnRelease() = 0;
  29. virtual void OnDeviceFound(const dbus::ObjectPath& device_path) = 0;
  30. virtual void OnDeviceLost(const dbus::ObjectPath& device_path) = 0;
  31. };
  32. virtual ~BluetoothAdvertisementMonitorServiceProvider();
  33. // Writes an array of the service's properties into the provided writer.
  34. virtual void WriteProperties(dbus::MessageWriter* writer) {}
  35. virtual const dbus::ObjectPath& object_path() const = 0;
  36. // Create a BluetoothAdvertisementMonitorServiceProvider instance for
  37. // exporting the object identified by |object_path| onto the D-Bus connection
  38. // |bus|.
  39. static std::unique_ptr<BluetoothAdvertisementMonitorServiceProvider> Create(
  40. dbus::Bus* bus,
  41. const dbus::ObjectPath& object_path,
  42. std::unique_ptr<device::BluetoothLowEnergyScanFilter> filter,
  43. base::WeakPtr<Delegate> delegate);
  44. protected:
  45. BluetoothAdvertisementMonitorServiceProvider();
  46. };
  47. } // namespace bluez
  48. #endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_ADVERTISEMENT_MONITOR_SERVICE_PROVIDER_H_