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