Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcozecchini 0:9fca2b23d0ba 1 /* mbed Microcontroller Library
marcozecchini 0:9fca2b23d0ba 2 * Copyright (c) 2006-2013 ARM Limited
marcozecchini 0:9fca2b23d0ba 3 *
marcozecchini 0:9fca2b23d0ba 4 * Licensed under the Apache License, Version 2.0 (the "License");
marcozecchini 0:9fca2b23d0ba 5 * you may not use this file except in compliance with the License.
marcozecchini 0:9fca2b23d0ba 6 * You may obtain a copy of the License at
marcozecchini 0:9fca2b23d0ba 7 *
marcozecchini 0:9fca2b23d0ba 8 * http://www.apache.org/licenses/LICENSE-2.0
marcozecchini 0:9fca2b23d0ba 9 *
marcozecchini 0:9fca2b23d0ba 10 * Unless required by applicable law or agreed to in writing, software
marcozecchini 0:9fca2b23d0ba 11 * distributed under the License is distributed on an "AS IS" BASIS,
marcozecchini 0:9fca2b23d0ba 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
marcozecchini 0:9fca2b23d0ba 13 * See the License for the specific language governing permissions and
marcozecchini 0:9fca2b23d0ba 14 * limitations under the License.
marcozecchini 0:9fca2b23d0ba 15 */
marcozecchini 0:9fca2b23d0ba 16
marcozecchini 0:9fca2b23d0ba 17 #ifndef MBED_GATT_CLIENT_H__
marcozecchini 0:9fca2b23d0ba 18 #define MBED_GATT_CLIENT_H__
marcozecchini 0:9fca2b23d0ba 19
marcozecchini 0:9fca2b23d0ba 20 #include "Gap.h"
marcozecchini 0:9fca2b23d0ba 21 #include "GattAttribute.h"
marcozecchini 0:9fca2b23d0ba 22 #include "ServiceDiscovery.h"
marcozecchini 0:9fca2b23d0ba 23 #include "CharacteristicDescriptorDiscovery.h"
marcozecchini 0:9fca2b23d0ba 24
marcozecchini 0:9fca2b23d0ba 25 #include "GattCallbackParamTypes.h"
marcozecchini 0:9fca2b23d0ba 26
marcozecchini 0:9fca2b23d0ba 27 #include "CallChainOfFunctionPointersWithContext.h"
marcozecchini 0:9fca2b23d0ba 28
marcozecchini 0:9fca2b23d0ba 29 /**
marcozecchini 0:9fca2b23d0ba 30 * @addtogroup ble
marcozecchini 0:9fca2b23d0ba 31 * @{
marcozecchini 0:9fca2b23d0ba 32 * @addtogroup gatt
marcozecchini 0:9fca2b23d0ba 33 * @{
marcozecchini 0:9fca2b23d0ba 34 * @addtogroup client
marcozecchini 0:9fca2b23d0ba 35 * @{
marcozecchini 0:9fca2b23d0ba 36 */
marcozecchini 0:9fca2b23d0ba 37
marcozecchini 0:9fca2b23d0ba 38 /**
marcozecchini 0:9fca2b23d0ba 39 * Define procedures required for interacting with a distant GATT server.
marcozecchini 0:9fca2b23d0ba 40 *
marcozecchini 0:9fca2b23d0ba 41 * @par Discovery procedures
marcozecchini 0:9fca2b23d0ba 42 *
marcozecchini 0:9fca2b23d0ba 43 * A GATT server hosts a fixed set of services. These services are a logical
marcozecchini 0:9fca2b23d0ba 44 * composition of characteristics that may be discovered, read, written or also
marcozecchini 0:9fca2b23d0ba 45 * broadcast their state to a connected client. These characteristics may also
marcozecchini 0:9fca2b23d0ba 46 * contain metainformation named characteristic descriptors. A characteristic
marcozecchini 0:9fca2b23d0ba 47 * descriptor may be used to indicate the unit used for a characteristic value,
marcozecchini 0:9fca2b23d0ba 48 * describe in a textual form the characterisic purpose or allow a client to
marcozecchini 0:9fca2b23d0ba 49 * register for notification of updates of the characteristic value.
marcozecchini 0:9fca2b23d0ba 50 *
marcozecchini 0:9fca2b23d0ba 51 * Prior to any interaction with server characteristic, a GATT client
marcozecchini 0:9fca2b23d0ba 52 * discovers the layout of the services and characteristics present on the
marcozecchini 0:9fca2b23d0ba 53 * server.
marcozecchini 0:9fca2b23d0ba 54 *
marcozecchini 0:9fca2b23d0ba 55 * The layout of the descriptors of a characteristic may also be issued to
marcozecchini 0:9fca2b23d0ba 56 * as an extra discovery step.
marcozecchini 0:9fca2b23d0ba 57 *
marcozecchini 0:9fca2b23d0ba 58 * @par Attribute manipulation
marcozecchini 0:9fca2b23d0ba 59 *
marcozecchini 0:9fca2b23d0ba 60 * As a result of the discovery process, the client can start interacting with
marcozecchini 0:9fca2b23d0ba 61 * the characteristic discovered. Depending on the characteristic properties
marcozecchini 0:9fca2b23d0ba 62 * (acquired during discovery), a client can read or write the value of a given
marcozecchini 0:9fca2b23d0ba 63 * characteristic.
marcozecchini 0:9fca2b23d0ba 64 *
marcozecchini 0:9fca2b23d0ba 65 * Mbed BLE abstracts most read and write operations to offer a single API that
marcozecchini 0:9fca2b23d0ba 66 * can be used to read or write characteristics values. Application code does not
marcozecchini 0:9fca2b23d0ba 67 * have to handle the fragmentation/reassembly process necessary if the attribute
marcozecchini 0:9fca2b23d0ba 68 * value to transported cannot fit in a single data packet.
marcozecchini 0:9fca2b23d0ba 69 *
marcozecchini 0:9fca2b23d0ba 70 * @par Server Initiated events
marcozecchini 0:9fca2b23d0ba 71 *
marcozecchini 0:9fca2b23d0ba 72 * If a characteristic has to notify or indicate a property set; then, a client may
marcozecchini 0:9fca2b23d0ba 73 * register to a notification or indication from the characteristic. When the
marcozecchini 0:9fca2b23d0ba 74 * server updates the characteristic value, the server can forward the
marcozecchini 0:9fca2b23d0ba 75 * new value to the registered clients. The notification/indication mechanism
marcozecchini 0:9fca2b23d0ba 76 * prevents polling from the client and therefore minimize the transactions
marcozecchini 0:9fca2b23d0ba 77 * involved between a client and a server.
marcozecchini 0:9fca2b23d0ba 78 *
marcozecchini 0:9fca2b23d0ba 79 * Registration is made by writing the Client Characteristic Configuration
marcozecchini 0:9fca2b23d0ba 80 * Descriptor, which is present in the characteristic if the notify or
marcozecchini 0:9fca2b23d0ba 81 * indicate properties are set. The client discovers that descriptor
marcozecchini 0:9fca2b23d0ba 82 * if it intends to register to server initiated events.
marcozecchini 0:9fca2b23d0ba 83 */
marcozecchini 0:9fca2b23d0ba 84 class GattClient {
marcozecchini 0:9fca2b23d0ba 85 public:
marcozecchini 0:9fca2b23d0ba 86 /**
marcozecchini 0:9fca2b23d0ba 87 * Attribute read event handler.
marcozecchini 0:9fca2b23d0ba 88 *
marcozecchini 0:9fca2b23d0ba 89 * @see GattClient::onDataRead().
marcozecchini 0:9fca2b23d0ba 90 */
marcozecchini 0:9fca2b23d0ba 91 typedef FunctionPointerWithContext<const GattReadCallbackParams*>
marcozecchini 0:9fca2b23d0ba 92 ReadCallback_t;
marcozecchini 0:9fca2b23d0ba 93
marcozecchini 0:9fca2b23d0ba 94 /**
marcozecchini 0:9fca2b23d0ba 95 * Callchain of attribute read event handlers.
marcozecchini 0:9fca2b23d0ba 96 */
marcozecchini 0:9fca2b23d0ba 97 typedef CallChainOfFunctionPointersWithContext<const GattReadCallbackParams*>
marcozecchini 0:9fca2b23d0ba 98 ReadCallbackChain_t;
marcozecchini 0:9fca2b23d0ba 99
marcozecchini 0:9fca2b23d0ba 100 /**
marcozecchini 0:9fca2b23d0ba 101 * GATT write operations.
marcozecchini 0:9fca2b23d0ba 102 */
marcozecchini 0:9fca2b23d0ba 103 enum WriteOp_t {
marcozecchini 0:9fca2b23d0ba 104 /**
marcozecchini 0:9fca2b23d0ba 105 * Write request.
marcozecchini 0:9fca2b23d0ba 106 *
marcozecchini 0:9fca2b23d0ba 107 * It is used to request the server to write the value of an attribute
marcozecchini 0:9fca2b23d0ba 108 * and acknowledge that this has been achieved in a Write Response.
marcozecchini 0:9fca2b23d0ba 109 */
marcozecchini 0:9fca2b23d0ba 110 GATT_OP_WRITE_REQ = 0x01,
marcozecchini 0:9fca2b23d0ba 111
marcozecchini 0:9fca2b23d0ba 112 /**
marcozecchini 0:9fca2b23d0ba 113 * Write command.
marcozecchini 0:9fca2b23d0ba 114 *
marcozecchini 0:9fca2b23d0ba 115 * It is used to request the server to write the value of an attribute.
marcozecchini 0:9fca2b23d0ba 116 * The server does not acknowledge the status of the operation.
marcozecchini 0:9fca2b23d0ba 117 */
marcozecchini 0:9fca2b23d0ba 118 GATT_OP_WRITE_CMD = 0x02,
marcozecchini 0:9fca2b23d0ba 119 };
marcozecchini 0:9fca2b23d0ba 120
marcozecchini 0:9fca2b23d0ba 121 /**
marcozecchini 0:9fca2b23d0ba 122 * Attribute write event handler.
marcozecchini 0:9fca2b23d0ba 123 *
marcozecchini 0:9fca2b23d0ba 124 * @see GattClient::onDataWrite().
marcozecchini 0:9fca2b23d0ba 125 */
marcozecchini 0:9fca2b23d0ba 126 typedef FunctionPointerWithContext<const GattWriteCallbackParams*>
marcozecchini 0:9fca2b23d0ba 127 WriteCallback_t;
marcozecchini 0:9fca2b23d0ba 128
marcozecchini 0:9fca2b23d0ba 129 /**
marcozecchini 0:9fca2b23d0ba 130 * Callchain of attribute write event handlers.
marcozecchini 0:9fca2b23d0ba 131 *
marcozecchini 0:9fca2b23d0ba 132 * @see GattClient::onDataWrite().
marcozecchini 0:9fca2b23d0ba 133 */
marcozecchini 0:9fca2b23d0ba 134 typedef CallChainOfFunctionPointersWithContext<const GattWriteCallbackParams*>
marcozecchini 0:9fca2b23d0ba 135 WriteCallbackChain_t;
marcozecchini 0:9fca2b23d0ba 136
marcozecchini 0:9fca2b23d0ba 137 /**
marcozecchini 0:9fca2b23d0ba 138 * Handle value notification/indication event handler.
marcozecchini 0:9fca2b23d0ba 139 *
marcozecchini 0:9fca2b23d0ba 140 * @see to GattClient::onHVX().
marcozecchini 0:9fca2b23d0ba 141 */
marcozecchini 0:9fca2b23d0ba 142 typedef FunctionPointerWithContext<const GattHVXCallbackParams*>
marcozecchini 0:9fca2b23d0ba 143 HVXCallback_t;
marcozecchini 0:9fca2b23d0ba 144
marcozecchini 0:9fca2b23d0ba 145 /**
marcozecchini 0:9fca2b23d0ba 146 * Callchain of handle value notification/indication event handlers.
marcozecchini 0:9fca2b23d0ba 147 *
marcozecchini 0:9fca2b23d0ba 148 * @see GattClient::onHVX().
marcozecchini 0:9fca2b23d0ba 149 */
marcozecchini 0:9fca2b23d0ba 150 typedef CallChainOfFunctionPointersWithContext<const GattHVXCallbackParams*>
marcozecchini 0:9fca2b23d0ba 151 HVXCallbackChain_t;
marcozecchini 0:9fca2b23d0ba 152
marcozecchini 0:9fca2b23d0ba 153 /**
marcozecchini 0:9fca2b23d0ba 154 * Shutdown event handler.
marcozecchini 0:9fca2b23d0ba 155 *
marcozecchini 0:9fca2b23d0ba 156 * @see GattClient::onShutdown().
marcozecchini 0:9fca2b23d0ba 157 */
marcozecchini 0:9fca2b23d0ba 158 typedef FunctionPointerWithContext<const GattClient *>
marcozecchini 0:9fca2b23d0ba 159 GattClientShutdownCallback_t;
marcozecchini 0:9fca2b23d0ba 160
marcozecchini 0:9fca2b23d0ba 161
marcozecchini 0:9fca2b23d0ba 162 /**
marcozecchini 0:9fca2b23d0ba 163 * Callchain of shutdown event handlers.
marcozecchini 0:9fca2b23d0ba 164 *
marcozecchini 0:9fca2b23d0ba 165 * @see to GattClient::onShutown().
marcozecchini 0:9fca2b23d0ba 166 */
marcozecchini 0:9fca2b23d0ba 167 typedef CallChainOfFunctionPointersWithContext<const GattClient *>
marcozecchini 0:9fca2b23d0ba 168 GattClientShutdownCallbackChain_t;
marcozecchini 0:9fca2b23d0ba 169
marcozecchini 0:9fca2b23d0ba 170 /*
marcozecchini 0:9fca2b23d0ba 171 * The following functions are meant to be overridden in the platform
marcozecchini 0:9fca2b23d0ba 172 * specific subclass.
marcozecchini 0:9fca2b23d0ba 173 */
marcozecchini 0:9fca2b23d0ba 174 public:
marcozecchini 0:9fca2b23d0ba 175
marcozecchini 0:9fca2b23d0ba 176 virtual ~GattClient() { }
marcozecchini 0:9fca2b23d0ba 177
marcozecchini 0:9fca2b23d0ba 178 /**
marcozecchini 0:9fca2b23d0ba 179 * Launch the service and characteristic discovery procedure of a GATT server
marcozecchini 0:9fca2b23d0ba 180 * peer.
marcozecchini 0:9fca2b23d0ba 181 *
marcozecchini 0:9fca2b23d0ba 182 * The procedure invokes application callbacks for matching services or
marcozecchini 0:9fca2b23d0ba 183 * characteristics. The process ends after all the services and
marcozecchini 0:9fca2b23d0ba 184 * characteristics present on the distant GATT server have been discovered.
marcozecchini 0:9fca2b23d0ba 185 * Termination callbacks registered with onServiceDiscoveryTermination() are
marcozecchini 0:9fca2b23d0ba 186 * invoked to notify the application of the termination of the procedure.
marcozecchini 0:9fca2b23d0ba 187 *
marcozecchini 0:9fca2b23d0ba 188 * Application code can track the status of the procedure by invoking the
marcozecchini 0:9fca2b23d0ba 189 * function isServiceDiscoveryActive(), which returns true if the
marcozecchini 0:9fca2b23d0ba 190 * procedure is ongoing.
marcozecchini 0:9fca2b23d0ba 191 *
marcozecchini 0:9fca2b23d0ba 192 * At any point, application code can prematurely terminate the discovery
marcozecchini 0:9fca2b23d0ba 193 * procedure by calling terminateServiceDiscovery().
marcozecchini 0:9fca2b23d0ba 194 *
marcozecchini 0:9fca2b23d0ba 195 * @param[in] connectionHandle Handle of the connection with the peer GATT
marcozecchini 0:9fca2b23d0ba 196 * server.
marcozecchini 0:9fca2b23d0ba 197 * @param[in] sc Service discovered event handler invoked when a matching
marcozecchini 0:9fca2b23d0ba 198 * service has been discovered. This parameter may be NULL.
marcozecchini 0:9fca2b23d0ba 199 * @param[in] cc Characteristic discovered event handler invoked when a
marcozecchini 0:9fca2b23d0ba 200 * matching characteristic has been found. This parameter may be NULL.
marcozecchini 0:9fca2b23d0ba 201 * @param[in] matchingServiceUUID UUID of the service the caller is
marcozecchini 0:9fca2b23d0ba 202 * interested in. If a service discovered matches this filter, then @p sc is
marcozecchini 0:9fca2b23d0ba 203 * invoked with it. The special value BLE_UUID_UNKNOWN acts as a wildcard,
marcozecchini 0:9fca2b23d0ba 204 * which can be used to discover all services present on the peer GATT
marcozecchini 0:9fca2b23d0ba 205 * server.
marcozecchini 0:9fca2b23d0ba 206 * @param[in] matchingCharacteristicUUIDIn UUID of the characteristic the
marcozecchini 0:9fca2b23d0ba 207 * caller is interested in. If a characteristic discovered matches this
marcozecchini 0:9fca2b23d0ba 208 * filter, then @p cc is invoked with it. The special value BLE_UUID_UNKNOWN
marcozecchini 0:9fca2b23d0ba 209 * acts as a wildcard, which can be used to discover all services present on
marcozecchini 0:9fca2b23d0ba 210 * the peer GATT server.
marcozecchini 0:9fca2b23d0ba 211 *
marcozecchini 0:9fca2b23d0ba 212 * @par Discovery procedure implementation detail
marcozecchini 0:9fca2b23d0ba 213 *
marcozecchini 0:9fca2b23d0ba 214 * It is recommended to implement several strategies based on the
marcozecchini 0:9fca2b23d0ba 215 * combination of callbacks and filters passed in input to efficiently
marcozecchini 0:9fca2b23d0ba 216 * realize the discovery procedure:
marcozecchini 0:9fca2b23d0ba 217 * - If @p sc and @p cc are NULL, then it is not necessay to initiate any
marcozecchini 0:9fca2b23d0ba 218 * discovery, and the termination handlers can be invoked immediately.
marcozecchini 0:9fca2b23d0ba 219 * - If @p matchingServiceUUID is set, then the GATT discover services by
marcozecchini 0:9fca2b23d0ba 220 * service UUID procedure should be used; otherwise, the GATT discover primary
marcozecchini 0:9fca2b23d0ba 221 * services procedure should be used.
marcozecchini 0:9fca2b23d0ba 222 * - If @p cc is NULL, then the discovery process should end after the discovery
marcozecchini 0:9fca2b23d0ba 223 * of the services.
marcozecchini 0:9fca2b23d0ba 224 *
marcozecchini 0:9fca2b23d0ba 225 * @return BLE_ERROR_NONE if the discovery procedure has been successfully
marcozecchini 0:9fca2b23d0ba 226 * started and an appropriate error otherwise.
marcozecchini 0:9fca2b23d0ba 227 */
marcozecchini 0:9fca2b23d0ba 228 virtual ble_error_t launchServiceDiscovery(
marcozecchini 0:9fca2b23d0ba 229 Gap::Handle_t connectionHandle,
marcozecchini 0:9fca2b23d0ba 230 ServiceDiscovery::ServiceCallback_t sc = NULL,
marcozecchini 0:9fca2b23d0ba 231 ServiceDiscovery::CharacteristicCallback_t cc = NULL,
marcozecchini 0:9fca2b23d0ba 232 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
marcozecchini 0:9fca2b23d0ba 233 const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)
marcozecchini 0:9fca2b23d0ba 234 ) {
marcozecchini 0:9fca2b23d0ba 235 /* Avoid compiler warnings about unused variables. */
marcozecchini 0:9fca2b23d0ba 236 (void)connectionHandle;
marcozecchini 0:9fca2b23d0ba 237 (void)sc;
marcozecchini 0:9fca2b23d0ba 238 (void)cc;
marcozecchini 0:9fca2b23d0ba 239 (void)matchingServiceUUID;
marcozecchini 0:9fca2b23d0ba 240 (void)matchingCharacteristicUUIDIn;
marcozecchini 0:9fca2b23d0ba 241
marcozecchini 0:9fca2b23d0ba 242 /* Requesting action from porters: override this API if this capability
marcozecchini 0:9fca2b23d0ba 243 is supported. */
marcozecchini 0:9fca2b23d0ba 244 return BLE_ERROR_NOT_IMPLEMENTED;
marcozecchini 0:9fca2b23d0ba 245 }
marcozecchini 0:9fca2b23d0ba 246
marcozecchini 0:9fca2b23d0ba 247 /**
marcozecchini 0:9fca2b23d0ba 248 * Launch the service discovery procedure of a GATT server peer.
marcozecchini 0:9fca2b23d0ba 249 *
marcozecchini 0:9fca2b23d0ba 250 * The procedure invokes the application callback for matching services.
marcozecchini 0:9fca2b23d0ba 251 * The process ends after all the services present on the distant GATT
marcozecchini 0:9fca2b23d0ba 252 * server have been discovered.
marcozecchini 0:9fca2b23d0ba 253 * Termination callbacks registered with onServiceDiscoveryTermination() are
marcozecchini 0:9fca2b23d0ba 254 * invoked to notify the application of the termination of the procedure.
marcozecchini 0:9fca2b23d0ba 255 *
marcozecchini 0:9fca2b23d0ba 256 * Application code can track the status of the procedure by invoking the
marcozecchini 0:9fca2b23d0ba 257 * function isServiceDiscoveryActive(), which returns true if the
marcozecchini 0:9fca2b23d0ba 258 * procedure is ongoing.
marcozecchini 0:9fca2b23d0ba 259 *
marcozecchini 0:9fca2b23d0ba 260 * At any point, application code can prematurely terminate the discovery
marcozecchini 0:9fca2b23d0ba 261 * procedure by calling terminateServiceDiscovery().
marcozecchini 0:9fca2b23d0ba 262 *
marcozecchini 0:9fca2b23d0ba 263 * @param[in] connectionHandle Handle of the connection with the peer GATT
marcozecchini 0:9fca2b23d0ba 264 * server.
marcozecchini 0:9fca2b23d0ba 265 * @param[in] callback Service discovered event handler invoked when a
marcozecchini 0:9fca2b23d0ba 266 * matching service has been discovered. This parameter may be NULL.
marcozecchini 0:9fca2b23d0ba 267 * @param[in] matchingServiceUUID UUID of the service the caller is
marcozecchini 0:9fca2b23d0ba 268 * interested in. If a service discovered matches this filter, then @p sc is
marcozecchini 0:9fca2b23d0ba 269 * invoked with it. The special value BLE_UUID_UNKNOWN act is a wildcard,
marcozecchini 0:9fca2b23d0ba 270 * which can be used to discover all services present on the peer GATT
marcozecchini 0:9fca2b23d0ba 271 * server.
marcozecchini 0:9fca2b23d0ba 272 *
marcozecchini 0:9fca2b23d0ba 273 * @return BLE_ERROR_NONE if the discovery procedure has been successfully
marcozecchini 0:9fca2b23d0ba 274 * started and an appropriate error otherwise.
marcozecchini 0:9fca2b23d0ba 275 */
marcozecchini 0:9fca2b23d0ba 276 virtual ble_error_t discoverServices(
marcozecchini 0:9fca2b23d0ba 277 Gap::Handle_t connectionHandle,
marcozecchini 0:9fca2b23d0ba 278 ServiceDiscovery::ServiceCallback_t callback,
marcozecchini 0:9fca2b23d0ba 279 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)
marcozecchini 0:9fca2b23d0ba 280 ) {
marcozecchini 0:9fca2b23d0ba 281 /* We take advantage of the property
marcozecchini 0:9fca2b23d0ba 282 * that providing NULL for the characteristic callback results in
marcozecchini 0:9fca2b23d0ba 283 * characteristic discovery being skipped for each matching
marcozecchini 0:9fca2b23d0ba 284 * service. This allows for an inexpensive method to discover only
marcozecchini 0:9fca2b23d0ba 285 * services. Porters are free to override this. */
marcozecchini 0:9fca2b23d0ba 286 return launchServiceDiscovery(
marcozecchini 0:9fca2b23d0ba 287 connectionHandle, callback, NULL, matchingServiceUUID
marcozecchini 0:9fca2b23d0ba 288 );
marcozecchini 0:9fca2b23d0ba 289 }
marcozecchini 0:9fca2b23d0ba 290
marcozecchini 0:9fca2b23d0ba 291 /**
marcozecchini 0:9fca2b23d0ba 292 * Launch the service discovery procedure of a GATT server peer.
marcozecchini 0:9fca2b23d0ba 293 *
marcozecchini 0:9fca2b23d0ba 294 * The process ends after all the services present in the attribute range @p
marcozecchini 0:9fca2b23d0ba 295 * startHandle to @p endHandle have been discovered.
marcozecchini 0:9fca2b23d0ba 296 *
marcozecchini 0:9fca2b23d0ba 297 * Termination callbacks registered with onServiceDiscoveryTermination() are
marcozecchini 0:9fca2b23d0ba 298 * invoked to notify the application of the termination of the procedure.
marcozecchini 0:9fca2b23d0ba 299 *
marcozecchini 0:9fca2b23d0ba 300 * Application code can track the status of the procedure by invoking the
marcozecchini 0:9fca2b23d0ba 301 * function isServiceDiscoveryActive(), which returns true if the
marcozecchini 0:9fca2b23d0ba 302 * procedure is ongoing.
marcozecchini 0:9fca2b23d0ba 303 *
marcozecchini 0:9fca2b23d0ba 304 * At any point, application code can prematurely terminate the discovery
marcozecchini 0:9fca2b23d0ba 305 * procedure by calling terminateServiceDiscovery().
marcozecchini 0:9fca2b23d0ba 306 *
marcozecchini 0:9fca2b23d0ba 307 * @param[in] connectionHandle Handle of the connection with the peer GATT
marcozecchini 0:9fca2b23d0ba 308 * server.
marcozecchini 0:9fca2b23d0ba 309 * @param[in] callback Service discovered event handler invoked when a
marcozecchini 0:9fca2b23d0ba 310 * matching service has been discovered. This parameter may be NULL.
marcozecchini 0:9fca2b23d0ba 311 * @param[in] startHandle First attribute handle of the discovery range.
marcozecchini 0:9fca2b23d0ba 312 * @param[in] endHandle end Lasr attribute handle of the discovery range.
marcozecchini 0:9fca2b23d0ba 313 *
marcozecchini 0:9fca2b23d0ba 314 * @return BLE_ERROR_NONE if the discovery procedure has been successfully
marcozecchini 0:9fca2b23d0ba 315 * started and an appropriate error otherwise.
marcozecchini 0:9fca2b23d0ba 316 */
marcozecchini 0:9fca2b23d0ba 317 virtual ble_error_t discoverServices(
marcozecchini 0:9fca2b23d0ba 318 Gap::Handle_t connectionHandle,
marcozecchini 0:9fca2b23d0ba 319 ServiceDiscovery::ServiceCallback_t callback,
marcozecchini 0:9fca2b23d0ba 320 GattAttribute::Handle_t startHandle,
marcozecchini 0:9fca2b23d0ba 321 GattAttribute::Handle_t endHandle
marcozecchini 0:9fca2b23d0ba 322 ) {
marcozecchini 0:9fca2b23d0ba 323 /* Avoid compiler warnings about unused variables. */
marcozecchini 0:9fca2b23d0ba 324 (void)connectionHandle;
marcozecchini 0:9fca2b23d0ba 325 (void)callback;
marcozecchini 0:9fca2b23d0ba 326 (void)startHandle;
marcozecchini 0:9fca2b23d0ba 327 (void)endHandle;
marcozecchini 0:9fca2b23d0ba 328
marcozecchini 0:9fca2b23d0ba 329 /* Requesting action from porters: override this API if this capability
marcozecchini 0:9fca2b23d0ba 330 is supported. */
marcozecchini 0:9fca2b23d0ba 331 return BLE_ERROR_NOT_IMPLEMENTED;
marcozecchini 0:9fca2b23d0ba 332 }
marcozecchini 0:9fca2b23d0ba 333
marcozecchini 0:9fca2b23d0ba 334 /**
marcozecchini 0:9fca2b23d0ba 335 * Check if the service discovery procedure is currently active.
marcozecchini 0:9fca2b23d0ba 336 *
marcozecchini 0:9fca2b23d0ba 337 * @return true if service discovery procedure is active and false otherwise.
marcozecchini 0:9fca2b23d0ba 338 */
marcozecchini 0:9fca2b23d0ba 339 virtual bool isServiceDiscoveryActive(void) const
marcozecchini 0:9fca2b23d0ba 340 {
marcozecchini 0:9fca2b23d0ba 341 /* Requesting action from porters: override this API if this capability
marcozecchini 0:9fca2b23d0ba 342 is supported. */
marcozecchini 0:9fca2b23d0ba 343 return false;
marcozecchini 0:9fca2b23d0ba 344 }
marcozecchini 0:9fca2b23d0ba 345
marcozecchini 0:9fca2b23d0ba 346 /**
marcozecchini 0:9fca2b23d0ba 347 * Terminate all ongoing service discovery procedures.
marcozecchini 0:9fca2b23d0ba 348 *
marcozecchini 0:9fca2b23d0ba 349 * It results in an invocation of the service discovery termination handler
marcozecchini 0:9fca2b23d0ba 350 * registered with onServiceDiscoveryTermination().
marcozecchini 0:9fca2b23d0ba 351 */
marcozecchini 0:9fca2b23d0ba 352 virtual void terminateServiceDiscovery(void)
marcozecchini 0:9fca2b23d0ba 353 {
marcozecchini 0:9fca2b23d0ba 354 /* Requesting action from porters: override this API if this capability
marcozecchini 0:9fca2b23d0ba 355 is supported. */
marcozecchini 0:9fca2b23d0ba 356 }
marcozecchini 0:9fca2b23d0ba 357
marcozecchini 0:9fca2b23d0ba 358 /**
marcozecchini 0:9fca2b23d0ba 359 * Initiate the read procedure of an attribute handle.
marcozecchini 0:9fca2b23d0ba 360 *
marcozecchini 0:9fca2b23d0ba 361 * Once the attribute value has been read in its entirety, the process issues
marcozecchini 0:9fca2b23d0ba 362 * an attribute read event and passes it to all events handlers registered
marcozecchini 0:9fca2b23d0ba 363 * by onDataRead.
marcozecchini 0:9fca2b23d0ba 364 *
marcozecchini 0:9fca2b23d0ba 365 * @param[in] connHandle Handle of the connection used to send the read
marcozecchini 0:9fca2b23d0ba 366 * request.
marcozecchini 0:9fca2b23d0ba 367 * @param[in] attributeHandle Handle of the attribute to read data from.
marcozecchini 0:9fca2b23d0ba 368 * @param[in] offset The offset from the start of the attribute value to be
marcozecchini 0:9fca2b23d0ba 369 * read.
marcozecchini 0:9fca2b23d0ba 370 *
marcozecchini 0:9fca2b23d0ba 371 * @return BLE_ERROR_NONE if read procedure successfully started.
marcozecchini 0:9fca2b23d0ba 372 *
marcozecchini 0:9fca2b23d0ba 373 * @par Implementation notes:
marcozecchini 0:9fca2b23d0ba 374 *
marcozecchini 0:9fca2b23d0ba 375 * Reading the attribute value in its entirety may involve sending several
marcozecchini 0:9fca2b23d0ba 376 * GATT requests to the peer. The following algorithm may be used to
marcozecchini 0:9fca2b23d0ba 377 * implement the process:
marcozecchini 0:9fca2b23d0ba 378 *
marcozecchini 0:9fca2b23d0ba 379 * If the offset is equal to 0, then send a read request; otherwise, send a
marcozecchini 0:9fca2b23d0ba 380 * read blob request at the specified offset.
marcozecchini 0:9fca2b23d0ba 381 *
marcozecchini 0:9fca2b23d0ba 382 * While the attribute data in the response are MTU - 1 long:
marcozecchini 0:9fca2b23d0ba 383 * - Concat the response to the value containing the previous responses.
marcozecchini 0:9fca2b23d0ba 384 * - Increment the value of the offset by MTU - 1.
marcozecchini 0:9fca2b23d0ba 385 * - Send a read blob request with the updated offset.
marcozecchini 0:9fca2b23d0ba 386 *
marcozecchini 0:9fca2b23d0ba 387 * Finally, concat the last response with the value containing all the
marcozecchini 0:9fca2b23d0ba 388 * previous responses and forward that value to the event handlers.
marcozecchini 0:9fca2b23d0ba 389 */
marcozecchini 0:9fca2b23d0ba 390 virtual ble_error_t read(
marcozecchini 0:9fca2b23d0ba 391 Gap::Handle_t connHandle,
marcozecchini 0:9fca2b23d0ba 392 GattAttribute::Handle_t attributeHandle,
marcozecchini 0:9fca2b23d0ba 393 uint16_t offset
marcozecchini 0:9fca2b23d0ba 394 ) const {
marcozecchini 0:9fca2b23d0ba 395 /* Avoid compiler warnings about unused variables. */
marcozecchini 0:9fca2b23d0ba 396 (void)connHandle;
marcozecchini 0:9fca2b23d0ba 397 (void)attributeHandle;
marcozecchini 0:9fca2b23d0ba 398 (void)offset;
marcozecchini 0:9fca2b23d0ba 399
marcozecchini 0:9fca2b23d0ba 400 /* Requesting action from porters: override this API if this capability
marcozecchini 0:9fca2b23d0ba 401 is supported. */
marcozecchini 0:9fca2b23d0ba 402 return BLE_ERROR_NOT_IMPLEMENTED;
marcozecchini 0:9fca2b23d0ba 403 }
marcozecchini 0:9fca2b23d0ba 404
marcozecchini 0:9fca2b23d0ba 405 /**
marcozecchini 0:9fca2b23d0ba 406 * Initiate a write procedure on an attribute value.
marcozecchini 0:9fca2b23d0ba 407 *
marcozecchini 0:9fca2b23d0ba 408 * If @p cmd is equal to GATT_OP_WRITE_REQ, then the status of the operation
marcozecchini 0:9fca2b23d0ba 409 * is reported to the event handlers registered through onDataWritten().
marcozecchini 0:9fca2b23d0ba 410 *
marcozecchini 0:9fca2b23d0ba 411 * @param[in] cmd Type of the write procedure used. If GATT_OP_WRITE_CMD
marcozecchini 0:9fca2b23d0ba 412 * is set, then value length is not greater than the size of the mtu
marcozecchini 0:9fca2b23d0ba 413 * of connHandle minus three.
marcozecchini 0:9fca2b23d0ba 414 * @param[in] connHandle Handle of the connection used to send the write
marcozecchini 0:9fca2b23d0ba 415 * request or command.
marcozecchini 0:9fca2b23d0ba 416 * @param[in] attributeHandle Handle of the attribute value to write.
marcozecchini 0:9fca2b23d0ba 417 * @param[in] length Number of bytes present in @p value.
marcozecchini 0:9fca2b23d0ba 418 * @param[in] value Data buffer to write to attributeHandle.
marcozecchini 0:9fca2b23d0ba 419 *
marcozecchini 0:9fca2b23d0ba 420 * @return BLE_ERROR_NONE if the write procedure successfully started.
marcozecchini 0:9fca2b23d0ba 421 *
marcozecchini 0:9fca2b23d0ba 422 * @par Implementation notes:
marcozecchini 0:9fca2b23d0ba 423 *
marcozecchini 0:9fca2b23d0ba 424 * If the operation is a write command, then an implementation uses the
marcozecchini 0:9fca2b23d0ba 425 * GATT write without response procedure and an error is returned if
marcozecchini 0:9fca2b23d0ba 426 * the data buffer to write is larger than the size of the MTU - 3.
marcozecchini 0:9fca2b23d0ba 427 *
marcozecchini 0:9fca2b23d0ba 428 * If the operation is a write command and the size of the data buffer to
marcozecchini 0:9fca2b23d0ba 429 * write is less than than the size of the MTU - 3, then the ATT write request
marcozecchini 0:9fca2b23d0ba 430 * procedure is used, and the response is reported to the handlers
marcozecchini 0:9fca2b23d0ba 431 * listening for write response.
marcozecchini 0:9fca2b23d0ba 432 *
marcozecchini 0:9fca2b23d0ba 433 * Otherwise, the data buffer to write is divided in chunks with a
marcozecchini 0:9fca2b23d0ba 434 * maximum size of MTU - 5. Those chunks are sent sequentially to the
marcozecchini 0:9fca2b23d0ba 435 * peer in ATT prepare write requests. If an error response is received
marcozecchini 0:9fca2b23d0ba 436 * during the process, the procedure ends immediately, the prepared
marcozecchini 0:9fca2b23d0ba 437 * write is discarded and an error is reported to the application handlers.
marcozecchini 0:9fca2b23d0ba 438 * Once all the chunks have been sent, the transaction is completed
marcozecchini 0:9fca2b23d0ba 439 * by sending an execute write request to the peer. The peer response is
marcozecchini 0:9fca2b23d0ba 440 * forwarded to the application handlers.
marcozecchini 0:9fca2b23d0ba 441 */
marcozecchini 0:9fca2b23d0ba 442 virtual ble_error_t write(
marcozecchini 0:9fca2b23d0ba 443 GattClient::WriteOp_t cmd,
marcozecchini 0:9fca2b23d0ba 444 Gap::Handle_t connHandle,
marcozecchini 0:9fca2b23d0ba 445 GattAttribute::Handle_t attributeHandle,
marcozecchini 0:9fca2b23d0ba 446 size_t length,
marcozecchini 0:9fca2b23d0ba 447 const uint8_t *value
marcozecchini 0:9fca2b23d0ba 448 ) const {
marcozecchini 0:9fca2b23d0ba 449 /* Avoid compiler warnings about unused variables. */
marcozecchini 0:9fca2b23d0ba 450 (void)cmd;
marcozecchini 0:9fca2b23d0ba 451 (void)connHandle;
marcozecchini 0:9fca2b23d0ba 452 (void)attributeHandle;
marcozecchini 0:9fca2b23d0ba 453 (void)length;
marcozecchini 0:9fca2b23d0ba 454 (void)value;
marcozecchini 0:9fca2b23d0ba 455
marcozecchini 0:9fca2b23d0ba 456 /* Requesting action from porters: override this API if this capability
marcozecchini 0:9fca2b23d0ba 457 is supported. */
marcozecchini 0:9fca2b23d0ba 458 return BLE_ERROR_NOT_IMPLEMENTED;
marcozecchini 0:9fca2b23d0ba 459 }
marcozecchini 0:9fca2b23d0ba 460
marcozecchini 0:9fca2b23d0ba 461 /* Event callback handlers. */
marcozecchini 0:9fca2b23d0ba 462 public:
marcozecchini 0:9fca2b23d0ba 463
marcozecchini 0:9fca2b23d0ba 464 /**
marcozecchini 0:9fca2b23d0ba 465 * Register an attribute read event handler.
marcozecchini 0:9fca2b23d0ba 466 *
marcozecchini 0:9fca2b23d0ba 467 * @note It is possible to unregister a callback using
marcozecchini 0:9fca2b23d0ba 468 * onDataRead().detach(callbackToRemove).
marcozecchini 0:9fca2b23d0ba 469 *
marcozecchini 0:9fca2b23d0ba 470 * @param[in] callback Event handler being registered.
marcozecchini 0:9fca2b23d0ba 471 */
marcozecchini 0:9fca2b23d0ba 472 void onDataRead(ReadCallback_t callback)
marcozecchini 0:9fca2b23d0ba 473 {
marcozecchini 0:9fca2b23d0ba 474 onDataReadCallbackChain.add(callback);
marcozecchini 0:9fca2b23d0ba 475 }
marcozecchini 0:9fca2b23d0ba 476
marcozecchini 0:9fca2b23d0ba 477 /**
marcozecchini 0:9fca2b23d0ba 478 * Get the callchain of attribute read event handlers.
marcozecchini 0:9fca2b23d0ba 479 *
marcozecchini 0:9fca2b23d0ba 480 * @return A reference to the read event callback chain.
marcozecchini 0:9fca2b23d0ba 481 *
marcozecchini 0:9fca2b23d0ba 482 * @note It is possible to register new handlers using
marcozecchini 0:9fca2b23d0ba 483 * onDataRead().add(callback).
marcozecchini 0:9fca2b23d0ba 484 *
marcozecchini 0:9fca2b23d0ba 485 * @note It is possible to unregister an handler by using
marcozecchini 0:9fca2b23d0ba 486 * onDataRead().detach(callback).
marcozecchini 0:9fca2b23d0ba 487 */
marcozecchini 0:9fca2b23d0ba 488 ReadCallbackChain_t& onDataRead()
marcozecchini 0:9fca2b23d0ba 489 {
marcozecchini 0:9fca2b23d0ba 490 return onDataReadCallbackChain;
marcozecchini 0:9fca2b23d0ba 491 }
marcozecchini 0:9fca2b23d0ba 492
marcozecchini 0:9fca2b23d0ba 493 /**
marcozecchini 0:9fca2b23d0ba 494 * Register an attribute write event handler.
marcozecchini 0:9fca2b23d0ba 495 *
marcozecchini 0:9fca2b23d0ba 496 * @param[in] callback Event handler being registered.
marcozecchini 0:9fca2b23d0ba 497 *
marcozecchini 0:9fca2b23d0ba 498 * @note It is possible to remove registered handlers using
marcozecchini 0:9fca2b23d0ba 499 * onDataWritten().detach(callbackToRemove).
marcozecchini 0:9fca2b23d0ba 500 *
marcozecchini 0:9fca2b23d0ba 501 * @note Write commands (issued using writeWoResponse) don't generate a
marcozecchini 0:9fca2b23d0ba 502 * response.
marcozecchini 0:9fca2b23d0ba 503 */
marcozecchini 0:9fca2b23d0ba 504 void onDataWritten(WriteCallback_t callback)
marcozecchini 0:9fca2b23d0ba 505 {
marcozecchini 0:9fca2b23d0ba 506 onDataWriteCallbackChain.add(callback);
marcozecchini 0:9fca2b23d0ba 507 }
marcozecchini 0:9fca2b23d0ba 508
marcozecchini 0:9fca2b23d0ba 509 /**
marcozecchini 0:9fca2b23d0ba 510 * Get the callchain of attribute write event handlers.
marcozecchini 0:9fca2b23d0ba 511 *
marcozecchini 0:9fca2b23d0ba 512 * @return A reference to the data written callbacks chain.
marcozecchini 0:9fca2b23d0ba 513 *
marcozecchini 0:9fca2b23d0ba 514 * @note It is possible to register new handlers by using
marcozecchini 0:9fca2b23d0ba 515 * onDataWritten().add(callback).
marcozecchini 0:9fca2b23d0ba 516 *
marcozecchini 0:9fca2b23d0ba 517 * @note It is possible to unregister an handler by using
marcozecchini 0:9fca2b23d0ba 518 * onDataWritten().detach(callback).
marcozecchini 0:9fca2b23d0ba 519 */
marcozecchini 0:9fca2b23d0ba 520 WriteCallbackChain_t& onDataWritten()
marcozecchini 0:9fca2b23d0ba 521 {
marcozecchini 0:9fca2b23d0ba 522 return onDataWriteCallbackChain;
marcozecchini 0:9fca2b23d0ba 523 }
marcozecchini 0:9fca2b23d0ba 524
marcozecchini 0:9fca2b23d0ba 525 /**
marcozecchini 0:9fca2b23d0ba 526 * Register an attribute write event handler.
marcozecchini 0:9fca2b23d0ba 527 *
marcozecchini 0:9fca2b23d0ba 528 * @param[in] callback Event handler being registered.
marcozecchini 0:9fca2b23d0ba 529 *
marcozecchini 0:9fca2b23d0ba 530 * @note It is possible to remove registered handlers using
marcozecchini 0:9fca2b23d0ba 531 * onDataWritten().detach(callbackToRemove).
marcozecchini 0:9fca2b23d0ba 532 *
marcozecchini 0:9fca2b23d0ba 533 * @note Write commands (issued using writeWoResponse) don't generate a
marcozecchini 0:9fca2b23d0ba 534 * response.
marcozecchini 0:9fca2b23d0ba 535 *
marcozecchini 0:9fca2b23d0ba 536 * @deprecated Use GattServer::onDataWritten().
marcozecchini 0:9fca2b23d0ba 537 */
marcozecchini 0:9fca2b23d0ba 538 MBED_DEPRECATED("Use GattServer::onDataWritten()")
marcozecchini 0:9fca2b23d0ba 539 void onDataWrite(WriteCallback_t callback)
marcozecchini 0:9fca2b23d0ba 540 {
marcozecchini 0:9fca2b23d0ba 541 onDataWritten(callback);
marcozecchini 0:9fca2b23d0ba 542 }
marcozecchini 0:9fca2b23d0ba 543
marcozecchini 0:9fca2b23d0ba 544 /**
marcozecchini 0:9fca2b23d0ba 545 * Register a service discovery termination event handler.
marcozecchini 0:9fca2b23d0ba 546 *
marcozecchini 0:9fca2b23d0ba 547 * @param[in] callback Event handler being registered.
marcozecchini 0:9fca2b23d0ba 548 */
marcozecchini 0:9fca2b23d0ba 549 virtual void onServiceDiscoveryTermination(
marcozecchini 0:9fca2b23d0ba 550 ServiceDiscovery::TerminationCallback_t callback
marcozecchini 0:9fca2b23d0ba 551 ) {
marcozecchini 0:9fca2b23d0ba 552 (void)callback; /* Avoid compiler warnings about ununsed variables. */
marcozecchini 0:9fca2b23d0ba 553
marcozecchini 0:9fca2b23d0ba 554 /* Requesting action from porters: override this API if this capability
marcozecchini 0:9fca2b23d0ba 555 is supported. */
marcozecchini 0:9fca2b23d0ba 556 }
marcozecchini 0:9fca2b23d0ba 557
marcozecchini 0:9fca2b23d0ba 558 /**
marcozecchini 0:9fca2b23d0ba 559 * Initiate the descriptor discovery procedure for a given characteristic.
marcozecchini 0:9fca2b23d0ba 560 *
marcozecchini 0:9fca2b23d0ba 561 * When a descriptor is discovered the discovered descriptor is forwarded
marcozecchini 0:9fca2b23d0ba 562 * to @p discoveryCallback. After the discovery of all the descriptors, the
marcozecchini 0:9fca2b23d0ba 563 * procedure ends and send a descriptor discovery termination event to @p
marcozecchini 0:9fca2b23d0ba 564 * termination callback.
marcozecchini 0:9fca2b23d0ba 565 *
marcozecchini 0:9fca2b23d0ba 566 * Application code may monitor the discovery process by querying its status
marcozecchini 0:9fca2b23d0ba 567 * with isCharacteristicDescriptorDiscoveryActive(). It can also end the
marcozecchini 0:9fca2b23d0ba 568 * discovery process by calling terminateCharacteristicDescriptorDiscovery().
marcozecchini 0:9fca2b23d0ba 569 *
marcozecchini 0:9fca2b23d0ba 570 * @param[in] characteristic The characteristic owning the descriptors to
marcozecchini 0:9fca2b23d0ba 571 * discover.
marcozecchini 0:9fca2b23d0ba 572 * @param[in] discoveryCallback Handle descriptor discovered events for the
marcozecchini 0:9fca2b23d0ba 573 * duration of the procedure.
marcozecchini 0:9fca2b23d0ba 574 * @param[in] terminationCallback Handle descriptor discovery termination
marcozecchini 0:9fca2b23d0ba 575 * event of the procedure.
marcozecchini 0:9fca2b23d0ba 576 *
marcozecchini 0:9fca2b23d0ba 577 * @return BLE_ERROR_NONE if the characteristic descriptor discovery
marcozecchini 0:9fca2b23d0ba 578 * procedure has been launched successfully otherwise an appropriate error.
marcozecchini 0:9fca2b23d0ba 579 */
marcozecchini 0:9fca2b23d0ba 580 virtual ble_error_t discoverCharacteristicDescriptors(
marcozecchini 0:9fca2b23d0ba 581 const DiscoveredCharacteristic& characteristic,
marcozecchini 0:9fca2b23d0ba 582 const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
marcozecchini 0:9fca2b23d0ba 583 const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
marcozecchini 0:9fca2b23d0ba 584 ) {
marcozecchini 0:9fca2b23d0ba 585 (void) characteristic;
marcozecchini 0:9fca2b23d0ba 586 (void) discoveryCallback;
marcozecchini 0:9fca2b23d0ba 587 (void) terminationCallback;
marcozecchini 0:9fca2b23d0ba 588 /* Requesting action from porter(s): override this API if this
marcozecchini 0:9fca2b23d0ba 589 capability is supported. */
marcozecchini 0:9fca2b23d0ba 590 return BLE_ERROR_NOT_IMPLEMENTED;
marcozecchini 0:9fca2b23d0ba 591 }
marcozecchini 0:9fca2b23d0ba 592
marcozecchini 0:9fca2b23d0ba 593 /**
marcozecchini 0:9fca2b23d0ba 594 * Query status of the descriptor discovery procedure for a given
marcozecchini 0:9fca2b23d0ba 595 * characteristic.
marcozecchini 0:9fca2b23d0ba 596 *
marcozecchini 0:9fca2b23d0ba 597 * @param[in] characteristic The characteristic concerned by the descriptors
marcozecchini 0:9fca2b23d0ba 598 * discovery.
marcozecchini 0:9fca2b23d0ba 599 *
marcozecchini 0:9fca2b23d0ba 600 * @return true if a descriptors discovery is active for the characteristic
marcozecchini 0:9fca2b23d0ba 601 * in input otherwise false.
marcozecchini 0:9fca2b23d0ba 602 */
marcozecchini 0:9fca2b23d0ba 603 virtual bool isCharacteristicDescriptorDiscoveryActive(
marcozecchini 0:9fca2b23d0ba 604 const DiscoveredCharacteristic& characteristic
marcozecchini 0:9fca2b23d0ba 605 ) const {
marcozecchini 0:9fca2b23d0ba 606 (void) characteristic;
marcozecchini 0:9fca2b23d0ba 607 /* Requesting action from porter(s): override this API if this
marcozecchini 0:9fca2b23d0ba 608 capability is supported. */
marcozecchini 0:9fca2b23d0ba 609 return false;
marcozecchini 0:9fca2b23d0ba 610 }
marcozecchini 0:9fca2b23d0ba 611
marcozecchini 0:9fca2b23d0ba 612 /**
marcozecchini 0:9fca2b23d0ba 613 * @brief Terminate an ongoing characteristic descriptor discovery procedure.
marcozecchini 0:9fca2b23d0ba 614 *
marcozecchini 0:9fca2b23d0ba 615 * If the procedure is active, then it ends, and the termination handler
marcozecchini 0:9fca2b23d0ba 616 * associated with the procedure is called.
marcozecchini 0:9fca2b23d0ba 617 *
marcozecchini 0:9fca2b23d0ba 618 * @param[in] characteristic The characteristic containing the descriptors
marcozecchini 0:9fca2b23d0ba 619 * being discovered.
marcozecchini 0:9fca2b23d0ba 620 */
marcozecchini 0:9fca2b23d0ba 621 virtual void terminateCharacteristicDescriptorDiscovery(
marcozecchini 0:9fca2b23d0ba 622 const DiscoveredCharacteristic& characteristic
marcozecchini 0:9fca2b23d0ba 623 ) {
marcozecchini 0:9fca2b23d0ba 624 /* Requesting action from porter(s): override this API if this
marcozecchini 0:9fca2b23d0ba 625 capability is supported. */
marcozecchini 0:9fca2b23d0ba 626 (void) characteristic;
marcozecchini 0:9fca2b23d0ba 627 }
marcozecchini 0:9fca2b23d0ba 628
marcozecchini 0:9fca2b23d0ba 629 /**
marcozecchini 0:9fca2b23d0ba 630 * Register an handler for Handle Value Notification/Indication events.
marcozecchini 0:9fca2b23d0ba 631 *
marcozecchini 0:9fca2b23d0ba 632 * @param callback Event handler to register.
marcozecchini 0:9fca2b23d0ba 633 *
marcozecchini 0:9fca2b23d0ba 634 * @note It is possible to unregister a callback by using
marcozecchini 0:9fca2b23d0ba 635 * onHVX().detach(callbackToRemove).
marcozecchini 0:9fca2b23d0ba 636 */
marcozecchini 0:9fca2b23d0ba 637 void onHVX(HVXCallback_t callback)
marcozecchini 0:9fca2b23d0ba 638 {
marcozecchini 0:9fca2b23d0ba 639 onHVXCallbackChain.add(callback);
marcozecchini 0:9fca2b23d0ba 640 }
marcozecchini 0:9fca2b23d0ba 641
marcozecchini 0:9fca2b23d0ba 642 /**
marcozecchini 0:9fca2b23d0ba 643 * Register a shutdown event handler.
marcozecchini 0:9fca2b23d0ba 644 *
marcozecchini 0:9fca2b23d0ba 645 * The registered handler is invoked when the GattClient instance is
marcozecchini 0:9fca2b23d0ba 646 * about to be shut down.
marcozecchini 0:9fca2b23d0ba 647 *
marcozecchini 0:9fca2b23d0ba 648 * @param[in] callback Event handler to invoke when a shutdown event is
marcozecchini 0:9fca2b23d0ba 649 * available.
marcozecchini 0:9fca2b23d0ba 650 *
marcozecchini 0:9fca2b23d0ba 651 * @note onShutdown().detach(callback) may be used to unregister a given
marcozecchini 0:9fca2b23d0ba 652 * callback.
marcozecchini 0:9fca2b23d0ba 653 *
marcozecchini 0:9fca2b23d0ba 654 * @see BLE::shutdown()
marcozecchini 0:9fca2b23d0ba 655 */
marcozecchini 0:9fca2b23d0ba 656 void onShutdown(const GattClientShutdownCallback_t& callback)
marcozecchini 0:9fca2b23d0ba 657 {
marcozecchini 0:9fca2b23d0ba 658 shutdownCallChain.add(callback);
marcozecchini 0:9fca2b23d0ba 659 }
marcozecchini 0:9fca2b23d0ba 660
marcozecchini 0:9fca2b23d0ba 661 /**
marcozecchini 0:9fca2b23d0ba 662 * Register a shutdown event handler.
marcozecchini 0:9fca2b23d0ba 663 *
marcozecchini 0:9fca2b23d0ba 664 * The registered handler is invoked when the GattClient instance is
marcozecchini 0:9fca2b23d0ba 665 * about to be shut down.
marcozecchini 0:9fca2b23d0ba 666 *
marcozecchini 0:9fca2b23d0ba 667 * @param[in] objPtr Instance that will be used to invoke @p memberPtr.
marcozecchini 0:9fca2b23d0ba 668 * @param[in] memberPtr Event handler to invoke when a shutdown event is
marcozecchini 0:9fca2b23d0ba 669 * available.
marcozecchini 0:9fca2b23d0ba 670 */
marcozecchini 0:9fca2b23d0ba 671 template <typename T>
marcozecchini 0:9fca2b23d0ba 672 void onShutdown(T *objPtr, void (T::*memberPtr)(const GattClient *))
marcozecchini 0:9fca2b23d0ba 673 {
marcozecchini 0:9fca2b23d0ba 674 shutdownCallChain.add(objPtr, memberPtr);
marcozecchini 0:9fca2b23d0ba 675 }
marcozecchini 0:9fca2b23d0ba 676
marcozecchini 0:9fca2b23d0ba 677 /**
marcozecchini 0:9fca2b23d0ba 678 * Get the callchain of shutdown event handlers.
marcozecchini 0:9fca2b23d0ba 679 *
marcozecchini 0:9fca2b23d0ba 680 * @return A reference to the shutdown event callbacks chain.
marcozecchini 0:9fca2b23d0ba 681 *
marcozecchini 0:9fca2b23d0ba 682 * @note onShutdown().add(callback) may be used to register new handlers.
marcozecchini 0:9fca2b23d0ba 683 *
marcozecchini 0:9fca2b23d0ba 684 * @note onShutdown().detach(callback) may be used to unregister an handler.
marcozecchini 0:9fca2b23d0ba 685 */
marcozecchini 0:9fca2b23d0ba 686 GattClientShutdownCallbackChain_t& onShutdown()
marcozecchini 0:9fca2b23d0ba 687 {
marcozecchini 0:9fca2b23d0ba 688 return shutdownCallChain;
marcozecchini 0:9fca2b23d0ba 689 }
marcozecchini 0:9fca2b23d0ba 690
marcozecchini 0:9fca2b23d0ba 691 /**
marcozecchini 0:9fca2b23d0ba 692 * @brief provide access to the callchain of HVX callbacks.
marcozecchini 0:9fca2b23d0ba 693 *
marcozecchini 0:9fca2b23d0ba 694 * @return A reference to the HVX callbacks chain.
marcozecchini 0:9fca2b23d0ba 695 *
marcozecchini 0:9fca2b23d0ba 696 * @note It is possible to register callbacks using onHVX().add(callback).
marcozecchini 0:9fca2b23d0ba 697 *
marcozecchini 0:9fca2b23d0ba 698 * @note It is possible to unregister callbacks using onHVX().detach(callback).
marcozecchini 0:9fca2b23d0ba 699 */
marcozecchini 0:9fca2b23d0ba 700 HVXCallbackChain_t& onHVX() {
marcozecchini 0:9fca2b23d0ba 701 return onHVXCallbackChain;
marcozecchini 0:9fca2b23d0ba 702 }
marcozecchini 0:9fca2b23d0ba 703
marcozecchini 0:9fca2b23d0ba 704 public:
marcozecchini 0:9fca2b23d0ba 705 /**
marcozecchini 0:9fca2b23d0ba 706 * Reset the state of the GattClient instance.
marcozecchini 0:9fca2b23d0ba 707 *
marcozecchini 0:9fca2b23d0ba 708 * Prior to any state modification, shutdown event handlers are notified
marcozecchini 0:9fca2b23d0ba 709 * that the GattClient instance is about to be shut down. Then, running
marcozecchini 0:9fca2b23d0ba 710 * procedures end. Finally, the state of the instance is reset.
marcozecchini 0:9fca2b23d0ba 711 *
marcozecchini 0:9fca2b23d0ba 712 * @par implementation note
marcozecchini 0:9fca2b23d0ba 713 *
marcozecchini 0:9fca2b23d0ba 714 * This function is meant to be overridden in the platform-specific
marcozecchini 0:9fca2b23d0ba 715 * subclass. Nevertheless, the subclass only resets its
marcozecchini 0:9fca2b23d0ba 716 * state and not the data held in GattClient members. This is achieved
marcozecchini 0:9fca2b23d0ba 717 * by a call to GattClient::reset() from the subclass' reset()
marcozecchini 0:9fca2b23d0ba 718 * implementation.
marcozecchini 0:9fca2b23d0ba 719 *
marcozecchini 0:9fca2b23d0ba 720 * @return BLE_ERROR_NONE on success.
marcozecchini 0:9fca2b23d0ba 721 */
marcozecchini 0:9fca2b23d0ba 722 virtual ble_error_t reset(void)
marcozecchini 0:9fca2b23d0ba 723 {
marcozecchini 0:9fca2b23d0ba 724 /* Notify that the instance is about to shut down. */
marcozecchini 0:9fca2b23d0ba 725 shutdownCallChain.call(this);
marcozecchini 0:9fca2b23d0ba 726 shutdownCallChain.clear();
marcozecchini 0:9fca2b23d0ba 727
marcozecchini 0:9fca2b23d0ba 728 onDataReadCallbackChain.clear();
marcozecchini 0:9fca2b23d0ba 729 onDataWriteCallbackChain.clear();
marcozecchini 0:9fca2b23d0ba 730 onHVXCallbackChain.clear();
marcozecchini 0:9fca2b23d0ba 731
marcozecchini 0:9fca2b23d0ba 732 return BLE_ERROR_NONE;
marcozecchini 0:9fca2b23d0ba 733 }
marcozecchini 0:9fca2b23d0ba 734
marcozecchini 0:9fca2b23d0ba 735 protected:
marcozecchini 0:9fca2b23d0ba 736 GattClient()
marcozecchini 0:9fca2b23d0ba 737 {
marcozecchini 0:9fca2b23d0ba 738 /* Empty */
marcozecchini 0:9fca2b23d0ba 739 }
marcozecchini 0:9fca2b23d0ba 740
marcozecchini 0:9fca2b23d0ba 741 /* Entry points for the underlying stack to report events back to the user. */
marcozecchini 0:9fca2b23d0ba 742 public:
marcozecchini 0:9fca2b23d0ba 743 /**
marcozecchini 0:9fca2b23d0ba 744 * Forward an attribute read event to all registered handlers.
marcozecchini 0:9fca2b23d0ba 745 *
marcozecchini 0:9fca2b23d0ba 746 * @important This function is meant to be called from the vendor
marcozecchini 0:9fca2b23d0ba 747 * implementation when an attribute read event occurs.
marcozecchini 0:9fca2b23d0ba 748 *
marcozecchini 0:9fca2b23d0ba 749 * @param[in] params Attribute read event to pass to the registered handlers.
marcozecchini 0:9fca2b23d0ba 750 */
marcozecchini 0:9fca2b23d0ba 751 void processReadResponse(const GattReadCallbackParams *params)
marcozecchini 0:9fca2b23d0ba 752 {
marcozecchini 0:9fca2b23d0ba 753 onDataReadCallbackChain(params);
marcozecchini 0:9fca2b23d0ba 754 }
marcozecchini 0:9fca2b23d0ba 755
marcozecchini 0:9fca2b23d0ba 756 /**
marcozecchini 0:9fca2b23d0ba 757 * Forward an attribute written event to all registered handlers.
marcozecchini 0:9fca2b23d0ba 758 *
marcozecchini 0:9fca2b23d0ba 759 * @important This function is meant to be called from the vendor
marcozecchini 0:9fca2b23d0ba 760 * implementation when an attribute written event occurs.
marcozecchini 0:9fca2b23d0ba 761 *
marcozecchini 0:9fca2b23d0ba 762 * @param[in] params Attribute written event to pass to the registered
marcozecchini 0:9fca2b23d0ba 763 * handlers.
marcozecchini 0:9fca2b23d0ba 764 */
marcozecchini 0:9fca2b23d0ba 765 void processWriteResponse(const GattWriteCallbackParams *params)
marcozecchini 0:9fca2b23d0ba 766 {
marcozecchini 0:9fca2b23d0ba 767 onDataWriteCallbackChain(params);
marcozecchini 0:9fca2b23d0ba 768 }
marcozecchini 0:9fca2b23d0ba 769
marcozecchini 0:9fca2b23d0ba 770 /**
marcozecchini 0:9fca2b23d0ba 771 * Forward a handle value notification or indication event to all registered
marcozecchini 0:9fca2b23d0ba 772 * handlers.
marcozecchini 0:9fca2b23d0ba 773 *
marcozecchini 0:9fca2b23d0ba 774 * @important This function is meant to be called from the vendor
marcozecchini 0:9fca2b23d0ba 775 * implementation when a notification or indication event is available.
marcozecchini 0:9fca2b23d0ba 776 *
marcozecchini 0:9fca2b23d0ba 777 * @param[in] params Notification or Indication event to pass to the
marcozecchini 0:9fca2b23d0ba 778 * registered handlers.
marcozecchini 0:9fca2b23d0ba 779 */
marcozecchini 0:9fca2b23d0ba 780 void processHVXEvent(const GattHVXCallbackParams *params)
marcozecchini 0:9fca2b23d0ba 781 {
marcozecchini 0:9fca2b23d0ba 782 if (onHVXCallbackChain) {
marcozecchini 0:9fca2b23d0ba 783 onHVXCallbackChain(params);
marcozecchini 0:9fca2b23d0ba 784 }
marcozecchini 0:9fca2b23d0ba 785 }
marcozecchini 0:9fca2b23d0ba 786
marcozecchini 0:9fca2b23d0ba 787 protected:
marcozecchini 0:9fca2b23d0ba 788 /**
marcozecchini 0:9fca2b23d0ba 789 * Callchain containing all registered event handlers for data read
marcozecchini 0:9fca2b23d0ba 790 * events.
marcozecchini 0:9fca2b23d0ba 791 */
marcozecchini 0:9fca2b23d0ba 792 ReadCallbackChain_t onDataReadCallbackChain;
marcozecchini 0:9fca2b23d0ba 793
marcozecchini 0:9fca2b23d0ba 794 /**
marcozecchini 0:9fca2b23d0ba 795 * Callchain containing all registered event handlers for data write
marcozecchini 0:9fca2b23d0ba 796 * events.
marcozecchini 0:9fca2b23d0ba 797 */
marcozecchini 0:9fca2b23d0ba 798 WriteCallbackChain_t onDataWriteCallbackChain;
marcozecchini 0:9fca2b23d0ba 799
marcozecchini 0:9fca2b23d0ba 800 /**
marcozecchini 0:9fca2b23d0ba 801 * Callchain containing all registered event handlers for update
marcozecchini 0:9fca2b23d0ba 802 * events.
marcozecchini 0:9fca2b23d0ba 803 */
marcozecchini 0:9fca2b23d0ba 804 HVXCallbackChain_t onHVXCallbackChain;
marcozecchini 0:9fca2b23d0ba 805
marcozecchini 0:9fca2b23d0ba 806 /**
marcozecchini 0:9fca2b23d0ba 807 * Callchain containing all registered event handlers for shutdown
marcozecchini 0:9fca2b23d0ba 808 * events.
marcozecchini 0:9fca2b23d0ba 809 */
marcozecchini 0:9fca2b23d0ba 810 GattClientShutdownCallbackChain_t shutdownCallChain;
marcozecchini 0:9fca2b23d0ba 811
marcozecchini 0:9fca2b23d0ba 812 private:
marcozecchini 0:9fca2b23d0ba 813 /* Disallow copy and assignment. */
marcozecchini 0:9fca2b23d0ba 814 GattClient(const GattClient &);
marcozecchini 0:9fca2b23d0ba 815 GattClient& operator=(const GattClient &);
marcozecchini 0:9fca2b23d0ba 816 };
marcozecchini 0:9fca2b23d0ba 817
marcozecchini 0:9fca2b23d0ba 818 /**
marcozecchini 0:9fca2b23d0ba 819 * @}
marcozecchini 0:9fca2b23d0ba 820 * @}
marcozecchini 0:9fca2b23d0ba 821 * @}
marcozecchini 0:9fca2b23d0ba 822 */
marcozecchini 0:9fca2b23d0ba 823
marcozecchini 0:9fca2b23d0ba 824 #endif /* ifndef MBED_GATT_CLIENT_H__ */