OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DEVICE_BLUETOOTH_GATT_CHARACTERISTIC_H_ | 5 #ifndef DEVICE_BLUETOOTH_GATT_CHARACTERISTIC_H_ |
6 #define DEVICE_BLUETOOTH_GATT_CHARACTERISTIC_H_ | 6 #define DEVICE_BLUETOOTH_GATT_CHARACTERISTIC_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 const std::vector<uint8>& value) {} | 88 const std::vector<uint8>& value) {} |
89 | 89 |
90 // Called when the descriptors that are associated with |characteristic| | 90 // Called when the descriptors that are associated with |characteristic| |
91 // have changed. | 91 // have changed. |
92 virtual void DescriptorsChanged( | 92 virtual void DescriptorsChanged( |
93 BluetoothGattCharacteristic* characteristic, | 93 BluetoothGattCharacteristic* characteristic, |
94 const std::vector<BluetoothGattDescriptor*>& descriptors) {} | 94 const std::vector<BluetoothGattDescriptor*>& descriptors) {} |
95 }; | 95 }; |
96 | 96 |
97 // The ErrorCallback is used by methods to asynchronously report errors. | 97 // The ErrorCallback is used by methods to asynchronously report errors. |
98 typedef base::Callback<const std::string&> ErrorCallback; | 98 typedef base::Callback<void(const std::string&)> ErrorCallback; |
| 99 |
| 100 // The ValueCallback is used to return the value of a remote characteristic |
| 101 // upon a read request. |
| 102 typedef base::Callback<void(const std::vector<uint8>&)> ValueCallback; |
99 | 103 |
100 // Adds and removes observers for events on this GATT characteristic. If | 104 // Adds and removes observers for events on this GATT characteristic. If |
101 // monitoring multiple characteristics, check the |characteristic| parameter | 105 // monitoring multiple characteristics, check the |characteristic| parameter |
102 // of observer methods to determine which characteristic is issuing the event. | 106 // of observer methods to determine which characteristic is issuing the event. |
103 virtual void AddObserver(Observer* observer) = 0; | 107 virtual void AddObserver(Observer* observer) = 0; |
104 virtual void RemoveObserver(Observer* observer) = 0; | 108 virtual void RemoveObserver(Observer* observer) = 0; |
105 | 109 |
106 // Constructs a BluetoothGattCharacteristic that can be associated with a | 110 // Constructs a BluetoothGattCharacteristic that can be associated with a |
107 // local GATT service when the adapter is in the peripheral role. To | 111 // local GATT service when the adapter is in the peripheral role. To |
108 // associate the returned characteristic with a service, add it to a local | 112 // associate the returned characteristic with a service, add it to a local |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // any notifications and indications that have been configured. This method | 157 // any notifications and indications that have been configured. This method |
154 // can be used in place of, and in conjunction with, | 158 // can be used in place of, and in conjunction with, |
155 // BluetoothGattService::Delegate methods to send updates to remote devices, | 159 // BluetoothGattService::Delegate methods to send updates to remote devices, |
156 // or simply to set update the cached value for read requests without having | 160 // or simply to set update the cached value for read requests without having |
157 // to implement the delegate methods. | 161 // to implement the delegate methods. |
158 // | 162 // |
159 // This method only makes sense for local characteristics and does nothing and | 163 // This method only makes sense for local characteristics and does nothing and |
160 // returns false if this instance represents a remote characteristic. | 164 // returns false if this instance represents a remote characteristic. |
161 virtual bool UpdateValue(const std::vector<uint8>& value) = 0; | 165 virtual bool UpdateValue(const std::vector<uint8>& value) = 0; |
162 | 166 |
| 167 // Sends a read request to a remote characteristic to read its value. |
| 168 // |callback| is called to return the read value on success and |
| 169 // |error_callback| is called for failures. |
| 170 virtual void ReadRemoteCharacteristic( |
| 171 const ValueCallback& callback, |
| 172 const ErrorCallback& error_callback) = 0; |
| 173 |
163 // Sends a write request to a remote characteristic, to modify the | 174 // Sends a write request to a remote characteristic, to modify the |
164 // characteristic's value starting at offset |offset| with the new value | 175 // characteristic's value starting at offset |offset| with the new value |
165 // |new_value|. |callback| is called to signal success and |error_callback| | 176 // |new_value|. |callback| is called to signal success and |error_callback| |
166 // for failures. This method only applies to remote characteristics and will | 177 // for failures. This method only applies to remote characteristics and will |
167 // fail for those that are locally hosted. | 178 // fail for those that are locally hosted. |
168 virtual void WriteRemoteCharacteristic( | 179 virtual void WriteRemoteCharacteristic( |
169 int offset, | 180 int offset, |
170 const std::vector<uint8>& new_value, | 181 const std::vector<uint8>& new_value, |
171 const base::Closure& callback, | 182 const base::Closure& callback, |
172 const ErrorCallback& error_callback) = 0; | 183 const ErrorCallback& error_callback) = 0; |
173 | 184 |
174 protected: | 185 protected: |
175 BluetoothGattCharacteristic(); | 186 BluetoothGattCharacteristic(); |
176 virtual ~BluetoothGattCharacteristic(); | 187 virtual ~BluetoothGattCharacteristic(); |
177 | 188 |
178 private: | 189 private: |
179 DISALLOW_COPY_AND_ASSIGN(BluetoothGattCharacteristic); | 190 DISALLOW_COPY_AND_ASSIGN(BluetoothGattCharacteristic); |
180 }; | 191 }; |
181 | 192 |
182 } // namespace device | 193 } // namespace device |
183 | 194 |
184 #endif // DEVICE_BLUETOOTH_GATT_CHARACTERISTIC_H_ | 195 #endif // DEVICE_BLUETOOTH_GATT_CHARACTERISTIC_H_ |
OLD | NEW |