prova invio BLE

Dependents:   BLE_HeartRate_IDB04A1

Fork of BLE_API by Bluetooth Low Energy

Committer:
vcoubard
Date:
Wed Apr 06 19:13:46 2016 +0100
Revision:
1131:692ddf04fc42
Parent:
1116:9cb51490b3f7
Child:
1135:22aada733dbd
Synchronized with git rev 13bf70b6
Author: Rohit Grover
Release 2.1.5
=============

A minor release to separate the concept of minlen and len in
GattCharacteristic. Also contains some improvements to documentation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 1131:692ddf04fc42 1 /* mbed Microcontroller Library
vcoubard 1131:692ddf04fc42 2 * Copyright (c) 2006-2013 ARM Limited
vcoubard 1131:692ddf04fc42 3 *
vcoubard 1131:692ddf04fc42 4 * Licensed under the Apache License, Version 2.0 (the "License");
vcoubard 1131:692ddf04fc42 5 * you may not use this file except in compliance with the License.
vcoubard 1131:692ddf04fc42 6 * You may obtain a copy of the License at
vcoubard 1131:692ddf04fc42 7 *
vcoubard 1131:692ddf04fc42 8 * http://www.apache.org/licenses/LICENSE-2.0
vcoubard 1131:692ddf04fc42 9 *
vcoubard 1131:692ddf04fc42 10 * Unless required by applicable law or agreed to in writing, software
vcoubard 1131:692ddf04fc42 11 * distributed under the License is distributed on an "AS IS" BASIS,
vcoubard 1131:692ddf04fc42 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
vcoubard 1131:692ddf04fc42 13 * See the License for the specific language governing permissions and
vcoubard 1131:692ddf04fc42 14 * limitations under the License.
vcoubard 1131:692ddf04fc42 15 */
vcoubard 1131:692ddf04fc42 16
vcoubard 1131:692ddf04fc42 17 #ifndef __GATT_CLIENT_H__
vcoubard 1131:692ddf04fc42 18 #define __GATT_CLIENT_H__
vcoubard 1131:692ddf04fc42 19
vcoubard 1131:692ddf04fc42 20 #include "Gap.h"
vcoubard 1131:692ddf04fc42 21 #include "GattAttribute.h"
vcoubard 1131:692ddf04fc42 22 #include "ServiceDiscovery.h"
vcoubard 1131:692ddf04fc42 23
vcoubard 1131:692ddf04fc42 24 #include "GattCallbackParamTypes.h"
vcoubard 1131:692ddf04fc42 25
vcoubard 1131:692ddf04fc42 26 #include "CallChainOfFunctionPointersWithContext.h"
vcoubard 1131:692ddf04fc42 27
vcoubard 1131:692ddf04fc42 28 class GattClient {
vcoubard 1131:692ddf04fc42 29 public:
vcoubard 1131:692ddf04fc42 30 typedef FunctionPointerWithContext<const GattReadCallbackParams*> ReadCallback_t;
vcoubard 1131:692ddf04fc42 31 typedef CallChainOfFunctionPointersWithContext<const GattReadCallbackParams*> ReadCallbackChain_t;
vcoubard 1131:692ddf04fc42 32
vcoubard 1131:692ddf04fc42 33 enum WriteOp_t {
vcoubard 1131:692ddf04fc42 34 GATT_OP_WRITE_REQ = 0x01, /**< Write request. */
vcoubard 1131:692ddf04fc42 35 GATT_OP_WRITE_CMD = 0x02, /**< Write command. */
vcoubard 1131:692ddf04fc42 36 };
vcoubard 1131:692ddf04fc42 37
vcoubard 1131:692ddf04fc42 38 typedef FunctionPointerWithContext<const GattWriteCallbackParams*> WriteCallback_t;
vcoubard 1131:692ddf04fc42 39 typedef CallChainOfFunctionPointersWithContext<const GattWriteCallbackParams*> WriteCallbackChain_t;
vcoubard 1131:692ddf04fc42 40
vcoubard 1131:692ddf04fc42 41 typedef FunctionPointerWithContext<const GattHVXCallbackParams*> HVXCallback_t;
vcoubard 1131:692ddf04fc42 42 typedef CallChainOfFunctionPointersWithContext<const GattHVXCallbackParams*> HVXCallbackChain_t;
vcoubard 1131:692ddf04fc42 43
vcoubard 1131:692ddf04fc42 44 /*
vcoubard 1131:692ddf04fc42 45 * The following functions are meant to be overridden in the platform-specific sub-class.
vcoubard 1131:692ddf04fc42 46 */
vcoubard 1131:692ddf04fc42 47 public:
vcoubard 1131:692ddf04fc42 48 /**
vcoubard 1131:692ddf04fc42 49 * Launch service discovery. Once launched, application callbacks will be
vcoubard 1131:692ddf04fc42 50 * invoked for matching services or characteristics. isServiceDiscoveryActive()
vcoubard 1131:692ddf04fc42 51 * can be used to determine status, and a termination callback (if one was set up)
vcoubard 1131:692ddf04fc42 52 * will be invoked at the end. Service discovery can be terminated prematurely,
vcoubard 1131:692ddf04fc42 53 * if needed, using terminateServiceDiscovery().
vcoubard 1131:692ddf04fc42 54 *
vcoubard 1131:692ddf04fc42 55 * @param connectionHandle
vcoubard 1131:692ddf04fc42 56 * Handle for the connection with the peer.
vcoubard 1131:692ddf04fc42 57 * @param sc
vcoubard 1131:692ddf04fc42 58 * This is the application callback for a matching service. Taken as
vcoubard 1131:692ddf04fc42 59 * NULL by default. Note: service discovery may still be active
vcoubard 1131:692ddf04fc42 60 * when this callback is issued; calling asynchronous BLE-stack
vcoubard 1131:692ddf04fc42 61 * APIs from within this application callback might cause the
vcoubard 1131:692ddf04fc42 62 * stack to abort service discovery. If this becomes an issue, it
vcoubard 1131:692ddf04fc42 63 * may be better to make a local copy of the discoveredService and
vcoubard 1131:692ddf04fc42 64 * wait for service discovery to terminate before operating on the
vcoubard 1131:692ddf04fc42 65 * service.
vcoubard 1131:692ddf04fc42 66 * @param cc
vcoubard 1131:692ddf04fc42 67 * This is the application callback for a matching characteristic.
vcoubard 1131:692ddf04fc42 68 * Taken as NULL by default. Note: service discovery may still be
vcoubard 1131:692ddf04fc42 69 * active when this callback is issued; calling asynchronous
vcoubard 1131:692ddf04fc42 70 * BLE-stack APIs from within this application callback might cause
vcoubard 1131:692ddf04fc42 71 * the stack to abort service discovery. If this becomes an issue,
vcoubard 1131:692ddf04fc42 72 * it may be better to make a local copy of the discoveredCharacteristic
vcoubard 1131:692ddf04fc42 73 * and wait for service discovery to terminate before operating on the
vcoubard 1131:692ddf04fc42 74 * characteristic.
vcoubard 1131:692ddf04fc42 75 * @param matchingServiceUUID
vcoubard 1131:692ddf04fc42 76 * UUID-based filter for specifying a service in which the application is
vcoubard 1131:692ddf04fc42 77 * interested. By default it is set as the wildcard UUID_UNKNOWN,
vcoubard 1131:692ddf04fc42 78 * in which case it matches all services. If characteristic-UUID
vcoubard 1131:692ddf04fc42 79 * filter (below) is set to the wildcard value, then a service
vcoubard 1131:692ddf04fc42 80 * callback will be invoked for the matching service (or for every
vcoubard 1131:692ddf04fc42 81 * service if the service filter is a wildcard).
vcoubard 1131:692ddf04fc42 82 * @param matchingCharacteristicUUIDIn
vcoubard 1131:692ddf04fc42 83 * UUID-based filter for specifying characteristic in which the application
vcoubard 1131:692ddf04fc42 84 * is interested. By default it is set as the wildcard UUID_UKNOWN
vcoubard 1131:692ddf04fc42 85 * to match against any characteristic. If both service-UUID
vcoubard 1131:692ddf04fc42 86 * filter and characteristic-UUID filter are used with non-wildcard
vcoubard 1131:692ddf04fc42 87 * values, then only a single characteristic callback is
vcoubard 1131:692ddf04fc42 88 * invoked for the matching characteristic.
vcoubard 1131:692ddf04fc42 89 *
vcoubard 1131:692ddf04fc42 90 * @note Using wildcard values for both service-UUID and characteristic-
vcoubard 1131:692ddf04fc42 91 * UUID will result in complete service discovery: callbacks being
vcoubard 1131:692ddf04fc42 92 * called for every service and characteristic.
vcoubard 1131:692ddf04fc42 93 *
vcoubard 1131:692ddf04fc42 94 * @note Providing NULL for the characteristic callback will result in
vcoubard 1131:692ddf04fc42 95 * characteristic discovery being skipped for each matching
vcoubard 1131:692ddf04fc42 96 * service. This allows for an inexpensive method to discover only
vcoubard 1131:692ddf04fc42 97 * services.
vcoubard 1131:692ddf04fc42 98 *
vcoubard 1131:692ddf04fc42 99 * @return
vcoubard 1131:692ddf04fc42 100 * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error.
vcoubard 1131:692ddf04fc42 101 */
vcoubard 1131:692ddf04fc42 102 virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle,
vcoubard 1131:692ddf04fc42 103 ServiceDiscovery::ServiceCallback_t sc = NULL,
vcoubard 1131:692ddf04fc42 104 ServiceDiscovery::CharacteristicCallback_t cc = NULL,
vcoubard 1131:692ddf04fc42 105 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
vcoubard 1131:692ddf04fc42 106 const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) {
vcoubard 1131:692ddf04fc42 107 /* Avoid compiler warnings about unused variables. */
vcoubard 1131:692ddf04fc42 108 (void)connectionHandle;
vcoubard 1131:692ddf04fc42 109 (void)sc;
vcoubard 1131:692ddf04fc42 110 (void)cc;
vcoubard 1131:692ddf04fc42 111 (void)matchingServiceUUID;
vcoubard 1131:692ddf04fc42 112 (void)matchingCharacteristicUUIDIn;
vcoubard 1131:692ddf04fc42 113
vcoubard 1131:692ddf04fc42 114 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */
vcoubard 1131:692ddf04fc42 115 }
vcoubard 1131:692ddf04fc42 116
vcoubard 1131:692ddf04fc42 117 /**
vcoubard 1131:692ddf04fc42 118 * Launch service discovery for services. Once launched, service discovery will remain
vcoubard 1131:692ddf04fc42 119 * active with service-callbacks being issued back into the application for matching
vcoubard 1131:692ddf04fc42 120 * services. isServiceDiscoveryActive() can be used to
vcoubard 1131:692ddf04fc42 121 * determine status, and a termination callback (if set up) will be invoked
vcoubard 1131:692ddf04fc42 122 * at the end. Service discovery can be terminated prematurely, if needed,
vcoubard 1131:692ddf04fc42 123 * using terminateServiceDiscovery().
vcoubard 1131:692ddf04fc42 124 *
vcoubard 1131:692ddf04fc42 125 * @param connectionHandle
vcoubard 1131:692ddf04fc42 126 * Handle for the connection with the peer.
vcoubard 1131:692ddf04fc42 127 * @param sc
vcoubard 1131:692ddf04fc42 128 * This is the application callback for a matching service. Note: service discovery may still be active
vcoubard 1131:692ddf04fc42 129 * when this callback is issued; calling asynchronous BLE-stack
vcoubard 1131:692ddf04fc42 130 * APIs from within this application callback might cause the
vcoubard 1131:692ddf04fc42 131 * stack to abort service discovery. If this becomes an issue, it
vcoubard 1131:692ddf04fc42 132 * may be better to make a local copy of the discoveredService and
vcoubard 1131:692ddf04fc42 133 * wait for service discovery to terminate before operating on the
vcoubard 1131:692ddf04fc42 134 * service.
vcoubard 1131:692ddf04fc42 135 * @param matchingServiceUUID
vcoubard 1131:692ddf04fc42 136 * UUID-based filter for specifying a service in which the application is
vcoubard 1131:692ddf04fc42 137 * interested. By default it is set as the wildcard UUID_UNKNOWN,
vcoubard 1131:692ddf04fc42 138 * in which case it matches all services.
vcoubard 1131:692ddf04fc42 139 *
vcoubard 1131:692ddf04fc42 140 * @return
vcoubard 1131:692ddf04fc42 141 * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error.
vcoubard 1131:692ddf04fc42 142 */
vcoubard 1131:692ddf04fc42 143 virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle,
vcoubard 1131:692ddf04fc42 144 ServiceDiscovery::ServiceCallback_t callback,
vcoubard 1131:692ddf04fc42 145 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) {
vcoubard 1131:692ddf04fc42 146 return launchServiceDiscovery(connectionHandle, callback, NULL, matchingServiceUUID); /* We take advantage of the property
vcoubard 1131:692ddf04fc42 147 * that providing NULL for the characteristic callback will result in
vcoubard 1131:692ddf04fc42 148 * characteristic discovery being skipped for each matching
vcoubard 1131:692ddf04fc42 149 * service. This allows for an inexpensive method to discover only
vcoubard 1131:692ddf04fc42 150 * services. Porters are free to override this. */
vcoubard 1131:692ddf04fc42 151 }
vcoubard 1131:692ddf04fc42 152
vcoubard 1131:692ddf04fc42 153 /**
vcoubard 1131:692ddf04fc42 154 * Launch service discovery for services. Once launched, service discovery will remain
vcoubard 1131:692ddf04fc42 155 * active with service-callbacks being issued back into the application for matching
vcoubard 1131:692ddf04fc42 156 * services. isServiceDiscoveryActive() can be used to
vcoubard 1131:692ddf04fc42 157 * determine status, and a termination callback (if set up) will be invoked
vcoubard 1131:692ddf04fc42 158 * at the end. Service discovery can be terminated prematurely, if needed,
vcoubard 1131:692ddf04fc42 159 * using terminateServiceDiscovery().
vcoubard 1131:692ddf04fc42 160 *
vcoubard 1131:692ddf04fc42 161 * @param connectionHandle
vcoubard 1131:692ddf04fc42 162 * Handle for the connection with the peer.
vcoubard 1131:692ddf04fc42 163 * @param sc
vcoubard 1131:692ddf04fc42 164 * This is the application callback for a matching service. Note: service discovery may still be active
vcoubard 1131:692ddf04fc42 165 * when this callback is issued; calling asynchronous BLE-stack
vcoubard 1131:692ddf04fc42 166 * APIs from within this application callback might cause the
vcoubard 1131:692ddf04fc42 167 * stack to abort service discovery. If this becomes an issue, it
vcoubard 1131:692ddf04fc42 168 * may be better to make a local copy of the discoveredService and
vcoubard 1131:692ddf04fc42 169 * wait for service discovery to terminate before operating on the
vcoubard 1131:692ddf04fc42 170 * service.
vcoubard 1131:692ddf04fc42 171 * @param startHandle, endHandle
vcoubard 1131:692ddf04fc42 172 * Handle range within which to limit the search.
vcoubard 1131:692ddf04fc42 173 *
vcoubard 1131:692ddf04fc42 174 * @return
vcoubard 1131:692ddf04fc42 175 * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error.
vcoubard 1131:692ddf04fc42 176 */
vcoubard 1131:692ddf04fc42 177 virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle,
vcoubard 1131:692ddf04fc42 178 ServiceDiscovery::ServiceCallback_t callback,
vcoubard 1131:692ddf04fc42 179 GattAttribute::Handle_t startHandle,
vcoubard 1131:692ddf04fc42 180 GattAttribute::Handle_t endHandle) {
vcoubard 1131:692ddf04fc42 181 /* Avoid compiler warnings about unused variables. */
vcoubard 1131:692ddf04fc42 182 (void)connectionHandle;
vcoubard 1131:692ddf04fc42 183 (void)callback;
vcoubard 1131:692ddf04fc42 184 (void)startHandle;
vcoubard 1131:692ddf04fc42 185 (void)endHandle;
vcoubard 1131:692ddf04fc42 186
vcoubard 1131:692ddf04fc42 187 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */
vcoubard 1131:692ddf04fc42 188 }
vcoubard 1131:692ddf04fc42 189
vcoubard 1131:692ddf04fc42 190 /**
vcoubard 1131:692ddf04fc42 191 * Is service-discovery currently active?
vcoubard 1131:692ddf04fc42 192 */
vcoubard 1131:692ddf04fc42 193 virtual bool isServiceDiscoveryActive(void) const {
vcoubard 1131:692ddf04fc42 194 return false; /* Requesting action from porters: override this API if this capability is supported. */
vcoubard 1131:692ddf04fc42 195 }
vcoubard 1131:692ddf04fc42 196
vcoubard 1131:692ddf04fc42 197 /**
vcoubard 1131:692ddf04fc42 198 * Terminate an ongoing service discovery. This should result in an
vcoubard 1131:692ddf04fc42 199 * invocation of TerminationCallback if service-discovery is active.
vcoubard 1131:692ddf04fc42 200 */
vcoubard 1131:692ddf04fc42 201 virtual void terminateServiceDiscovery(void) {
vcoubard 1131:692ddf04fc42 202 /* Requesting action from porters: override this API if this capability is supported. */
vcoubard 1131:692ddf04fc42 203 }
vcoubard 1131:692ddf04fc42 204
vcoubard 1131:692ddf04fc42 205 /* Initiate a GATT Client read procedure by attribute-handle. */
vcoubard 1131:692ddf04fc42 206 virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const {
vcoubard 1131:692ddf04fc42 207 /* Avoid compiler warnings about unused variables. */
vcoubard 1131:692ddf04fc42 208 (void)connHandle;
vcoubard 1131:692ddf04fc42 209 (void)attributeHandle;
vcoubard 1131:692ddf04fc42 210 (void)offset;
vcoubard 1131:692ddf04fc42 211
vcoubard 1131:692ddf04fc42 212 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */
vcoubard 1131:692ddf04fc42 213 }
vcoubard 1131:692ddf04fc42 214
vcoubard 1131:692ddf04fc42 215 /**
vcoubard 1131:692ddf04fc42 216 * Initiate a GATT Client write procedure.
vcoubard 1131:692ddf04fc42 217 *
vcoubard 1131:692ddf04fc42 218 * @param[in] cmd
vcoubard 1131:692ddf04fc42 219 * Command can be either a write-request (which generates a
vcoubard 1131:692ddf04fc42 220 * matching response from the peripheral), or a write-command
vcoubard 1131:692ddf04fc42 221 * (which doesn't require the connected peer to respond).
vcoubard 1131:692ddf04fc42 222 * @param[in] connHandle
vcoubard 1131:692ddf04fc42 223 * Connection handle.
vcoubard 1131:692ddf04fc42 224 * @param[in] attributeHandle
vcoubard 1131:692ddf04fc42 225 * Handle for the target attribtue on the remote GATT server.
vcoubard 1131:692ddf04fc42 226 * @param[in] length
vcoubard 1131:692ddf04fc42 227 * Length of the new value.
vcoubard 1131:692ddf04fc42 228 * @param[in] value
vcoubard 1131:692ddf04fc42 229 * New value being written.
vcoubard 1131:692ddf04fc42 230 */
vcoubard 1131:692ddf04fc42 231 virtual ble_error_t write(GattClient::WriteOp_t cmd,
vcoubard 1131:692ddf04fc42 232 Gap::Handle_t connHandle,
vcoubard 1131:692ddf04fc42 233 GattAttribute::Handle_t attributeHandle,
vcoubard 1131:692ddf04fc42 234 size_t length,
vcoubard 1131:692ddf04fc42 235 const uint8_t *value) const {
vcoubard 1131:692ddf04fc42 236 /* Avoid compiler warnings about unused variables. */
vcoubard 1131:692ddf04fc42 237 (void)cmd;
vcoubard 1131:692ddf04fc42 238 (void)connHandle;
vcoubard 1131:692ddf04fc42 239 (void)attributeHandle;
vcoubard 1131:692ddf04fc42 240 (void)length;
vcoubard 1131:692ddf04fc42 241 (void)value;
vcoubard 1131:692ddf04fc42 242
vcoubard 1131:692ddf04fc42 243 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */
vcoubard 1131:692ddf04fc42 244 }
vcoubard 1131:692ddf04fc42 245
vcoubard 1131:692ddf04fc42 246 /* Event callback handlers. */
vcoubard 1131:692ddf04fc42 247 public:
vcoubard 1131:692ddf04fc42 248 /**
vcoubard 1131:692ddf04fc42 249 * Set up a callback for read response events.
vcoubard 1131:692ddf04fc42 250 * It is possible to remove registered callbacks using
vcoubard 1131:692ddf04fc42 251 * onDataRead().detach(callbackToRemove)
vcoubard 1131:692ddf04fc42 252 */
vcoubard 1131:692ddf04fc42 253 void onDataRead(ReadCallback_t callback) {
vcoubard 1131:692ddf04fc42 254 onDataReadCallbackChain.add(callback);
vcoubard 1131:692ddf04fc42 255 }
vcoubard 1131:692ddf04fc42 256
vcoubard 1131:692ddf04fc42 257 /**
vcoubard 1131:692ddf04fc42 258 * @brief provide access to the callchain of read callbacks
vcoubard 1131:692ddf04fc42 259 * It is possible to register callbacks using onDataRead().add(callback);
vcoubard 1131:692ddf04fc42 260 * It is possible to unregister callbacks using onDataRead().detach(callback)
vcoubard 1131:692ddf04fc42 261 * @return The read callbacks chain
vcoubard 1131:692ddf04fc42 262 */
vcoubard 1131:692ddf04fc42 263 ReadCallbackChain_t& onDataRead() {
vcoubard 1131:692ddf04fc42 264 return onDataReadCallbackChain;
vcoubard 1131:692ddf04fc42 265 }
vcoubard 1131:692ddf04fc42 266
vcoubard 1131:692ddf04fc42 267 /**
vcoubard 1131:692ddf04fc42 268 * Set up a callback for write response events.
vcoubard 1131:692ddf04fc42 269 * It is possible to remove registered callbacks using
vcoubard 1131:692ddf04fc42 270 * onDataWritten().detach(callbackToRemove).
vcoubard 1131:692ddf04fc42 271 * @Note: Write commands (issued using writeWoResponse) don't generate a response.
vcoubard 1131:692ddf04fc42 272 */
vcoubard 1131:692ddf04fc42 273 void onDataWritten(WriteCallback_t callback) {
vcoubard 1131:692ddf04fc42 274 onDataWriteCallbackChain.add(callback);
vcoubard 1131:692ddf04fc42 275 }
vcoubard 1131:692ddf04fc42 276
vcoubard 1131:692ddf04fc42 277 /**
vcoubard 1131:692ddf04fc42 278 * @brief provide access to the callchain of data written callbacks
vcoubard 1131:692ddf04fc42 279 * It is possible to register callbacks using onDataWritten().add(callback);
vcoubard 1131:692ddf04fc42 280 * It is possible to unregister callbacks using onDataWritten().detach(callback)
vcoubard 1131:692ddf04fc42 281 * @return The data written callbacks chain
vcoubard 1131:692ddf04fc42 282 */
vcoubard 1131:692ddf04fc42 283 WriteCallbackChain_t& onDataWritten() {
vcoubard 1131:692ddf04fc42 284 return onDataWriteCallbackChain;
vcoubard 1131:692ddf04fc42 285 }
vcoubard 1131:692ddf04fc42 286
vcoubard 1131:692ddf04fc42 287 /**
vcoubard 1131:692ddf04fc42 288 * Set up a callback for write response events.
vcoubard 1131:692ddf04fc42 289 * @Note: Write commands (issued using writeWoResponse) don't generate a response.
vcoubard 1131:692ddf04fc42 290 *
vcoubard 1131:692ddf04fc42 291 * @note: This API is now *deprecated* and will be dropped in the future.
vcoubard 1131:692ddf04fc42 292 * Please use onDataWritten() instead.
vcoubard 1131:692ddf04fc42 293 */
vcoubard 1131:692ddf04fc42 294 void onDataWrite(WriteCallback_t callback) {
vcoubard 1131:692ddf04fc42 295 onDataWritten(callback);
vcoubard 1131:692ddf04fc42 296 }
vcoubard 1131:692ddf04fc42 297
vcoubard 1131:692ddf04fc42 298 /**
vcoubard 1131:692ddf04fc42 299 * Set up a callback for when serviceDiscovery terminates.
vcoubard 1131:692ddf04fc42 300 */
vcoubard 1131:692ddf04fc42 301 virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) {
vcoubard 1131:692ddf04fc42 302 (void)callback; /* Avoid compiler warnings about ununsed variables. */
vcoubard 1131:692ddf04fc42 303
vcoubard 1131:692ddf04fc42 304 /* Requesting action from porters: override this API if this capability is supported. */
vcoubard 1131:692ddf04fc42 305 }
vcoubard 1131:692ddf04fc42 306
vcoubard 1131:692ddf04fc42 307 /**
vcoubard 1131:692ddf04fc42 308 * Set up a callback for when the GATT client receives an update event
vcoubard 1131:692ddf04fc42 309 * corresponding to a change in the value of a characteristic on the remote
vcoubard 1131:692ddf04fc42 310 * GATT server.
vcoubard 1131:692ddf04fc42 311 * It is possible to remove registered callbacks using onHVX().detach(callbackToRemove).
vcoubard 1131:692ddf04fc42 312 */
vcoubard 1131:692ddf04fc42 313 void onHVX(HVXCallback_t callback) {
vcoubard 1131:692ddf04fc42 314 onHVXCallbackChain.add(callback);
vcoubard 1131:692ddf04fc42 315 }
vcoubard 1131:692ddf04fc42 316
vcoubard 1131:692ddf04fc42 317
vcoubard 1131:692ddf04fc42 318 /**
vcoubard 1131:692ddf04fc42 319 * @brief provide access to the callchain of HVX callbacks
vcoubard 1131:692ddf04fc42 320 * It is possible to register callbacks using onHVX().add(callback);
vcoubard 1131:692ddf04fc42 321 * It is possible to unregister callbacks using onHVX().detach(callback)
vcoubard 1131:692ddf04fc42 322 * @return The HVX callbacks chain
vcoubard 1131:692ddf04fc42 323 */
vcoubard 1131:692ddf04fc42 324 HVXCallbackChain_t& onHVX() {
vcoubard 1131:692ddf04fc42 325 return onHVXCallbackChain;
vcoubard 1131:692ddf04fc42 326 }
vcoubard 1131:692ddf04fc42 327
vcoubard 1131:692ddf04fc42 328 protected:
vcoubard 1131:692ddf04fc42 329 GattClient() {
vcoubard 1131:692ddf04fc42 330 /* Empty */
vcoubard 1131:692ddf04fc42 331 }
vcoubard 1131:692ddf04fc42 332
vcoubard 1131:692ddf04fc42 333 /* Entry points for the underlying stack to report events back to the user. */
vcoubard 1131:692ddf04fc42 334 public:
vcoubard 1131:692ddf04fc42 335 void processReadResponse(const GattReadCallbackParams *params) {
vcoubard 1131:692ddf04fc42 336 onDataReadCallbackChain(params);
vcoubard 1131:692ddf04fc42 337 }
vcoubard 1131:692ddf04fc42 338
vcoubard 1131:692ddf04fc42 339 void processWriteResponse(const GattWriteCallbackParams *params) {
vcoubard 1131:692ddf04fc42 340 onDataWriteCallbackChain(params);
vcoubard 1131:692ddf04fc42 341 }
vcoubard 1131:692ddf04fc42 342
vcoubard 1131:692ddf04fc42 343 void processHVXEvent(const GattHVXCallbackParams *params) {
vcoubard 1131:692ddf04fc42 344 if (onHVXCallbackChain) {
vcoubard 1131:692ddf04fc42 345 onHVXCallbackChain(params);
vcoubard 1131:692ddf04fc42 346 }
vcoubard 1131:692ddf04fc42 347 }
vcoubard 1131:692ddf04fc42 348
vcoubard 1131:692ddf04fc42 349 protected:
vcoubard 1131:692ddf04fc42 350 ReadCallbackChain_t onDataReadCallbackChain;
vcoubard 1131:692ddf04fc42 351 WriteCallbackChain_t onDataWriteCallbackChain;
vcoubard 1131:692ddf04fc42 352 HVXCallbackChain_t onHVXCallbackChain;
vcoubard 1131:692ddf04fc42 353
vcoubard 1131:692ddf04fc42 354 private:
vcoubard 1131:692ddf04fc42 355 /* Disallow copy and assignment. */
vcoubard 1131:692ddf04fc42 356 GattClient(const GattClient &);
vcoubard 1131:692ddf04fc42 357 GattClient& operator=(const GattClient &);
vcoubard 1131:692ddf04fc42 358 };
vcoubard 1131:692ddf04fc42 359
rgrover1 716:11b41f651697 360 #endif // ifndef __GATT_CLIENT_H__