rkc | 12223975 | 2016-04-20 23:59:08 | [diff] [blame] | 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 | |
| 5 | #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_CHARACTERISTIC_H_ |
| 6 | #define DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_CHARACTERISTIC_H_ |
| 7 | |
| 8 | #include <stdint.h> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/macros.h" |
| 12 | #include "device/bluetooth/bluetooth_export.h" |
| 13 | #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
| 14 | #include "device/bluetooth/bluetooth_local_gatt_service.h" |
| 15 | #include "device/bluetooth/bluetooth_uuid.h" |
| 16 | |
| 17 | namespace device { |
| 18 | |
| 19 | // BluetoothLocalGattCharacteristic represents a local GATT characteristic. This |
| 20 | // class is used to represent GATT characteristics that belong to a locally |
| 21 | // hosted service. To achieve this, users need to specify the instance of the |
| 22 | // GATT service that contains this characteristic during construction. |
| 23 | // |
| 24 | // Note: We use virtual inheritance on the GATT characteristic since it will be |
| 25 | // inherited by platform specific versions of the GATT characteristic classes |
| 26 | // also. The platform specific remote GATT characteristic classes will inherit |
| 27 | // both this class and their GATT characteristic class, hence causing an |
| 28 | // inheritance diamond. |
| 29 | class DEVICE_BLUETOOTH_EXPORT BluetoothLocalGattCharacteristic |
| 30 | : public virtual BluetoothGattCharacteristic { |
| 31 | public: |
rkc | d1e6dc4 | 2016-05-12 23:12:47 | [diff] [blame] | 32 | enum NotificationStatus { |
| 33 | NOTIFICATION_SUCCESS = 0, |
| 34 | NOTIFY_PROPERTY_NOT_SET, |
| 35 | INDICATE_PROPERTY_NOT_SET, |
| 36 | SERVICE_NOT_REGISTERED, |
| 37 | }; |
| 38 | |
rkc | 12223975 | 2016-04-20 23:59:08 | [diff] [blame] | 39 | // Constructs a BluetoothLocalGattCharacteristic associated with a local GATT |
| 40 | // service when the adapter is in the peripheral role. |
| 41 | // |
| 42 | // This method constructs a characteristic with UUID |uuid|, initial cached |
| 43 | // value |value|, properties |properties|, and permissions |permissions|. |
| 44 | // |value| will be cached and returned for read requests and automatically set |
| 45 | // for write requests by default, unless an instance of |
| 46 | // BluetoothRemoteGattService::Delegate has been provided to the associated |
| 47 | // BluetoothRemoteGattService instance, in which case the delegate will handle |
| 48 | // read and write requests. The service instance will contain this |
| 49 | // characteristic. |
| 50 | // TODO(rkc): Investigate how to handle |PROPERTY_EXTENDED_PROPERTIES| |
| 51 | // correctly. |
rkc | a65ced97 | 2016-04-28 06:56:38 | [diff] [blame] | 52 | static base::WeakPtr<BluetoothLocalGattCharacteristic> Create( |
rkc | 12223975 | 2016-04-20 23:59:08 | [diff] [blame] | 53 | const BluetoothUUID& uuid, |
rkc | 12223975 | 2016-04-20 23:59:08 | [diff] [blame] | 54 | Properties properties, |
| 55 | Permissions permissions, |
| 56 | BluetoothLocalGattService* service); |
| 57 | |
rkc | d4ba1a5 | 2016-05-17 22:42:34 | [diff] [blame] | 58 | // Notify the remote device |device| that the value of characteristic |
| 59 | // |characteristic| has changed and the new value is |new_value|. |indicate| |
| 60 | // should be set to true if we want to use an indication instead of a |
| 61 | // notification. An indication waits for a response from the remote, making |
| 62 | // it more reliable but notifications may be faster. |
rkc | d1e6dc4 | 2016-05-12 23:12:47 | [diff] [blame] | 63 | virtual NotificationStatus NotifyValueChanged( |
rkc | d4ba1a5 | 2016-05-17 22:42:34 | [diff] [blame] | 64 | const BluetoothDevice* device, |
rkc | d1e6dc4 | 2016-05-12 23:12:47 | [diff] [blame] | 65 | const std::vector<uint8_t>& new_value, |
| 66 | bool indicate) = 0; |
| 67 | |
rkc | d4ba1a5 | 2016-05-17 22:42:34 | [diff] [blame] | 68 | virtual BluetoothLocalGattService* GetService() const = 0; |
| 69 | |
rkc | 12223975 | 2016-04-20 23:59:08 | [diff] [blame] | 70 | protected: |
| 71 | BluetoothLocalGattCharacteristic(); |
| 72 | ~BluetoothLocalGattCharacteristic() override; |
| 73 | |
| 74 | private: |
| 75 | DISALLOW_COPY_AND_ASSIGN(BluetoothLocalGattCharacteristic); |
| 76 | }; |
| 77 | |
| 78 | } // namespace device |
| 79 | |
| 80 | #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_CHARACTERISTIC_H_ |