17 #ifndef MBED_GATT_SERVER_H__ 18 #define MBED_GATT_SERVER_H__ 20 #include "ble/common/StaticInterface.h" 21 #include "ble/GattService.h" 22 #include "ble/GattAttribute.h" 23 #include "ble/GattServerEvents.h" 24 #include "ble/GattCallbackParamTypes.h" 25 #include "ble/CallChainOfFunctionPointersWithContext.h" 26 #include "BleImplementationForward.h" 28 #if !defined(DOXYGEN_ONLY) 94 #if !defined(DOXYGEN_ONLY) 96 class GattServer :
public StaticInterface<Impl, GattServer> {
133 eventHandler = handler;
311 const uint8_t *value,
313 bool localOnly =
false 340 const uint8_t *value,
342 bool localOnly =
false 389 bool isOnDataReadAvailable()
const;
406 dataSentCallChain.add(callback);
418 template <
typename T>
419 void onDataSent(T *objPtr,
void (T::*memberPtr)(
unsigned count))
421 dataSentCallChain.add(objPtr, memberPtr);
431 return dataSentCallChain;
445 dataWrittenCallChain.add(callback);
457 template <
typename T>
462 dataWrittenCallChain.add(objPtr, memberPtr);
478 return dataWrittenCallChain;
501 if (!isOnDataReadAvailable()) {
505 dataReadCallChain.add(callback);
517 template <
typename T>
522 if (!isOnDataReadAvailable()) {
526 dataReadCallChain.add(objPtr, memberPtr);
543 return dataReadCallChain;
561 shutdownCallChain.add(callback);
575 template <
typename T>
578 shutdownCallChain.add(objPtr, memberPtr);
594 return shutdownCallChain;
629 confirmationReceivedCallback =
callback;
646 dataWrittenCallChain.call(params);
661 dataReadCallChain.call(params);
682 if (updatesEnabledCallback) {
683 updatesEnabledCallback(attributeHandle);
687 if (updatesDisabledCallback) {
688 updatesDisabledCallback(attributeHandle);
692 if (confirmationReceivedCallback) {
693 confirmationReceivedCallback(attributeHandle);
699 handleDataSentEvent(1);
718 dataSentCallChain.call(count);
759 const uint8_t *value,
767 const uint8_t *value,
783 bool isOnDataReadAvailable_()
const;
829 EventCallback_t updatesEnabledCallback;
834 EventCallback_t updatesDisabledCallback;
839 EventCallback_t confirmationReceivedCallback;
853 #if !defined(DOXYGEN_ONLY) ble_error_t onDataRead(T *objPtr, void(T::*memberPtr)(const GattReadCallbackParams *context))
Set an event handler that monitors attribute reads from connected clients.
uint8_t serviceCount
The total number of services added to the ATT table.
Definition of the general handler of GattServer related events.
FunctionPointerWithContext< const GattServer * > GattServerShutdownCallback_t
Event handler invoked when the GattServer is reset.
void handleDataWrittenEvent(const GattWriteCallbackParams *params)
Helper function that notifies all registered handlers of an occurrence of a data written event...
void handleDataSentEvent(unsigned count)
Helper function that notifies all registered handlers of an occurrence of a data sent event...
uintptr_t connection_handle_t
Opaque reference to a connection.
GattServerShutdownCallbackChain_t & onShutdown()
Access the callchain of shutdown event handlers.
void setEventHandler(EventHandler *handler)
Assign the event handler implementation that will be used by the module to signal events back to the ...
CallChainOfFunctionPointersWithContext< const GattWriteCallbackParams * > DataWrittenCallbackChain_t
Callchain of DataWrittenCallback_t objects.
DataWrittenCallbackChain_t & onDataWritten()
Access the callchain of data written event handlers.
void onShutdown(const GattServerShutdownCallback_t &callback)
Set an event handler that monitors shutdown or reset of the GattServer.
ble_error_t onDataRead(const DataReadCallback_t &callback)
Set an event handler that monitors attribute reads from connected clients.
void onDataWritten(T *objPtr, void(T::*memberPtr)(const GattWriteCallbackParams *context))
Set an event handler that is called after a connected peer has written an attribute.
virtual void onAttMtuChange(ble::connection_handle_t connectionHandle, uint16_t attMtuSize)
Function invoked when the connections changes the ATT_MTU which controls the maximum size of an attri...
CallChainOfFunctionPointersWithContext< unsigned > DataSentCallbackChain_t
Callchain of DataSentCallback_t objects.
DataSentCallbackChain_t & onDataSent()
Access the callchain of data sent event handlers.
void handleEvent(GattServerEvents::gattEvent_e type, GattAttribute::Handle_t attributeHandle)
Helper function that notifies the registered handler of an occurrence of updates enabled, updates disabled or confirmation received events.
void onDataSent(const DataSentCallback_t &callback)
Add an event handler that monitors emission of characteristic value updates.
gattEvent_e
Enumeration of events, which a GattServer implementation can generate.
ble::attribute_handle_t Handle_t
Representation of an attribute handle.
FunctionPointerWithContext< unsigned > DataSentCallback_t
Event handler invoked when the server has sent data to a client.
Notification or indication enabled in CCCD.
Construct and operates a GATT server.
GATT Write event definition.
CallChainOfFunctionPointersWithContext< const GattServer * > GattServerShutdownCallbackChain_t
Callchain of GattServerShutdownCallback_t.
GATT Read event definition.
Representation of a GattServer characteristic.
Fired when a server event was successfully sent.
void onShutdown(T *objPtr, void(T::*memberPtr)(const GattServer *))
Set an event handler that monitors shutdown or reset of the GattServer.
EventHandler * eventHandler
Event handler provided by the application.
FunctionPointerWithContext< const GattWriteCallbackParams * > DataWrittenCallback_t
Event handler invoked when the client has written an attribute of the server.
void handleDataReadEvent(const GattReadCallbackParams *params)
Helper function that notifies all registered handlers of an occurrence of a data read event...
DataReadCallbackChain_t & onDataRead()
Access the callchain of data read event handlers.
void onConfirmationReceived(EventCallback_t callback)
Set up an event handler that monitors notification acknowledgment.
Representation of a GattServer service.
void onUpdatesEnabled(EventCallback_t callback)
Set up an event handler that monitors subscription to characteristic updates.
Requested a feature that isn't yet implemented or isn't supported by the target HW.
FunctionPointerWithContext< GattAttribute::Handle_t > EventCallback_t
Event handler that handles subscription to characteristic updates, unsubscription from characteristic...
void onUpdatesDisabled(EventCallback_t callback)
Set up an event handler that monitors unsubscription from characteristic updates. ...
void onDataWritten(const DataWrittenCallback_t &callback)
Set an event handler that is called after a connected peer has written an attribute.
FunctionPointerWithContext< const GattReadCallbackParams * > DataReadCallback_t
Event handler invoked when the client has read an attribute of the server.
Notification or Indication disabled in CCCD.
Entry namespace for all BLE API definitions.
Response received from Characteristic Value Indication message.
CallChainOfFunctionPointersWithContext< const GattReadCallbackParams * > DataReadCallbackChain_t
Callchain of DataReadCallback_t.
void onDataSent(T *objPtr, void(T::*memberPtr)(unsigned count))
Add an event handler that monitors emission of characteristic value updates.
uint8_t characteristicCount
The total number of characteristics added to the ATT table.
ble_error_t
Error codes for the BLE API.