bluetooth_gatt_service_client.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_DBUS_BLUETOOTH_GATT_SERVICE_CLIENT_H_
  5. #define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_SERVICE_CLIENT_H_
  6. #include <string>
  7. #include <vector>
  8. #include "dbus/object_path.h"
  9. #include "dbus/property.h"
  10. #include "device/bluetooth/bluetooth_export.h"
  11. #include "device/bluetooth/dbus/bluez_dbus_client.h"
  12. namespace bluez {
  13. // BluetoothGattServiceClient is used to communicate with remote GATT service
  14. // objects exposed by the Bluetooth daemon.
  15. class DEVICE_BLUETOOTH_EXPORT BluetoothGattServiceClient
  16. : public BluezDBusClient {
  17. public:
  18. // Structure of properties associated with GATT services.
  19. struct Properties : public dbus::PropertySet {
  20. // The 128-bit service UUID. [read-only]
  21. dbus::Property<std::string> uuid;
  22. // Object path of the Bluetooth device that the GATT service belongs to.
  23. dbus::Property<dbus::ObjectPath> device;
  24. // Whether or not this service is a primary service.
  25. dbus::Property<bool> primary;
  26. // Array of object paths representing the included services of this service.
  27. // [read-only]
  28. dbus::Property<std::vector<dbus::ObjectPath>> includes;
  29. Properties(dbus::ObjectProxy* object_proxy,
  30. const std::string& interface_name,
  31. const PropertyChangedCallback& callback);
  32. ~Properties() override;
  33. };
  34. // Interface for observing changes from a remote GATT service.
  35. class Observer {
  36. public:
  37. virtual ~Observer() {}
  38. // Called when the GATT service with object path |object_path| is added to
  39. // the system.
  40. virtual void GattServiceAdded(const dbus::ObjectPath& object_path) {}
  41. // Called when the GATT service with object path |object_path| is removed
  42. // from the system.
  43. virtual void GattServiceRemoved(const dbus::ObjectPath& object_path) {}
  44. // Called when the GATT service with object path |object_path| has a change
  45. // in the value of the property named |property_name|.
  46. virtual void GattServicePropertyChanged(const dbus::ObjectPath& object_path,
  47. const std::string& property_name) {}
  48. };
  49. BluetoothGattServiceClient(const BluetoothGattServiceClient&) = delete;
  50. BluetoothGattServiceClient& operator=(const BluetoothGattServiceClient&) =
  51. delete;
  52. ~BluetoothGattServiceClient() override;
  53. // Adds and removes observers for events on all remote GATT services. Check
  54. // the |object_path| parameter of observer methods to determine which GATT
  55. // service is issuing the event.
  56. virtual void AddObserver(Observer* observer) = 0;
  57. virtual void RemoveObserver(Observer* observer) = 0;
  58. // Returns the list of GATT service object paths known to the system.
  59. virtual std::vector<dbus::ObjectPath> GetServices() = 0;
  60. // Obtain the properties for the GATT service with object path |object_path|.
  61. // Values should be copied if needed.
  62. virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
  63. // Creates the instance.
  64. static BluetoothGattServiceClient* Create();
  65. protected:
  66. BluetoothGattServiceClient();
  67. };
  68. } // namespace bluez
  69. #endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_SERVICE_CLIENT_H_