Updated
Fork of BLE_API by
ble/GattClient.h@1072:dd09fe419587, 2016-01-11 (annotated)
- Committer:
- vcoubard
- Date:
- Mon Jan 11 08:51:41 2016 +0000
- Revision:
- 1072:dd09fe419587
- Parent:
- 1063:187f9929cb60
- Child:
- 1074:1fedc77d9add
Synchronized with git rev 726a144e
Author: Vincent Coubard
Fix whitespace and improve documentation of Descriptors discovery
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 | 1063:187f9929cb60 | 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 | |
rgrover1 | 716:11b41f651697 | 45 | /* |
rgrover1 | 716:11b41f651697 | 46 | * The following functions are meant to be overridden in the platform-specific sub-class. |
rgrover1 | 716:11b41f651697 | 47 | */ |
rgrover1 | 716:11b41f651697 | 48 | public: |
rgrover1 | 716:11b41f651697 | 49 | /** |
rgrover1 | 728:997ba5e7b3b6 | 50 | * Launch service discovery. Once launched, application callbacks will be |
vcoubard | 1048:efb29faf12fc | 51 | * invoked for matching services or characteristics. isServiceDiscoveryActive() |
vcoubard | 1048:efb29faf12fc | 52 | * can be used to determine status, and a termination callback (if one was set up) |
vcoubard | 1048:efb29faf12fc | 53 | * will be invoked at the end. Service discovery can be terminated prematurely, |
vcoubard | 1048:efb29faf12fc | 54 | * if needed, using terminateServiceDiscovery(). |
rgrover1 | 716:11b41f651697 | 55 | * |
rgrover1 | 716:11b41f651697 | 56 | * @param connectionHandle |
rgrover1 | 716:11b41f651697 | 57 | * Handle for the connection with the peer. |
rgrover1 | 716:11b41f651697 | 58 | * @param sc |
vcoubard | 1048:efb29faf12fc | 59 | * This is the application callback for a matching service. Taken as |
rgrover1 | 716:11b41f651697 | 60 | * NULL by default. Note: service discovery may still be active |
rgrover1 | 716:11b41f651697 | 61 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 716:11b41f651697 | 62 | * APIs from within this application callback might cause the |
rgrover1 | 716:11b41f651697 | 63 | * stack to abort service discovery. If this becomes an issue, it |
vcoubard | 1048:efb29faf12fc | 64 | * may be better to make a local copy of the discoveredService and |
rgrover1 | 716:11b41f651697 | 65 | * wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 66 | * service. |
rgrover1 | 716:11b41f651697 | 67 | * @param cc |
vcoubard | 1048:efb29faf12fc | 68 | * This is the application callback for a matching characteristic. |
rgrover1 | 716:11b41f651697 | 69 | * Taken as NULL by default. Note: service discovery may still be |
rgrover1 | 716:11b41f651697 | 70 | * active when this callback is issued; calling asynchronous |
rgrover1 | 716:11b41f651697 | 71 | * BLE-stack APIs from within this application callback might cause |
rgrover1 | 716:11b41f651697 | 72 | * the stack to abort service discovery. If this becomes an issue, |
vcoubard | 1048:efb29faf12fc | 73 | * it may be better to make a local copy of the discoveredCharacteristic |
rgrover1 | 716:11b41f651697 | 74 | * and wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 75 | * characteristic. |
rgrover1 | 716:11b41f651697 | 76 | * @param matchingServiceUUID |
vcoubard | 1048:efb29faf12fc | 77 | * UUID-based filter for specifying a service in which the application is |
rgrover1 | 716:11b41f651697 | 78 | * interested. By default it is set as the wildcard UUID_UNKNOWN, |
rgrover1 | 716:11b41f651697 | 79 | * in which case it matches all services. If characteristic-UUID |
rgrover1 | 716:11b41f651697 | 80 | * filter (below) is set to the wildcard value, then a service |
rgrover1 | 716:11b41f651697 | 81 | * callback will be invoked for the matching service (or for every |
rgrover1 | 716:11b41f651697 | 82 | * service if the service filter is a wildcard). |
rgrover1 | 716:11b41f651697 | 83 | * @param matchingCharacteristicUUIDIn |
vcoubard | 1048:efb29faf12fc | 84 | * UUID-based filter for specifying characteristic in which the application |
rgrover1 | 716:11b41f651697 | 85 | * is interested. By default it is set as the wildcard UUID_UKNOWN |
rgrover1 | 716:11b41f651697 | 86 | * to match against any characteristic. If both service-UUID |
vcoubard | 1048:efb29faf12fc | 87 | * filter and characteristic-UUID filter are used with non-wildcard |
rgrover1 | 716:11b41f651697 | 88 | * values, then only a single characteristic callback is |
rgrover1 | 716:11b41f651697 | 89 | * invoked for the matching characteristic. |
rgrover1 | 716:11b41f651697 | 90 | * |
rgrover1 | 716:11b41f651697 | 91 | * @note Using wildcard values for both service-UUID and characteristic- |
vcoubard | 1048:efb29faf12fc | 92 | * UUID will result in complete service discovery: callbacks being |
rgrover1 | 716:11b41f651697 | 93 | * called for every service and characteristic. |
rgrover1 | 716:11b41f651697 | 94 | * |
rgrover1 | 716:11b41f651697 | 95 | * @note Providing NULL for the characteristic callback will result in |
rgrover1 | 716:11b41f651697 | 96 | * characteristic discovery being skipped for each matching |
rgrover1 | 716:11b41f651697 | 97 | * service. This allows for an inexpensive method to discover only |
rgrover1 | 716:11b41f651697 | 98 | * services. |
rgrover1 | 716:11b41f651697 | 99 | * |
rgrover1 | 716:11b41f651697 | 100 | * @return |
rgrover1 | 716:11b41f651697 | 101 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 716:11b41f651697 | 102 | */ |
rgrover1 | 716:11b41f651697 | 103 | virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle, |
rgrover1 | 716:11b41f651697 | 104 | ServiceDiscovery::ServiceCallback_t sc = NULL, |
rgrover1 | 716:11b41f651697 | 105 | ServiceDiscovery::CharacteristicCallback_t cc = NULL, |
rgrover1 | 716:11b41f651697 | 106 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN), |
rgrover1 | 716:11b41f651697 | 107 | const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) { |
vcoubard | 1048:efb29faf12fc | 108 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 734:4872b70437ce | 109 | (void)connectionHandle; |
rgrover1 | 734:4872b70437ce | 110 | (void)sc; |
rgrover1 | 734:4872b70437ce | 111 | (void)cc; |
rgrover1 | 734:4872b70437ce | 112 | (void)matchingServiceUUID; |
rgrover1 | 734:4872b70437ce | 113 | (void)matchingCharacteristicUUIDIn; |
rgrover1 | 734:4872b70437ce | 114 | |
vcoubard | 1048:efb29faf12fc | 115 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 116 | } |
rgrover1 | 716:11b41f651697 | 117 | |
rgrover1 | 716:11b41f651697 | 118 | /** |
rgrover1 | 716:11b41f651697 | 119 | * Launch service discovery for services. Once launched, service discovery will remain |
rgrover1 | 716:11b41f651697 | 120 | * active with service-callbacks being issued back into the application for matching |
rgrover1 | 716:11b41f651697 | 121 | * services. isServiceDiscoveryActive() can be used to |
vcoubard | 1048:efb29faf12fc | 122 | * determine status, and a termination callback (if set up) will be invoked |
vcoubard | 1048:efb29faf12fc | 123 | * at the end. Service discovery can be terminated prematurely, if needed, |
rgrover1 | 716:11b41f651697 | 124 | * using terminateServiceDiscovery(). |
rgrover1 | 716:11b41f651697 | 125 | * |
rgrover1 | 716:11b41f651697 | 126 | * @param connectionHandle |
rgrover1 | 716:11b41f651697 | 127 | * Handle for the connection with the peer. |
rgrover1 | 716:11b41f651697 | 128 | * @param sc |
vcoubard | 1048:efb29faf12fc | 129 | * This is the application callback for a matching service. Note: service discovery may still be active |
rgrover1 | 716:11b41f651697 | 130 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 716:11b41f651697 | 131 | * APIs from within this application callback might cause the |
rgrover1 | 716:11b41f651697 | 132 | * stack to abort service discovery. If this becomes an issue, it |
vcoubard | 1048:efb29faf12fc | 133 | * may be better to make a local copy of the discoveredService and |
rgrover1 | 716:11b41f651697 | 134 | * wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 135 | * service. |
rgrover1 | 716:11b41f651697 | 136 | * @param matchingServiceUUID |
vcoubard | 1048:efb29faf12fc | 137 | * UUID-based filter for specifying a service in which the application is |
rgrover1 | 716:11b41f651697 | 138 | * interested. By default it is set as the wildcard UUID_UNKNOWN, |
rgrover1 | 716:11b41f651697 | 139 | * in which case it matches all services. |
rgrover1 | 716:11b41f651697 | 140 | * |
rgrover1 | 716:11b41f651697 | 141 | * @return |
rgrover1 | 716:11b41f651697 | 142 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 716:11b41f651697 | 143 | */ |
rgrover1 | 716:11b41f651697 | 144 | virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, |
rgrover1 | 716:11b41f651697 | 145 | ServiceDiscovery::ServiceCallback_t callback, |
rgrover1 | 716:11b41f651697 | 146 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) { |
rgrover1 | 742:861ed7eb186d | 147 | return launchServiceDiscovery(connectionHandle, callback, NULL, matchingServiceUUID); /* We take advantage of the property |
rgrover1 | 742:861ed7eb186d | 148 | * that providing NULL for the characteristic callback will result in |
rgrover1 | 742:861ed7eb186d | 149 | * characteristic discovery being skipped for each matching |
rgrover1 | 742:861ed7eb186d | 150 | * service. This allows for an inexpensive method to discover only |
vcoubard | 1048:efb29faf12fc | 151 | * services. Porters are free to override this. */ |
rgrover1 | 716:11b41f651697 | 152 | } |
rgrover1 | 716:11b41f651697 | 153 | |
rgrover1 | 716:11b41f651697 | 154 | /** |
rgrover1 | 716:11b41f651697 | 155 | * Launch service discovery for services. Once launched, service discovery will remain |
rgrover1 | 716:11b41f651697 | 156 | * active with service-callbacks being issued back into the application for matching |
rgrover1 | 716:11b41f651697 | 157 | * services. isServiceDiscoveryActive() can be used to |
vcoubard | 1048:efb29faf12fc | 158 | * determine status, and a termination callback (if set up) will be invoked |
vcoubard | 1048:efb29faf12fc | 159 | * at the end. Service discovery can be terminated prematurely, if needed, |
rgrover1 | 716:11b41f651697 | 160 | * using terminateServiceDiscovery(). |
rgrover1 | 716:11b41f651697 | 161 | * |
rgrover1 | 716:11b41f651697 | 162 | * @param connectionHandle |
rgrover1 | 716:11b41f651697 | 163 | * Handle for the connection with the peer. |
rgrover1 | 716:11b41f651697 | 164 | * @param sc |
vcoubard | 1048:efb29faf12fc | 165 | * This is the application callback for a matching service. Note: service discovery may still be active |
rgrover1 | 716:11b41f651697 | 166 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 716:11b41f651697 | 167 | * APIs from within this application callback might cause the |
rgrover1 | 716:11b41f651697 | 168 | * stack to abort service discovery. If this becomes an issue, it |
vcoubard | 1048:efb29faf12fc | 169 | * may be better to make a local copy of the discoveredService and |
rgrover1 | 716:11b41f651697 | 170 | * wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 171 | * service. |
rgrover1 | 716:11b41f651697 | 172 | * @param startHandle, endHandle |
vcoubard | 1048:efb29faf12fc | 173 | * Handle range within which to limit the search. |
rgrover1 | 716:11b41f651697 | 174 | * |
rgrover1 | 716:11b41f651697 | 175 | * @return |
rgrover1 | 716:11b41f651697 | 176 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 716:11b41f651697 | 177 | */ |
rgrover1 | 716:11b41f651697 | 178 | virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, |
rgrover1 | 716:11b41f651697 | 179 | ServiceDiscovery::ServiceCallback_t callback, |
rgrover1 | 716:11b41f651697 | 180 | GattAttribute::Handle_t startHandle, |
rgrover1 | 716:11b41f651697 | 181 | GattAttribute::Handle_t endHandle) { |
vcoubard | 1048:efb29faf12fc | 182 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 734:4872b70437ce | 183 | (void)connectionHandle; |
rgrover1 | 734:4872b70437ce | 184 | (void)callback; |
rgrover1 | 734:4872b70437ce | 185 | (void)startHandle; |
rgrover1 | 734:4872b70437ce | 186 | (void)endHandle; |
rgrover1 | 734:4872b70437ce | 187 | |
vcoubard | 1048:efb29faf12fc | 188 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 189 | } |
rgrover1 | 716:11b41f651697 | 190 | |
rgrover1 | 716:11b41f651697 | 191 | /** |
rgrover1 | 716:11b41f651697 | 192 | * Is service-discovery currently active? |
rgrover1 | 716:11b41f651697 | 193 | */ |
rgrover1 | 716:11b41f651697 | 194 | virtual bool isServiceDiscoveryActive(void) const { |
vcoubard | 1048:efb29faf12fc | 195 | return false; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 196 | } |
rgrover1 | 716:11b41f651697 | 197 | |
rgrover1 | 716:11b41f651697 | 198 | /** |
vcoubard | 1048:efb29faf12fc | 199 | * Terminate an ongoing service discovery. This should result in an |
vcoubard | 1048:efb29faf12fc | 200 | * invocation of TerminationCallback if service-discovery is active. |
rgrover1 | 716:11b41f651697 | 201 | */ |
rgrover1 | 716:11b41f651697 | 202 | virtual void terminateServiceDiscovery(void) { |
vcoubard | 1048:efb29faf12fc | 203 | /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 204 | } |
rgrover1 | 716:11b41f651697 | 205 | |
vcoubard | 1048:efb29faf12fc | 206 | /* Initiate a GATT Client read procedure by attribute-handle. */ |
rgrover1 | 716:11b41f651697 | 207 | virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const { |
vcoubard | 1048:efb29faf12fc | 208 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 734:4872b70437ce | 209 | (void)connHandle; |
rgrover1 | 734:4872b70437ce | 210 | (void)attributeHandle; |
rgrover1 | 734:4872b70437ce | 211 | (void)offset; |
rgrover1 | 734:4872b70437ce | 212 | |
vcoubard | 1048:efb29faf12fc | 213 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 214 | } |
rgrover1 | 716:11b41f651697 | 215 | |
rgrover1 | 716:11b41f651697 | 216 | /** |
rgrover1 | 716:11b41f651697 | 217 | * Initiate a GATT Client write procedure. |
rgrover1 | 716:11b41f651697 | 218 | * |
rgrover1 | 716:11b41f651697 | 219 | * @param[in] cmd |
vcoubard | 1072:dd09fe419587 | 220 | * Command can be either a write-request (which generates a |
vcoubard | 1072:dd09fe419587 | 221 | * matching response from the peripheral), or a write-command |
vcoubard | 1048:efb29faf12fc | 222 | * (which doesn't require the connected peer to respond). |
rgrover1 | 716:11b41f651697 | 223 | * @param[in] connHandle |
rgrover1 | 716:11b41f651697 | 224 | * Connection handle. |
rgrover1 | 716:11b41f651697 | 225 | * @param[in] attributeHandle |
vcoubard | 1048:efb29faf12fc | 226 | * Handle for the target attribtue on the remote GATT server. |
rgrover1 | 716:11b41f651697 | 227 | * @param[in] length |
vcoubard | 1048:efb29faf12fc | 228 | * Length of the new value. |
rgrover1 | 716:11b41f651697 | 229 | * @param[in] value |
vcoubard | 1048:efb29faf12fc | 230 | * New value being written. |
rgrover1 | 716:11b41f651697 | 231 | */ |
rgrover1 | 716:11b41f651697 | 232 | virtual ble_error_t write(GattClient::WriteOp_t cmd, |
rgrover1 | 716:11b41f651697 | 233 | Gap::Handle_t connHandle, |
rgrover1 | 716:11b41f651697 | 234 | GattAttribute::Handle_t attributeHandle, |
rgrover1 | 716:11b41f651697 | 235 | size_t length, |
rgrover1 | 716:11b41f651697 | 236 | const uint8_t *value) const { |
vcoubard | 1048:efb29faf12fc | 237 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 734:4872b70437ce | 238 | (void)cmd; |
rgrover1 | 734:4872b70437ce | 239 | (void)connHandle; |
rgrover1 | 734:4872b70437ce | 240 | (void)attributeHandle; |
rgrover1 | 734:4872b70437ce | 241 | (void)length; |
rgrover1 | 734:4872b70437ce | 242 | (void)value; |
rgrover1 | 734:4872b70437ce | 243 | |
vcoubard | 1048:efb29faf12fc | 244 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 728:997ba5e7b3b6 | 245 | } |
rgrover1 | 728:997ba5e7b3b6 | 246 | |
rgrover1 | 728:997ba5e7b3b6 | 247 | /* Event callback handlers. */ |
rgrover1 | 728:997ba5e7b3b6 | 248 | public: |
rgrover1 | 728:997ba5e7b3b6 | 249 | /** |
vcoubard | 1072:dd09fe419587 | 250 | * Set up a callback for read response events. |
vcoubard | 1072:dd09fe419587 | 251 | * It is possible to remove registered callbacks using |
vcoubard | 1052:b55e1ad3e1b3 | 252 | * onDataRead().detach(callbackToRemove) |
rgrover1 | 728:997ba5e7b3b6 | 253 | */ |
rgrover1 | 728:997ba5e7b3b6 | 254 | void onDataRead(ReadCallback_t callback) { |
vcoubard | 1052:b55e1ad3e1b3 | 255 | onDataReadCallbackChain.add(callback); |
vcoubard | 1052:b55e1ad3e1b3 | 256 | } |
vcoubard | 1052:b55e1ad3e1b3 | 257 | |
vcoubard | 1052:b55e1ad3e1b3 | 258 | /** |
vcoubard | 1052:b55e1ad3e1b3 | 259 | * @brief provide access to the callchain of read callbacks |
vcoubard | 1052:b55e1ad3e1b3 | 260 | * It is possible to register callbacks using onDataRead().add(callback); |
vcoubard | 1072:dd09fe419587 | 261 | * It is possible to unregister callbacks using onDataRead().detach(callback) |
vcoubard | 1052:b55e1ad3e1b3 | 262 | * @return The read callbacks chain |
vcoubard | 1052:b55e1ad3e1b3 | 263 | */ |
vcoubard | 1052:b55e1ad3e1b3 | 264 | ReadCallbackChain_t& onDataRead() { |
vcoubard | 1052:b55e1ad3e1b3 | 265 | return onDataReadCallbackChain; |
rgrover1 | 728:997ba5e7b3b6 | 266 | } |
rgrover1 | 728:997ba5e7b3b6 | 267 | |
rgrover1 | 728:997ba5e7b3b6 | 268 | /** |
vcoubard | 1048:efb29faf12fc | 269 | * Set up a callback for write response events. |
vcoubard | 1072:dd09fe419587 | 270 | * It is possible to remove registered callbacks using |
vcoubard | 1052:b55e1ad3e1b3 | 271 | * onDataWritten().detach(callbackToRemove). |
vcoubard | 1048:efb29faf12fc | 272 | * @Note: Write commands (issued using writeWoResponse) don't generate a response. |
rgrover1 | 728:997ba5e7b3b6 | 273 | */ |
rgrover1 | 768:8914bea92690 | 274 | void onDataWritten(WriteCallback_t callback) { |
vcoubard | 1052:b55e1ad3e1b3 | 275 | onDataWriteCallbackChain.add(callback); |
vcoubard | 1052:b55e1ad3e1b3 | 276 | } |
vcoubard | 1052:b55e1ad3e1b3 | 277 | |
vcoubard | 1052:b55e1ad3e1b3 | 278 | /** |
vcoubard | 1052:b55e1ad3e1b3 | 279 | * @brief provide access to the callchain of data written callbacks |
vcoubard | 1052:b55e1ad3e1b3 | 280 | * It is possible to register callbacks using onDataWritten().add(callback); |
vcoubard | 1072:dd09fe419587 | 281 | * It is possible to unregister callbacks using onDataWritten().detach(callback) |
vcoubard | 1052:b55e1ad3e1b3 | 282 | * @return The data written callbacks chain |
vcoubard | 1052:b55e1ad3e1b3 | 283 | */ |
vcoubard | 1072:dd09fe419587 | 284 | WriteCallbackChain_t& onDataWritten() { |
vcoubard | 1052:b55e1ad3e1b3 | 285 | return onDataWriteCallbackChain; |
rgrover1 | 990:53ac0ac3aa39 | 286 | } |
rgrover1 | 990:53ac0ac3aa39 | 287 | |
rgrover1 | 990:53ac0ac3aa39 | 288 | /** |
vcoubard | 1048:efb29faf12fc | 289 | * Set up a callback for write response events. |
vcoubard | 1048:efb29faf12fc | 290 | * @Note: Write commands (issued using writeWoResponse) don't generate a response. |
rgrover1 | 768:8914bea92690 | 291 | * |
rgrover1 | 768:8914bea92690 | 292 | * @note: This API is now *deprecated* and will be dropped in the future. |
rgrover1 | 768:8914bea92690 | 293 | * Please use onDataWritten() instead. |
rgrover1 | 768:8914bea92690 | 294 | */ |
rgrover1 | 728:997ba5e7b3b6 | 295 | void onDataWrite(WriteCallback_t callback) { |
rgrover1 | 768:8914bea92690 | 296 | onDataWritten(callback); |
rgrover1 | 720:ce8a760a4504 | 297 | } |
rgrover1 | 720:ce8a760a4504 | 298 | |
rgrover1 | 716:11b41f651697 | 299 | /** |
vcoubard | 1048:efb29faf12fc | 300 | * Set up a callback for when serviceDiscovery terminates. |
rgrover1 | 716:11b41f651697 | 301 | */ |
rgrover1 | 716:11b41f651697 | 302 | virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) { |
vcoubard | 1048:efb29faf12fc | 303 | (void)callback; /* Avoid compiler warnings about ununsed variables. */ |
rgrover1 | 734:4872b70437ce | 304 | |
vcoubard | 1048:efb29faf12fc | 305 | /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 306 | } |
rgrover1 | 716:11b41f651697 | 307 | |
rgrover1 | 737:79d95f9b93be | 308 | /** |
vcoubard | 1063:187f9929cb60 | 309 | * @brief launch discovery of descriptors for a given characteristic |
vcoubard | 1072:dd09fe419587 | 310 | * @details This function will discover all descriptors available for a |
vcoubard | 1072:dd09fe419587 | 311 | * specific characteristic. |
vcoubard | 1072:dd09fe419587 | 312 | * |
vcoubard | 1072:dd09fe419587 | 313 | * @param characteristic[in] The characteristic targeted by this discovery |
vcoubard | 1072:dd09fe419587 | 314 | * procedure |
vcoubard | 1072:dd09fe419587 | 315 | * @param discoveryCallback[in] User function called each time a descriptor |
vcoubard | 1072:dd09fe419587 | 316 | * is found during the procedure. |
vcoubard | 1072:dd09fe419587 | 317 | * @param terminationCallback[in] User provided function which will be called |
vcoubard | 1072:dd09fe419587 | 318 | * once the discovery procedure is terminating. This will get called when all |
vcoubard | 1072:dd09fe419587 | 319 | * the descriptors have been discovered or if an error occur during the discovery |
vcoubard | 1072:dd09fe419587 | 320 | * procedure. |
vcoubard | 1072:dd09fe419587 | 321 | * |
vcoubard | 1072:dd09fe419587 | 322 | * @return |
vcoubard | 1072:dd09fe419587 | 323 | * BLE_ERROR_NONE if characteristic descriptor discovery is launched |
vcoubard | 1063:187f9929cb60 | 324 | * successfully; else an appropriate error. |
vcoubard | 1063:187f9929cb60 | 325 | */ |
vcoubard | 1063:187f9929cb60 | 326 | virtual ble_error_t discoverCharacteristicDescriptors( |
vcoubard | 1063:187f9929cb60 | 327 | const DiscoveredCharacteristic& characteristic, |
vcoubard | 1063:187f9929cb60 | 328 | const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback, |
vcoubard | 1063:187f9929cb60 | 329 | const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback) { |
vcoubard | 1063:187f9929cb60 | 330 | (void) characteristic; |
vcoubard | 1063:187f9929cb60 | 331 | (void) discoveryCallback; |
vcoubard | 1063:187f9929cb60 | 332 | (void) terminationCallback; |
vcoubard | 1072:dd09fe419587 | 333 | /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1072:dd09fe419587 | 334 | return BLE_ERROR_NOT_IMPLEMENTED; |
vcoubard | 1063:187f9929cb60 | 335 | } |
vcoubard | 1063:187f9929cb60 | 336 | |
vcoubard | 1063:187f9929cb60 | 337 | /** |
vcoubard | 1072:dd09fe419587 | 338 | * @brief Indicate if the discovery of characteristic descriptors is active for a given characteristic |
vcoubard | 1072:dd09fe419587 | 339 | * or not. |
vcoubard | 1072:dd09fe419587 | 340 | * @param characteristic[in] The characteristic concerned by the descriptors discovery. |
vcoubard | 1072:dd09fe419587 | 341 | * @return true if a descriptors discovery is active for the characteristic in input; otherwise false. |
vcoubard | 1063:187f9929cb60 | 342 | */ |
vcoubard | 1072:dd09fe419587 | 343 | virtual bool isCharacteristicDescriptorsDiscoveryActive(const DiscoveredCharacteristic& characteristic) const |
vcoubard | 1063:187f9929cb60 | 344 | { |
vcoubard | 1063:187f9929cb60 | 345 | (void) characteristic; |
vcoubard | 1063:187f9929cb60 | 346 | return false; /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1063:187f9929cb60 | 347 | } |
vcoubard | 1063:187f9929cb60 | 348 | |
vcoubard | 1063:187f9929cb60 | 349 | /** |
vcoubard | 1072:dd09fe419587 | 350 | * @brief Terminate an ongoing characteristic descriptor discovery. |
vcoubard | 1072:dd09fe419587 | 351 | * @detail This should result in an invocation of the TerminationCallback if |
vcoubard | 1072:dd09fe419587 | 352 | * the characteristic descriptor discovery is active. |
vcoubard | 1072:dd09fe419587 | 353 | * @param characteristic[in] The characteristic on which the running descriptors |
vcoubard | 1072:dd09fe419587 | 354 | * discovery should be stopped. |
vcoubard | 1063:187f9929cb60 | 355 | */ |
vcoubard | 1063:187f9929cb60 | 356 | virtual void terminateCharacteristicDescriptorsDiscovery(const DiscoveredCharacteristic& characteristic) { |
vcoubard | 1063:187f9929cb60 | 357 | /* Requesting action from porter(s): override this API if this capability is supported. */ |
vcoubard | 1063:187f9929cb60 | 358 | (void) characteristic; |
vcoubard | 1063:187f9929cb60 | 359 | } |
vcoubard | 1063:187f9929cb60 | 360 | |
vcoubard | 1063:187f9929cb60 | 361 | /** |
vcoubard | 1048:efb29faf12fc | 362 | * Set up a callback for when the GATT client receives an update event |
vcoubard | 1048:efb29faf12fc | 363 | * corresponding to a change in the value of a characteristic on the remote |
vcoubard | 1048:efb29faf12fc | 364 | * GATT server. |
vcoubard | 1052:b55e1ad3e1b3 | 365 | * It is possible to remove registered callbacks using onHVX().detach(callbackToRemove). |
rgrover1 | 737:79d95f9b93be | 366 | */ |
rgrover1 | 737:79d95f9b93be | 367 | void onHVX(HVXCallback_t callback) { |
vcoubard | 1052:b55e1ad3e1b3 | 368 | onHVXCallbackChain.add(callback); |
vcoubard | 1052:b55e1ad3e1b3 | 369 | } |
vcoubard | 1052:b55e1ad3e1b3 | 370 | |
vcoubard | 1052:b55e1ad3e1b3 | 371 | |
vcoubard | 1052:b55e1ad3e1b3 | 372 | /** |
vcoubard | 1052:b55e1ad3e1b3 | 373 | * @brief provide access to the callchain of HVX callbacks |
vcoubard | 1052:b55e1ad3e1b3 | 374 | * It is possible to register callbacks using onHVX().add(callback); |
vcoubard | 1072:dd09fe419587 | 375 | * It is possible to unregister callbacks using onHVX().detach(callback) |
vcoubard | 1052:b55e1ad3e1b3 | 376 | * @return The HVX callbacks chain |
vcoubard | 1052:b55e1ad3e1b3 | 377 | */ |
vcoubard | 1072:dd09fe419587 | 378 | HVXCallbackChain_t& onHVX() { |
vcoubard | 1052:b55e1ad3e1b3 | 379 | return onHVXCallbackChain; |
rgrover1 | 737:79d95f9b93be | 380 | } |
rgrover1 | 737:79d95f9b93be | 381 | |
rgrover1 | 716:11b41f651697 | 382 | protected: |
rgrover1 | 716:11b41f651697 | 383 | GattClient() { |
vcoubard | 1048:efb29faf12fc | 384 | /* Empty */ |
rgrover1 | 716:11b41f651697 | 385 | } |
rgrover1 | 716:11b41f651697 | 386 | |
rgrover1 | 728:997ba5e7b3b6 | 387 | /* Entry points for the underlying stack to report events back to the user. */ |
rgrover1 | 728:997ba5e7b3b6 | 388 | public: |
rgrover1 | 728:997ba5e7b3b6 | 389 | void processReadResponse(const GattReadCallbackParams *params) { |
vcoubard | 1052:b55e1ad3e1b3 | 390 | onDataReadCallbackChain(params); |
rgrover1 | 728:997ba5e7b3b6 | 391 | } |
rgrover1 | 728:997ba5e7b3b6 | 392 | |
rgrover1 | 728:997ba5e7b3b6 | 393 | void processWriteResponse(const GattWriteCallbackParams *params) { |
vcoubard | 1052:b55e1ad3e1b3 | 394 | onDataWriteCallbackChain(params); |
rgrover1 | 728:997ba5e7b3b6 | 395 | } |
rgrover1 | 728:997ba5e7b3b6 | 396 | |
rgrover1 | 737:79d95f9b93be | 397 | void processHVXEvent(const GattHVXCallbackParams *params) { |
vcoubard | 1052:b55e1ad3e1b3 | 398 | if (onHVXCallbackChain) { |
vcoubard | 1052:b55e1ad3e1b3 | 399 | onHVXCallbackChain(params); |
rgrover1 | 737:79d95f9b93be | 400 | } |
rgrover1 | 737:79d95f9b93be | 401 | } |
rgrover1 | 737:79d95f9b93be | 402 | |
rgrover1 | 728:997ba5e7b3b6 | 403 | protected: |
vcoubard | 1052:b55e1ad3e1b3 | 404 | ReadCallbackChain_t onDataReadCallbackChain; |
vcoubard | 1052:b55e1ad3e1b3 | 405 | WriteCallbackChain_t onDataWriteCallbackChain; |
vcoubard | 1052:b55e1ad3e1b3 | 406 | HVXCallbackChain_t onHVXCallbackChain; |
rgrover1 | 728:997ba5e7b3b6 | 407 | |
rgrover1 | 716:11b41f651697 | 408 | private: |
vcoubard | 1048:efb29faf12fc | 409 | /* Disallow copy and assignment. */ |
rgrover1 | 716:11b41f651697 | 410 | GattClient(const GattClient &); |
rgrover1 | 716:11b41f651697 | 411 | GattClient& operator=(const GattClient &); |
rgrover1 | 716:11b41f651697 | 412 | }; |
rgrover1 | 716:11b41f651697 | 413 | |
rgrover1 | 716:11b41f651697 | 414 | #endif // ifndef __GATT_CLIENT_H__ |