prova

Fork of BLE_API by Bluetooth Low Energy

Revision:
1164:7e84487d45fc
Parent:
1156:e1ea38b576c6
Child:
1179:4ab722f8dca0
--- a/ble/GattClient.h	Wed Apr 06 19:14:51 2016 +0100
+++ b/ble/GattClient.h	Wed Apr 06 19:14:53 2016 +0100
@@ -28,21 +28,52 @@
 
 class GattClient {
 public:
+    /**
+     * Type for the registered callbacks added to the data read callchain.
+     * Refer to GattClient::onDataRead().
+     */
     typedef FunctionPointerWithContext<const GattReadCallbackParams*> ReadCallback_t;
+    /**
+     * Type for the data read event callchain. Refer to GattClient::onDataRead().
+     */
     typedef CallChainOfFunctionPointersWithContext<const GattReadCallbackParams*> ReadCallbackChain_t;
 
+    /**
+     * Enumerator for write operations.
+     */
     enum WriteOp_t {
         GATT_OP_WRITE_REQ = 0x01,  /**< Write request. */
         GATT_OP_WRITE_CMD = 0x02,  /**< Write command. */
     };
 
+    /**
+     * Type for the registered callbacks added to the data write callchain.
+     * Refer to GattClient::onDataWrite().
+     */
     typedef FunctionPointerWithContext<const GattWriteCallbackParams*> WriteCallback_t;
+    /**
+     * Type for the data write event callchain. Refer to GattClient::onDataWrite().
+     */
     typedef CallChainOfFunctionPointersWithContext<const GattWriteCallbackParams*> WriteCallbackChain_t;
 
+    /**
+     * Type for the registered callbacks added to the update event callchain.
+     * Refer to GattClient::onHVX().
+     */
     typedef FunctionPointerWithContext<const GattHVXCallbackParams*> HVXCallback_t;
+    /**
+     * Type for the update event callchain. Refer to GattClient::onHVX().
+     */
     typedef CallChainOfFunctionPointersWithContext<const GattHVXCallbackParams*> HVXCallbackChain_t;
 
+    /**
+     * Type for the registered callbacks added to the shutdown callchain.
+     * Refer to GattClient::onShutdown().
+     */
     typedef FunctionPointerWithContext<const GattClient *> GattClientShutdownCallback_t;
+    /**
+     * Type for the shutdown event callchain. Refer to GattClient::onShutown().
+     */
     typedef CallChainOfFunctionPointersWithContext<const GattClient *> GattClientShutdownCallbackChain_t;
 
     /*
@@ -56,40 +87,40 @@
      * will be invoked at the end. Service discovery can be terminated prematurely,
      * if needed, using terminateServiceDiscovery().
      *
-     * @param  connectionHandle
-     *           Handle for the connection with the peer.
-     * @param  sc
-     *           This is the application callback for a matching service. Taken as
-     *           NULL by default. Note: service discovery may still be active
-     *           when this callback is issued; calling asynchronous BLE-stack
-     *           APIs from within this application callback might cause the
-     *           stack to abort service discovery. If this becomes an issue, it
-     *           may be better to make a local copy of the discoveredService and
-     *           wait for service discovery to terminate before operating on the
-     *           service.
-     * @param  cc
-     *           This is the application callback for a matching characteristic.
-     *           Taken as NULL by default. Note: service discovery may still be
-     *           active when this callback is issued; calling asynchronous
-     *           BLE-stack APIs from within this application callback might cause
-     *           the stack to abort service discovery. If this becomes an issue,
-     *           it may be better to make a local copy of the discoveredCharacteristic
-     *           and wait for service discovery to terminate before operating on the
-     *           characteristic.
-     * @param  matchingServiceUUID
-     *           UUID-based filter for specifying a service in which the application is
-     *           interested. By default it is set as the wildcard UUID_UNKNOWN,
-     *           in which case it matches all services. If characteristic-UUID
-     *           filter (below) is set to the wildcard value, then a service
-     *           callback will be invoked for the matching service (or for every
-     *           service if the service filter is a wildcard).
-     * @param  matchingCharacteristicUUIDIn
-     *           UUID-based filter for specifying characteristic in which the application
-     *           is interested. By default it is set as the wildcard UUID_UKNOWN
-     *           to match against any characteristic. If both service-UUID
-     *           filter and characteristic-UUID filter are used with non-wildcard
-     *           values, then only a single characteristic callback is
-     *           invoked for the matching characteristic.
+     * @param[in]  connectionHandle
+     *              Handle for the connection with the peer.
+     * @param[in]  sc
+     *              This is the application callback for a matching service. Taken as
+     *              NULL by default. Note: service discovery may still be active
+     *              when this callback is issued; calling asynchronous BLE-stack
+     *              APIs from within this application callback might cause the
+     *              stack to abort service discovery. If this becomes an issue, it
+     *              may be better to make a local copy of the discoveredService and
+     *              wait for service discovery to terminate before operating on the
+     *              service.
+     * @param[in]  cc
+     *              This is the application callback for a matching characteristic.
+     *              Taken as NULL by default. Note: service discovery may still be
+     *              active when this callback is issued; calling asynchronous
+     *              BLE-stack APIs from within this application callback might cause
+     *              the stack to abort service discovery. If this becomes an issue,
+     *              it may be better to make a local copy of the discoveredCharacteristic
+     *              and wait for service discovery to terminate before operating on the
+     *              characteristic.
+     * @param[in]  matchingServiceUUID
+     *              UUID-based filter for specifying a service in which the application is
+     *              interested. By default it is set as the wildcard UUID_UNKNOWN,
+     *              in which case it matches all services. If characteristic-UUID
+     *              filter (below) is set to the wildcard value, then a service
+     *              callback will be invoked for the matching service (or for every
+     *              service if the service filter is a wildcard).
+     * @param[in]  matchingCharacteristicUUIDIn
+     *              UUID-based filter for specifying characteristic in which the application
+     *              is interested. By default it is set as the wildcard UUID_UKNOWN
+     *              to match against any characteristic. If both service-UUID
+     *              filter and characteristic-UUID filter are used with non-wildcard
+     *              values, then only a single characteristic callback is
+     *              invoked for the matching characteristic.
      *
      * @note     Using wildcard values for both service-UUID and characteristic-
      *           UUID will result in complete service discovery: callbacks being
@@ -126,20 +157,21 @@
      * at the end. Service discovery can be terminated prematurely, if needed,
      * using terminateServiceDiscovery().
      *
-     * @param  connectionHandle
-     *           Handle for the connection with the peer.
-     * @param  sc
-     *           This is the application callback for a matching service. Note: service discovery may still be active
-     *           when this callback is issued; calling asynchronous BLE-stack
-     *           APIs from within this application callback might cause the
-     *           stack to abort service discovery. If this becomes an issue, it
-     *           may be better to make a local copy of the discoveredService and
-     *           wait for service discovery to terminate before operating on the
-     *           service.
-     * @param  matchingServiceUUID
-     *           UUID-based filter for specifying a service in which the application is
-     *           interested. By default it is set as the wildcard UUID_UNKNOWN,
-     *           in which case it matches all services.
+     * @param[in]  connectionHandle
+     *              Handle for the connection with the peer.
+     * @param[in]  callback
+     *              This is the application callback for a matching service.
+     *              Note: service discovery may still be active
+     *              when this callback is issued; calling asynchronous BLE-stack
+     *              APIs from within this application callback might cause the
+     *              stack to abort service discovery. If this becomes an issue, it
+     *              may be better to make a local copy of the discoveredService and
+     *              wait for service discovery to terminate before operating on the
+     *              service.
+     * @param[in]  matchingServiceUUID
+     *              UUID-based filter for specifying a service in which the application is
+     *              interested. By default it is set as the wildcard UUID_UNKNOWN,
+     *              in which case it matches all services.
      *
      * @return
      *           BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error.
@@ -162,18 +194,19 @@
      * at the end. Service discovery can be terminated prematurely, if needed,
      * using terminateServiceDiscovery().
      *
-     * @param  connectionHandle
-     *           Handle for the connection with the peer.
-     * @param  sc
-     *           This is the application callback for a matching service. Note: service discovery may still be active
-     *           when this callback is issued; calling asynchronous BLE-stack
-     *           APIs from within this application callback might cause the
-     *           stack to abort service discovery. If this becomes an issue, it
-     *           may be better to make a local copy of the discoveredService and
-     *           wait for service discovery to terminate before operating on the
-     *           service.
-     * @param  startHandle, endHandle
-     *           Handle range within which to limit the search.
+     * @param[in]  connectionHandle
+     *              Handle for the connection with the peer.
+     * @param[in]  callback
+     *              This is the application callback for a matching service.
+     *              Note: service discovery may still be active
+     *              when this callback is issued; calling asynchronous BLE-stack
+     *              APIs from within this application callback might cause the
+     *              stack to abort service discovery. If this becomes an issue, it
+     *              may be better to make a local copy of the discoveredService and
+     *              wait for service discovery to terminate before operating on the
+     *              service.
+     * @param[in]  startHandle, endHandle
+     *              Handle range within which to limit the search.
      *
      * @return
      *           BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error.
@@ -192,7 +225,9 @@
     }
 
     /**
-     * Is service-discovery currently active?
+     * Check if service-discovery is currently active.
+     *
+     * @return true if service-discovery is active, false otherwise.
      */
     virtual bool isServiceDiscoveryActive(void) const {
         return false; /* Requesting action from porters: override this API if this capability is supported. */
@@ -206,7 +241,19 @@
         /* Requesting action from porters: override this API if this capability is supported. */
     }
 
-    /* Initiate a GATT Client read procedure by attribute-handle. */
+    /**
+     * Initiate a GATT Client read procedure by attribute-handle.
+     *
+     * @param[in] connHandle
+     *              Handle for the connection with the peer.
+     * @param[in] attributeHandle
+     *              Handle of the attribute to read data from.
+     * @param[in] offset
+     *              The offset from the start of the attribute value to be read.
+     *
+     * @return
+     *          BLE_ERROR_NONE if read procedure was successfully started.
+     */
     virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const {
         /* Avoid compiler warnings about unused variables. */
         (void)connHandle;
@@ -231,6 +278,9 @@
      *              Length of the new value.
      * @param[in] value
      *              New value being written.
+     *
+     * @return
+     *          BLE_ERROR_NONE if write procedure was successfully started.
      */
     virtual ble_error_t write(GattClient::WriteOp_t    cmd,
                               Gap::Handle_t            connHandle,
@@ -251,18 +301,28 @@
 public:
     /**
      * Set up a callback for read response events.
-     * It is possible to remove registered callbacks using
-     * onDataRead().detach(callbackToRemove)
+     *
+     * @param[in] callback
+     *              Event handler being registered.
+     *
+     * @note It is possible to chain together multiple onDataRead callbacks
+     * (potentially from different modules of an application).
+     *
+     * @note It is possible to unregister a callback using
+     * onDataRead().detach(callbackToRemove).
      */
     void onDataRead(ReadCallback_t callback) {
         onDataReadCallbackChain.add(callback);
     }
 
     /**
-     * @brief provide access to the callchain of read callbacks
-     * It is possible to register callbacks using onDataRead().add(callback);
-     * It is possible to unregister callbacks using onDataRead().detach(callback)
-     * @return The read callbacks chain
+     * @brief Provide access to the callchain of read event callbacks.
+     *
+     * @return A reference to the read event callback chain.
+     *
+     * @note It is possible to register callbacks using onDataRead().add(callback).
+     *
+     * @note It is possible to unregister callbacks using onDataRead().detach(callback).
      */
     ReadCallbackChain_t& onDataRead() {
         return onDataReadCallbackChain;
@@ -270,19 +330,27 @@
 
     /**
      * Set up a callback for write response events.
-     * It is possible to remove registered callbacks using
+     *
+     * @param[in] callback
+     *              Event handler being registered.
+     *
+     * @note It is possible to remove registered callbacks using
      * onDataWritten().detach(callbackToRemove).
-     * @Note: Write commands (issued using writeWoResponse) don't generate a response.
+     *
+     * @note  Write commands (issued using writeWoResponse) don't generate a response.
      */
     void onDataWritten(WriteCallback_t callback) {
         onDataWriteCallbackChain.add(callback);
     }
 
     /**
-     * @brief provide access to the callchain of data written callbacks
-     * It is possible to register callbacks using onDataWritten().add(callback);
-     * It is possible to unregister callbacks using onDataWritten().detach(callback)
-     * @return The data written callbacks chain
+     * @brief Provide access to the callchain of data written callbacks.
+     *
+     * @return A reference to the data written callbacks chain.
+     *
+     * @note It is possible to register callbacks using onDataWritten().add(callback).
+     *
+     * @note It is possible to unregister callbacks using onDataWritten().detach(callback).
      */
     WriteCallbackChain_t& onDataWritten() {
         return onDataWriteCallbackChain;
@@ -290,10 +358,13 @@
 
     /**
      * Set up a callback for write response events.
-     * @Note: Write commands (issued using writeWoResponse) don't generate a response.
+     *
+     * @param[in] callback
+     *              Event handler being registered.
      *
-     * @note: This API is now *deprecated* and will be dropped in the future.
-     * Please use onDataWritten() instead.
+     * @note  Write commands (issued using writeWoResponse) don't generate a response.
+     *
+     * @deprecated Please use GattServer::onDataWritten() instead.
      */
     void onDataWrite(WriteCallback_t callback) {
         onDataWritten(callback);
@@ -301,6 +372,9 @@
 
     /**
      * Set up a callback for when serviceDiscovery terminates.
+     *
+     * @param[in] callback
+     *              Event handler being registered.
      */
     virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) {
         (void)callback; /* Avoid compiler warnings about ununsed variables. */
@@ -309,18 +383,21 @@
     }
 
     /**
-     * @brief launch discovery of descriptors for a given characteristic
+     * @brief Launch discovery of descriptors for a given characteristic.
+     *
      * @details This function will discover all descriptors available for a
-     * specific characteristic.
+     *          specific characteristic.
      *
-     * @param characteristic[in] The characteristic targeted by this discovery
-     * procedure
-     * @param discoveryCallback[in] User function called each time a descriptor
-     * is found during the procedure.
-     * @param terminationCallback[in] User provided function which will be called
-     * once the discovery procedure is terminating. This will get called when all
-     * the descriptors have been discovered or if an error occur during the discovery
-     * procedure.
+     * @param[in] characteristic
+     *              The characteristic targeted by this discovery procedure.
+     * @param[in] discoveryCallback
+     *              User function called each time a descriptor is found during
+     *              the procedure.
+     * @param[in] terminationCallback
+     *              User provided function which will be called once the
+     *              discovery procedure is terminating. This will get called
+     *              when all the descriptors have been discovered or if an
+     *              error occur during the discovery procedure.
      *
      * @return
      *   BLE_ERROR_NONE if characteristic descriptor discovery is launched
@@ -338,10 +415,14 @@
     }
 
     /**
-     * @brief Indicate if the discovery of characteristic descriptors is active for a given characteristic
-     * or not.
-     * @param characteristic[in] The characteristic concerned by the descriptors discovery.
-     * @return true if a descriptors discovery is active for the characteristic in input; otherwise false.
+     * @brief Indicate if the discovery of characteristic descriptors is active
+     *        for a given characteristic or not.
+     *
+     * @param[in] characteristic
+     *              The characteristic concerned by the descriptors discovery.
+     *
+     * @return true if a descriptors discovery is active for the characteristic
+     *         in input; otherwise false.
      */
     virtual bool isCharacteristicDescriptorDiscoveryActive(const DiscoveredCharacteristic& characteristic) const
      {
@@ -351,10 +432,13 @@
 
     /**
      * @brief Terminate an ongoing characteristic descriptor discovery.
+     *
      * @details This should result in an invocation of the TerminationCallback if
-     * the characteristic descriptor discovery is active.
-     * @param characteristic[in] The characteristic on which the running descriptors
-     * discovery should be stopped.
+     *          the characteristic descriptor discovery is active.
+     *
+     * @param[in] characteristic
+     *              The characteristic on which the running descriptors
+     *              discovery should be stopped.
      */
     virtual void terminateCharacteristicDescriptorDiscovery(const DiscoveredCharacteristic& characteristic) {
         /* Requesting action from porter(s): override this API if this capability is supported. */
@@ -362,10 +446,12 @@
     }
 
     /**
-     * Set up a callback for when the GATT client receives an update event
+     * Set up a callback for when the GATT Client receives an update event
      * corresponding to a change in the value of a characteristic on the remote
-     * GATT server.
-     * It is possible to remove registered callbacks using onHVX().detach(callbackToRemove).
+     * GATT Server.
+     *
+     * @note It is possible to unregister callbacks using
+     *       onHVX().detach(callbackToRemove).
      */
     void onHVX(HVXCallback_t callback) {
         onHVXCallbackChain.add(callback);
@@ -376,38 +462,60 @@
      * GattClient instance is about to shutdown (possibly as a result of a call
      * to BLE::shutdown()).
      *
-     * @Note: It is possible to chain together multiple onShutdown callbacks
-     * (potentially from different modules of an application) to be notified
-     * before the GattClient is shutdown.
+     * @param[in] callback
+     *              Event handler being registered.
      *
-     * @Note: It is also possible to set up a callback into a member function of
-     * some object.
+     * @note  It is possible to chain together multiple onShutdown callbacks
+     *        (potentially from different modules of an application) to be notified
+     *        before the GattClient is shutdown.
      *
-     * @Note It is possible to unregister a callback using onShutdown().detach(callback)
+     * @note  It is also possible to set up a callback into a member function of
+     *        some object.
+     *
+     * @note It is possible to unregister a callback using onShutdown().detach(callback).
      */
     void onShutdown(const GattClientShutdownCallback_t& callback) {
         shutdownCallChain.add(callback);
     }
+
+    /**
+     * Same as GattClient::onShutdown(), but allows the possibility to add an object
+     * reference and member function as handler for shutdown event
+     * callbacks.
+     *
+     * @param[in] objPtr
+     *              Pointer to the object of a class defining the member callback
+     *              function (@p memberPtr).
+     * @param[in] memberPtr
+     *              The member callback (within the context of an object) to be
+     *              invoked.
+     */
     template <typename T>
     void onShutdown(T *objPtr, void (T::*memberPtr)(void)) {
         shutdownCallChain.add(objPtr, memberPtr);
     }
 
     /**
-     * @brief provide access to the callchain of shutdown event callbacks
-     * It is possible to register callbacks using onShutdown().add(callback);
-     * It is possible to unregister callbacks using onShutdown().detach(callback)
-     * @return The shutdown event callbacks chain
+     * @brief Provide access to the callchain of shutdown event callbacks.
+     *
+     * @return A reference to the shutdown event callbacks chain.
+     *
+     * @note It is possible to register callbacks using onShutdown().add(callback).
+     *
+     * @note It is possible to unregister callbacks using onShutdown().detach(callback).
      */
     GattClientShutdownCallbackChain_t& onShutdown() {
         return shutdownCallChain;
     }
 
     /**
-     * @brief provide access to the callchain of HVX callbacks
-     * It is possible to register callbacks using onHVX().add(callback);
-     * It is possible to unregister callbacks using onHVX().detach(callback)
-     * @return The HVX callbacks chain
+     * @brief provide access to the callchain of HVX callbacks.
+     *
+     * @return A reference to the HVX callbacks chain.
+     *
+     * @note It is possible to register callbacks using onHVX().add(callback).
+     *
+     * @note It is possible to unregister callbacks using onHVX().detach(callback).
      */
     HVXCallbackChain_t& onHVX() {
         return onHVXCallbackChain;
@@ -446,14 +554,41 @@
 
     /* Entry points for the underlying stack to report events back to the user. */
 public:
+    /**
+     * Helper function that notifies all registered handlers of an occurrence
+     * of a data read event. This function is meant to be called from the
+     * BLE stack specific implementation when a data read event occurs.
+     *
+     * @param[in] params
+     *              The data read parameters passed to the registered
+     *              handlers.
+     */
     void processReadResponse(const GattReadCallbackParams *params) {
         onDataReadCallbackChain(params);
     }
 
+    /**
+     * Helper function that notifies all registered handlers of an occurrence
+     * of a data written event. This function is meant to be called from the
+     * BLE stack specific implementation when a data written event occurs.
+     *
+     * @param[in] params
+     *              The data written parameters passed to the registered
+     *              handlers.
+     */
     void processWriteResponse(const GattWriteCallbackParams *params) {
         onDataWriteCallbackChain(params);
     }
 
+    /**
+     * Helper function that notifies all registered handlers of an occurrence
+     * of an update event. This function is meant to be called from the
+     * BLE stack specific implementation when an update event occurs.
+     *
+     * @param[in] params
+     *              The update event parameters passed to the registered
+     *              handlers.
+     */
     void processHVXEvent(const GattHVXCallbackParams *params) {
         if (onHVXCallbackChain) {
             onHVXCallbackChain(params);
@@ -461,9 +596,25 @@
     }
 
 protected:
+    /**
+     * Callchain containing all registered callback handlers for data read
+     * events.
+     */
     ReadCallbackChain_t               onDataReadCallbackChain;
+    /**
+     * Callchain containing all registered callback handlers for data write
+     * events.
+     */
     WriteCallbackChain_t              onDataWriteCallbackChain;
+    /**
+     * Callchain containing all registered callback handlers for update
+     * events.
+     */
     HVXCallbackChain_t                onHVXCallbackChain;
+    /**
+     * Callchain containing all registered callback handlers for shutdown
+     * events.
+     */
     GattClientShutdownCallbackChain_t shutdownCallChain;
 
 private:
@@ -472,4 +623,4 @@
     GattClient& operator=(const GattClient &);
 };
 
-#endif // ifndef __GATT_CLIENT_H__
\ No newline at end of file
+#endif /* ifndef __GATT_CLIENT_H__ */
\ No newline at end of file