bluetooth_le_advertising_manager_client.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2015 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_LE_ADVERTISING_MANAGER_CLIENT_H_
  5. #define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_LE_ADVERTISING_MANAGER_CLIENT_H_
  6. #include <cstdint>
  7. #include <memory>
  8. #include <string>
  9. #include <vector>
  10. #include "base/callback.h"
  11. #include "dbus/object_path.h"
  12. #include "device/bluetooth/bluetooth_export.h"
  13. #include "device/bluetooth/dbus/bluez_dbus_client.h"
  14. namespace bluez {
  15. // BluetoothAdvertisingManagerClient is used to communicate with the advertising
  16. // manager object of the BlueZ daemon.
  17. class DEVICE_BLUETOOTH_EXPORT BluetoothLEAdvertisingManagerClient
  18. : public BluezDBusClient {
  19. public:
  20. // Interface for observing changes to advertising managers.
  21. class Observer {
  22. public:
  23. virtual ~Observer() {}
  24. // Called when an advertising manager with object path |object_path| is
  25. // added to the system.
  26. virtual void AdvertisingManagerAdded(const dbus::ObjectPath& object_path) {}
  27. // Called when an advertising manager with object path |object_path| is
  28. // removed from the system.
  29. virtual void AdvertisingManagerRemoved(
  30. const dbus::ObjectPath& object_path) {}
  31. };
  32. BluetoothLEAdvertisingManagerClient(
  33. const BluetoothLEAdvertisingManagerClient&) = delete;
  34. BluetoothLEAdvertisingManagerClient& operator=(
  35. const BluetoothLEAdvertisingManagerClient&) = delete;
  36. ~BluetoothLEAdvertisingManagerClient() override;
  37. // Adds and removes observers for events which change the advertising
  38. // managers on the system.
  39. virtual void AddObserver(Observer* observer) = 0;
  40. virtual void RemoveObserver(Observer* observer) = 0;
  41. // The ErrorCallback is used by advertising manager methods to indicate
  42. // failure. It receives two arguments: the name of the error in |error_name|
  43. // and an optional message in |error_message|.
  44. using ErrorCallback =
  45. base::OnceCallback<void(const std::string& error_name,
  46. const std::string& error_message)>;
  47. // Registers an advertisement with the DBus object path
  48. // |advertisement_object_path| with BlueZ's advertising manager.
  49. virtual void RegisterAdvertisement(
  50. const dbus::ObjectPath& manager_object_path,
  51. const dbus::ObjectPath& advertisement_object_path,
  52. base::OnceClosure callback,
  53. ErrorCallback error_callback) = 0;
  54. // Unregisters an advertisement with the DBus object path
  55. // |advertisement_object_path| with BlueZ's advertising manager.
  56. virtual void UnregisterAdvertisement(
  57. const dbus::ObjectPath& manager_object_path,
  58. const dbus::ObjectPath& advertisement_object_path,
  59. base::OnceClosure callback,
  60. ErrorCallback error_callback) = 0;
  61. // Set's the advertising interval.
  62. virtual void SetAdvertisingInterval(
  63. const dbus::ObjectPath& manager_object_path,
  64. uint16_t min_interval_ms,
  65. uint16_t max_interval_ms,
  66. base::OnceClosure callback,
  67. ErrorCallback error_callback) = 0;
  68. // Resets advertising.
  69. virtual void ResetAdvertising(const dbus::ObjectPath& manager_object_path,
  70. base::OnceClosure callback,
  71. ErrorCallback error_callback) = 0;
  72. // Creates the instance.
  73. static BluetoothLEAdvertisingManagerClient* Create();
  74. // Constants used to indicate exceptional error conditions.
  75. static const char kNoResponseError[];
  76. protected:
  77. BluetoothLEAdvertisingManagerClient();
  78. };
  79. } // namespace bluez
  80. #endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_LE_ADVERTISING_MANAGER_CLIENT_H_