Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: ble/BLE.h
- Revision:
- 874:0607a58418ce
- Parent:
- 861:2afa79e3ed0a
- Child:
- 875:25480c83e3cc
diff -r 2e1a7bcf6590 -r 0607a58418ce ble/BLE.h
--- a/ble/BLE.h Tue Nov 03 12:51:24 2015 +0000
+++ b/ble/BLE.h Tue Nov 03 12:51:24 2015 +0000
@@ -41,16 +41,28 @@
typedef unsigned InstanceID_t; /** The type returned by BLE::getInstanceID(). */
/**
- * The function signature for callbacks for initialization completion.
+ * The context provided to init-completion-callbacks (see init() below).
+ *
* @param ble
* A reference to the BLE instance being initialized.
* @param error
* This captures the result of initialization. It is set to
* BLE_ERROR_NONE if initialization completed successfully. Else
* the error value is implementation specific.
- *
*/
- typedef void (*InitializationCompleteCallback_t)(BLE &ble, ble_error_t error);
+ struct InitializationCompleteCallbackContext {
+ BLE& ble; /* Reference to the BLE object which has been initialized */
+ ble_error_t error; /* Error status of the initialization. It is set to BLE_ERROR_NONE initialization completed successfully. */
+ };
+
+ /**
+ * The signature for function-pointer like callbacks for initialization-completion.
+ *
+ * @note There are two versions of init(). In addition to the simple
+ * function-pointer, init() can also take a <Object, member> tuple as its
+ * callback target. In case of the latter, the following declaration doesn't apply.
+ */
+ typedef void (*InitializationCompleteCallback_t)(InitializationCompleteCallbackContext *context);
/**
* Initialize the BLE controller. This should be called before using
@@ -72,19 +84,32 @@
* @return BLE_ERROR_NONE if the initialization procedure was started
* successfully.
*
- * @note The underlying stack must invoke the initialization completion
- * callback in response to init(). In some cases, initialization is
- * instantaneous (or blocking); if so, it is acceptable for the stack-
- * specific implementation of init() to invoke the completion callback
- * directly--i.e. within its own context.
+ * @note If init() returns BLE_ERROR_NONE, the underlying stack must invoke
+ * the initialization completion callback at some point.
+ *
+ * @note In some cases, initialization is instantaneous (or blocking); if
+ * so, it is acceptable for the stack-specific implementation of init()
+ * to invoke the completion callback directly--i.e. within its own
+ * context.
*
* @note Nearly all BLE APIs would return
* BLE_ERROR_INITIALIZATION_INCOMPLETE if used on an instance before the
* corresponding transport is initialized.
+ *
+ * @note There are two versions of init(). In addition to the simple
+ * function-pointer, init() can also take an <Object, member> tuple as its
+ * callback target.
*/
ble_error_t init(InitializationCompleteCallback_t callback = NULL);
/**
+ * An alternate declaration for init(). This one takes an <Object, member> tuple as its
+ * callback target.
+ */
+ template<typename T>
+ ble_error_t init(T *object, void (T::*initCompleteCallback)(InitializationCompleteCallbackContext *context));
+
+ /**
* @return true if initialization has completed for the underlying BLE
* transport.
*