test
Dependents: BLE_PowerBank_HeyFaradey
Fork of BLE_API by
ble/GattClient.h@927:b6bde304c9be, 2015-11-26 (annotated)
- Committer:
- rgrover1
- Date:
- Thu Nov 26 12:52:05 2015 +0000
- Revision:
- 927:b6bde304c9be
- Parent:
- 913:690bea02c431
- Child:
- 933:3ec277a0d780
Synchronized with git rev 24377826
Author: Vincent Coubard
Replace simple callbacks by callchains
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" |
rgrover1 | 716:11b41f651697 | 23 | |
rgrover1 | 716:11b41f651697 | 24 | #include "GattCallbackParamTypes.h" |
rgrover1 | 716:11b41f651697 | 25 | |
rgrover1 | 927:b6bde304c9be | 26 | #include "CallChainOfFunctionPointersWithContext.h" |
rgrover1 | 927:b6bde304c9be | 27 | |
rgrover1 | 716:11b41f651697 | 28 | class GattClient { |
rgrover1 | 716:11b41f651697 | 29 | public: |
rgrover1 | 927:b6bde304c9be | 30 | typedef FunctionPointerWithContext<const GattReadCallbackParams*> ReadCallback_t; |
rgrover1 | 927:b6bde304c9be | 31 | typedef CallChainOfFunctionPointersWithContext<const GattReadCallbackParams*> ReadCallbackChain_t; |
rgrover1 | 716:11b41f651697 | 32 | |
rgrover1 | 716:11b41f651697 | 33 | enum WriteOp_t { |
rgrover1 | 913:690bea02c431 | 34 | GATT_OP_WRITE_REQ = 0x01, /**< Write request. */ |
rgrover1 | 913:690bea02c431 | 35 | GATT_OP_WRITE_CMD = 0x02, /**< Write command. */ |
rgrover1 | 716:11b41f651697 | 36 | }; |
rgrover1 | 716:11b41f651697 | 37 | |
rgrover1 | 927:b6bde304c9be | 38 | typedef FunctionPointerWithContext<const GattWriteCallbackParams*> WriteCallback_t; |
rgrover1 | 927:b6bde304c9be | 39 | typedef CallChainOfFunctionPointersWithContext<const GattWriteCallbackParams*> WriteCallbackChain_t; |
rgrover1 | 716:11b41f651697 | 40 | |
rgrover1 | 927:b6bde304c9be | 41 | typedef FunctionPointerWithContext<const GattHVXCallbackParams*> HVXCallback_t; |
rgrover1 | 927:b6bde304c9be | 42 | typedef CallChainOfFunctionPointersWithContext<const GattHVXCallbackParams*> HVXCallbackChain_t; |
rgrover1 | 737:79d95f9b93be | 43 | |
rgrover1 | 716:11b41f651697 | 44 | /* |
rgrover1 | 716:11b41f651697 | 45 | * The following functions are meant to be overridden in the platform-specific sub-class. |
rgrover1 | 716:11b41f651697 | 46 | */ |
rgrover1 | 716:11b41f651697 | 47 | public: |
rgrover1 | 716:11b41f651697 | 48 | /** |
rgrover1 | 728:997ba5e7b3b6 | 49 | * Launch service discovery. Once launched, application callbacks will be |
rgrover1 | 913:690bea02c431 | 50 | * invoked for matching services or characteristics. isServiceDiscoveryActive() |
rgrover1 | 913:690bea02c431 | 51 | * can be used to determine status, and a termination callback (if one was set up) |
rgrover1 | 913:690bea02c431 | 52 | * will be invoked at the end. Service discovery can be terminated prematurely, |
rgrover1 | 913:690bea02c431 | 53 | * if needed, using terminateServiceDiscovery(). |
rgrover1 | 716:11b41f651697 | 54 | * |
rgrover1 | 716:11b41f651697 | 55 | * @param connectionHandle |
rgrover1 | 716:11b41f651697 | 56 | * Handle for the connection with the peer. |
rgrover1 | 716:11b41f651697 | 57 | * @param sc |
rgrover1 | 913:690bea02c431 | 58 | * This is the application callback for a matching service. Taken as |
rgrover1 | 716:11b41f651697 | 59 | * NULL by default. Note: service discovery may still be active |
rgrover1 | 716:11b41f651697 | 60 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 716:11b41f651697 | 61 | * APIs from within this application callback might cause the |
rgrover1 | 716:11b41f651697 | 62 | * stack to abort service discovery. If this becomes an issue, it |
rgrover1 | 913:690bea02c431 | 63 | * may be better to make a local copy of the discoveredService and |
rgrover1 | 716:11b41f651697 | 64 | * wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 65 | * service. |
rgrover1 | 716:11b41f651697 | 66 | * @param cc |
rgrover1 | 913:690bea02c431 | 67 | * This is the application callback for a matching characteristic. |
rgrover1 | 716:11b41f651697 | 68 | * Taken as NULL by default. Note: service discovery may still be |
rgrover1 | 716:11b41f651697 | 69 | * active when this callback is issued; calling asynchronous |
rgrover1 | 716:11b41f651697 | 70 | * BLE-stack APIs from within this application callback might cause |
rgrover1 | 716:11b41f651697 | 71 | * the stack to abort service discovery. If this becomes an issue, |
rgrover1 | 913:690bea02c431 | 72 | * it may be better to make a local copy of the discoveredCharacteristic |
rgrover1 | 716:11b41f651697 | 73 | * and wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 74 | * characteristic. |
rgrover1 | 716:11b41f651697 | 75 | * @param matchingServiceUUID |
rgrover1 | 913:690bea02c431 | 76 | * UUID-based filter for specifying a service in which the application is |
rgrover1 | 716:11b41f651697 | 77 | * interested. By default it is set as the wildcard UUID_UNKNOWN, |
rgrover1 | 716:11b41f651697 | 78 | * in which case it matches all services. If characteristic-UUID |
rgrover1 | 716:11b41f651697 | 79 | * filter (below) is set to the wildcard value, then a service |
rgrover1 | 716:11b41f651697 | 80 | * callback will be invoked for the matching service (or for every |
rgrover1 | 716:11b41f651697 | 81 | * service if the service filter is a wildcard). |
rgrover1 | 716:11b41f651697 | 82 | * @param matchingCharacteristicUUIDIn |
rgrover1 | 913:690bea02c431 | 83 | * UUID-based filter for specifying characteristic in which the application |
rgrover1 | 716:11b41f651697 | 84 | * is interested. By default it is set as the wildcard UUID_UKNOWN |
rgrover1 | 716:11b41f651697 | 85 | * to match against any characteristic. If both service-UUID |
rgrover1 | 913:690bea02c431 | 86 | * filter and characteristic-UUID filter are used with non-wildcard |
rgrover1 | 716:11b41f651697 | 87 | * values, then only a single characteristic callback is |
rgrover1 | 716:11b41f651697 | 88 | * invoked for the matching characteristic. |
rgrover1 | 716:11b41f651697 | 89 | * |
rgrover1 | 716:11b41f651697 | 90 | * @note Using wildcard values for both service-UUID and characteristic- |
rgrover1 | 913:690bea02c431 | 91 | * UUID will result in complete service discovery: callbacks being |
rgrover1 | 716:11b41f651697 | 92 | * called for every service and characteristic. |
rgrover1 | 716:11b41f651697 | 93 | * |
rgrover1 | 716:11b41f651697 | 94 | * @note Providing NULL for the characteristic callback will result in |
rgrover1 | 716:11b41f651697 | 95 | * characteristic discovery being skipped for each matching |
rgrover1 | 716:11b41f651697 | 96 | * service. This allows for an inexpensive method to discover only |
rgrover1 | 716:11b41f651697 | 97 | * services. |
rgrover1 | 716:11b41f651697 | 98 | * |
rgrover1 | 716:11b41f651697 | 99 | * @return |
rgrover1 | 716:11b41f651697 | 100 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 716:11b41f651697 | 101 | */ |
rgrover1 | 716:11b41f651697 | 102 | virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle, |
rgrover1 | 716:11b41f651697 | 103 | ServiceDiscovery::ServiceCallback_t sc = NULL, |
rgrover1 | 716:11b41f651697 | 104 | ServiceDiscovery::CharacteristicCallback_t cc = NULL, |
rgrover1 | 716:11b41f651697 | 105 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN), |
rgrover1 | 716:11b41f651697 | 106 | const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) { |
rgrover1 | 913:690bea02c431 | 107 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 734:4872b70437ce | 108 | (void)connectionHandle; |
rgrover1 | 734:4872b70437ce | 109 | (void)sc; |
rgrover1 | 734:4872b70437ce | 110 | (void)cc; |
rgrover1 | 734:4872b70437ce | 111 | (void)matchingServiceUUID; |
rgrover1 | 734:4872b70437ce | 112 | (void)matchingCharacteristicUUIDIn; |
rgrover1 | 734:4872b70437ce | 113 | |
rgrover1 | 913:690bea02c431 | 114 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 115 | } |
rgrover1 | 716:11b41f651697 | 116 | |
rgrover1 | 716:11b41f651697 | 117 | /** |
rgrover1 | 716:11b41f651697 | 118 | * Launch service discovery for services. Once launched, service discovery will remain |
rgrover1 | 716:11b41f651697 | 119 | * active with service-callbacks being issued back into the application for matching |
rgrover1 | 716:11b41f651697 | 120 | * services. isServiceDiscoveryActive() can be used to |
rgrover1 | 913:690bea02c431 | 121 | * determine status, and a termination callback (if set up) will be invoked |
rgrover1 | 913:690bea02c431 | 122 | * at the end. Service discovery can be terminated prematurely, if needed, |
rgrover1 | 716:11b41f651697 | 123 | * using terminateServiceDiscovery(). |
rgrover1 | 716:11b41f651697 | 124 | * |
rgrover1 | 716:11b41f651697 | 125 | * @param connectionHandle |
rgrover1 | 716:11b41f651697 | 126 | * Handle for the connection with the peer. |
rgrover1 | 716:11b41f651697 | 127 | * @param sc |
rgrover1 | 913:690bea02c431 | 128 | * This is the application callback for a matching service. Note: service discovery may still be active |
rgrover1 | 716:11b41f651697 | 129 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 716:11b41f651697 | 130 | * APIs from within this application callback might cause the |
rgrover1 | 716:11b41f651697 | 131 | * stack to abort service discovery. If this becomes an issue, it |
rgrover1 | 913:690bea02c431 | 132 | * may be better to make a local copy of the discoveredService and |
rgrover1 | 716:11b41f651697 | 133 | * wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 134 | * service. |
rgrover1 | 716:11b41f651697 | 135 | * @param matchingServiceUUID |
rgrover1 | 913:690bea02c431 | 136 | * UUID-based filter for specifying a service in which the application is |
rgrover1 | 716:11b41f651697 | 137 | * interested. By default it is set as the wildcard UUID_UNKNOWN, |
rgrover1 | 716:11b41f651697 | 138 | * in which case it matches all services. |
rgrover1 | 716:11b41f651697 | 139 | * |
rgrover1 | 716:11b41f651697 | 140 | * @return |
rgrover1 | 716:11b41f651697 | 141 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 716:11b41f651697 | 142 | */ |
rgrover1 | 716:11b41f651697 | 143 | virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, |
rgrover1 | 716:11b41f651697 | 144 | ServiceDiscovery::ServiceCallback_t callback, |
rgrover1 | 716:11b41f651697 | 145 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) { |
rgrover1 | 742:861ed7eb186d | 146 | return launchServiceDiscovery(connectionHandle, callback, NULL, matchingServiceUUID); /* We take advantage of the property |
rgrover1 | 742:861ed7eb186d | 147 | * that providing NULL for the characteristic callback will result in |
rgrover1 | 742:861ed7eb186d | 148 | * characteristic discovery being skipped for each matching |
rgrover1 | 742:861ed7eb186d | 149 | * service. This allows for an inexpensive method to discover only |
rgrover1 | 913:690bea02c431 | 150 | * services. Porters are free to override this. */ |
rgrover1 | 716:11b41f651697 | 151 | } |
rgrover1 | 716:11b41f651697 | 152 | |
rgrover1 | 716:11b41f651697 | 153 | /** |
rgrover1 | 716:11b41f651697 | 154 | * Launch service discovery for services. Once launched, service discovery will remain |
rgrover1 | 716:11b41f651697 | 155 | * active with service-callbacks being issued back into the application for matching |
rgrover1 | 716:11b41f651697 | 156 | * services. isServiceDiscoveryActive() can be used to |
rgrover1 | 913:690bea02c431 | 157 | * determine status, and a termination callback (if set up) will be invoked |
rgrover1 | 913:690bea02c431 | 158 | * at the end. Service discovery can be terminated prematurely, if needed, |
rgrover1 | 716:11b41f651697 | 159 | * using terminateServiceDiscovery(). |
rgrover1 | 716:11b41f651697 | 160 | * |
rgrover1 | 716:11b41f651697 | 161 | * @param connectionHandle |
rgrover1 | 716:11b41f651697 | 162 | * Handle for the connection with the peer. |
rgrover1 | 716:11b41f651697 | 163 | * @param sc |
rgrover1 | 913:690bea02c431 | 164 | * This is the application callback for a matching service. Note: service discovery may still be active |
rgrover1 | 716:11b41f651697 | 165 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 716:11b41f651697 | 166 | * APIs from within this application callback might cause the |
rgrover1 | 716:11b41f651697 | 167 | * stack to abort service discovery. If this becomes an issue, it |
rgrover1 | 913:690bea02c431 | 168 | * may be better to make a local copy of the discoveredService and |
rgrover1 | 716:11b41f651697 | 169 | * wait for service discovery to terminate before operating on the |
rgrover1 | 716:11b41f651697 | 170 | * service. |
rgrover1 | 716:11b41f651697 | 171 | * @param startHandle, endHandle |
rgrover1 | 913:690bea02c431 | 172 | * Handle range within which to limit the search. |
rgrover1 | 716:11b41f651697 | 173 | * |
rgrover1 | 716:11b41f651697 | 174 | * @return |
rgrover1 | 716:11b41f651697 | 175 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 716:11b41f651697 | 176 | */ |
rgrover1 | 716:11b41f651697 | 177 | virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, |
rgrover1 | 716:11b41f651697 | 178 | ServiceDiscovery::ServiceCallback_t callback, |
rgrover1 | 716:11b41f651697 | 179 | GattAttribute::Handle_t startHandle, |
rgrover1 | 716:11b41f651697 | 180 | GattAttribute::Handle_t endHandle) { |
rgrover1 | 913:690bea02c431 | 181 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 734:4872b70437ce | 182 | (void)connectionHandle; |
rgrover1 | 734:4872b70437ce | 183 | (void)callback; |
rgrover1 | 734:4872b70437ce | 184 | (void)startHandle; |
rgrover1 | 734:4872b70437ce | 185 | (void)endHandle; |
rgrover1 | 734:4872b70437ce | 186 | |
rgrover1 | 913:690bea02c431 | 187 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 188 | } |
rgrover1 | 716:11b41f651697 | 189 | |
rgrover1 | 716:11b41f651697 | 190 | /** |
rgrover1 | 716:11b41f651697 | 191 | * Is service-discovery currently active? |
rgrover1 | 716:11b41f651697 | 192 | */ |
rgrover1 | 716:11b41f651697 | 193 | virtual bool isServiceDiscoveryActive(void) const { |
rgrover1 | 913:690bea02c431 | 194 | return false; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 195 | } |
rgrover1 | 716:11b41f651697 | 196 | |
rgrover1 | 716:11b41f651697 | 197 | /** |
rgrover1 | 913:690bea02c431 | 198 | * Terminate an ongoing service discovery. This should result in an |
rgrover1 | 913:690bea02c431 | 199 | * invocation of TerminationCallback if service-discovery is active. |
rgrover1 | 716:11b41f651697 | 200 | */ |
rgrover1 | 716:11b41f651697 | 201 | virtual void terminateServiceDiscovery(void) { |
rgrover1 | 913:690bea02c431 | 202 | /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 203 | } |
rgrover1 | 716:11b41f651697 | 204 | |
rgrover1 | 913:690bea02c431 | 205 | /* Initiate a GATT Client read procedure by attribute-handle. */ |
rgrover1 | 716:11b41f651697 | 206 | virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const { |
rgrover1 | 913:690bea02c431 | 207 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 734:4872b70437ce | 208 | (void)connHandle; |
rgrover1 | 734:4872b70437ce | 209 | (void)attributeHandle; |
rgrover1 | 734:4872b70437ce | 210 | (void)offset; |
rgrover1 | 734:4872b70437ce | 211 | |
rgrover1 | 913:690bea02c431 | 212 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 213 | } |
rgrover1 | 716:11b41f651697 | 214 | |
rgrover1 | 716:11b41f651697 | 215 | /** |
rgrover1 | 716:11b41f651697 | 216 | * Initiate a GATT Client write procedure. |
rgrover1 | 716:11b41f651697 | 217 | * |
rgrover1 | 716:11b41f651697 | 218 | * @param[in] cmd |
rgrover1 | 913:690bea02c431 | 219 | * Command can be either a write-request (which generates a |
rgrover1 | 913:690bea02c431 | 220 | * matching response from the peripheral), or a write-command |
rgrover1 | 913:690bea02c431 | 221 | * (which doesn't require the connected peer to respond). |
rgrover1 | 716:11b41f651697 | 222 | * @param[in] connHandle |
rgrover1 | 716:11b41f651697 | 223 | * Connection handle. |
rgrover1 | 716:11b41f651697 | 224 | * @param[in] attributeHandle |
rgrover1 | 913:690bea02c431 | 225 | * Handle for the target attribtue on the remote GATT server. |
rgrover1 | 716:11b41f651697 | 226 | * @param[in] length |
rgrover1 | 913:690bea02c431 | 227 | * Length of the new value. |
rgrover1 | 716:11b41f651697 | 228 | * @param[in] value |
rgrover1 | 913:690bea02c431 | 229 | * New value being written. |
rgrover1 | 716:11b41f651697 | 230 | */ |
rgrover1 | 716:11b41f651697 | 231 | virtual ble_error_t write(GattClient::WriteOp_t cmd, |
rgrover1 | 716:11b41f651697 | 232 | Gap::Handle_t connHandle, |
rgrover1 | 716:11b41f651697 | 233 | GattAttribute::Handle_t attributeHandle, |
rgrover1 | 716:11b41f651697 | 234 | size_t length, |
rgrover1 | 716:11b41f651697 | 235 | const uint8_t *value) const { |
rgrover1 | 913:690bea02c431 | 236 | /* Avoid compiler warnings about unused variables. */ |
rgrover1 | 734:4872b70437ce | 237 | (void)cmd; |
rgrover1 | 734:4872b70437ce | 238 | (void)connHandle; |
rgrover1 | 734:4872b70437ce | 239 | (void)attributeHandle; |
rgrover1 | 734:4872b70437ce | 240 | (void)length; |
rgrover1 | 734:4872b70437ce | 241 | (void)value; |
rgrover1 | 734:4872b70437ce | 242 | |
rgrover1 | 913:690bea02c431 | 243 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 728:997ba5e7b3b6 | 244 | } |
rgrover1 | 728:997ba5e7b3b6 | 245 | |
rgrover1 | 728:997ba5e7b3b6 | 246 | /* Event callback handlers. */ |
rgrover1 | 728:997ba5e7b3b6 | 247 | public: |
rgrover1 | 728:997ba5e7b3b6 | 248 | /** |
rgrover1 | 913:690bea02c431 | 249 | * Set up a callback for read response events. |
rgrover1 | 728:997ba5e7b3b6 | 250 | */ |
rgrover1 | 728:997ba5e7b3b6 | 251 | void onDataRead(ReadCallback_t callback) { |
rgrover1 | 927:b6bde304c9be | 252 | onDataReadCallbackChain.add(callback); |
rgrover1 | 927:b6bde304c9be | 253 | } |
rgrover1 | 927:b6bde304c9be | 254 | |
rgrover1 | 927:b6bde304c9be | 255 | ReadCallbackChain_t& onDataRead() { |
rgrover1 | 927:b6bde304c9be | 256 | return onDataReadCallbackChain; |
rgrover1 | 728:997ba5e7b3b6 | 257 | } |
rgrover1 | 728:997ba5e7b3b6 | 258 | |
rgrover1 | 728:997ba5e7b3b6 | 259 | /** |
rgrover1 | 913:690bea02c431 | 260 | * Set up a callback for write response events. |
rgrover1 | 913:690bea02c431 | 261 | * @Note: Write commands (issued using writeWoResponse) don't generate a response. |
rgrover1 | 728:997ba5e7b3b6 | 262 | */ |
rgrover1 | 768:8914bea92690 | 263 | void onDataWritten(WriteCallback_t callback) { |
rgrover1 | 927:b6bde304c9be | 264 | onDataWriteCallbackChain.add(callback); |
rgrover1 | 927:b6bde304c9be | 265 | } |
rgrover1 | 927:b6bde304c9be | 266 | |
rgrover1 | 927:b6bde304c9be | 267 | WriteCallbackChain_t& onDataWritten() { |
rgrover1 | 927:b6bde304c9be | 268 | return onDataWriteCallbackChain; |
rgrover1 | 768:8914bea92690 | 269 | } |
rgrover1 | 768:8914bea92690 | 270 | |
rgrover1 | 768:8914bea92690 | 271 | /** |
rgrover1 | 913:690bea02c431 | 272 | * Set up a callback for write response events. |
rgrover1 | 913:690bea02c431 | 273 | * @Note: Write commands (issued using writeWoResponse) don't generate a response. |
rgrover1 | 768:8914bea92690 | 274 | * |
rgrover1 | 768:8914bea92690 | 275 | * @note: This API is now *deprecated* and will be dropped in the future. |
rgrover1 | 768:8914bea92690 | 276 | * Please use onDataWritten() instead. |
rgrover1 | 768:8914bea92690 | 277 | */ |
rgrover1 | 728:997ba5e7b3b6 | 278 | void onDataWrite(WriteCallback_t callback) { |
rgrover1 | 768:8914bea92690 | 279 | onDataWritten(callback); |
rgrover1 | 720:ce8a760a4504 | 280 | } |
rgrover1 | 720:ce8a760a4504 | 281 | |
rgrover1 | 716:11b41f651697 | 282 | /** |
rgrover1 | 913:690bea02c431 | 283 | * Set up a callback for when serviceDiscovery terminates. |
rgrover1 | 716:11b41f651697 | 284 | */ |
rgrover1 | 716:11b41f651697 | 285 | virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) { |
rgrover1 | 913:690bea02c431 | 286 | (void)callback; /* Avoid compiler warnings about ununsed variables. */ |
rgrover1 | 734:4872b70437ce | 287 | |
rgrover1 | 913:690bea02c431 | 288 | /* Requesting action from porters: override this API if this capability is supported. */ |
rgrover1 | 716:11b41f651697 | 289 | } |
rgrover1 | 716:11b41f651697 | 290 | |
rgrover1 | 737:79d95f9b93be | 291 | /** |
rgrover1 | 913:690bea02c431 | 292 | * Set up a callback for when the GATT client receives an update event |
rgrover1 | 913:690bea02c431 | 293 | * corresponding to a change in the value of a characteristic on the remote |
rgrover1 | 913:690bea02c431 | 294 | * GATT server. |
rgrover1 | 737:79d95f9b93be | 295 | */ |
rgrover1 | 737:79d95f9b93be | 296 | void onHVX(HVXCallback_t callback) { |
rgrover1 | 927:b6bde304c9be | 297 | onHVXCallbackChain.add(callback); |
rgrover1 | 927:b6bde304c9be | 298 | } |
rgrover1 | 927:b6bde304c9be | 299 | |
rgrover1 | 927:b6bde304c9be | 300 | HVXCallbackChain_t& onHVX() { |
rgrover1 | 927:b6bde304c9be | 301 | return onHVXCallbackChain; |
rgrover1 | 737:79d95f9b93be | 302 | } |
rgrover1 | 737:79d95f9b93be | 303 | |
rgrover1 | 716:11b41f651697 | 304 | protected: |
rgrover1 | 716:11b41f651697 | 305 | GattClient() { |
rgrover1 | 913:690bea02c431 | 306 | /* Empty */ |
rgrover1 | 716:11b41f651697 | 307 | } |
rgrover1 | 716:11b41f651697 | 308 | |
rgrover1 | 728:997ba5e7b3b6 | 309 | /* Entry points for the underlying stack to report events back to the user. */ |
rgrover1 | 728:997ba5e7b3b6 | 310 | public: |
rgrover1 | 728:997ba5e7b3b6 | 311 | void processReadResponse(const GattReadCallbackParams *params) { |
rgrover1 | 927:b6bde304c9be | 312 | onDataReadCallbackChain(params); |
rgrover1 | 728:997ba5e7b3b6 | 313 | } |
rgrover1 | 728:997ba5e7b3b6 | 314 | |
rgrover1 | 728:997ba5e7b3b6 | 315 | void processWriteResponse(const GattWriteCallbackParams *params) { |
rgrover1 | 927:b6bde304c9be | 316 | onDataWriteCallbackChain(params); |
rgrover1 | 728:997ba5e7b3b6 | 317 | } |
rgrover1 | 728:997ba5e7b3b6 | 318 | |
rgrover1 | 737:79d95f9b93be | 319 | void processHVXEvent(const GattHVXCallbackParams *params) { |
rgrover1 | 927:b6bde304c9be | 320 | if (onHVXCallbackChain) { |
rgrover1 | 927:b6bde304c9be | 321 | onHVXCallbackChain(params); |
rgrover1 | 737:79d95f9b93be | 322 | } |
rgrover1 | 737:79d95f9b93be | 323 | } |
rgrover1 | 737:79d95f9b93be | 324 | |
rgrover1 | 728:997ba5e7b3b6 | 325 | protected: |
rgrover1 | 927:b6bde304c9be | 326 | ReadCallbackChain_t onDataReadCallbackChain; |
rgrover1 | 927:b6bde304c9be | 327 | WriteCallbackChain_t onDataWriteCallbackChain; |
rgrover1 | 927:b6bde304c9be | 328 | HVXCallbackChain_t onHVXCallbackChain; |
rgrover1 | 728:997ba5e7b3b6 | 329 | |
rgrover1 | 716:11b41f651697 | 330 | private: |
rgrover1 | 913:690bea02c431 | 331 | /* Disallow copy and assignment. */ |
rgrover1 | 716:11b41f651697 | 332 | GattClient(const GattClient &); |
rgrover1 | 716:11b41f651697 | 333 | GattClient& operator=(const GattClient &); |
rgrover1 | 716:11b41f651697 | 334 | }; |
rgrover1 | 716:11b41f651697 | 335 | |
rgrover1 | 716:11b41f651697 | 336 | #endif // ifndef __GATT_CLIENT_H__ |