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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 128 // Interface for observing changes from a BluetoothGattService. Properties |
129 // of remote services are received asynchronously. The Observer interface can | 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 | 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. | 131 // as well as when successive changes occur during its life cycle. |
132 class Observer { | 132 class Observer { |
133 public: | 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 |
134 // Called when properties of the remote GATT service |service| have changed. | 141 // Called when properties of the remote GATT service |service| have changed. |
135 // This will get called for properties such as UUID, as well as for changes | 142 // This will get called for properties such as UUID, as well as for changes |
136 // to the list of known characteristics and included services. Observers | 143 // to the list of known characteristics and included services. Observers |
137 // should read all GATT characteristic and descriptors objects and do any | 144 // should read all GATT characteristic and descriptors objects and do any |
138 // necessary set up required for a changed service. This method may be | 145 // necessary set up required for a changed service. |
139 // called several times, especially when the service is discovered for the | |
140 // first time. It will be called for each characteristic and characteristic | |
141 // descriptor that is discovered or removed. Hence this method should be | |
142 // used to check whether or not all characteristics of a service have been | |
143 // discovered that correspond to the profile implemented by the Observer. | |
144 virtual void GattServiceChanged(BluetoothGattService* service) {} | 146 virtual void GattServiceChanged(BluetoothGattService* service) {} |
145 | 147 |
146 // Called when the remote GATT characteristic |characteristic| belonging to | 148 // Called when the remote GATT characteristic |characteristic| belonging to |
147 // GATT service |service| has been discovered. Use this to issue any initial | 149 // GATT service |service| has been discovered. Use this to issue any initial |
148 // read/write requests to the characteristic but don't cache the pointer as | 150 // read/write requests to the characteristic but don't cache the pointer as |
149 // it may become invalid. Instead, use the specially assigned identifier | 151 // it may become invalid. Instead, use the specially assigned identifier |
150 // to obtain a characteristic and cache that identifier as necessary, as it | 152 // to obtain a characteristic and cache that identifier as necessary, as it |
151 // can be used to retrieve the characteristic from its GATT service. The | 153 // can be used to retrieve the characteristic from its GATT service. The |
152 // number of characteristics with the same UUID belonging to a service | 154 // number of characteristics with the same UUID belonging to a service |
153 // depends on the particular profile the remote device implements, hence the | 155 // depends on the particular profile the remote device implements, hence the |
154 // client of a GATT based profile will usually operate on the whole set of | 156 // client of a GATT based profile will usually operate on the whole set of |
155 // characteristics and not just one. | 157 // characteristics and not just one. |
156 // | |
157 // This method will always be followed by a call to GattServiceChanged, | |
158 // which can be used by observers to get all the characteristics of a | |
159 // service and perform the necessary updates. GattCharacteristicAdded exists | |
160 // mostly for convenience. | |
161 virtual void GattCharacteristicAdded( | 158 virtual void GattCharacteristicAdded( |
162 BluetoothGattService* service, | 159 BluetoothGattService* service, |
163 BluetoothGattCharacteristic* characteristic) {} | 160 BluetoothGattCharacteristic* characteristic) {} |
164 | 161 |
165 // Called when a GATT characteristic |characteristic| belonging to GATT | 162 // Called when a GATT characteristic |characteristic| belonging to GATT |
166 // service |service| has been removed. This method is for convenience | 163 // service |service| has been removed. |
167 // and will be followed by a call to GattServiceChanged (except when called | |
168 // after the service gets removed) which should be used for bootstrapping a | |
169 // GATT based profile. See the documentation of GattCharacteristicAdded and | |
170 // GattServiceChanged for more information. Try to obtain the service from | |
171 // its device to see whether or not the service has been removed. | |
172 virtual void GattCharacteristicRemoved( | 164 virtual void GattCharacteristicRemoved( |
173 BluetoothGattService* service, | 165 BluetoothGattService* service, |
174 BluetoothGattCharacteristic* characteristic) {} | 166 BluetoothGattCharacteristic* characteristic) {} |
175 | 167 |
176 // Called when the remote GATT characteristic descriptor |descriptor| | 168 // Called when the remote GATT characteristic descriptor |descriptor| |
177 // belonging to characteristic |characteristic| has been discovered. Don't | 169 // belonging to characteristic |characteristic| has been discovered. Don't |
178 // cache the arguments as the pointers may become invalid. Instead, use the | 170 // cache the arguments as the pointers may become invalid. Instead, use the |
179 // specially assigned identifier to obtain a descriptor and cache that | 171 // specially assigned identifier to obtain a descriptor and cache that |
180 // identifier as necessary. | 172 // identifier as necessary. |
181 // | |
182 // This method will always be followed by a call to GattServiceChanged, | |
183 // which can be used by observers to get all the characteristics of a | |
184 // service and perform the necessary updates. GattDescriptorAdded exists | |
185 // mostly for convenience. | |
186 virtual void GattDescriptorAdded( | 173 virtual void GattDescriptorAdded( |
187 BluetoothGattCharacteristic* characteristic, | 174 BluetoothGattCharacteristic* characteristic, |
188 BluetoothGattDescriptor* descriptor) {} | 175 BluetoothGattDescriptor* descriptor) {} |
189 | 176 |
190 // Called when a GATT characteristic descriptor |descriptor| belonging to | 177 // Called when a GATT characteristic descriptor |descriptor| belonging to |
191 // characteristic |characteristic| has been removed. This method is for | 178 // characteristic |characteristic| has been removed. |
192 // convenience and will be followed by a call to GattServiceChanged (except | |
193 // when called after the service gets removed). | |
194 virtual void GattDescriptorRemoved( | 179 virtual void GattDescriptorRemoved( |
195 BluetoothGattCharacteristic* characteristic, | 180 BluetoothGattCharacteristic* characteristic, |
196 BluetoothGattDescriptor* descriptor) {} | 181 BluetoothGattDescriptor* descriptor) {} |
197 | 182 |
198 // Called when the value of a characteristic has changed. This might be a | 183 // Called when the value of a characteristic has changed. This might be a |
199 // result of a read/write request to, or a notification/indication from, a | 184 // result of a read/write request to, or a notification/indication from, a |
200 // remote GATT characteristic. | 185 // remote GATT characteristic. |
201 virtual void GattCharacteristicValueChanged( | 186 virtual void GattCharacteristicValueChanged( |
202 BluetoothGattService* service, | 187 BluetoothGattService* service, |
203 BluetoothGattCharacteristic* characteristic, | 188 BluetoothGattCharacteristic* characteristic, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 protected: | 283 protected: |
299 BluetoothGattService(); | 284 BluetoothGattService(); |
300 | 285 |
301 private: | 286 private: |
302 DISALLOW_COPY_AND_ASSIGN(BluetoothGattService); | 287 DISALLOW_COPY_AND_ASSIGN(BluetoothGattService); |
303 }; | 288 }; |
304 | 289 |
305 } // namespace device | 290 } // namespace device |
306 | 291 |
307 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_H_ | 292 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_SERVICE_H_ |
OLD | NEW |