Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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