prova invio BLE
Dependents: BLE_HeartRate_IDB04A1
Fork of BLE_API by
ble/GattServer.h@1209:28067a1925b5, 2018-02-12 (annotated)
- Committer:
- carlotara
- Date:
- Mon Feb 12 08:45:34 2018 +0000
- Revision:
- 1209:28067a1925b5
- Parent:
- 1192:718787de23b7
prova invio da BLE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vcoubard | 1131:692ddf04fc42 | 1 | /* mbed Microcontroller Library |
vcoubard | 1131:692ddf04fc42 | 2 | * Copyright (c) 2006-2013 ARM Limited |
vcoubard | 1131:692ddf04fc42 | 3 | * |
vcoubard | 1131:692ddf04fc42 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
vcoubard | 1131:692ddf04fc42 | 5 | * you may not use this file except in compliance with the License. |
vcoubard | 1131:692ddf04fc42 | 6 | * You may obtain a copy of the License at |
vcoubard | 1131:692ddf04fc42 | 7 | * |
vcoubard | 1131:692ddf04fc42 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
vcoubard | 1131:692ddf04fc42 | 9 | * |
vcoubard | 1131:692ddf04fc42 | 10 | * Unless required by applicable law or agreed to in writing, software |
vcoubard | 1131:692ddf04fc42 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
vcoubard | 1131:692ddf04fc42 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
vcoubard | 1131:692ddf04fc42 | 13 | * See the License for the specific language governing permissions and |
vcoubard | 1131:692ddf04fc42 | 14 | * limitations under the License. |
vcoubard | 1131:692ddf04fc42 | 15 | */ |
vcoubard | 1131:692ddf04fc42 | 16 | |
vcoubard | 1131:692ddf04fc42 | 17 | #ifndef __GATT_SERVER_H__ |
vcoubard | 1131:692ddf04fc42 | 18 | #define __GATT_SERVER_H__ |
vcoubard | 1131:692ddf04fc42 | 19 | |
vcoubard | 1131:692ddf04fc42 | 20 | #include "Gap.h" |
vcoubard | 1131:692ddf04fc42 | 21 | #include "GattService.h" |
vcoubard | 1131:692ddf04fc42 | 22 | #include "GattAttribute.h" |
vcoubard | 1131:692ddf04fc42 | 23 | #include "GattServerEvents.h" |
vcoubard | 1131:692ddf04fc42 | 24 | #include "GattCallbackParamTypes.h" |
vcoubard | 1131:692ddf04fc42 | 25 | #include "CallChainOfFunctionPointersWithContext.h" |
vcoubard | 1131:692ddf04fc42 | 26 | |
vcoubard | 1131:692ddf04fc42 | 27 | class GattServer { |
vcoubard | 1131:692ddf04fc42 | 28 | public: |
vcoubard | 1183:1589830dbdb7 | 29 | /** |
vcoubard | 1183:1589830dbdb7 | 30 | * Type for the registered callbacks added to the data sent callchain. |
vcoubard | 1183:1589830dbdb7 | 31 | * Refer to GattServer::onDataSent(). |
vcoubard | 1183:1589830dbdb7 | 32 | */ |
vcoubard | 1131:692ddf04fc42 | 33 | typedef FunctionPointerWithContext<unsigned> DataSentCallback_t; |
vcoubard | 1183:1589830dbdb7 | 34 | /** |
vcoubard | 1183:1589830dbdb7 | 35 | * Type for the data sent event callchain. Refer to GattServer::onDataSent(). |
vcoubard | 1183:1589830dbdb7 | 36 | */ |
vcoubard | 1131:692ddf04fc42 | 37 | typedef CallChainOfFunctionPointersWithContext<unsigned> DataSentCallbackChain_t; |
vcoubard | 1131:692ddf04fc42 | 38 | |
vcoubard | 1183:1589830dbdb7 | 39 | /** |
vcoubard | 1183:1589830dbdb7 | 40 | * Type for the registered callbacks added to the data written callchain. |
vcoubard | 1183:1589830dbdb7 | 41 | * Refer to GattServer::onDataWritten(). |
vcoubard | 1183:1589830dbdb7 | 42 | */ |
vcoubard | 1131:692ddf04fc42 | 43 | typedef FunctionPointerWithContext<const GattWriteCallbackParams*> DataWrittenCallback_t; |
vcoubard | 1183:1589830dbdb7 | 44 | /** |
vcoubard | 1183:1589830dbdb7 | 45 | * Type for the data written event callchain. Refer to GattServer::onDataWritten(). |
vcoubard | 1183:1589830dbdb7 | 46 | */ |
vcoubard | 1135:22aada733dbd | 47 | typedef CallChainOfFunctionPointersWithContext<const GattWriteCallbackParams*> DataWrittenCallbackChain_t; |
vcoubard | 1131:692ddf04fc42 | 48 | |
vcoubard | 1183:1589830dbdb7 | 49 | /** |
vcoubard | 1183:1589830dbdb7 | 50 | * Type for the registered callbacks added to the data read callchain. |
vcoubard | 1183:1589830dbdb7 | 51 | * Refer to GattServer::onDataRead(). |
vcoubard | 1183:1589830dbdb7 | 52 | */ |
vcoubard | 1131:692ddf04fc42 | 53 | typedef FunctionPointerWithContext<const GattReadCallbackParams*> DataReadCallback_t; |
vcoubard | 1183:1589830dbdb7 | 54 | /** |
vcoubard | 1183:1589830dbdb7 | 55 | * Type for the data read event callchain. Refer to GattServer::onDataRead(). |
vcoubard | 1183:1589830dbdb7 | 56 | */ |
vcoubard | 1131:692ddf04fc42 | 57 | typedef CallChainOfFunctionPointersWithContext<const GattReadCallbackParams *> DataReadCallbackChain_t; |
vcoubard | 1131:692ddf04fc42 | 58 | |
vcoubard | 1183:1589830dbdb7 | 59 | /** |
vcoubard | 1183:1589830dbdb7 | 60 | * Type for the registered callbacks added to the shutdown callchain. |
vcoubard | 1183:1589830dbdb7 | 61 | * Refer to GattServer::onShutdown(). |
vcoubard | 1183:1589830dbdb7 | 62 | */ |
vcoubard | 1135:22aada733dbd | 63 | typedef FunctionPointerWithContext<const GattServer *> GattServerShutdownCallback_t; |
vcoubard | 1183:1589830dbdb7 | 64 | /** |
vcoubard | 1183:1589830dbdb7 | 65 | * Type for the shutdown event callchain. Refer to GattServer::onShutdown(). |
vcoubard | 1183:1589830dbdb7 | 66 | */ |
vcoubard | 1135:22aada733dbd | 67 | typedef CallChainOfFunctionPointersWithContext<const GattServer *> GattServerShutdownCallbackChain_t; |
vcoubard | 1135:22aada733dbd | 68 | |
vcoubard | 1183:1589830dbdb7 | 69 | /** |
vcoubard | 1183:1589830dbdb7 | 70 | * Type for the registered callback for various events. Refer to |
vcoubard | 1183:1589830dbdb7 | 71 | * GattServer::onUpdatesEnabled(), GattServer::onUpdateDisabled() and |
vcoubard | 1183:1589830dbdb7 | 72 | * GattServer::onConfirmationReceived(). |
vcoubard | 1183:1589830dbdb7 | 73 | */ |
vcoubard | 1131:692ddf04fc42 | 74 | typedef FunctionPointerWithContext<GattAttribute::Handle_t> EventCallback_t; |
vcoubard | 1131:692ddf04fc42 | 75 | |
vcoubard | 1131:692ddf04fc42 | 76 | protected: |
vcoubard | 1183:1589830dbdb7 | 77 | /** |
vcoubard | 1183:1589830dbdb7 | 78 | * Construct a GattServer instance. |
vcoubard | 1183:1589830dbdb7 | 79 | */ |
vcoubard | 1131:692ddf04fc42 | 80 | GattServer() : |
vcoubard | 1131:692ddf04fc42 | 81 | serviceCount(0), |
vcoubard | 1131:692ddf04fc42 | 82 | characteristicCount(0), |
vcoubard | 1131:692ddf04fc42 | 83 | dataSentCallChain(), |
vcoubard | 1131:692ddf04fc42 | 84 | dataWrittenCallChain(), |
vcoubard | 1131:692ddf04fc42 | 85 | dataReadCallChain(), |
vcoubard | 1131:692ddf04fc42 | 86 | updatesEnabledCallback(NULL), |
vcoubard | 1131:692ddf04fc42 | 87 | updatesDisabledCallback(NULL), |
vcoubard | 1131:692ddf04fc42 | 88 | confirmationReceivedCallback(NULL) { |
vcoubard | 1131:692ddf04fc42 | 89 | /* empty */ |
vcoubard | 1131:692ddf04fc42 | 90 | } |
vcoubard | 1131:692ddf04fc42 | 91 | |
vcoubard | 1131:692ddf04fc42 | 92 | /* |
vcoubard | 1131:692ddf04fc42 | 93 | * The following functions are meant to be overridden in the platform-specific sub-class. |
vcoubard | 1131:692ddf04fc42 | 94 | */ |
vcoubard | 1131:692ddf04fc42 | 95 | public: |
vcoubard | 1131:692ddf04fc42 | 96 | |
vcoubard | 1131:692ddf04fc42 | 97 | /** |
vcoubard | 1131:692ddf04fc42 | 98 | * Add a service declaration to the local server ATT table. Also add the |
vcoubard | 1131:692ddf04fc42 | 99 | * characteristics contained within. |
vcoubard | 1183:1589830dbdb7 | 100 | * |
vcoubard | 1183:1589830dbdb7 | 101 | * @param[in] service |
vcoubard | 1183:1589830dbdb7 | 102 | * The service to be added. |
vcoubard | 1183:1589830dbdb7 | 103 | * |
vcoubard | 1183:1589830dbdb7 | 104 | * @return BLE_ERROR_NONE if the service was successfully added. |
vcoubard | 1131:692ddf04fc42 | 105 | */ |
vcoubard | 1131:692ddf04fc42 | 106 | virtual ble_error_t addService(GattService &service) { |
vcoubard | 1131:692ddf04fc42 | 107 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1131:692ddf04fc42 | 108 | (void)service; |
vcoubard | 1131:692ddf04fc42 | 109 | |
vcoubard | 1131:692ddf04fc42 | 110 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
vcoubard | 1131:692ddf04fc42 | 111 | } |
vcoubard | 1131:692ddf04fc42 | 112 | |
vcoubard | 1131:692ddf04fc42 | 113 | /** |
vcoubard | 1131:692ddf04fc42 | 114 | * Read the value of a characteristic from the local GATT server. |
vcoubard | 1183:1589830dbdb7 | 115 | * |
vcoubard | 1131:692ddf04fc42 | 116 | * @param[in] attributeHandle |
vcoubard | 1131:692ddf04fc42 | 117 | * Attribute handle for the value attribute of the characteristic. |
vcoubard | 1131:692ddf04fc42 | 118 | * @param[out] buffer |
vcoubard | 1131:692ddf04fc42 | 119 | * A buffer to hold the value being read. |
vcoubard | 1183:1589830dbdb7 | 120 | * @param[in,out] lengthP |
vcoubard | 1131:692ddf04fc42 | 121 | * Length of the buffer being supplied. If the attribute |
vcoubard | 1131:692ddf04fc42 | 122 | * value is longer than the size of the supplied buffer, |
vcoubard | 1131:692ddf04fc42 | 123 | * this variable will hold upon return the total attribute value length |
vcoubard | 1131:692ddf04fc42 | 124 | * (excluding offset). The application may use this |
vcoubard | 1131:692ddf04fc42 | 125 | * information to allocate a suitable buffer size. |
vcoubard | 1131:692ddf04fc42 | 126 | * |
vcoubard | 1131:692ddf04fc42 | 127 | * @return BLE_ERROR_NONE if a value was read successfully into the buffer. |
vcoubard | 1131:692ddf04fc42 | 128 | */ |
vcoubard | 1131:692ddf04fc42 | 129 | virtual ble_error_t read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP) { |
vcoubard | 1131:692ddf04fc42 | 130 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1131:692ddf04fc42 | 131 | (void)attributeHandle; |
vcoubard | 1131:692ddf04fc42 | 132 | (void)buffer; |
vcoubard | 1131:692ddf04fc42 | 133 | (void)lengthP; |
vcoubard | 1131:692ddf04fc42 | 134 | |
vcoubard | 1131:692ddf04fc42 | 135 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
vcoubard | 1131:692ddf04fc42 | 136 | } |
vcoubard | 1131:692ddf04fc42 | 137 | |
vcoubard | 1131:692ddf04fc42 | 138 | /** |
vcoubard | 1131:692ddf04fc42 | 139 | * Read the value of a characteristic from the local GATT server. |
vcoubard | 1183:1589830dbdb7 | 140 | * |
vcoubard | 1131:692ddf04fc42 | 141 | * @param[in] connectionHandle |
vcoubard | 1131:692ddf04fc42 | 142 | * Connection handle. |
vcoubard | 1131:692ddf04fc42 | 143 | * @param[in] attributeHandle |
vcoubard | 1131:692ddf04fc42 | 144 | * Attribute handle for the value attribute of the characteristic. |
vcoubard | 1131:692ddf04fc42 | 145 | * @param[out] buffer |
vcoubard | 1131:692ddf04fc42 | 146 | * A buffer to hold the value being read. |
vcoubard | 1183:1589830dbdb7 | 147 | * @param[in,out] lengthP |
vcoubard | 1131:692ddf04fc42 | 148 | * Length of the buffer being supplied. If the attribute |
vcoubard | 1131:692ddf04fc42 | 149 | * value is longer than the size of the supplied buffer, |
vcoubard | 1131:692ddf04fc42 | 150 | * this variable will hold upon return the total attribute value length |
vcoubard | 1131:692ddf04fc42 | 151 | * (excluding offset). The application may use this |
vcoubard | 1131:692ddf04fc42 | 152 | * information to allocate a suitable buffer size. |
vcoubard | 1131:692ddf04fc42 | 153 | * |
vcoubard | 1131:692ddf04fc42 | 154 | * @return BLE_ERROR_NONE if a value was read successfully into the buffer. |
vcoubard | 1131:692ddf04fc42 | 155 | * |
vcoubard | 1131:692ddf04fc42 | 156 | * @note This API is a version of the above, with an additional connection handle |
vcoubard | 1131:692ddf04fc42 | 157 | * parameter to allow fetches for connection-specific multivalued |
vcoubard | 1131:692ddf04fc42 | 158 | * attributes (such as the CCCDs). |
vcoubard | 1131:692ddf04fc42 | 159 | */ |
vcoubard | 1131:692ddf04fc42 | 160 | virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP) { |
vcoubard | 1131:692ddf04fc42 | 161 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1131:692ddf04fc42 | 162 | (void)connectionHandle; |
vcoubard | 1131:692ddf04fc42 | 163 | (void)attributeHandle; |
vcoubard | 1131:692ddf04fc42 | 164 | (void)buffer; |
vcoubard | 1131:692ddf04fc42 | 165 | (void)lengthP; |
vcoubard | 1131:692ddf04fc42 | 166 | |
vcoubard | 1131:692ddf04fc42 | 167 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
vcoubard | 1131:692ddf04fc42 | 168 | } |
vcoubard | 1131:692ddf04fc42 | 169 | |
vcoubard | 1131:692ddf04fc42 | 170 | /** |
vcoubard | 1131:692ddf04fc42 | 171 | * Update the value of a characteristic on the local GATT server. |
vcoubard | 1131:692ddf04fc42 | 172 | * |
vcoubard | 1131:692ddf04fc42 | 173 | * @param[in] attributeHandle |
vcoubard | 1131:692ddf04fc42 | 174 | * Handle for the value attribute of the characteristic. |
vcoubard | 1131:692ddf04fc42 | 175 | * @param[in] value |
vcoubard | 1131:692ddf04fc42 | 176 | * A pointer to a buffer holding the new value. |
vcoubard | 1131:692ddf04fc42 | 177 | * @param[in] size |
vcoubard | 1131:692ddf04fc42 | 178 | * Size of the new value (in bytes). |
vcoubard | 1131:692ddf04fc42 | 179 | * @param[in] localOnly |
vcoubard | 1131:692ddf04fc42 | 180 | * Should this update be kept on the local |
vcoubard | 1131:692ddf04fc42 | 181 | * GATT server regardless of the state of the |
vcoubard | 1131:692ddf04fc42 | 182 | * notify/indicate flag in the CCCD for this |
vcoubard | 1131:692ddf04fc42 | 183 | * Characteristic? If set to true, no notification |
vcoubard | 1131:692ddf04fc42 | 184 | * or indication is generated. |
vcoubard | 1131:692ddf04fc42 | 185 | * |
vcoubard | 1131:692ddf04fc42 | 186 | * @return BLE_ERROR_NONE if we have successfully set the value of the attribute. |
vcoubard | 1131:692ddf04fc42 | 187 | */ |
vcoubard | 1131:692ddf04fc42 | 188 | virtual ble_error_t write(GattAttribute::Handle_t attributeHandle, const uint8_t *value, uint16_t size, bool localOnly = false) { |
vcoubard | 1131:692ddf04fc42 | 189 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1131:692ddf04fc42 | 190 | (void)attributeHandle; |
vcoubard | 1131:692ddf04fc42 | 191 | (void)value; |
vcoubard | 1131:692ddf04fc42 | 192 | (void)size; |
vcoubard | 1131:692ddf04fc42 | 193 | (void)localOnly; |
vcoubard | 1131:692ddf04fc42 | 194 | |
vcoubard | 1131:692ddf04fc42 | 195 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
vcoubard | 1131:692ddf04fc42 | 196 | } |
vcoubard | 1131:692ddf04fc42 | 197 | |
vcoubard | 1131:692ddf04fc42 | 198 | /** |
vcoubard | 1131:692ddf04fc42 | 199 | * Update the value of a characteristic on the local GATT server. A version |
vcoubard | 1131:692ddf04fc42 | 200 | * of the same as the above, with a connection handle parameter to allow updates |
vcoubard | 1131:692ddf04fc42 | 201 | * for connection-specific multivalued attributes (such as the CCCDs). |
vcoubard | 1131:692ddf04fc42 | 202 | * |
vcoubard | 1131:692ddf04fc42 | 203 | * @param[in] connectionHandle |
vcoubard | 1131:692ddf04fc42 | 204 | * Connection handle. |
vcoubard | 1131:692ddf04fc42 | 205 | * @param[in] attributeHandle |
vcoubard | 1131:692ddf04fc42 | 206 | * Handle for the value attribute of the characteristic. |
vcoubard | 1131:692ddf04fc42 | 207 | * @param[in] value |
vcoubard | 1131:692ddf04fc42 | 208 | * A pointer to a buffer holding the new value. |
vcoubard | 1131:692ddf04fc42 | 209 | * @param[in] size |
vcoubard | 1131:692ddf04fc42 | 210 | * Size of the new value (in bytes). |
vcoubard | 1131:692ddf04fc42 | 211 | * @param[in] localOnly |
vcoubard | 1131:692ddf04fc42 | 212 | * Should this update be kept on the local |
vcoubard | 1131:692ddf04fc42 | 213 | * GattServer regardless of the state of the |
vcoubard | 1131:692ddf04fc42 | 214 | * notify/indicate flag in the CCCD for this |
vcoubard | 1131:692ddf04fc42 | 215 | * Characteristic? If set to true, no notification |
vcoubard | 1131:692ddf04fc42 | 216 | * or indication is generated. |
vcoubard | 1131:692ddf04fc42 | 217 | * |
vcoubard | 1131:692ddf04fc42 | 218 | * @return BLE_ERROR_NONE if we have successfully set the value of the attribute. |
vcoubard | 1131:692ddf04fc42 | 219 | */ |
vcoubard | 1131:692ddf04fc42 | 220 | virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t *value, uint16_t size, bool localOnly = false) { |
vcoubard | 1131:692ddf04fc42 | 221 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1131:692ddf04fc42 | 222 | (void)connectionHandle; |
vcoubard | 1131:692ddf04fc42 | 223 | (void)attributeHandle; |
vcoubard | 1131:692ddf04fc42 | 224 | (void)value; |
vcoubard | 1131:692ddf04fc42 | 225 | (void)size; |
vcoubard | 1131:692ddf04fc42 | 226 | (void)localOnly; |
vcoubard | 1131:692ddf04fc42 | 227 | |
vcoubard | 1131:692ddf04fc42 | 228 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
vcoubard | 1131:692ddf04fc42 | 229 | } |
vcoubard | 1131:692ddf04fc42 | 230 | |
vcoubard | 1131:692ddf04fc42 | 231 | /** |
vcoubard | 1131:692ddf04fc42 | 232 | * Determine the updates-enabled status (notification or indication) for the current connection from a characteristic's CCCD. |
vcoubard | 1131:692ddf04fc42 | 233 | * |
vcoubard | 1183:1589830dbdb7 | 234 | * @param[in] characteristic |
vcoubard | 1131:692ddf04fc42 | 235 | * The characteristic. |
vcoubard | 1131:692ddf04fc42 | 236 | * @param[out] enabledP |
vcoubard | 1131:692ddf04fc42 | 237 | * Upon return, *enabledP is true if updates are enabled, else false. |
vcoubard | 1131:692ddf04fc42 | 238 | * |
vcoubard | 1131:692ddf04fc42 | 239 | * @return BLE_ERROR_NONE if the connection and handle are found. False otherwise. |
vcoubard | 1131:692ddf04fc42 | 240 | */ |
vcoubard | 1131:692ddf04fc42 | 241 | virtual ble_error_t areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP) { |
vcoubard | 1131:692ddf04fc42 | 242 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1131:692ddf04fc42 | 243 | (void)characteristic; |
vcoubard | 1131:692ddf04fc42 | 244 | (void)enabledP; |
vcoubard | 1131:692ddf04fc42 | 245 | |
vcoubard | 1131:692ddf04fc42 | 246 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
vcoubard | 1131:692ddf04fc42 | 247 | } |
vcoubard | 1131:692ddf04fc42 | 248 | |
vcoubard | 1131:692ddf04fc42 | 249 | /** |
vcoubard | 1131:692ddf04fc42 | 250 | * Determine the connection-specific updates-enabled status (notification or indication) from a characteristic's CCCD. |
vcoubard | 1131:692ddf04fc42 | 251 | * |
vcoubard | 1183:1589830dbdb7 | 252 | * @param[in] connectionHandle |
vcoubard | 1131:692ddf04fc42 | 253 | * The connection handle. |
vcoubard | 1183:1589830dbdb7 | 254 | * @param[in] characteristic |
vcoubard | 1183:1589830dbdb7 | 255 | * The characteristic. |
vcoubard | 1131:692ddf04fc42 | 256 | * @param[out] enabledP |
vcoubard | 1131:692ddf04fc42 | 257 | * Upon return, *enabledP is true if updates are enabled, else false. |
vcoubard | 1131:692ddf04fc42 | 258 | * |
vcoubard | 1131:692ddf04fc42 | 259 | * @return BLE_ERROR_NONE if the connection and handle are found. False otherwise. |
vcoubard | 1131:692ddf04fc42 | 260 | */ |
vcoubard | 1131:692ddf04fc42 | 261 | virtual ble_error_t areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP) { |
vcoubard | 1131:692ddf04fc42 | 262 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1131:692ddf04fc42 | 263 | (void)connectionHandle; |
vcoubard | 1131:692ddf04fc42 | 264 | (void)characteristic; |
vcoubard | 1131:692ddf04fc42 | 265 | (void)enabledP; |
vcoubard | 1131:692ddf04fc42 | 266 | |
vcoubard | 1131:692ddf04fc42 | 267 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if this capability is supported. */ |
vcoubard | 1131:692ddf04fc42 | 268 | } |
vcoubard | 1131:692ddf04fc42 | 269 | |
vcoubard | 1131:692ddf04fc42 | 270 | /** |
vcoubard | 1131:692ddf04fc42 | 271 | * A virtual function to allow underlying stacks to indicate if they support |
vcoubard | 1131:692ddf04fc42 | 272 | * onDataRead(). It should be overridden to return true as applicable. |
vcoubard | 1183:1589830dbdb7 | 273 | * |
vcoubard | 1183:1589830dbdb7 | 274 | * @return true if onDataRead is supported, false otherwise. |
vcoubard | 1131:692ddf04fc42 | 275 | */ |
vcoubard | 1131:692ddf04fc42 | 276 | virtual bool isOnDataReadAvailable() const { |
vcoubard | 1131:692ddf04fc42 | 277 | return false; /* Requesting action from porters: override this API if this capability is supported. */ |
vcoubard | 1131:692ddf04fc42 | 278 | } |
vcoubard | 1131:692ddf04fc42 | 279 | |
vcoubard | 1131:692ddf04fc42 | 280 | /* |
vcoubard | 1131:692ddf04fc42 | 281 | * APIs with non-virtual implementations. |
vcoubard | 1131:692ddf04fc42 | 282 | */ |
vcoubard | 1131:692ddf04fc42 | 283 | public: |
vcoubard | 1131:692ddf04fc42 | 284 | /** |
vcoubard | 1131:692ddf04fc42 | 285 | * Add a callback for the GATT event DATA_SENT (which is triggered when |
vcoubard | 1131:692ddf04fc42 | 286 | * updates are sent out by GATT in the form of notifications). |
vcoubard | 1131:692ddf04fc42 | 287 | * |
vcoubard | 1183:1589830dbdb7 | 288 | * @param[in] callback |
vcoubard | 1183:1589830dbdb7 | 289 | * Event handler being registered. |
vcoubard | 1183:1589830dbdb7 | 290 | * |
vcoubard | 1183:1589830dbdb7 | 291 | * @note It is possible to chain together multiple onDataSent callbacks |
vcoubard | 1183:1589830dbdb7 | 292 | * (potentially from different modules of an application) to receive updates |
vcoubard | 1183:1589830dbdb7 | 293 | * to characteristics. |
vcoubard | 1165:0717ca5ed305 | 294 | * |
vcoubard | 1183:1589830dbdb7 | 295 | * @note It is also possible to set up a callback into a member function of |
vcoubard | 1183:1589830dbdb7 | 296 | * some object. |
vcoubard | 1131:692ddf04fc42 | 297 | */ |
vcoubard | 1183:1589830dbdb7 | 298 | void onDataSent(const DataSentCallback_t& callback) { |
vcoubard | 1183:1589830dbdb7 | 299 | dataSentCallChain.add(callback); |
vcoubard | 1183:1589830dbdb7 | 300 | } |
vcoubard | 1183:1589830dbdb7 | 301 | |
vcoubard | 1183:1589830dbdb7 | 302 | /** |
vcoubard | 1183:1589830dbdb7 | 303 | * Same as GattServer::onDataSent(), but allows the possibility to add an object |
vcoubard | 1183:1589830dbdb7 | 304 | * reference and member function as handler for DATA_SENT event |
vcoubard | 1183:1589830dbdb7 | 305 | * callbacks. |
vcoubard | 1183:1589830dbdb7 | 306 | * |
vcoubard | 1183:1589830dbdb7 | 307 | * @param[in] objPtr |
vcoubard | 1183:1589830dbdb7 | 308 | * Pointer to the object of a class defining the member callback |
vcoubard | 1183:1589830dbdb7 | 309 | * function (@p memberPtr). |
vcoubard | 1183:1589830dbdb7 | 310 | * @param[in] memberPtr |
vcoubard | 1183:1589830dbdb7 | 311 | * The member callback (within the context of an object) to be |
vcoubard | 1183:1589830dbdb7 | 312 | * invoked. |
vcoubard | 1183:1589830dbdb7 | 313 | */ |
vcoubard | 1131:692ddf04fc42 | 314 | template <typename T> |
vcoubard | 1131:692ddf04fc42 | 315 | void onDataSent(T *objPtr, void (T::*memberPtr)(unsigned count)) { |
vcoubard | 1131:692ddf04fc42 | 316 | dataSentCallChain.add(objPtr, memberPtr); |
vcoubard | 1131:692ddf04fc42 | 317 | } |
vcoubard | 1131:692ddf04fc42 | 318 | |
vcoubard | 1131:692ddf04fc42 | 319 | /** |
vcoubard | 1183:1589830dbdb7 | 320 | * @brief Provide access to the callchain of DATA_SENT event callbacks. |
vcoubard | 1183:1589830dbdb7 | 321 | * |
vcoubard | 1183:1589830dbdb7 | 322 | * @return A reference to the DATA_SENT event callback chain. |
vcoubard | 1131:692ddf04fc42 | 323 | */ |
vcoubard | 1135:22aada733dbd | 324 | DataSentCallbackChain_t& onDataSent() { |
vcoubard | 1131:692ddf04fc42 | 325 | return dataSentCallChain; |
vcoubard | 1131:692ddf04fc42 | 326 | } |
vcoubard | 1131:692ddf04fc42 | 327 | |
vcoubard | 1131:692ddf04fc42 | 328 | /** |
vcoubard | 1131:692ddf04fc42 | 329 | * Set up a callback for when an attribute has its value updated by or at the |
vcoubard | 1131:692ddf04fc42 | 330 | * connected peer. For a peripheral, this callback is triggered when the local |
vcoubard | 1131:692ddf04fc42 | 331 | * GATT server has an attribute updated by a write command from the peer. |
vcoubard | 1131:692ddf04fc42 | 332 | * For a central, this callback is triggered when a response is received for |
vcoubard | 1131:692ddf04fc42 | 333 | * a write request. |
vcoubard | 1131:692ddf04fc42 | 334 | * |
vcoubard | 1183:1589830dbdb7 | 335 | * @param[in] callback |
vcoubard | 1183:1589830dbdb7 | 336 | * Event handler being registered. |
vcoubard | 1183:1589830dbdb7 | 337 | * |
vcoubard | 1183:1589830dbdb7 | 338 | * @note It is possible to chain together multiple onDataWritten callbacks |
vcoubard | 1131:692ddf04fc42 | 339 | * (potentially from different modules of an application) to receive updates |
vcoubard | 1131:692ddf04fc42 | 340 | * to characteristics. Many services, such as DFU and UART, add their own |
vcoubard | 1131:692ddf04fc42 | 341 | * onDataWritten callbacks behind the scenes to trap interesting events. |
vcoubard | 1131:692ddf04fc42 | 342 | * |
vcoubard | 1183:1589830dbdb7 | 343 | * @note It is also possible to set up a callback into a member function of |
vcoubard | 1131:692ddf04fc42 | 344 | * some object. |
vcoubard | 1135:22aada733dbd | 345 | * |
vcoubard | 1183:1589830dbdb7 | 346 | * @note It is possible to unregister a callback using onDataWritten().detach(callback) |
vcoubard | 1131:692ddf04fc42 | 347 | */ |
vcoubard | 1183:1589830dbdb7 | 348 | void onDataWritten(const DataWrittenCallback_t& callback) { |
vcoubard | 1183:1589830dbdb7 | 349 | dataWrittenCallChain.add(callback); |
vcoubard | 1183:1589830dbdb7 | 350 | } |
vcoubard | 1183:1589830dbdb7 | 351 | |
vcoubard | 1183:1589830dbdb7 | 352 | /** |
vcoubard | 1183:1589830dbdb7 | 353 | * Same as GattServer::onDataWritten(), but allows the possibility to add an object |
vcoubard | 1183:1589830dbdb7 | 354 | * reference and member function as handler for data written event |
vcoubard | 1183:1589830dbdb7 | 355 | * callbacks. |
vcoubard | 1183:1589830dbdb7 | 356 | * |
vcoubard | 1183:1589830dbdb7 | 357 | * @param[in] objPtr |
vcoubard | 1183:1589830dbdb7 | 358 | * Pointer to the object of a class defining the member callback |
vcoubard | 1183:1589830dbdb7 | 359 | * function (@p memberPtr). |
vcoubard | 1183:1589830dbdb7 | 360 | * @param[in] memberPtr |
vcoubard | 1183:1589830dbdb7 | 361 | * The member callback (within the context of an object) to be |
vcoubard | 1183:1589830dbdb7 | 362 | * invoked. |
vcoubard | 1183:1589830dbdb7 | 363 | */ |
vcoubard | 1131:692ddf04fc42 | 364 | template <typename T> |
vcoubard | 1131:692ddf04fc42 | 365 | void onDataWritten(T *objPtr, void (T::*memberPtr)(const GattWriteCallbackParams *context)) { |
vcoubard | 1131:692ddf04fc42 | 366 | dataWrittenCallChain.add(objPtr, memberPtr); |
vcoubard | 1131:692ddf04fc42 | 367 | } |
vcoubard | 1131:692ddf04fc42 | 368 | |
vcoubard | 1131:692ddf04fc42 | 369 | /** |
vcoubard | 1183:1589830dbdb7 | 370 | * @brief Provide access to the callchain of data written event callbacks. |
vcoubard | 1183:1589830dbdb7 | 371 | * |
vcoubard | 1183:1589830dbdb7 | 372 | * @return A reference to the data written event callbacks chain. |
vcoubard | 1183:1589830dbdb7 | 373 | * |
vcoubard | 1183:1589830dbdb7 | 374 | * @note It is possible to register callbacks using onDataWritten().add(callback). |
vcoubard | 1183:1589830dbdb7 | 375 | * |
vcoubard | 1183:1589830dbdb7 | 376 | * @note It is possible to unregister callbacks using onDataWritten().detach(callback). |
vcoubard | 1135:22aada733dbd | 377 | */ |
vcoubard | 1131:692ddf04fc42 | 378 | DataWrittenCallbackChain_t& onDataWritten() { |
vcoubard | 1131:692ddf04fc42 | 379 | return dataWrittenCallChain; |
vcoubard | 1131:692ddf04fc42 | 380 | } |
vcoubard | 1131:692ddf04fc42 | 381 | |
vcoubard | 1131:692ddf04fc42 | 382 | /** |
vcoubard | 1131:692ddf04fc42 | 383 | * Setup a callback to be invoked on the peripheral when an attribute is |
vcoubard | 1131:692ddf04fc42 | 384 | * being read by a remote client. |
vcoubard | 1131:692ddf04fc42 | 385 | * |
vcoubard | 1183:1589830dbdb7 | 386 | * @param[in] callback |
vcoubard | 1183:1589830dbdb7 | 387 | * Event handler being registered. |
vcoubard | 1183:1589830dbdb7 | 388 | * |
vcoubard | 1183:1589830dbdb7 | 389 | * @return BLE_ERROR_NOT_IMPLEMENTED if this functionality isn't available; |
vcoubard | 1183:1589830dbdb7 | 390 | * else BLE_ERROR_NONE. |
vcoubard | 1183:1589830dbdb7 | 391 | * |
vcoubard | 1183:1589830dbdb7 | 392 | * @note This functionality may not be available on all underlying stacks. |
vcoubard | 1131:692ddf04fc42 | 393 | * You could use GattCharacteristic::setReadAuthorizationCallback() as an |
vcoubard | 1131:692ddf04fc42 | 394 | * alternative. Refer to isOnDataReadAvailable(). |
vcoubard | 1131:692ddf04fc42 | 395 | * |
vcoubard | 1183:1589830dbdb7 | 396 | * @note It is possible to chain together multiple onDataRead callbacks |
vcoubard | 1131:692ddf04fc42 | 397 | * (potentially from different modules of an application) to receive updates |
vcoubard | 1131:692ddf04fc42 | 398 | * to characteristics. Services may add their own onDataRead callbacks |
vcoubard | 1131:692ddf04fc42 | 399 | * behind the scenes to trap interesting events. |
vcoubard | 1131:692ddf04fc42 | 400 | * |
vcoubard | 1183:1589830dbdb7 | 401 | * @note It is also possible to set up a callback into a member function of |
vcoubard | 1131:692ddf04fc42 | 402 | * some object. |
vcoubard | 1131:692ddf04fc42 | 403 | * |
vcoubard | 1183:1589830dbdb7 | 404 | * @note It is possible to unregister a callback using onDataRead().detach(callback). |
vcoubard | 1131:692ddf04fc42 | 405 | */ |
vcoubard | 1131:692ddf04fc42 | 406 | ble_error_t onDataRead(const DataReadCallback_t& callback) { |
vcoubard | 1131:692ddf04fc42 | 407 | if (!isOnDataReadAvailable()) { |
vcoubard | 1131:692ddf04fc42 | 408 | return BLE_ERROR_NOT_IMPLEMENTED; |
vcoubard | 1131:692ddf04fc42 | 409 | } |
vcoubard | 1131:692ddf04fc42 | 410 | |
vcoubard | 1131:692ddf04fc42 | 411 | dataReadCallChain.add(callback); |
vcoubard | 1131:692ddf04fc42 | 412 | return BLE_ERROR_NONE; |
vcoubard | 1131:692ddf04fc42 | 413 | } |
vcoubard | 1183:1589830dbdb7 | 414 | |
vcoubard | 1183:1589830dbdb7 | 415 | /** |
vcoubard | 1183:1589830dbdb7 | 416 | * Same as GattServer::onDataRead(), but allows the possibility to add an object |
vcoubard | 1183:1589830dbdb7 | 417 | * reference and member function as handler for data read event |
vcoubard | 1183:1589830dbdb7 | 418 | * callbacks. |
vcoubard | 1183:1589830dbdb7 | 419 | * |
vcoubard | 1183:1589830dbdb7 | 420 | * @param[in] objPtr |
vcoubard | 1183:1589830dbdb7 | 421 | * Pointer to the object of a class defining the member callback |
vcoubard | 1183:1589830dbdb7 | 422 | * function (@p memberPtr). |
vcoubard | 1183:1589830dbdb7 | 423 | * @param[in] memberPtr |
vcoubard | 1183:1589830dbdb7 | 424 | * The member callback (within the context of an object) to be |
vcoubard | 1183:1589830dbdb7 | 425 | * invoked. |
vcoubard | 1183:1589830dbdb7 | 426 | */ |
vcoubard | 1131:692ddf04fc42 | 427 | template <typename T> |
vcoubard | 1131:692ddf04fc42 | 428 | ble_error_t onDataRead(T *objPtr, void (T::*memberPtr)(const GattReadCallbackParams *context)) { |
vcoubard | 1131:692ddf04fc42 | 429 | if (!isOnDataReadAvailable()) { |
vcoubard | 1131:692ddf04fc42 | 430 | return BLE_ERROR_NOT_IMPLEMENTED; |
vcoubard | 1131:692ddf04fc42 | 431 | } |
vcoubard | 1131:692ddf04fc42 | 432 | |
vcoubard | 1131:692ddf04fc42 | 433 | dataReadCallChain.add(objPtr, memberPtr); |
vcoubard | 1131:692ddf04fc42 | 434 | return BLE_ERROR_NONE; |
vcoubard | 1131:692ddf04fc42 | 435 | } |
vcoubard | 1131:692ddf04fc42 | 436 | |
vcoubard | 1131:692ddf04fc42 | 437 | /** |
vcoubard | 1183:1589830dbdb7 | 438 | * @brief Provide access to the callchain of data read event callbacks. |
vcoubard | 1183:1589830dbdb7 | 439 | * |
vcoubard | 1183:1589830dbdb7 | 440 | * @return A reference to the data read event callbacks chain. |
vcoubard | 1183:1589830dbdb7 | 441 | * |
vcoubard | 1183:1589830dbdb7 | 442 | * @note It is possible to register callbacks using onDataRead().add(callback). |
vcoubard | 1183:1589830dbdb7 | 443 | * |
vcoubard | 1183:1589830dbdb7 | 444 | * @note It is possible to unregister callbacks using onDataRead().detach(callback). |
vcoubard | 1131:692ddf04fc42 | 445 | */ |
vcoubard | 1131:692ddf04fc42 | 446 | DataReadCallbackChain_t& onDataRead() { |
vcoubard | 1131:692ddf04fc42 | 447 | return dataReadCallChain; |
vcoubard | 1131:692ddf04fc42 | 448 | } |
vcoubard | 1131:692ddf04fc42 | 449 | |
vcoubard | 1131:692ddf04fc42 | 450 | /** |
vcoubard | 1135:22aada733dbd | 451 | * Setup a callback to be invoked to notify the user application that the |
vcoubard | 1135:22aada733dbd | 452 | * GattServer instance is about to shutdown (possibly as a result of a call |
vcoubard | 1135:22aada733dbd | 453 | * to BLE::shutdown()). |
vcoubard | 1135:22aada733dbd | 454 | * |
vcoubard | 1183:1589830dbdb7 | 455 | * @param[in] callback |
vcoubard | 1183:1589830dbdb7 | 456 | * Event handler being registered. |
vcoubard | 1183:1589830dbdb7 | 457 | * |
vcoubard | 1183:1589830dbdb7 | 458 | * @note It is possible to chain together multiple onShutdown callbacks |
vcoubard | 1135:22aada733dbd | 459 | * (potentially from different modules of an application) to be notified |
vcoubard | 1135:22aada733dbd | 460 | * before the GattServer is shutdown. |
vcoubard | 1135:22aada733dbd | 461 | * |
vcoubard | 1183:1589830dbdb7 | 462 | * @note It is also possible to set up a callback into a member function of |
vcoubard | 1135:22aada733dbd | 463 | * some object. |
vcoubard | 1135:22aada733dbd | 464 | * |
vcoubard | 1183:1589830dbdb7 | 465 | * @note It is possible to unregister a callback using onShutdown().detach(callback) |
vcoubard | 1135:22aada733dbd | 466 | */ |
vcoubard | 1135:22aada733dbd | 467 | void onShutdown(const GattServerShutdownCallback_t& callback) { |
vcoubard | 1135:22aada733dbd | 468 | shutdownCallChain.add(callback); |
vcoubard | 1135:22aada733dbd | 469 | } |
vcoubard | 1183:1589830dbdb7 | 470 | |
vcoubard | 1183:1589830dbdb7 | 471 | /** |
vcoubard | 1183:1589830dbdb7 | 472 | * Same as GattServer::onShutdown(), but allows the possibility to add an object |
vcoubard | 1183:1589830dbdb7 | 473 | * reference and member function as handler for shutdown event |
vcoubard | 1183:1589830dbdb7 | 474 | * callbacks. |
vcoubard | 1183:1589830dbdb7 | 475 | * |
vcoubard | 1183:1589830dbdb7 | 476 | * @param[in] objPtr |
vcoubard | 1183:1589830dbdb7 | 477 | * Pointer to the object of a class defining the member callback |
vcoubard | 1183:1589830dbdb7 | 478 | * function (@p memberPtr). |
vcoubard | 1183:1589830dbdb7 | 479 | * @param[in] memberPtr |
vcoubard | 1183:1589830dbdb7 | 480 | * The member callback (within the context of an object) to be |
vcoubard | 1183:1589830dbdb7 | 481 | * invoked. |
vcoubard | 1183:1589830dbdb7 | 482 | */ |
vcoubard | 1135:22aada733dbd | 483 | template <typename T> |
vcoubard | 1192:718787de23b7 | 484 | void onShutdown(T *objPtr, void (T::*memberPtr)(const GattServer *)) { |
vcoubard | 1135:22aada733dbd | 485 | shutdownCallChain.add(objPtr, memberPtr); |
vcoubard | 1135:22aada733dbd | 486 | } |
vcoubard | 1135:22aada733dbd | 487 | |
vcoubard | 1135:22aada733dbd | 488 | /** |
vcoubard | 1183:1589830dbdb7 | 489 | * @brief Provide access to the callchain of shutdown event callbacks. |
vcoubard | 1183:1589830dbdb7 | 490 | * |
vcoubard | 1183:1589830dbdb7 | 491 | * @return A reference to the shutdown event callbacks chain. |
vcoubard | 1183:1589830dbdb7 | 492 | * |
vcoubard | 1183:1589830dbdb7 | 493 | * @note It is possible to register callbacks using onShutdown().add(callback). |
vcoubard | 1183:1589830dbdb7 | 494 | * |
vcoubard | 1183:1589830dbdb7 | 495 | * @note It is possible to unregister callbacks using onShutdown().detach(callback). |
vcoubard | 1135:22aada733dbd | 496 | */ |
vcoubard | 1135:22aada733dbd | 497 | GattServerShutdownCallbackChain_t& onShutdown() { |
vcoubard | 1135:22aada733dbd | 498 | return shutdownCallChain; |
vcoubard | 1135:22aada733dbd | 499 | } |
vcoubard | 1135:22aada733dbd | 500 | |
vcoubard | 1135:22aada733dbd | 501 | /** |
vcoubard | 1131:692ddf04fc42 | 502 | * Set up a callback for when notifications or indications are enabled for a |
vcoubard | 1131:692ddf04fc42 | 503 | * characteristic on the local GATT server. |
vcoubard | 1183:1589830dbdb7 | 504 | * |
vcoubard | 1183:1589830dbdb7 | 505 | * @param[in] callback |
vcoubard | 1183:1589830dbdb7 | 506 | * Event handler being registered. |
vcoubard | 1131:692ddf04fc42 | 507 | */ |
vcoubard | 1183:1589830dbdb7 | 508 | void onUpdatesEnabled(EventCallback_t callback) { |
vcoubard | 1183:1589830dbdb7 | 509 | updatesEnabledCallback = callback; |
vcoubard | 1183:1589830dbdb7 | 510 | } |
vcoubard | 1131:692ddf04fc42 | 511 | |
vcoubard | 1131:692ddf04fc42 | 512 | /** |
vcoubard | 1131:692ddf04fc42 | 513 | * Set up a callback for when notifications or indications are disabled for a |
vcoubard | 1131:692ddf04fc42 | 514 | * characteristic on the local GATT server. |
vcoubard | 1183:1589830dbdb7 | 515 | * |
vcoubard | 1183:1589830dbdb7 | 516 | * @param[in] callback |
vcoubard | 1183:1589830dbdb7 | 517 | * Event handler being registered. |
vcoubard | 1131:692ddf04fc42 | 518 | */ |
vcoubard | 1183:1589830dbdb7 | 519 | void onUpdatesDisabled(EventCallback_t callback) { |
vcoubard | 1183:1589830dbdb7 | 520 | updatesDisabledCallback = callback; |
vcoubard | 1183:1589830dbdb7 | 521 | } |
vcoubard | 1131:692ddf04fc42 | 522 | |
vcoubard | 1131:692ddf04fc42 | 523 | /** |
vcoubard | 1131:692ddf04fc42 | 524 | * Set up a callback for when the GATT server receives a response for an |
vcoubard | 1131:692ddf04fc42 | 525 | * indication event sent previously. |
vcoubard | 1183:1589830dbdb7 | 526 | * |
vcoubard | 1183:1589830dbdb7 | 527 | * @param[in] callback |
vcoubard | 1183:1589830dbdb7 | 528 | * Event handler being registered. |
vcoubard | 1131:692ddf04fc42 | 529 | */ |
vcoubard | 1183:1589830dbdb7 | 530 | void onConfirmationReceived(EventCallback_t callback) { |
vcoubard | 1183:1589830dbdb7 | 531 | confirmationReceivedCallback = callback; |
vcoubard | 1183:1589830dbdb7 | 532 | } |
vcoubard | 1131:692ddf04fc42 | 533 | |
vcoubard | 1131:692ddf04fc42 | 534 | /* Entry points for the underlying stack to report events back to the user. */ |
vcoubard | 1131:692ddf04fc42 | 535 | protected: |
vcoubard | 1183:1589830dbdb7 | 536 | /** |
vcoubard | 1183:1589830dbdb7 | 537 | * Helper function that notifies all registered handlers of an occurrence |
vcoubard | 1183:1589830dbdb7 | 538 | * of a data written event. This function is meant to be called from the |
vcoubard | 1183:1589830dbdb7 | 539 | * BLE stack specific implementation when a data written event occurs. |
vcoubard | 1183:1589830dbdb7 | 540 | * |
vcoubard | 1183:1589830dbdb7 | 541 | * @param[in] params |
vcoubard | 1183:1589830dbdb7 | 542 | * The data written parameters passed to the registered |
vcoubard | 1183:1589830dbdb7 | 543 | * handlers. |
vcoubard | 1183:1589830dbdb7 | 544 | */ |
vcoubard | 1131:692ddf04fc42 | 545 | void handleDataWrittenEvent(const GattWriteCallbackParams *params) { |
vcoubard | 1131:692ddf04fc42 | 546 | dataWrittenCallChain.call(params); |
vcoubard | 1131:692ddf04fc42 | 547 | } |
vcoubard | 1131:692ddf04fc42 | 548 | |
vcoubard | 1183:1589830dbdb7 | 549 | /** |
vcoubard | 1183:1589830dbdb7 | 550 | * Helper function that notifies all registered handlers of an occurrence |
vcoubard | 1183:1589830dbdb7 | 551 | * of a data read event. This function is meant to be called from the |
vcoubard | 1183:1589830dbdb7 | 552 | * BLE stack specific implementation when a data read event occurs. |
vcoubard | 1183:1589830dbdb7 | 553 | * |
vcoubard | 1183:1589830dbdb7 | 554 | * @param[in] params |
vcoubard | 1183:1589830dbdb7 | 555 | * The data read parameters passed to the registered |
vcoubard | 1183:1589830dbdb7 | 556 | * handlers. |
vcoubard | 1183:1589830dbdb7 | 557 | */ |
vcoubard | 1131:692ddf04fc42 | 558 | void handleDataReadEvent(const GattReadCallbackParams *params) { |
vcoubard | 1131:692ddf04fc42 | 559 | dataReadCallChain.call(params); |
vcoubard | 1131:692ddf04fc42 | 560 | } |
vcoubard | 1131:692ddf04fc42 | 561 | |
vcoubard | 1183:1589830dbdb7 | 562 | /** |
vcoubard | 1183:1589830dbdb7 | 563 | * Helper function that notifies the registered handler of an occurrence |
vcoubard | 1183:1589830dbdb7 | 564 | * of updates enabled, updates disabled and confirmation received events. |
vcoubard | 1183:1589830dbdb7 | 565 | * This function is meant to be called from the BLE stack specific |
vcoubard | 1183:1589830dbdb7 | 566 | * implementation when any of these events occurs. |
vcoubard | 1183:1589830dbdb7 | 567 | * |
vcoubard | 1183:1589830dbdb7 | 568 | * @param[in] type |
vcoubard | 1183:1589830dbdb7 | 569 | * The type of event that occurred. |
vcoubard | 1183:1589830dbdb7 | 570 | * @param[in] attributeHandle |
vcoubard | 1183:1589830dbdb7 | 571 | * The handle of the attribute that was modified. |
vcoubard | 1183:1589830dbdb7 | 572 | */ |
vcoubard | 1131:692ddf04fc42 | 573 | void handleEvent(GattServerEvents::gattEvent_e type, GattAttribute::Handle_t attributeHandle) { |
vcoubard | 1131:692ddf04fc42 | 574 | switch (type) { |
vcoubard | 1131:692ddf04fc42 | 575 | case GattServerEvents::GATT_EVENT_UPDATES_ENABLED: |
vcoubard | 1131:692ddf04fc42 | 576 | if (updatesEnabledCallback) { |
vcoubard | 1131:692ddf04fc42 | 577 | updatesEnabledCallback(attributeHandle); |
vcoubard | 1131:692ddf04fc42 | 578 | } |
vcoubard | 1131:692ddf04fc42 | 579 | break; |
vcoubard | 1131:692ddf04fc42 | 580 | case GattServerEvents::GATT_EVENT_UPDATES_DISABLED: |
vcoubard | 1131:692ddf04fc42 | 581 | if (updatesDisabledCallback) { |
vcoubard | 1131:692ddf04fc42 | 582 | updatesDisabledCallback(attributeHandle); |
vcoubard | 1131:692ddf04fc42 | 583 | } |
vcoubard | 1131:692ddf04fc42 | 584 | break; |
vcoubard | 1131:692ddf04fc42 | 585 | case GattServerEvents::GATT_EVENT_CONFIRMATION_RECEIVED: |
vcoubard | 1131:692ddf04fc42 | 586 | if (confirmationReceivedCallback) { |
vcoubard | 1131:692ddf04fc42 | 587 | confirmationReceivedCallback(attributeHandle); |
vcoubard | 1131:692ddf04fc42 | 588 | } |
vcoubard | 1131:692ddf04fc42 | 589 | break; |
vcoubard | 1131:692ddf04fc42 | 590 | default: |
vcoubard | 1131:692ddf04fc42 | 591 | break; |
vcoubard | 1131:692ddf04fc42 | 592 | } |
vcoubard | 1131:692ddf04fc42 | 593 | } |
vcoubard | 1131:692ddf04fc42 | 594 | |
vcoubard | 1183:1589830dbdb7 | 595 | /** |
vcoubard | 1183:1589830dbdb7 | 596 | * Helper function that notifies all registered handlers of an occurrence |
vcoubard | 1183:1589830dbdb7 | 597 | * of a data sent event. This function is meant to be called from the |
vcoubard | 1183:1589830dbdb7 | 598 | * BLE stack specific implementation when a data sent event occurs. |
vcoubard | 1183:1589830dbdb7 | 599 | * |
vcoubard | 1183:1589830dbdb7 | 600 | * @param[in] count |
vcoubard | 1183:1589830dbdb7 | 601 | * Number of packets sent. |
vcoubard | 1183:1589830dbdb7 | 602 | */ |
vcoubard | 1131:692ddf04fc42 | 603 | void handleDataSentEvent(unsigned count) { |
vcoubard | 1131:692ddf04fc42 | 604 | dataSentCallChain.call(count); |
vcoubard | 1131:692ddf04fc42 | 605 | } |
vcoubard | 1131:692ddf04fc42 | 606 | |
vcoubard | 1135:22aada733dbd | 607 | public: |
vcoubard | 1135:22aada733dbd | 608 | /** |
vcoubard | 1135:22aada733dbd | 609 | * Notify all registered onShutdown callbacks that the GattServer is |
vcoubard | 1135:22aada733dbd | 610 | * about to be shutdown and clear all GattServer state of the |
vcoubard | 1135:22aada733dbd | 611 | * associated object. |
vcoubard | 1135:22aada733dbd | 612 | * |
vcoubard | 1135:22aada733dbd | 613 | * This function is meant to be overridden in the platform-specific |
vcoubard | 1135:22aada733dbd | 614 | * sub-class. Nevertheless, the sub-class is only expected to reset its |
vcoubard | 1135:22aada733dbd | 615 | * state and not the data held in GattServer members. This shall be achieved |
vcoubard | 1135:22aada733dbd | 616 | * by a call to GattServer::reset() from the sub-class' reset() |
vcoubard | 1135:22aada733dbd | 617 | * implementation. |
vcoubard | 1135:22aada733dbd | 618 | * |
vcoubard | 1135:22aada733dbd | 619 | * @return BLE_ERROR_NONE on success. |
vcoubard | 1135:22aada733dbd | 620 | */ |
vcoubard | 1135:22aada733dbd | 621 | virtual ble_error_t reset(void) { |
vcoubard | 1135:22aada733dbd | 622 | /* Notify that the instance is about to shutdown */ |
vcoubard | 1135:22aada733dbd | 623 | shutdownCallChain.call(this); |
vcoubard | 1135:22aada733dbd | 624 | shutdownCallChain.clear(); |
vcoubard | 1135:22aada733dbd | 625 | |
vcoubard | 1135:22aada733dbd | 626 | serviceCount = 0; |
vcoubard | 1135:22aada733dbd | 627 | characteristicCount = 0; |
vcoubard | 1135:22aada733dbd | 628 | |
vcoubard | 1135:22aada733dbd | 629 | dataSentCallChain.clear(); |
vcoubard | 1135:22aada733dbd | 630 | dataWrittenCallChain.clear(); |
vcoubard | 1135:22aada733dbd | 631 | dataReadCallChain.clear(); |
vcoubard | 1135:22aada733dbd | 632 | updatesEnabledCallback = NULL; |
vcoubard | 1135:22aada733dbd | 633 | updatesDisabledCallback = NULL; |
vcoubard | 1135:22aada733dbd | 634 | confirmationReceivedCallback = NULL; |
vcoubard | 1135:22aada733dbd | 635 | |
vcoubard | 1135:22aada733dbd | 636 | return BLE_ERROR_NONE; |
vcoubard | 1135:22aada733dbd | 637 | } |
vcoubard | 1135:22aada733dbd | 638 | |
vcoubard | 1131:692ddf04fc42 | 639 | protected: |
vcoubard | 1183:1589830dbdb7 | 640 | /** |
vcoubard | 1183:1589830dbdb7 | 641 | * The total number of services added to the ATT table. |
vcoubard | 1183:1589830dbdb7 | 642 | */ |
vcoubard | 1131:692ddf04fc42 | 643 | uint8_t serviceCount; |
vcoubard | 1183:1589830dbdb7 | 644 | /** |
vcoubard | 1183:1589830dbdb7 | 645 | * The total number of characteristics added to the ATT table. |
vcoubard | 1183:1589830dbdb7 | 646 | */ |
vcoubard | 1131:692ddf04fc42 | 647 | uint8_t characteristicCount; |
vcoubard | 1131:692ddf04fc42 | 648 | |
vcoubard | 1131:692ddf04fc42 | 649 | private: |
vcoubard | 1183:1589830dbdb7 | 650 | /** |
vcoubard | 1183:1589830dbdb7 | 651 | * Callchain containing all registered callback handlers for data sent |
vcoubard | 1183:1589830dbdb7 | 652 | * events. |
vcoubard | 1183:1589830dbdb7 | 653 | */ |
vcoubard | 1135:22aada733dbd | 654 | DataSentCallbackChain_t dataSentCallChain; |
vcoubard | 1183:1589830dbdb7 | 655 | /** |
vcoubard | 1183:1589830dbdb7 | 656 | * Callchain containing all registered callback handlers for data written |
vcoubard | 1183:1589830dbdb7 | 657 | * events. |
vcoubard | 1183:1589830dbdb7 | 658 | */ |
vcoubard | 1135:22aada733dbd | 659 | DataWrittenCallbackChain_t dataWrittenCallChain; |
vcoubard | 1183:1589830dbdb7 | 660 | /** |
vcoubard | 1183:1589830dbdb7 | 661 | * Callchain containing all registered callback handlers for data read |
vcoubard | 1183:1589830dbdb7 | 662 | * events. |
vcoubard | 1183:1589830dbdb7 | 663 | */ |
vcoubard | 1135:22aada733dbd | 664 | DataReadCallbackChain_t dataReadCallChain; |
vcoubard | 1183:1589830dbdb7 | 665 | /** |
vcoubard | 1183:1589830dbdb7 | 666 | * Callchain containing all registered callback handlers for shutdown |
vcoubard | 1183:1589830dbdb7 | 667 | * events. |
vcoubard | 1183:1589830dbdb7 | 668 | */ |
vcoubard | 1135:22aada733dbd | 669 | GattServerShutdownCallbackChain_t shutdownCallChain; |
vcoubard | 1183:1589830dbdb7 | 670 | /** |
vcoubard | 1183:1589830dbdb7 | 671 | * The registered callback handler for updates enabled events. |
vcoubard | 1183:1589830dbdb7 | 672 | */ |
vcoubard | 1135:22aada733dbd | 673 | EventCallback_t updatesEnabledCallback; |
vcoubard | 1183:1589830dbdb7 | 674 | /** |
vcoubard | 1183:1589830dbdb7 | 675 | * The registered callback handler for updates disabled events. |
vcoubard | 1183:1589830dbdb7 | 676 | */ |
vcoubard | 1135:22aada733dbd | 677 | EventCallback_t updatesDisabledCallback; |
vcoubard | 1183:1589830dbdb7 | 678 | /** |
vcoubard | 1183:1589830dbdb7 | 679 | * The registered callback handler for confirmation received events. |
vcoubard | 1183:1589830dbdb7 | 680 | */ |
vcoubard | 1135:22aada733dbd | 681 | EventCallback_t confirmationReceivedCallback; |
vcoubard | 1131:692ddf04fc42 | 682 | |
vcoubard | 1131:692ddf04fc42 | 683 | private: |
vcoubard | 1131:692ddf04fc42 | 684 | /* Disallow copy and assignment. */ |
vcoubard | 1131:692ddf04fc42 | 685 | GattServer(const GattServer &); |
vcoubard | 1131:692ddf04fc42 | 686 | GattServer& operator=(const GattServer &); |
vcoubard | 1131:692ddf04fc42 | 687 | }; |
vcoubard | 1131:692ddf04fc42 | 688 | |
vcoubard | 1183:1589830dbdb7 | 689 | #endif /* ifndef __GATT_SERVER_H__ */ |