Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

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