Abstract away BLE-capable radio transceivers or SOCs. More...
#include <BLE.h>
Data Structures | |
struct | InitializationCompleteCallbackContext |
Initialization complete event. More... | |
struct | OnEventsToProcessCallbackContext |
Events to process event. More... | |
Public Types | |
typedef unsigned | InstanceID_t |
Opaque type used to store the ID of a BLE instance. More... | |
typedef FunctionPointerWithContext< OnEventsToProcessCallbackContext * > | OnEventsToProcessCallback_t |
Events to process event handler. More... | |
typedef void(* | InitializationCompleteCallback_t) (InitializationCompleteCallbackContext *context) |
Initialization complete event handler. More... | |
Public Member Functions | |
InstanceID_t | getInstanceID () const |
Fetch the ID of a BLE instance. More... | |
void | onEventsToProcess (const OnEventsToProcessCallback_t &on_event_cb) |
Register a callback called when the BLE stack has pending work. More... | |
void | processEvents () |
Process ALL pending events living in the BLE stack and return once all events have been consumed. More... | |
ble_error_t | init (InitializationCompleteCallback_t completion_cb=nullptr) |
Initialize the BLE controller/stack. More... | |
template<typename T > | |
ble_error_t | init (T *object, void(T::*completion_cb)(InitializationCompleteCallbackContext *context)) |
Initialize the BLE controller/stack. More... | |
bool | hasInitialized () const |
Indicate if the BLE instance has been initialized. More... | |
ble_error_t | shutdown () |
Shut down the underlying stack, and reset state of this BLE instance. More... | |
const char * | getVersion () |
This call allows the application to get the BLE stack version information. More... | |
ble::Gap & | gap () |
Accessor to Gap. More... | |
const ble::Gap & | gap () const |
A const alternative to gap(). More... | |
ble::GattServer & | gattServer () |
Accessor to GattServer. More... | |
const ble::GattServer & | gattServer () const |
A const alternative to gattServer(). More... | |
ble::GattClient & | gattClient () |
Accessors to GattClient. More... | |
const ble::GattClient & | gattClient () const |
A const alternative to gattClient(). More... | |
ble::SecurityManager & | securityManager () |
Accessors to SecurityManager. More... | |
const ble::SecurityManager & | securityManager () const |
A const alternative to securityManager(). More... | |
void | signalEventsToProcess () |
This function allows the BLE stack to signal that there is work to do and event processing should be done (BLE::processEvent()). More... | |
Static Public Member Functions | |
static BLE & | Instance () |
Get a reference to the BLE singleton. More... | |
static BLE & | Instance (InstanceID_t id) |
Get a reference to the BLE singleton corresponding to a given interface. More... | |
static const char * | errorToString (ble_error_t error) |
Translate error code into a printable string. More... | |
Static Public Attributes | |
static const InstanceID_t | DEFAULT_INSTANCE = 0 |
The value of the BLE::InstanceID_t for the default BLE instance. More... | |
static const InstanceID_t | NUM_INSTANCES = 1 |
The number of permitted BLE instances for the application. More... | |
Abstract away BLE-capable radio transceivers or SOCs.
Instances of this class have three responsibilities:
The user should not create BLE instances directly but rather access to the singleton(s) holding the BLE interfaces present in the system by using the static function Instance().
Next, the signal handling/process mechanism should be set up. By design, Mbed BLE does not impose to the user an event handling/processing mechanism; however, it exposes APIs, which allows an application to compose its own:
It is common to bind BLE event mechanism with Mbed EventQueue:
Once the event processing mechanism is in place, the Bluetooth subsystem can be initialized with the init() function. That function accepts in input a callback, which will be invoked once the initialization process has finished.