bluetooth_battery_client.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2020 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_BATTERY_CLIENT_H_
  5. #define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_BATTERY_CLIENT_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include <vector>
  9. #include "base/callback.h"
  10. #include "dbus/object_path.h"
  11. #include "dbus/property.h"
  12. #include "device/bluetooth/bluetooth_export.h"
  13. #include "device/bluetooth/dbus/bluez_dbus_client.h"
  14. namespace bluez {
  15. // BluetoothBatteryClient is used to communicate with objects on BlueZ's
  16. // org.bluez.Battery1 interface.
  17. class DEVICE_BLUETOOTH_EXPORT BluetoothBatteryClient : public BluezDBusClient {
  18. public:
  19. // Structure of properties on org.bluez.Battery1 interface.
  20. struct Properties : public dbus::PropertySet {
  21. // The percentage (0-100) of the battery. Read-only.
  22. dbus::Property<uint8_t> percentage;
  23. Properties(dbus::ObjectProxy* object_proxy,
  24. const std::string& interface_name,
  25. const PropertyChangedCallback& callback);
  26. ~Properties() override;
  27. };
  28. // Interface for observing changes from a remote bluetooth battery.
  29. class Observer {
  30. public:
  31. virtual ~Observer() = default;
  32. // Called when the remote battery with object path |object_path| is added
  33. // to the set of known batteries.
  34. virtual void BatteryAdded(const dbus::ObjectPath& object_path) {}
  35. // Called when the remote battery with object path |object_path| is removed
  36. // from the set of known batteries.
  37. virtual void BatteryRemoved(const dbus::ObjectPath& object_path) {}
  38. // Called when the battery with object path |object_path| has a
  39. // change in value of the property named |property_name|.
  40. virtual void BatteryPropertyChanged(const dbus::ObjectPath& object_path,
  41. const std::string& property_name) {}
  42. };
  43. BluetoothBatteryClient(const BluetoothBatteryClient&) = delete;
  44. BluetoothBatteryClient& operator=(const BluetoothBatteryClient&) = delete;
  45. ~BluetoothBatteryClient() override;
  46. // Adds and removes observers for events on all remote bluetooth
  47. // batteries. Check the |object_path| parameter of observer methods to
  48. // determine which battery is issuing the event.
  49. virtual void AddObserver(Observer* observer) = 0;
  50. virtual void RemoveObserver(Observer* observer) = 0;
  51. // Obtain the properties for the battery with object path |object_path|,
  52. // any values should be copied if needed.
  53. virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
  54. // Creates the instance.
  55. static BluetoothBatteryClient* Create();
  56. protected:
  57. BluetoothBatteryClient();
  58. };
  59. } // namespace bluez
  60. #endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_BATTERY_CLIENT_H_