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