blob: d573caccc08b26d2da13556667f7271191fcb240 [file] [log] [blame]
rkc122239752016-04-20 23:59:081// 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
17namespace 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.
29class DEVICE_BLUETOOTH_EXPORT BluetoothLocalGattCharacteristic
30 : public virtual BluetoothGattCharacteristic {
31 public:
rkcd1e6dc42016-05-12 23:12:4732 enum NotificationStatus {
33 NOTIFICATION_SUCCESS = 0,
34 NOTIFY_PROPERTY_NOT_SET,
35 INDICATE_PROPERTY_NOT_SET,
36 SERVICE_NOT_REGISTERED,
37 };
38
rkc122239752016-04-20 23:59:0839 // 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.
rkca65ced972016-04-28 06:56:3852 static base::WeakPtr<BluetoothLocalGattCharacteristic> Create(
rkc122239752016-04-20 23:59:0853 const BluetoothUUID& uuid,
rkc122239752016-04-20 23:59:0854 Properties properties,
55 Permissions permissions,
56 BluetoothLocalGattService* service);
57
rkcd4ba1a52016-05-17 22:42:3458 // 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.
rkcd1e6dc42016-05-12 23:12:4763 virtual NotificationStatus NotifyValueChanged(
rkcd4ba1a52016-05-17 22:42:3464 const BluetoothDevice* device,
rkcd1e6dc42016-05-12 23:12:4765 const std::vector<uint8_t>& new_value,
66 bool indicate) = 0;
67
rkcd4ba1a52016-05-17 22:42:3468 virtual BluetoothLocalGattService* GetService() const = 0;
69
rkc122239752016-04-20 23:59:0870 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_