Skip to content

[BLE] Update parameters passed to onDataSent, onUpdatesEnabled/Disabled, and onConfirmationReceived callbacks #13727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions connectivity/FEATURE_BLE/include/ble/GattServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ifndef MBED_GATT_SERVER_H__
#define MBED_GATT_SERVER_H__

#include "platform/mbed_toolchain.h"

#include "ble/common/CallChainOfFunctionPointersWithContext.h"
#include "ble/common/blecommon.h"

Expand Down Expand Up @@ -118,6 +120,84 @@ class GattServer {
(void)connectionHandle;
(void)attMtuSize;
}

/**
* Function invoked when the server has sent data to a client as
* part of a notification/indication.
*
* @note params has a temporary scope and should be copied by the
* application if needed later
*/
virtual void onDataSent(const GattDataSentCallbackParams &params) {
(void)params;
}

/**
* Function invoked when a client writes an attribute
*
* @note params has a temporary scope and should be copied by the
* application if needed later
*/
virtual void onDataWritten(const GattWriteCallbackParams &params) {
(void)params;
}

/**
* Function invoked when a client reads an attribute
*
* @note This functionality may not be available on all underlying stacks.
* Application code may work around that limitation by monitoring read
* requests instead of read events.
*
* @note params has a temporary scope and should be copied by the
* application if needed later
*
* @see GattCharacteristic::setReadAuthorizationCallback()
* @see isOnDataReadAvailable().
*/
virtual void onDataRead(const GattReadCallbackParams &params) {
(void)params;
}

/**
* Function invoked when the GattServer instance is about
* to be shut down. This can result in a call to reset() or BLE::reset().
*/
virtual void onShutdown(const GattServer &server) {
(void)server;
}

/**
* Function invoked when the client has subscribed to characteristic updates
*
* @note params has a temporary scope and should be copied by the
* application if needed later
*/
virtual void onUpdatesEnabled(const GattUpdatesEnabledCallbackParams &params) {
(void)params;
}

/**
* Function invoked when the client has unsubscribed to characteristic updates
*
* @note params has a temporary scope and should be copied by the
* application if needed later
*/
virtual void onUpdatesDisabled(const GattUpdatesDisabledCallbackParams &params) {
(void)params;
}

/**
* Function invoked when an ACK has been received for an
* indication sent to the client.
*
* @note params has a temporary scope and should be copied by the
* application if needed later
*/
virtual void onConfirmationReceived(const GattConfirmationReceivedCallbackParams &params) {
(void)params;
}

protected:
/**
* Prevent polymorphic deletion and avoid unnecessary virtual destructor
Expand Down Expand Up @@ -401,6 +481,8 @@ class GattServer {
* @note It is possible to chain together multiple onDataSent callbacks
* (potentially from different modules of an application).
*/
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
void onDataSent(const DataSentCallback_t &callback);

/**
Expand All @@ -413,6 +495,8 @@ class GattServer {
* function.
*/
template <typename T>
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
void onDataSent(T *objPtr, void (T::*memberPtr)(unsigned count))
{
onDataSent({objPtr, memberPtr});
Expand All @@ -423,6 +507,8 @@ class GattServer {
*
* @return A reference to the DATA_SENT event callback chain.
*/
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
DataSentCallbackChain_t &onDataSent();

/**
Expand All @@ -434,6 +520,8 @@ class GattServer {
* @attention It is possible to set multiple event handlers. Registered
* handlers may be removed with onDataWritten().detach(callback).
*/
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
void onDataWritten(const DataWrittenCallback_t &callback);

/**
Expand All @@ -446,6 +534,8 @@ class GattServer {
* function.
*/
template <typename T>
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
void onDataWritten(
T *objPtr,
void (T::*memberPtr)(const GattWriteCallbackParams *context)
Expand All @@ -465,6 +555,8 @@ class GattServer {
* @note It is possible to unregister callbacks using
* onDataWritten().detach(callback).
*/
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
DataWrittenCallbackChain_t &onDataWritten();

/**
Expand All @@ -485,6 +577,8 @@ class GattServer {
* @attention It is possible to set multiple event handlers. Registered
* handlers may be removed with onDataRead().detach(callback).
*/
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
ble_error_t onDataRead(const DataReadCallback_t &callback);

/**
Expand All @@ -496,6 +590,8 @@ class GattServer {
* function.
*/
template <typename T>
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
ble_error_t onDataRead(
T *objPtr,
void (T::*memberPtr)(const GattReadCallbackParams *context)
Expand All @@ -515,6 +611,8 @@ class GattServer {
* @note It is possible to unregister callbacks using
* onDataRead().detach(callback).
*/
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
DataReadCallbackChain_t &onDataRead();

/**
Expand All @@ -530,6 +628,8 @@ class GattServer {
* @note It is possible to unregister a callback using
* onShutdown().detach(callback)
*/
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
void onShutdown(const GattServerShutdownCallback_t &callback);

/**
Expand All @@ -544,6 +644,8 @@ class GattServer {
* function.
*/
template <typename T>
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
void onShutdown(T *objPtr, void (T::*memberPtr)(const GattServer *))
{
onShutdown({objPtr, memberPtr});
Expand All @@ -560,6 +662,8 @@ class GattServer {
* @note It is possible to unregister callbacks using
* onShutdown().detach(callback).
*/
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
GattServerShutdownCallbackChain_t& onShutdown();

/**
Expand All @@ -568,6 +672,8 @@ class GattServer {
*
* @param[in] callback Event handler being registered.
*/
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
void onUpdatesEnabled(EventCallback_t callback);

/**
Expand All @@ -576,6 +682,8 @@ class GattServer {
*
* @param[in] callback Event handler being registered.
*/
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
void onUpdatesDisabled(EventCallback_t callback);

/**
Expand All @@ -586,6 +694,8 @@ class GattServer {
*
* @param[in] callback Event handler being registered.
*/
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
"been replaced by GattServer::setEventHandler. Use that function instead.")
void onConfirmationReceived(EventCallback_t callback);

#if !defined(DOXYGEN_ONLY)
Expand Down
23 changes: 23 additions & 0 deletions connectivity/FEATURE_BLE/include/ble/gatt/GattCallbackParamTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,29 @@ struct GattHVXCallbackParams {

};

/**
* Gatt Data Sent Attribute related events
*
* Used by `onDataSent`
*/
struct GattDataSentCallbackParams {

/**
* The handle of the connection that triggered the event.
*/
ble::connection_handle_t connHandle;

/**
* Attribute Handle to which the event applies
*/
GattAttribute::Handle_t attHandle;

};

using GattUpdatesEnabledCallbackParams = GattDataSentCallbackParams;
using GattUpdatesDisabledCallbackParams = GattDataSentCallbackParams;
using GattConfirmationReceivedCallbackParams = GattDataSentCallbackParams;

namespace ble {

/**
Expand Down
8 changes: 4 additions & 4 deletions connectivity/FEATURE_BLE/source/GattServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,17 @@ GattServer::GattServerShutdownCallbackChain_t& GattServer::onShutdown()

void GattServer::onUpdatesEnabled(EventCallback_t callback)
{
return impl->onUpdatesEnabled(callback);
impl->onUpdatesEnabled(callback);
}

void GattServer::onUpdatesDisabled(EventCallback_t callback)
{
return impl->onUpdatesDisabled(callback);
impl->onUpdatesDisabled(callback);
}

void GattServer::onConfirmationReceived(EventCallback_t callback)
{
return impl->onConfirmationReceived(callback);
impl->onConfirmationReceived(callback);
}

} // ble
} // ble
Loading