bluetooth_remote_gatt_service.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2016 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_REMOTE_GATT_SERVICE_H_
  5. #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "base/containers/flat_map.h"
  10. #include "device/bluetooth/bluetooth_export.h"
  11. #include "device/bluetooth/bluetooth_gatt_service.h"
  12. namespace device {
  13. class BluetoothDevice;
  14. class BluetoothRemoteGattCharacteristic;
  15. class BluetoothUUID;
  16. // BluetoothRemoteGattService represents a remote GATT service.
  17. //
  18. // Instances of the BluetoothRemoteGATTService class are used to represent GATT
  19. // attribute hierarchies that have been received from a
  20. // remote Bluetooth GATT peripheral. Such BluetoothRemoteGattService instances
  21. // are constructed and owned by a BluetoothDevice.
  22. //
  23. // Note: We use virtual inheritance on the GATT service since it will be
  24. // inherited by platform specific versions of the GATT service classes also. The
  25. // platform specific remote GATT service classes will inherit both this class
  26. // and their GATT service class, hence causing an inheritance diamond.
  27. class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattService
  28. : public virtual BluetoothGattService {
  29. public:
  30. BluetoothRemoteGattService(const BluetoothRemoteGattService&) = delete;
  31. BluetoothRemoteGattService& operator=(const BluetoothRemoteGattService&) =
  32. delete;
  33. ~BluetoothRemoteGattService() override;
  34. // Returns the BluetoothDevice that this GATT service was received from, which
  35. // also owns this service.
  36. virtual BluetoothDevice* GetDevice() const = 0;
  37. // List of characteristics that belong to this service.
  38. virtual std::vector<BluetoothRemoteGattCharacteristic*> GetCharacteristics()
  39. const;
  40. // List of GATT services that are included by this service.
  41. virtual std::vector<BluetoothRemoteGattService*> GetIncludedServices()
  42. const = 0;
  43. // Returns the GATT characteristic with identifier |identifier| if it belongs
  44. // to this GATT service.
  45. virtual BluetoothRemoteGattCharacteristic* GetCharacteristic(
  46. const std::string& identifier) const;
  47. // List of characteristics that belong to this service and have a UUID equal
  48. // to |characteristic_uuid|.
  49. virtual std::vector<BluetoothRemoteGattCharacteristic*>
  50. GetCharacteristicsByUUID(const BluetoothUUID& characteristic_uuid) const;
  51. // Returns true if all the characteristics have been discovered.
  52. virtual bool IsDiscoveryComplete() const;
  53. // Sets characteristic discovery as complete or incomplete.
  54. virtual void SetDiscoveryComplete(bool complete);
  55. protected:
  56. using CharacteristicMap =
  57. base::flat_map<std::string,
  58. std::unique_ptr<BluetoothRemoteGattCharacteristic>>;
  59. BluetoothRemoteGattService();
  60. bool AddCharacteristic(
  61. std::unique_ptr<BluetoothRemoteGattCharacteristic> characteristic);
  62. CharacteristicMap characteristics_;
  63. private:
  64. // Is true if all the characteristics have been discovered.
  65. bool discovery_complete_ = false;
  66. };
  67. } // namespace device
  68. #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_H_