Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_characteristic.h

Issue 1898643002: Refactor device::BluetoothGattXXX classes to split into remote/local. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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_REMOTE_GATT_CHARACTERISTIC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_H_
7
8 #include <stdint.h>
9 #include <string>
10 #include <vector>
11
12 #include "base/callback.h"
13 #include "base/callback_forward.h"
14 #include "base/macros.h"
15 #include "device/bluetooth/bluetooth_export.h"
16 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
17 #include "device/bluetooth/bluetooth_uuid.h"
18
19 namespace device {
20
21 class BluetoothGattNotifySession;
22 class BluetoothRemoteGattDescriptor;
23 class BluetoothRemoteGattService;
24
25 // BluetoothRemoteGattCharacteristic represents a remote GATT characteristic.
26 // This class is used to represent GATT characteristics that belong to a service
27 // hosted by a remote device. In this case the characteristic will be
28 // constructed by the subsystem.
29 //
30 // Note: We use virtual inheritance on the GATT characteristic since it will be
31 // inherited by platform specific versions of the GATT characteristic classes
32 // also. The platform specific remote GATT characteristic classes will inherit
33 // both this class and their GATT characteristic class, hence causing an
34 // inheritance diamond.
35 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristic
36 : public virtual BluetoothGattCharacteristic {
37 public:
38 // The ValueCallback is used to return the value of a remote characteristic
39 // upon a read request.
40 typedef base::Callback<void(const std::vector<uint8_t>&)> ValueCallback;
41
42 // The NotifySessionCallback is used to return sessions after they have
43 // been successfully started.
44 typedef base::Callback<void(std::unique_ptr<BluetoothGattNotifySession>)>
45 NotifySessionCallback;
46
47 // The Bluetooth-specific UUID of the characteristic.
48 virtual BluetoothUUID GetUUID() const = 0;
49
50 // Returns the value of the characteristic. For remote characteristics, this
51 // is the most recently cached value. For local characteristics, this is the
52 // most recently updated value or the value retrieved from the delegate.
53 virtual const std::vector<uint8_t>& GetValue() const = 0;
54
55 // Returns a pointer to the GATT service this characteristic belongs to.
56 virtual BluetoothRemoteGattService* GetService() const = 0;
57
58 // Returns the bitmask of characteristic properties.
59 virtual Properties GetProperties() const = 0;
60
61 // Returns the bitmask of characteristic attribute permissions.
62 virtual Permissions GetPermissions() const = 0;
63
64 // Returns whether or not this characteristic is currently sending value
65 // updates in the form of a notification or indication.
66 virtual bool IsNotifying() const = 0;
67
68 // Returns the list of GATT characteristic descriptors that provide more
69 // information about this characteristic.
70 virtual std::vector<BluetoothRemoteGattDescriptor*> GetDescriptors()
71 const = 0;
72
73 // Returns the GATT characteristic descriptor with identifier |identifier| if
74 // it belongs to this GATT characteristic.
75 virtual BluetoothRemoteGattDescriptor* GetDescriptor(
76 const std::string& identifier) const = 0;
77
78 // Returns the GATT characteristic descriptors that match |uuid|. There may be
79 // multiple, as illustrated by Core Bluetooth Specification [V4.2 Vol 3 Part G
80 // 3.3.3.5 Characteristic Presentation Format].
81 std::vector<BluetoothRemoteGattDescriptor*> GetDescriptorsByUUID(
82 const BluetoothUUID& uuid);
83
84 // Starts a notify session for the remote characteristic, if it supports
85 // notifications/indications. On success, the characteristic starts sending
86 // value notifications and |callback| is called with a session object whose
87 // ownership belongs to the caller. |error_callback| is called on errors.
88 //
89 // Writes to the Client Characteristic Configuration descriptor to enable
90 // notifications/indications. Core Bluetooth Specification [V4.2 Vol 3 Part G
91 // Section 3.3.1.1. Characteristic Properties] requires this descriptor to be
92 // present when notifications/indications are supported. If the descriptor is
93 // not present |error_callback| will be run.
94 virtual void StartNotifySession(const NotifySessionCallback& callback,
95 const ErrorCallback& error_callback) = 0;
96
97 // Sends a read request to a remote characteristic to read its value.
98 // |callback| is called to return the read value on success and
99 // |error_callback| is called for failures.
100 virtual void ReadRemoteCharacteristic(
101 const ValueCallback& callback,
102 const ErrorCallback& error_callback) = 0;
103
104 // Sends a write request to a remote characteristic, to modify the
105 // characteristic's value with the new value |new_value|. |callback| is
106 // called to signal success and |error_callback| for failures. This method
107 // only applies to remote characteristics and will fail for those that are
108 // locally hosted.
109 virtual void WriteRemoteCharacteristic(
110 const std::vector<uint8_t>& new_value,
111 const base::Closure& callback,
112 const ErrorCallback& error_callback) = 0;
113
114 protected:
115 BluetoothRemoteGattCharacteristic();
116 ~BluetoothRemoteGattCharacteristic() override;
117
118 private:
119 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristic);
120 };
121
122 } // namespace device
123
124 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698