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