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