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