| 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_BLUETOOTH_GATT_SERVICE_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // delegates MUST invoke either |callback| or |error_callback|. | 118 // delegates MUST invoke either |callback| or |error_callback|. |
| 119 virtual void OnDescriptorWriteRequest( | 119 virtual void OnDescriptorWriteRequest( |
| 120 const BluetoothGattService* service, | 120 const BluetoothGattService* service, |
| 121 const BluetoothGattDescriptor* descriptor, | 121 const BluetoothGattDescriptor* descriptor, |
| 122 const std::vector<uint8>& value, | 122 const std::vector<uint8>& value, |
| 123 int offset, | 123 int offset, |
| 124 const ValueCallback& callback, | 124 const ValueCallback& callback, |
| 125 const ErrorCallback& error_callback) = 0; | 125 const ErrorCallback& error_callback) = 0; |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 // Interface for observing changes from a BluetoothGattService. Properties | |
| 129 // of remote services are received asynchronously. The Observer interface can | |
| 130 // be used to be notified when the initial values of a service are received | |
| 131 // as well as when successive changes occur during its life cycle. | |
| 132 class Observer { | |
| 133 public: | |
| 134 // Called when all characteristic and descriptor discovery procedures are | |
| 135 // known to be completed for the GATT service |service|. This method will be | |
| 136 // called after the initial discovery of a GATT service and will usually be | |
| 137 // preceded by calls to GattCharacteristicAdded and GattDescriptorAdded. | |
| 138 virtual void GattDiscoveryCompleteForService( | |
| 139 BluetoothGattService* service) {} | |
| 140 | |
| 141 // Called when properties of the remote GATT service |service| have changed. | |
| 142 // This will get called for properties such as UUID, as well as for changes | |
| 143 // to the list of known characteristics and included services. Observers | |
| 144 // should read all GATT characteristic and descriptors objects and do any | |
| 145 // necessary set up required for a changed service. | |
| 146 virtual void GattServiceChanged(BluetoothGattService* service) {} | |
| 147 | |
| 148 // Called when the remote GATT characteristic |characteristic| belonging to | |
| 149 // GATT service |service| has been discovered. Use this to issue any initial | |
| 150 // read/write requests to the characteristic but don't cache the pointer as | |
| 151 // it may become invalid. Instead, use the specially assigned identifier | |
| 152 // to obtain a characteristic and cache that identifier as necessary, as it | |
| 153 // can be used to retrieve the characteristic from its GATT service. The | |
| 154 // number of characteristics with the same UUID belonging to a service | |
| 155 // depends on the particular profile the remote device implements, hence the | |
| 156 // client of a GATT based profile will usually operate on the whole set of | |
| 157 // characteristics and not just one. | |
| 158 virtual void GattCharacteristicAdded( | |
| 159 BluetoothGattService* service, | |
| 160 BluetoothGattCharacteristic* characteristic) {} | |
| 161 | |
| 162 // Called when a GATT characteristic |characteristic| belonging to GATT | |
| 163 // service |service| has been removed. | |
| 164 virtual void GattCharacteristicRemoved( | |
| 165 BluetoothGattService* service, | |
| 166 BluetoothGattCharacteristic* characteristic) {} | |
| 167 | |
| 168 // Called when the remote GATT characteristic descriptor |descriptor| | |
| 169 // belonging to characteristic |characteristic| has been discovered. Don't | |
| 170 // cache the arguments as the pointers may become invalid. Instead, use the | |
| 171 // specially assigned identifier to obtain a descriptor and cache that | |
| 172 // identifier as necessary. | |
| 173 virtual void GattDescriptorAdded( | |
| 174 BluetoothGattCharacteristic* characteristic, | |
| 175 BluetoothGattDescriptor* descriptor) {} | |
| 176 | |
| 177 // Called when a GATT characteristic descriptor |descriptor| belonging to | |
| 178 // characteristic |characteristic| has been removed. | |
| 179 virtual void GattDescriptorRemoved( | |
| 180 BluetoothGattCharacteristic* characteristic, | |
| 181 BluetoothGattDescriptor* descriptor) {} | |
| 182 | |
| 183 // Called when the value of a characteristic has changed. This might be a | |
| 184 // result of a read/write request to, or a notification/indication from, a | |
| 185 // remote GATT characteristic. | |
| 186 virtual void GattCharacteristicValueChanged( | |
| 187 BluetoothGattService* service, | |
| 188 BluetoothGattCharacteristic* characteristic, | |
| 189 const std::vector<uint8>& value) {} | |
| 190 | |
| 191 // Called when the value of a characteristic descriptor has been updated. | |
| 192 virtual void GattDescriptorValueChanged( | |
| 193 BluetoothGattCharacteristic* characteristic, | |
| 194 BluetoothGattDescriptor* descriptor, | |
| 195 const std::vector<uint8>& value) {} | |
| 196 }; | |
| 197 | |
| 198 // The ErrorCallback is used by methods to asynchronously report errors. | 128 // The ErrorCallback is used by methods to asynchronously report errors. |
| 199 typedef base::Closure ErrorCallback; | 129 typedef base::Closure ErrorCallback; |
| 200 | 130 |
| 201 virtual ~BluetoothGattService(); | 131 virtual ~BluetoothGattService(); |
| 202 | 132 |
| 203 // Adds and removes observers for events on this GATT service. If monitoring | |
| 204 // multiple services, check the |service| parameter of observer methods to | |
| 205 // determine which service is issuing the event. | |
| 206 virtual void AddObserver(Observer* observer) = 0; | |
| 207 virtual void RemoveObserver(Observer* observer) = 0; | |
| 208 | |
| 209 // Constructs a BluetoothGattService that can be locally hosted when the local | 133 // Constructs a BluetoothGattService that can be locally hosted when the local |
| 210 // adapter is in the peripheral role. The resulting object can then be made | 134 // adapter is in the peripheral role. The resulting object can then be made |
| 211 // available by calling the "Register" method. This method constructs a | 135 // available by calling the "Register" method. This method constructs a |
| 212 // service with UUID |uuid|. Whether the constructed service is primary or | 136 // service with UUID |uuid|. Whether the constructed service is primary or |
| 213 // secondary is determined by |is_primary|. |delegate| is used to send certain | 137 // secondary is determined by |is_primary|. |delegate| is used to send certain |
| 214 // peripheral role events. If |delegate| is NULL, then this service will | 138 // peripheral role events. If |delegate| is NULL, then this service will |
| 215 // employ a default behavior when responding to read and write requests based | 139 // employ a default behavior when responding to read and write requests based |
| 216 // on the cached value of its characteristics and descriptors at a given time. | 140 // on the cached value of its characteristics and descriptors at a given time. |
| 217 static BluetoothGattService* Create(const BluetoothUUID& uuid, | 141 static BluetoothGattService* Create(const BluetoothUUID& uuid, |
| 218 bool is_primary, | 142 bool is_primary, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 protected: | 207 protected: |
| 284 BluetoothGattService(); | 208 BluetoothGattService(); |
| 285 | 209 |
| 286 private: | 210 private: |
| 287 DISALLOW_COPY_AND_ASSIGN(BluetoothGattService); | 211 DISALLOW_COPY_AND_ASSIGN(BluetoothGattService); |
| 288 }; | 212 }; |
| 289 | 213 |
| 290 } // namespace device | 214 } // namespace device |
| 291 | 215 |
| 292 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_H_ | 216 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_H_ |
| OLD | NEW |