bluetooth_gatt_service.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_BLUETOOTH_GATT_SERVICE_H_
  5. #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_H_
  6. #include <string>
  7. #include "base/callback_forward.h"
  8. #include "device/bluetooth/bluetooth_export.h"
  9. #include "device/bluetooth/public/cpp/bluetooth_uuid.h"
  10. namespace device {
  11. // BluetoothGattService represents a local or remote GATT service. A GATT
  12. // service is hosted by a peripheral and represents a collection of data in
  13. // the form of GATT characteristics and a set of included GATT services if this
  14. // service is what is called "a primary service".
  15. class DEVICE_BLUETOOTH_EXPORT BluetoothGattService {
  16. public:
  17. // Interacting with Characteristics and Descriptors can produce
  18. // this set of errors.
  19. // These values are persisted to logs. Entries should not be renumbered and
  20. // numeric values should never be reused. This enum should be kept in sync
  21. // with the BluetoothGattServiceGattErrorCode enum in
  22. // src/tools/metrics/histograms/enums.xml.
  23. enum GattErrorCode {
  24. GATT_ERROR_UNKNOWN = 0,
  25. GATT_ERROR_FAILED = 1,
  26. GATT_ERROR_IN_PROGRESS = 2,
  27. GATT_ERROR_INVALID_LENGTH = 3,
  28. GATT_ERROR_NOT_PERMITTED = 4,
  29. GATT_ERROR_NOT_AUTHORIZED = 5,
  30. GATT_ERROR_NOT_PAIRED = 6,
  31. GATT_ERROR_NOT_SUPPORTED = 7,
  32. kMaxValue = GATT_ERROR_NOT_SUPPORTED,
  33. };
  34. // The ErrorCallback is used by methods to asynchronously report errors.
  35. using ErrorCallback = base::OnceCallback<void(GattErrorCode error_code)>;
  36. // Identifier used to uniquely identify a GATT service object. This is
  37. // different from the service UUID: while multiple services with the same UUID
  38. // can exist on a Bluetooth device, the identifier returned from this method
  39. // is unique among all services on the adapter. The contents of the identifier
  40. // are platform specific.
  41. virtual std::string GetIdentifier() const = 0;
  42. // The Bluetooth-specific UUID of the service.
  43. virtual BluetoothUUID GetUUID() const = 0;
  44. // Indicates whether the type of this service is primary or secondary. A
  45. // primary service describes the primary function of the peripheral that
  46. // hosts it, while a secondary service only makes sense in the presence of a
  47. // primary service. A primary service may include other primary or secondary
  48. // services.
  49. virtual bool IsPrimary() const = 0;
  50. BluetoothGattService(const BluetoothGattService&) = delete;
  51. BluetoothGattService& operator=(const BluetoothGattService&) = delete;
  52. virtual ~BluetoothGattService();
  53. protected:
  54. BluetoothGattService();
  55. };
  56. } // namespace device
  57. #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_H_