diff --git a/features/FEATURE_BLE/ble/pal/PalGattClient.h b/features/FEATURE_BLE/ble/pal/PalGattClient.h index d0362240e5..da798e4f5f 100644 --- a/features/FEATURE_BLE/ble/pal/PalGattClient.h +++ b/features/FEATURE_BLE/ble/pal/PalGattClient.h @@ -601,8 +601,27 @@ public: _transaction_timeout_cb = cb; } + /** + * Sets the event handler that us called by the PAL porters to notify the stack of events + * which will in turn be passed onto the user application when appropriate. + * + * @param event_handler The new event handler interface implementation. + */ + void set_event_handler(EventHandler* event_handler) { + _event_handler = event_handler; + } + + /** + * Get the currently registered event handler. + * + * @return Currently registered event handler. NULL if no event handler is present. + */ + EventHandler* get_event_handler() { + return _event_handler; + } + protected: - GattClient() { } + GattClient() : _event_handler(NULL) { } virtual ~GattClient() { } @@ -640,6 +659,8 @@ protected: } private: + EventHandler* _event_handler; + /** * Callback called when the client receive a message from the server. */ diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h index a8083c3bbe..695114911d 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h @@ -107,6 +107,13 @@ public: */ virtual generic::GenericGattClient &getGattClient(); + /** + * Get the PAL Gatt Client. + * + * @return PAL Gatt Client. + */ + pal::AttClientToGattClientAdapter &BLE::getPalGattClient(); + /** * @see BLEInstanceBase::getSecurityManager */ diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp index 37b6373d43..35eb9122db 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp @@ -26,8 +26,10 @@ void CordioAttClient::att_client_handler(const attEvt_t* event) { if (event->hdr.status == ATT_SUCCESS && event->hdr.event == ATT_MTU_UPDATE_IND) { ble::vendor::cordio::BLE& ble = ble::vendor::cordio::BLE::deviceInstance(); - ble::pal::GattClient::EventHandler &handler = ble.getGattClient(); - handler.on_att_mtu_change(event->hdr.param, event->mtu); + ble::pal::GattClient::EventHandler *handler = ble.getPalGattClient().get_event_handler(); + if (handler) { + handler->on_att_mtu_change(event->hdr.param, event->mtu); + } } else { // all handlers are stored in a static array static const event_handler_t handlers[] = { diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp index 5cffdac74b..de6dd0bd82 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp @@ -199,13 +199,19 @@ const GattServer& BLE::getGattServer() const } generic::GenericGattClient& BLE::getGattClient() +{ + static generic::GenericGattClient gatt_client(&getPalGattClient()); + + return gatt_client; +} + +pal::AttClientToGattClientAdapter& BLE::getPalGattClient() { static pal::AttClientToGattClientAdapter pal_client( pal::vendor::cordio::CordioAttClient::get_client() ); - static generic::GenericGattClient client(&pal_client); - return client; + return pal_client; } SecurityManager& BLE::getSecurityManager()