Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Simon Cooksey 0:fb7af294d5d9 1 /* mbed Microcontroller Library
Simon Cooksey 0:fb7af294d5d9 2 * Copyright (c) 2006-2013 ARM Limited
Simon Cooksey 0:fb7af294d5d9 3 *
Simon Cooksey 0:fb7af294d5d9 4 * Licensed under the Apache License, Version 2.0 (the "License");
Simon Cooksey 0:fb7af294d5d9 5 * you may not use this file except in compliance with the License.
Simon Cooksey 0:fb7af294d5d9 6 * You may obtain a copy of the License at
Simon Cooksey 0:fb7af294d5d9 7 *
Simon Cooksey 0:fb7af294d5d9 8 * http://www.apache.org/licenses/LICENSE-2.0
Simon Cooksey 0:fb7af294d5d9 9 *
Simon Cooksey 0:fb7af294d5d9 10 * Unless required by applicable law or agreed to in writing, software
Simon Cooksey 0:fb7af294d5d9 11 * distributed under the License is distributed on an "AS IS" BASIS,
Simon Cooksey 0:fb7af294d5d9 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Simon Cooksey 0:fb7af294d5d9 13 * See the License for the specific language governing permissions and
Simon Cooksey 0:fb7af294d5d9 14 * limitations under the License.
Simon Cooksey 0:fb7af294d5d9 15 */
Simon Cooksey 0:fb7af294d5d9 16
Simon Cooksey 0:fb7af294d5d9 17 #ifndef __GATT_CLIENT_H__
Simon Cooksey 0:fb7af294d5d9 18 #define __GATT_CLIENT_H__
Simon Cooksey 0:fb7af294d5d9 19
Simon Cooksey 0:fb7af294d5d9 20 #include "Gap.h"
Simon Cooksey 0:fb7af294d5d9 21 #include "GattAttribute.h"
Simon Cooksey 0:fb7af294d5d9 22 #include "ServiceDiscovery.h"
Simon Cooksey 0:fb7af294d5d9 23 #include "CharacteristicDescriptorDiscovery.h"
Simon Cooksey 0:fb7af294d5d9 24
Simon Cooksey 0:fb7af294d5d9 25 #include "GattCallbackParamTypes.h"
Simon Cooksey 0:fb7af294d5d9 26
Simon Cooksey 0:fb7af294d5d9 27 #include "CallChainOfFunctionPointersWithContext.h"
Simon Cooksey 0:fb7af294d5d9 28
Simon Cooksey 0:fb7af294d5d9 29 class GattClient {
Simon Cooksey 0:fb7af294d5d9 30 public:
Simon Cooksey 0:fb7af294d5d9 31 /**
Simon Cooksey 0:fb7af294d5d9 32 * Type for the registered callbacks added to the data read callchain.
Simon Cooksey 0:fb7af294d5d9 33 * Refer to GattClient::onDataRead().
Simon Cooksey 0:fb7af294d5d9 34 */
Simon Cooksey 0:fb7af294d5d9 35 typedef FunctionPointerWithContext<const GattReadCallbackParams*> ReadCallback_t;
Simon Cooksey 0:fb7af294d5d9 36 /**
Simon Cooksey 0:fb7af294d5d9 37 * Type for the data read event callchain. Refer to GattClient::onDataRead().
Simon Cooksey 0:fb7af294d5d9 38 */
Simon Cooksey 0:fb7af294d5d9 39 typedef CallChainOfFunctionPointersWithContext<const GattReadCallbackParams*> ReadCallbackChain_t;
Simon Cooksey 0:fb7af294d5d9 40
Simon Cooksey 0:fb7af294d5d9 41 /**
Simon Cooksey 0:fb7af294d5d9 42 * Enumerator for write operations.
Simon Cooksey 0:fb7af294d5d9 43 */
Simon Cooksey 0:fb7af294d5d9 44 enum WriteOp_t {
Simon Cooksey 0:fb7af294d5d9 45 GATT_OP_WRITE_REQ = 0x01, /**< Write request. */
Simon Cooksey 0:fb7af294d5d9 46 GATT_OP_WRITE_CMD = 0x02, /**< Write command. */
Simon Cooksey 0:fb7af294d5d9 47 };
Simon Cooksey 0:fb7af294d5d9 48
Simon Cooksey 0:fb7af294d5d9 49 /**
Simon Cooksey 0:fb7af294d5d9 50 * Type for the registered callbacks added to the data write callchain.
Simon Cooksey 0:fb7af294d5d9 51 * Refer to GattClient::onDataWrite().
Simon Cooksey 0:fb7af294d5d9 52 */
Simon Cooksey 0:fb7af294d5d9 53 typedef FunctionPointerWithContext<const GattWriteCallbackParams*> WriteCallback_t;
Simon Cooksey 0:fb7af294d5d9 54 /**
Simon Cooksey 0:fb7af294d5d9 55 * Type for the data write event callchain. Refer to GattClient::onDataWrite().
Simon Cooksey 0:fb7af294d5d9 56 */
Simon Cooksey 0:fb7af294d5d9 57 typedef CallChainOfFunctionPointersWithContext<const GattWriteCallbackParams*> WriteCallbackChain_t;
Simon Cooksey 0:fb7af294d5d9 58
Simon Cooksey 0:fb7af294d5d9 59 /**
Simon Cooksey 0:fb7af294d5d9 60 * Type for the registered callbacks added to the update event callchain.
Simon Cooksey 0:fb7af294d5d9 61 * Refer to GattClient::onHVX().
Simon Cooksey 0:fb7af294d5d9 62 */
Simon Cooksey 0:fb7af294d5d9 63 typedef FunctionPointerWithContext<const GattHVXCallbackParams*> HVXCallback_t;
Simon Cooksey 0:fb7af294d5d9 64 /**
Simon Cooksey 0:fb7af294d5d9 65 * Type for the update event callchain. Refer to GattClient::onHVX().
Simon Cooksey 0:fb7af294d5d9 66 */
Simon Cooksey 0:fb7af294d5d9 67 typedef CallChainOfFunctionPointersWithContext<const GattHVXCallbackParams*> HVXCallbackChain_t;
Simon Cooksey 0:fb7af294d5d9 68
Simon Cooksey 0:fb7af294d5d9 69 /**
Simon Cooksey 0:fb7af294d5d9 70 * Type for the registered callbacks added to the shutdown callchain.
Simon Cooksey 0:fb7af294d5d9 71 * Refer to GattClient::onShutdown().
Simon Cooksey 0:fb7af294d5d9 72 */
Simon Cooksey 0:fb7af294d5d9 73 typedef FunctionPointerWithContext<const GattClient *> GattClientShutdownCallback_t;
Simon Cooksey 0:fb7af294d5d9 74 /**
Simon Cooksey 0:fb7af294d5d9 75 * Type for the shutdown event callchain. Refer to GattClient::onShutown().
Simon Cooksey 0:fb7af294d5d9 76 */
Simon Cooksey 0:fb7af294d5d9 77 typedef CallChainOfFunctionPointersWithContext<const GattClient *> GattClientShutdownCallbackChain_t;
Simon Cooksey 0:fb7af294d5d9 78
Simon Cooksey 0:fb7af294d5d9 79 /*
Simon Cooksey 0:fb7af294d5d9 80 * The following functions are meant to be overridden in the platform-specific sub-class.
Simon Cooksey 0:fb7af294d5d9 81 */
Simon Cooksey 0:fb7af294d5d9 82 public:
Simon Cooksey 0:fb7af294d5d9 83 /**
Simon Cooksey 0:fb7af294d5d9 84 * Launch service discovery. Once launched, application callbacks will be
Simon Cooksey 0:fb7af294d5d9 85 * invoked for matching services or characteristics. isServiceDiscoveryActive()
Simon Cooksey 0:fb7af294d5d9 86 * can be used to determine status, and a termination callback (if one was set up)
Simon Cooksey 0:fb7af294d5d9 87 * will be invoked at the end. Service discovery can be terminated prematurely,
Simon Cooksey 0:fb7af294d5d9 88 * if needed, using terminateServiceDiscovery().
Simon Cooksey 0:fb7af294d5d9 89 *
Simon Cooksey 0:fb7af294d5d9 90 * @param[in] connectionHandle
Simon Cooksey 0:fb7af294d5d9 91 * Handle for the connection with the peer.
Simon Cooksey 0:fb7af294d5d9 92 * @param[in] sc
Simon Cooksey 0:fb7af294d5d9 93 * This is the application callback for a matching service. Taken as
Simon Cooksey 0:fb7af294d5d9 94 * NULL by default. Note: service discovery may still be active
Simon Cooksey 0:fb7af294d5d9 95 * when this callback is issued; calling asynchronous BLE-stack
Simon Cooksey 0:fb7af294d5d9 96 * APIs from within this application callback might cause the
Simon Cooksey 0:fb7af294d5d9 97 * stack to abort service discovery. If this becomes an issue, it
Simon Cooksey 0:fb7af294d5d9 98 * may be better to make a local copy of the discoveredService and
Simon Cooksey 0:fb7af294d5d9 99 * wait for service discovery to terminate before operating on the
Simon Cooksey 0:fb7af294d5d9 100 * service.
Simon Cooksey 0:fb7af294d5d9 101 * @param[in] cc
Simon Cooksey 0:fb7af294d5d9 102 * This is the application callback for a matching characteristic.
Simon Cooksey 0:fb7af294d5d9 103 * Taken as NULL by default. Note: service discovery may still be
Simon Cooksey 0:fb7af294d5d9 104 * active when this callback is issued; calling asynchronous
Simon Cooksey 0:fb7af294d5d9 105 * BLE-stack APIs from within this application callback might cause
Simon Cooksey 0:fb7af294d5d9 106 * the stack to abort service discovery. If this becomes an issue,
Simon Cooksey 0:fb7af294d5d9 107 * it may be better to make a local copy of the discoveredCharacteristic
Simon Cooksey 0:fb7af294d5d9 108 * and wait for service discovery to terminate before operating on the
Simon Cooksey 0:fb7af294d5d9 109 * characteristic.
Simon Cooksey 0:fb7af294d5d9 110 * @param[in] matchingServiceUUID
Simon Cooksey 0:fb7af294d5d9 111 * UUID-based filter for specifying a service in which the application is
Simon Cooksey 0:fb7af294d5d9 112 * interested. By default it is set as the wildcard UUID_UNKNOWN,
Simon Cooksey 0:fb7af294d5d9 113 * in which case it matches all services. If characteristic-UUID
Simon Cooksey 0:fb7af294d5d9 114 * filter (below) is set to the wildcard value, then a service
Simon Cooksey 0:fb7af294d5d9 115 * callback will be invoked for the matching service (or for every
Simon Cooksey 0:fb7af294d5d9 116 * service if the service filter is a wildcard).
Simon Cooksey 0:fb7af294d5d9 117 * @param[in] matchingCharacteristicUUIDIn
Simon Cooksey 0:fb7af294d5d9 118 * UUID-based filter for specifying characteristic in which the application
Simon Cooksey 0:fb7af294d5d9 119 * is interested. By default it is set as the wildcard UUID_UKNOWN
Simon Cooksey 0:fb7af294d5d9 120 * to match against any characteristic. If both service-UUID
Simon Cooksey 0:fb7af294d5d9 121 * filter and characteristic-UUID filter are used with non-wildcard
Simon Cooksey 0:fb7af294d5d9 122 * values, then only a single characteristic callback is
Simon Cooksey 0:fb7af294d5d9 123 * invoked for the matching characteristic.
Simon Cooksey 0:fb7af294d5d9 124 *
Simon Cooksey 0:fb7af294d5d9 125 * @note Using wildcard values for both service-UUID and characteristic-
Simon Cooksey 0:fb7af294d5d9 126 * UUID will result in complete service discovery: callbacks being
Simon Cooksey 0:fb7af294d5d9 127 * called for every service and characteristic.
Simon Cooksey 0:fb7af294d5d9 128 *
Simon Cooksey 0:fb7af294d5d9 129 * @note Providing NULL for the characteristic callback will result in
Simon Cooksey 0:fb7af294d5d9 130 * characteristic discovery being skipped for each matching
Simon Cooksey 0:fb7af294d5d9 131 * service. This allows for an inexpensive method to discover only
Simon Cooksey 0:fb7af294d5d9 132 * services.
Simon Cooksey 0:fb7af294d5d9 133 *
Simon Cooksey 0:fb7af294d5d9 134 * @return
Simon Cooksey 0:fb7af294d5d9 135 * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error.
Simon Cooksey 0:fb7af294d5d9 136 */
Simon Cooksey 0:fb7af294d5d9 137 virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle,
Simon Cooksey 0:fb7af294d5d9 138 ServiceDiscovery::ServiceCallback_t sc = NULL,
Simon Cooksey 0:fb7af294d5d9 139 ServiceDiscovery::CharacteristicCallback_t cc = NULL,
Simon Cooksey 0:fb7af294d5d9 140 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
Simon Cooksey 0:fb7af294d5d9 141 const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) {
Simon Cooksey 0:fb7af294d5d9 142 /* Avoid compiler warnings about unused variables. */
Simon Cooksey 0:fb7af294d5d9 143 (void)connectionHandle;
Simon Cooksey 0:fb7af294d5d9 144 (void)sc;
Simon Cooksey 0:fb7af294d5d9 145 (void)cc;
Simon Cooksey 0:fb7af294d5d9 146 (void)matchingServiceUUID;
Simon Cooksey 0:fb7af294d5d9 147 (void)matchingCharacteristicUUIDIn;
Simon Cooksey 0:fb7af294d5d9 148
Simon Cooksey 0:fb7af294d5d9 149 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */
Simon Cooksey 0:fb7af294d5d9 150 }
Simon Cooksey 0:fb7af294d5d9 151
Simon Cooksey 0:fb7af294d5d9 152 /**
Simon Cooksey 0:fb7af294d5d9 153 * Launch service discovery for services. Once launched, service discovery will remain
Simon Cooksey 0:fb7af294d5d9 154 * active with service-callbacks being issued back into the application for matching
Simon Cooksey 0:fb7af294d5d9 155 * services. isServiceDiscoveryActive() can be used to
Simon Cooksey 0:fb7af294d5d9 156 * determine status, and a termination callback (if set up) will be invoked
Simon Cooksey 0:fb7af294d5d9 157 * at the end. Service discovery can be terminated prematurely, if needed,
Simon Cooksey 0:fb7af294d5d9 158 * using terminateServiceDiscovery().
Simon Cooksey 0:fb7af294d5d9 159 *
Simon Cooksey 0:fb7af294d5d9 160 * @param[in] connectionHandle
Simon Cooksey 0:fb7af294d5d9 161 * Handle for the connection with the peer.
Simon Cooksey 0:fb7af294d5d9 162 * @param[in] callback
Simon Cooksey 0:fb7af294d5d9 163 * This is the application callback for a matching service.
Simon Cooksey 0:fb7af294d5d9 164 * Note: service discovery may still be active
Simon Cooksey 0:fb7af294d5d9 165 * when this callback is issued; calling asynchronous BLE-stack
Simon Cooksey 0:fb7af294d5d9 166 * APIs from within this application callback might cause the
Simon Cooksey 0:fb7af294d5d9 167 * stack to abort service discovery. If this becomes an issue, it
Simon Cooksey 0:fb7af294d5d9 168 * may be better to make a local copy of the discoveredService and
Simon Cooksey 0:fb7af294d5d9 169 * wait for service discovery to terminate before operating on the
Simon Cooksey 0:fb7af294d5d9 170 * service.
Simon Cooksey 0:fb7af294d5d9 171 * @param[in] matchingServiceUUID
Simon Cooksey 0:fb7af294d5d9 172 * UUID-based filter for specifying a service in which the application is
Simon Cooksey 0:fb7af294d5d9 173 * interested. By default it is set as the wildcard UUID_UNKNOWN,
Simon Cooksey 0:fb7af294d5d9 174 * in which case it matches all services.
Simon Cooksey 0:fb7af294d5d9 175 *
Simon Cooksey 0:fb7af294d5d9 176 * @return
Simon Cooksey 0:fb7af294d5d9 177 * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error.
Simon Cooksey 0:fb7af294d5d9 178 */
Simon Cooksey 0:fb7af294d5d9 179 virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle,
Simon Cooksey 0:fb7af294d5d9 180 ServiceDiscovery::ServiceCallback_t callback,
Simon Cooksey 0:fb7af294d5d9 181 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) {
Simon Cooksey 0:fb7af294d5d9 182 return launchServiceDiscovery(connectionHandle, callback, NULL, matchingServiceUUID); /* We take advantage of the property
Simon Cooksey 0:fb7af294d5d9 183 * that providing NULL for the characteristic callback will result in
Simon Cooksey 0:fb7af294d5d9 184 * characteristic discovery being skipped for each matching
Simon Cooksey 0:fb7af294d5d9 185 * service. This allows for an inexpensive method to discover only
Simon Cooksey 0:fb7af294d5d9 186 * services. Porters are free to override this. */
Simon Cooksey 0:fb7af294d5d9 187 }
Simon Cooksey 0:fb7af294d5d9 188
Simon Cooksey 0:fb7af294d5d9 189 /**
Simon Cooksey 0:fb7af294d5d9 190 * Launch service discovery for services. Once launched, service discovery will remain
Simon Cooksey 0:fb7af294d5d9 191 * active with service-callbacks being issued back into the application for matching
Simon Cooksey 0:fb7af294d5d9 192 * services. isServiceDiscoveryActive() can be used to
Simon Cooksey 0:fb7af294d5d9 193 * determine status, and a termination callback (if set up) will be invoked
Simon Cooksey 0:fb7af294d5d9 194 * at the end. Service discovery can be terminated prematurely, if needed,
Simon Cooksey 0:fb7af294d5d9 195 * using terminateServiceDiscovery().
Simon Cooksey 0:fb7af294d5d9 196 *
Simon Cooksey 0:fb7af294d5d9 197 * @param[in] connectionHandle
Simon Cooksey 0:fb7af294d5d9 198 * Handle for the connection with the peer.
Simon Cooksey 0:fb7af294d5d9 199 * @param[in] callback
Simon Cooksey 0:fb7af294d5d9 200 * This is the application callback for a matching service.
Simon Cooksey 0:fb7af294d5d9 201 * Note: service discovery may still be active
Simon Cooksey 0:fb7af294d5d9 202 * when this callback is issued; calling asynchronous BLE-stack
Simon Cooksey 0:fb7af294d5d9 203 * APIs from within this application callback might cause the
Simon Cooksey 0:fb7af294d5d9 204 * stack to abort service discovery. If this becomes an issue, it
Simon Cooksey 0:fb7af294d5d9 205 * may be better to make a local copy of the discoveredService and
Simon Cooksey 0:fb7af294d5d9 206 * wait for service discovery to terminate before operating on the
Simon Cooksey 0:fb7af294d5d9 207 * service.
Simon Cooksey 0:fb7af294d5d9 208 * @param[in] startHandle, endHandle
Simon Cooksey 0:fb7af294d5d9 209 * Handle range within which to limit the search.
Simon Cooksey 0:fb7af294d5d9 210 *
Simon Cooksey 0:fb7af294d5d9 211 * @return
Simon Cooksey 0:fb7af294d5d9 212 * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error.
Simon Cooksey 0:fb7af294d5d9 213 */
Simon Cooksey 0:fb7af294d5d9 214 virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle,
Simon Cooksey 0:fb7af294d5d9 215 ServiceDiscovery::ServiceCallback_t callback,
Simon Cooksey 0:fb7af294d5d9 216 GattAttribute::Handle_t startHandle,
Simon Cooksey 0:fb7af294d5d9 217 GattAttribute::Handle_t endHandle) {
Simon Cooksey 0:fb7af294d5d9 218 /* Avoid compiler warnings about unused variables. */
Simon Cooksey 0:fb7af294d5d9 219 (void)connectionHandle;
Simon Cooksey 0:fb7af294d5d9 220 (void)callback;
Simon Cooksey 0:fb7af294d5d9 221 (void)startHandle;
Simon Cooksey 0:fb7af294d5d9 222 (void)endHandle;
Simon Cooksey 0:fb7af294d5d9 223
Simon Cooksey 0:fb7af294d5d9 224 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */
Simon Cooksey 0:fb7af294d5d9 225 }
Simon Cooksey 0:fb7af294d5d9 226
Simon Cooksey 0:fb7af294d5d9 227 /**
Simon Cooksey 0:fb7af294d5d9 228 * Check if service-discovery is currently active.
Simon Cooksey 0:fb7af294d5d9 229 *
Simon Cooksey 0:fb7af294d5d9 230 * @return true if service-discovery is active, false otherwise.
Simon Cooksey 0:fb7af294d5d9 231 */
Simon Cooksey 0:fb7af294d5d9 232 virtual bool isServiceDiscoveryActive(void) const {
Simon Cooksey 0:fb7af294d5d9 233 return false; /* Requesting action from porters: override this API if this capability is supported. */
Simon Cooksey 0:fb7af294d5d9 234 }
Simon Cooksey 0:fb7af294d5d9 235
Simon Cooksey 0:fb7af294d5d9 236 /**
Simon Cooksey 0:fb7af294d5d9 237 * Terminate an ongoing service discovery. This should result in an
Simon Cooksey 0:fb7af294d5d9 238 * invocation of TerminationCallback if service-discovery is active.
Simon Cooksey 0:fb7af294d5d9 239 */
Simon Cooksey 0:fb7af294d5d9 240 virtual void terminateServiceDiscovery(void) {
Simon Cooksey 0:fb7af294d5d9 241 /* Requesting action from porters: override this API if this capability is supported. */
Simon Cooksey 0:fb7af294d5d9 242 }
Simon Cooksey 0:fb7af294d5d9 243
Simon Cooksey 0:fb7af294d5d9 244 /**
Simon Cooksey 0:fb7af294d5d9 245 * Initiate a GATT Client read procedure by attribute-handle.
Simon Cooksey 0:fb7af294d5d9 246 *
Simon Cooksey 0:fb7af294d5d9 247 * @param[in] connHandle
Simon Cooksey 0:fb7af294d5d9 248 * Handle for the connection with the peer.
Simon Cooksey 0:fb7af294d5d9 249 * @param[in] attributeHandle
Simon Cooksey 0:fb7af294d5d9 250 * Handle of the attribute to read data from.
Simon Cooksey 0:fb7af294d5d9 251 * @param[in] offset
Simon Cooksey 0:fb7af294d5d9 252 * The offset from the start of the attribute value to be read.
Simon Cooksey 0:fb7af294d5d9 253 *
Simon Cooksey 0:fb7af294d5d9 254 * @return
Simon Cooksey 0:fb7af294d5d9 255 * BLE_ERROR_NONE if read procedure was successfully started.
Simon Cooksey 0:fb7af294d5d9 256 */
Simon Cooksey 0:fb7af294d5d9 257 virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const {
Simon Cooksey 0:fb7af294d5d9 258 /* Avoid compiler warnings about unused variables. */
Simon Cooksey 0:fb7af294d5d9 259 (void)connHandle;
Simon Cooksey 0:fb7af294d5d9 260 (void)attributeHandle;
Simon Cooksey 0:fb7af294d5d9 261 (void)offset;
Simon Cooksey 0:fb7af294d5d9 262
Simon Cooksey 0:fb7af294d5d9 263 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */
Simon Cooksey 0:fb7af294d5d9 264 }
Simon Cooksey 0:fb7af294d5d9 265
Simon Cooksey 0:fb7af294d5d9 266 /**
Simon Cooksey 0:fb7af294d5d9 267 * Initiate a GATT Client write procedure.
Simon Cooksey 0:fb7af294d5d9 268 *
Simon Cooksey 0:fb7af294d5d9 269 * @param[in] cmd
Simon Cooksey 0:fb7af294d5d9 270 * Command can be either a write-request (which generates a
Simon Cooksey 0:fb7af294d5d9 271 * matching response from the peripheral), or a write-command
Simon Cooksey 0:fb7af294d5d9 272 * (which doesn't require the connected peer to respond).
Simon Cooksey 0:fb7af294d5d9 273 * @param[in] connHandle
Simon Cooksey 0:fb7af294d5d9 274 * Connection handle.
Simon Cooksey 0:fb7af294d5d9 275 * @param[in] attributeHandle
Simon Cooksey 0:fb7af294d5d9 276 * Handle for the target attribtue on the remote GATT server.
Simon Cooksey 0:fb7af294d5d9 277 * @param[in] length
Simon Cooksey 0:fb7af294d5d9 278 * Length of the new value.
Simon Cooksey 0:fb7af294d5d9 279 * @param[in] value
Simon Cooksey 0:fb7af294d5d9 280 * New value being written.
Simon Cooksey 0:fb7af294d5d9 281 *
Simon Cooksey 0:fb7af294d5d9 282 * @return
Simon Cooksey 0:fb7af294d5d9 283 * BLE_ERROR_NONE if write procedure was successfully started.
Simon Cooksey 0:fb7af294d5d9 284 */
Simon Cooksey 0:fb7af294d5d9 285 virtual ble_error_t write(GattClient::WriteOp_t cmd,
Simon Cooksey 0:fb7af294d5d9 286 Gap::Handle_t connHandle,
Simon Cooksey 0:fb7af294d5d9 287 GattAttribute::Handle_t attributeHandle,
Simon Cooksey 0:fb7af294d5d9 288 size_t length,
Simon Cooksey 0:fb7af294d5d9 289 const uint8_t *value) const {
Simon Cooksey 0:fb7af294d5d9 290 /* Avoid compiler warnings about unused variables. */
Simon Cooksey 0:fb7af294d5d9 291 (void)cmd;
Simon Cooksey 0:fb7af294d5d9 292 (void)connHandle;
Simon Cooksey 0:fb7af294d5d9 293 (void)attributeHandle;
Simon Cooksey 0:fb7af294d5d9 294 (void)length;
Simon Cooksey 0:fb7af294d5d9 295 (void)value;
Simon Cooksey 0:fb7af294d5d9 296
Simon Cooksey 0:fb7af294d5d9 297 return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */
Simon Cooksey 0:fb7af294d5d9 298 }
Simon Cooksey 0:fb7af294d5d9 299
Simon Cooksey 0:fb7af294d5d9 300 /* Event callback handlers. */
Simon Cooksey 0:fb7af294d5d9 301 public:
Simon Cooksey 0:fb7af294d5d9 302 /**
Simon Cooksey 0:fb7af294d5d9 303 * Set up a callback for read response events.
Simon Cooksey 0:fb7af294d5d9 304 *
Simon Cooksey 0:fb7af294d5d9 305 * @param[in] callback
Simon Cooksey 0:fb7af294d5d9 306 * Event handler being registered.
Simon Cooksey 0:fb7af294d5d9 307 *
Simon Cooksey 0:fb7af294d5d9 308 * @note It is possible to chain together multiple onDataRead callbacks
Simon Cooksey 0:fb7af294d5d9 309 * (potentially from different modules of an application).
Simon Cooksey 0:fb7af294d5d9 310 *
Simon Cooksey 0:fb7af294d5d9 311 * @note It is possible to unregister a callback using
Simon Cooksey 0:fb7af294d5d9 312 * onDataRead().detach(callbackToRemove).
Simon Cooksey 0:fb7af294d5d9 313 */
Simon Cooksey 0:fb7af294d5d9 314 void onDataRead(ReadCallback_t callback) {
Simon Cooksey 0:fb7af294d5d9 315 onDataReadCallbackChain.add(callback);
Simon Cooksey 0:fb7af294d5d9 316 }
Simon Cooksey 0:fb7af294d5d9 317
Simon Cooksey 0:fb7af294d5d9 318 /**
Simon Cooksey 0:fb7af294d5d9 319 * @brief Provide access to the callchain of read event callbacks.
Simon Cooksey 0:fb7af294d5d9 320 *
Simon Cooksey 0:fb7af294d5d9 321 * @return A reference to the read event callback chain.
Simon Cooksey 0:fb7af294d5d9 322 *
Simon Cooksey 0:fb7af294d5d9 323 * @note It is possible to register callbacks using onDataRead().add(callback).
Simon Cooksey 0:fb7af294d5d9 324 *
Simon Cooksey 0:fb7af294d5d9 325 * @note It is possible to unregister callbacks using onDataRead().detach(callback).
Simon Cooksey 0:fb7af294d5d9 326 */
Simon Cooksey 0:fb7af294d5d9 327 ReadCallbackChain_t& onDataRead() {
Simon Cooksey 0:fb7af294d5d9 328 return onDataReadCallbackChain;
Simon Cooksey 0:fb7af294d5d9 329 }
Simon Cooksey 0:fb7af294d5d9 330
Simon Cooksey 0:fb7af294d5d9 331 /**
Simon Cooksey 0:fb7af294d5d9 332 * Set up a callback for write response events.
Simon Cooksey 0:fb7af294d5d9 333 *
Simon Cooksey 0:fb7af294d5d9 334 * @param[in] callback
Simon Cooksey 0:fb7af294d5d9 335 * Event handler being registered.
Simon Cooksey 0:fb7af294d5d9 336 *
Simon Cooksey 0:fb7af294d5d9 337 * @note It is possible to remove registered callbacks using
Simon Cooksey 0:fb7af294d5d9 338 * onDataWritten().detach(callbackToRemove).
Simon Cooksey 0:fb7af294d5d9 339 *
Simon Cooksey 0:fb7af294d5d9 340 * @note Write commands (issued using writeWoResponse) don't generate a response.
Simon Cooksey 0:fb7af294d5d9 341 */
Simon Cooksey 0:fb7af294d5d9 342 void onDataWritten(WriteCallback_t callback) {
Simon Cooksey 0:fb7af294d5d9 343 onDataWriteCallbackChain.add(callback);
Simon Cooksey 0:fb7af294d5d9 344 }
Simon Cooksey 0:fb7af294d5d9 345
Simon Cooksey 0:fb7af294d5d9 346 /**
Simon Cooksey 0:fb7af294d5d9 347 * @brief Provide access to the callchain of data written callbacks.
Simon Cooksey 0:fb7af294d5d9 348 *
Simon Cooksey 0:fb7af294d5d9 349 * @return A reference to the data written callbacks chain.
Simon Cooksey 0:fb7af294d5d9 350 *
Simon Cooksey 0:fb7af294d5d9 351 * @note It is possible to register callbacks using onDataWritten().add(callback).
Simon Cooksey 0:fb7af294d5d9 352 *
Simon Cooksey 0:fb7af294d5d9 353 * @note It is possible to unregister callbacks using onDataWritten().detach(callback).
Simon Cooksey 0:fb7af294d5d9 354 */
Simon Cooksey 0:fb7af294d5d9 355 WriteCallbackChain_t& onDataWritten() {
Simon Cooksey 0:fb7af294d5d9 356 return onDataWriteCallbackChain;
Simon Cooksey 0:fb7af294d5d9 357 }
Simon Cooksey 0:fb7af294d5d9 358
Simon Cooksey 0:fb7af294d5d9 359 /**
Simon Cooksey 0:fb7af294d5d9 360 * Set up a callback for write response events.
Simon Cooksey 0:fb7af294d5d9 361 *
Simon Cooksey 0:fb7af294d5d9 362 * @param[in] callback
Simon Cooksey 0:fb7af294d5d9 363 * Event handler being registered.
Simon Cooksey 0:fb7af294d5d9 364 *
Simon Cooksey 0:fb7af294d5d9 365 * @note Write commands (issued using writeWoResponse) don't generate a response.
Simon Cooksey 0:fb7af294d5d9 366 *
Simon Cooksey 0:fb7af294d5d9 367 * @deprecated Please use GattServer::onDataWritten() instead.
Simon Cooksey 0:fb7af294d5d9 368 */
Simon Cooksey 0:fb7af294d5d9 369 void onDataWrite(WriteCallback_t callback) {
Simon Cooksey 0:fb7af294d5d9 370 onDataWritten(callback);
Simon Cooksey 0:fb7af294d5d9 371 }
Simon Cooksey 0:fb7af294d5d9 372
Simon Cooksey 0:fb7af294d5d9 373 /**
Simon Cooksey 0:fb7af294d5d9 374 * Set up a callback for when serviceDiscovery terminates.
Simon Cooksey 0:fb7af294d5d9 375 *
Simon Cooksey 0:fb7af294d5d9 376 * @param[in] callback
Simon Cooksey 0:fb7af294d5d9 377 * Event handler being registered.
Simon Cooksey 0:fb7af294d5d9 378 */
Simon Cooksey 0:fb7af294d5d9 379 virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) {
Simon Cooksey 0:fb7af294d5d9 380 (void)callback; /* Avoid compiler warnings about ununsed variables. */
Simon Cooksey 0:fb7af294d5d9 381
Simon Cooksey 0:fb7af294d5d9 382 /* Requesting action from porters: override this API if this capability is supported. */
Simon Cooksey 0:fb7af294d5d9 383 }
Simon Cooksey 0:fb7af294d5d9 384
Simon Cooksey 0:fb7af294d5d9 385 /**
Simon Cooksey 0:fb7af294d5d9 386 * @brief Launch discovery of descriptors for a given characteristic.
Simon Cooksey 0:fb7af294d5d9 387 *
Simon Cooksey 0:fb7af294d5d9 388 * @details This function will discover all descriptors available for a
Simon Cooksey 0:fb7af294d5d9 389 * specific characteristic.
Simon Cooksey 0:fb7af294d5d9 390 *
Simon Cooksey 0:fb7af294d5d9 391 * @param[in] characteristic
Simon Cooksey 0:fb7af294d5d9 392 * The characteristic targeted by this discovery procedure.
Simon Cooksey 0:fb7af294d5d9 393 * @param[in] discoveryCallback
Simon Cooksey 0:fb7af294d5d9 394 * User function called each time a descriptor is found during
Simon Cooksey 0:fb7af294d5d9 395 * the procedure.
Simon Cooksey 0:fb7af294d5d9 396 * @param[in] terminationCallback
Simon Cooksey 0:fb7af294d5d9 397 * User provided function which will be called once the
Simon Cooksey 0:fb7af294d5d9 398 * discovery procedure is terminating. This will get called
Simon Cooksey 0:fb7af294d5d9 399 * when all the descriptors have been discovered or if an
Simon Cooksey 0:fb7af294d5d9 400 * error occur during the discovery procedure.
Simon Cooksey 0:fb7af294d5d9 401 *
Simon Cooksey 0:fb7af294d5d9 402 * @return
Simon Cooksey 0:fb7af294d5d9 403 * BLE_ERROR_NONE if characteristic descriptor discovery is launched
Simon Cooksey 0:fb7af294d5d9 404 * successfully; else an appropriate error.
Simon Cooksey 0:fb7af294d5d9 405 */
Simon Cooksey 0:fb7af294d5d9 406 virtual ble_error_t discoverCharacteristicDescriptors(
Simon Cooksey 0:fb7af294d5d9 407 const DiscoveredCharacteristic& characteristic,
Simon Cooksey 0:fb7af294d5d9 408 const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
Simon Cooksey 0:fb7af294d5d9 409 const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback) {
Simon Cooksey 0:fb7af294d5d9 410 (void) characteristic;
Simon Cooksey 0:fb7af294d5d9 411 (void) discoveryCallback;
Simon Cooksey 0:fb7af294d5d9 412 (void) terminationCallback;
Simon Cooksey 0:fb7af294d5d9 413 /* Requesting action from porter(s): override this API if this capability is supported. */
Simon Cooksey 0:fb7af294d5d9 414 return BLE_ERROR_NOT_IMPLEMENTED;
Simon Cooksey 0:fb7af294d5d9 415 }
Simon Cooksey 0:fb7af294d5d9 416
Simon Cooksey 0:fb7af294d5d9 417 /**
Simon Cooksey 0:fb7af294d5d9 418 * @brief Indicate if the discovery of characteristic descriptors is active
Simon Cooksey 0:fb7af294d5d9 419 * for a given characteristic or not.
Simon Cooksey 0:fb7af294d5d9 420 *
Simon Cooksey 0:fb7af294d5d9 421 * @param[in] characteristic
Simon Cooksey 0:fb7af294d5d9 422 * The characteristic concerned by the descriptors discovery.
Simon Cooksey 0:fb7af294d5d9 423 *
Simon Cooksey 0:fb7af294d5d9 424 * @return true if a descriptors discovery is active for the characteristic
Simon Cooksey 0:fb7af294d5d9 425 * in input; otherwise false.
Simon Cooksey 0:fb7af294d5d9 426 */
Simon Cooksey 0:fb7af294d5d9 427 virtual bool isCharacteristicDescriptorDiscoveryActive(const DiscoveredCharacteristic& characteristic) const
Simon Cooksey 0:fb7af294d5d9 428 {
Simon Cooksey 0:fb7af294d5d9 429 (void) characteristic;
Simon Cooksey 0:fb7af294d5d9 430 return false; /* Requesting action from porter(s): override this API if this capability is supported. */
Simon Cooksey 0:fb7af294d5d9 431 }
Simon Cooksey 0:fb7af294d5d9 432
Simon Cooksey 0:fb7af294d5d9 433 /**
Simon Cooksey 0:fb7af294d5d9 434 * @brief Terminate an ongoing characteristic descriptor discovery.
Simon Cooksey 0:fb7af294d5d9 435 *
Simon Cooksey 0:fb7af294d5d9 436 * @details This should result in an invocation of the TerminationCallback if
Simon Cooksey 0:fb7af294d5d9 437 * the characteristic descriptor discovery is active.
Simon Cooksey 0:fb7af294d5d9 438 *
Simon Cooksey 0:fb7af294d5d9 439 * @param[in] characteristic
Simon Cooksey 0:fb7af294d5d9 440 * The characteristic on which the running descriptors
Simon Cooksey 0:fb7af294d5d9 441 * discovery should be stopped.
Simon Cooksey 0:fb7af294d5d9 442 */
Simon Cooksey 0:fb7af294d5d9 443 virtual void terminateCharacteristicDescriptorDiscovery(const DiscoveredCharacteristic& characteristic) {
Simon Cooksey 0:fb7af294d5d9 444 /* Requesting action from porter(s): override this API if this capability is supported. */
Simon Cooksey 0:fb7af294d5d9 445 (void) characteristic;
Simon Cooksey 0:fb7af294d5d9 446 }
Simon Cooksey 0:fb7af294d5d9 447
Simon Cooksey 0:fb7af294d5d9 448 /**
Simon Cooksey 0:fb7af294d5d9 449 * Set up a callback for when the GATT Client receives an update event
Simon Cooksey 0:fb7af294d5d9 450 * corresponding to a change in the value of a characteristic on the remote
Simon Cooksey 0:fb7af294d5d9 451 * GATT Server.
Simon Cooksey 0:fb7af294d5d9 452 *
Simon Cooksey 0:fb7af294d5d9 453 * @note It is possible to unregister callbacks using
Simon Cooksey 0:fb7af294d5d9 454 * onHVX().detach(callbackToRemove).
Simon Cooksey 0:fb7af294d5d9 455 */
Simon Cooksey 0:fb7af294d5d9 456 void onHVX(HVXCallback_t callback) {
Simon Cooksey 0:fb7af294d5d9 457 onHVXCallbackChain.add(callback);
Simon Cooksey 0:fb7af294d5d9 458 }
Simon Cooksey 0:fb7af294d5d9 459
Simon Cooksey 0:fb7af294d5d9 460 /**
Simon Cooksey 0:fb7af294d5d9 461 * Setup a callback to be invoked to notify the user application that the
Simon Cooksey 0:fb7af294d5d9 462 * GattClient instance is about to shutdown (possibly as a result of a call
Simon Cooksey 0:fb7af294d5d9 463 * to BLE::shutdown()).
Simon Cooksey 0:fb7af294d5d9 464 *
Simon Cooksey 0:fb7af294d5d9 465 * @param[in] callback
Simon Cooksey 0:fb7af294d5d9 466 * Event handler being registered.
Simon Cooksey 0:fb7af294d5d9 467 *
Simon Cooksey 0:fb7af294d5d9 468 * @note It is possible to chain together multiple onShutdown callbacks
Simon Cooksey 0:fb7af294d5d9 469 * (potentially from different modules of an application) to be notified
Simon Cooksey 0:fb7af294d5d9 470 * before the GattClient is shutdown.
Simon Cooksey 0:fb7af294d5d9 471 *
Simon Cooksey 0:fb7af294d5d9 472 * @note It is also possible to set up a callback into a member function of
Simon Cooksey 0:fb7af294d5d9 473 * some object.
Simon Cooksey 0:fb7af294d5d9 474 *
Simon Cooksey 0:fb7af294d5d9 475 * @note It is possible to unregister a callback using onShutdown().detach(callback).
Simon Cooksey 0:fb7af294d5d9 476 */
Simon Cooksey 0:fb7af294d5d9 477 void onShutdown(const GattClientShutdownCallback_t& callback) {
Simon Cooksey 0:fb7af294d5d9 478 shutdownCallChain.add(callback);
Simon Cooksey 0:fb7af294d5d9 479 }
Simon Cooksey 0:fb7af294d5d9 480
Simon Cooksey 0:fb7af294d5d9 481 /**
Simon Cooksey 0:fb7af294d5d9 482 * Same as GattClient::onShutdown(), but allows the possibility to add an object
Simon Cooksey 0:fb7af294d5d9 483 * reference and member function as handler for shutdown event
Simon Cooksey 0:fb7af294d5d9 484 * callbacks.
Simon Cooksey 0:fb7af294d5d9 485 *
Simon Cooksey 0:fb7af294d5d9 486 * @param[in] objPtr
Simon Cooksey 0:fb7af294d5d9 487 * Pointer to the object of a class defining the member callback
Simon Cooksey 0:fb7af294d5d9 488 * function (@p memberPtr).
Simon Cooksey 0:fb7af294d5d9 489 * @param[in] memberPtr
Simon Cooksey 0:fb7af294d5d9 490 * The member callback (within the context of an object) to be
Simon Cooksey 0:fb7af294d5d9 491 * invoked.
Simon Cooksey 0:fb7af294d5d9 492 */
Simon Cooksey 0:fb7af294d5d9 493 template <typename T>
Simon Cooksey 0:fb7af294d5d9 494 void onShutdown(T *objPtr, void (T::*memberPtr)(const GattClient *)) {
Simon Cooksey 0:fb7af294d5d9 495 shutdownCallChain.add(objPtr, memberPtr);
Simon Cooksey 0:fb7af294d5d9 496 }
Simon Cooksey 0:fb7af294d5d9 497
Simon Cooksey 0:fb7af294d5d9 498 /**
Simon Cooksey 0:fb7af294d5d9 499 * @brief Provide access to the callchain of shutdown event callbacks.
Simon Cooksey 0:fb7af294d5d9 500 *
Simon Cooksey 0:fb7af294d5d9 501 * @return A reference to the shutdown event callbacks chain.
Simon Cooksey 0:fb7af294d5d9 502 *
Simon Cooksey 0:fb7af294d5d9 503 * @note It is possible to register callbacks using onShutdown().add(callback).
Simon Cooksey 0:fb7af294d5d9 504 *
Simon Cooksey 0:fb7af294d5d9 505 * @note It is possible to unregister callbacks using onShutdown().detach(callback).
Simon Cooksey 0:fb7af294d5d9 506 */
Simon Cooksey 0:fb7af294d5d9 507 GattClientShutdownCallbackChain_t& onShutdown() {
Simon Cooksey 0:fb7af294d5d9 508 return shutdownCallChain;
Simon Cooksey 0:fb7af294d5d9 509 }
Simon Cooksey 0:fb7af294d5d9 510
Simon Cooksey 0:fb7af294d5d9 511 /**
Simon Cooksey 0:fb7af294d5d9 512 * @brief provide access to the callchain of HVX callbacks.
Simon Cooksey 0:fb7af294d5d9 513 *
Simon Cooksey 0:fb7af294d5d9 514 * @return A reference to the HVX callbacks chain.
Simon Cooksey 0:fb7af294d5d9 515 *
Simon Cooksey 0:fb7af294d5d9 516 * @note It is possible to register callbacks using onHVX().add(callback).
Simon Cooksey 0:fb7af294d5d9 517 *
Simon Cooksey 0:fb7af294d5d9 518 * @note It is possible to unregister callbacks using onHVX().detach(callback).
Simon Cooksey 0:fb7af294d5d9 519 */
Simon Cooksey 0:fb7af294d5d9 520 HVXCallbackChain_t& onHVX() {
Simon Cooksey 0:fb7af294d5d9 521 return onHVXCallbackChain;
Simon Cooksey 0:fb7af294d5d9 522 }
Simon Cooksey 0:fb7af294d5d9 523
Simon Cooksey 0:fb7af294d5d9 524 public:
Simon Cooksey 0:fb7af294d5d9 525 /**
Simon Cooksey 0:fb7af294d5d9 526 * Notify all registered onShutdown callbacks that the GattClient is
Simon Cooksey 0:fb7af294d5d9 527 * about to be shutdown and clear all GattClient state of the
Simon Cooksey 0:fb7af294d5d9 528 * associated object.
Simon Cooksey 0:fb7af294d5d9 529 *
Simon Cooksey 0:fb7af294d5d9 530 * This function is meant to be overridden in the platform-specific
Simon Cooksey 0:fb7af294d5d9 531 * sub-class. Nevertheless, the sub-class is only expected to reset its
Simon Cooksey 0:fb7af294d5d9 532 * state and not the data held in GattClient members. This shall be achieved
Simon Cooksey 0:fb7af294d5d9 533 * by a call to GattClient::reset() from the sub-class' reset()
Simon Cooksey 0:fb7af294d5d9 534 * implementation.
Simon Cooksey 0:fb7af294d5d9 535 *
Simon Cooksey 0:fb7af294d5d9 536 * @return BLE_ERROR_NONE on success.
Simon Cooksey 0:fb7af294d5d9 537 */
Simon Cooksey 0:fb7af294d5d9 538 virtual ble_error_t reset(void) {
Simon Cooksey 0:fb7af294d5d9 539 /* Notify that the instance is about to shutdown */
Simon Cooksey 0:fb7af294d5d9 540 shutdownCallChain.call(this);
Simon Cooksey 0:fb7af294d5d9 541 shutdownCallChain.clear();
Simon Cooksey 0:fb7af294d5d9 542
Simon Cooksey 0:fb7af294d5d9 543 onDataReadCallbackChain.clear();
Simon Cooksey 0:fb7af294d5d9 544 onDataWriteCallbackChain.clear();
Simon Cooksey 0:fb7af294d5d9 545 onHVXCallbackChain.clear();
Simon Cooksey 0:fb7af294d5d9 546
Simon Cooksey 0:fb7af294d5d9 547 return BLE_ERROR_NONE;
Simon Cooksey 0:fb7af294d5d9 548 }
Simon Cooksey 0:fb7af294d5d9 549
Simon Cooksey 0:fb7af294d5d9 550 protected:
Simon Cooksey 0:fb7af294d5d9 551 GattClient() {
Simon Cooksey 0:fb7af294d5d9 552 /* Empty */
Simon Cooksey 0:fb7af294d5d9 553 }
Simon Cooksey 0:fb7af294d5d9 554
Simon Cooksey 0:fb7af294d5d9 555 /* Entry points for the underlying stack to report events back to the user. */
Simon Cooksey 0:fb7af294d5d9 556 public:
Simon Cooksey 0:fb7af294d5d9 557 /**
Simon Cooksey 0:fb7af294d5d9 558 * Helper function that notifies all registered handlers of an occurrence
Simon Cooksey 0:fb7af294d5d9 559 * of a data read event. This function is meant to be called from the
Simon Cooksey 0:fb7af294d5d9 560 * BLE stack specific implementation when a data read event occurs.
Simon Cooksey 0:fb7af294d5d9 561 *
Simon Cooksey 0:fb7af294d5d9 562 * @param[in] params
Simon Cooksey 0:fb7af294d5d9 563 * The data read parameters passed to the registered
Simon Cooksey 0:fb7af294d5d9 564 * handlers.
Simon Cooksey 0:fb7af294d5d9 565 */
Simon Cooksey 0:fb7af294d5d9 566 void processReadResponse(const GattReadCallbackParams *params) {
Simon Cooksey 0:fb7af294d5d9 567 onDataReadCallbackChain(params);
Simon Cooksey 0:fb7af294d5d9 568 }
Simon Cooksey 0:fb7af294d5d9 569
Simon Cooksey 0:fb7af294d5d9 570 /**
Simon Cooksey 0:fb7af294d5d9 571 * Helper function that notifies all registered handlers of an occurrence
Simon Cooksey 0:fb7af294d5d9 572 * of a data written event. This function is meant to be called from the
Simon Cooksey 0:fb7af294d5d9 573 * BLE stack specific implementation when a data written event occurs.
Simon Cooksey 0:fb7af294d5d9 574 *
Simon Cooksey 0:fb7af294d5d9 575 * @param[in] params
Simon Cooksey 0:fb7af294d5d9 576 * The data written parameters passed to the registered
Simon Cooksey 0:fb7af294d5d9 577 * handlers.
Simon Cooksey 0:fb7af294d5d9 578 */
Simon Cooksey 0:fb7af294d5d9 579 void processWriteResponse(const GattWriteCallbackParams *params) {
Simon Cooksey 0:fb7af294d5d9 580 onDataWriteCallbackChain(params);
Simon Cooksey 0:fb7af294d5d9 581 }
Simon Cooksey 0:fb7af294d5d9 582
Simon Cooksey 0:fb7af294d5d9 583 /**
Simon Cooksey 0:fb7af294d5d9 584 * Helper function that notifies all registered handlers of an occurrence
Simon Cooksey 0:fb7af294d5d9 585 * of an update event. This function is meant to be called from the
Simon Cooksey 0:fb7af294d5d9 586 * BLE stack specific implementation when an update event occurs.
Simon Cooksey 0:fb7af294d5d9 587 *
Simon Cooksey 0:fb7af294d5d9 588 * @param[in] params
Simon Cooksey 0:fb7af294d5d9 589 * The update event parameters passed to the registered
Simon Cooksey 0:fb7af294d5d9 590 * handlers.
Simon Cooksey 0:fb7af294d5d9 591 */
Simon Cooksey 0:fb7af294d5d9 592 void processHVXEvent(const GattHVXCallbackParams *params) {
Simon Cooksey 0:fb7af294d5d9 593 if (onHVXCallbackChain) {
Simon Cooksey 0:fb7af294d5d9 594 onHVXCallbackChain(params);
Simon Cooksey 0:fb7af294d5d9 595 }
Simon Cooksey 0:fb7af294d5d9 596 }
Simon Cooksey 0:fb7af294d5d9 597
Simon Cooksey 0:fb7af294d5d9 598 protected:
Simon Cooksey 0:fb7af294d5d9 599 /**
Simon Cooksey 0:fb7af294d5d9 600 * Callchain containing all registered callback handlers for data read
Simon Cooksey 0:fb7af294d5d9 601 * events.
Simon Cooksey 0:fb7af294d5d9 602 */
Simon Cooksey 0:fb7af294d5d9 603 ReadCallbackChain_t onDataReadCallbackChain;
Simon Cooksey 0:fb7af294d5d9 604 /**
Simon Cooksey 0:fb7af294d5d9 605 * Callchain containing all registered callback handlers for data write
Simon Cooksey 0:fb7af294d5d9 606 * events.
Simon Cooksey 0:fb7af294d5d9 607 */
Simon Cooksey 0:fb7af294d5d9 608 WriteCallbackChain_t onDataWriteCallbackChain;
Simon Cooksey 0:fb7af294d5d9 609 /**
Simon Cooksey 0:fb7af294d5d9 610 * Callchain containing all registered callback handlers for update
Simon Cooksey 0:fb7af294d5d9 611 * events.
Simon Cooksey 0:fb7af294d5d9 612 */
Simon Cooksey 0:fb7af294d5d9 613 HVXCallbackChain_t onHVXCallbackChain;
Simon Cooksey 0:fb7af294d5d9 614 /**
Simon Cooksey 0:fb7af294d5d9 615 * Callchain containing all registered callback handlers for shutdown
Simon Cooksey 0:fb7af294d5d9 616 * events.
Simon Cooksey 0:fb7af294d5d9 617 */
Simon Cooksey 0:fb7af294d5d9 618 GattClientShutdownCallbackChain_t shutdownCallChain;
Simon Cooksey 0:fb7af294d5d9 619
Simon Cooksey 0:fb7af294d5d9 620 private:
Simon Cooksey 0:fb7af294d5d9 621 /* Disallow copy and assignment. */
Simon Cooksey 0:fb7af294d5d9 622 GattClient(const GattClient &);
Simon Cooksey 0:fb7af294d5d9 623 GattClient& operator=(const GattClient &);
Simon Cooksey 0:fb7af294d5d9 624 };
Simon Cooksey 0:fb7af294d5d9 625
Simon Cooksey 0:fb7af294d5d9 626 #endif /* ifndef __GATT_CLIENT_H__ */