Skip to content

Commit 03b747a

Browse files
Get the pal event handler from pal gattclient
1 parent b628285 commit 03b747a

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

features/FEATURE_BLE/ble/pal/PalGattClient.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,27 @@ class GattClient {
601601
_transaction_timeout_cb = cb;
602602
}
603603

604+
/**
605+
* Sets the event handler that us called by the PAL porters to notify the stack of events
606+
* which will in turn be passed onto the user application when appropriate.
607+
*
608+
* @param event_handler The new event handler interface implementation.
609+
*/
610+
void set_event_handler(EventHandler* event_handler) {
611+
_event_handler = event_handler;
612+
}
613+
614+
/**
615+
* Get the currently registered event handler.
616+
*
617+
* @return Currently registered event handler. NULL if no event handler is present.
618+
*/
619+
EventHandler* get_event_handler() {
620+
return _event_handler;
621+
}
622+
604623
protected:
605-
GattClient() { }
624+
GattClient() : _event_handler(NULL) { }
606625

607626
virtual ~GattClient() { }
608627

@@ -640,6 +659,8 @@ class GattClient {
640659
}
641660

642661
private:
662+
EventHandler* _event_handler;
663+
643664
/**
644665
* Callback called when the client receive a message from the server.
645666
*/

features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ class BLE : public ::BLEInstanceBase {
107107
*/
108108
virtual generic::GenericGattClient &getGattClient();
109109

110+
/**
111+
* Get the PAL Gatt Client.
112+
*
113+
* @return PAL Gatt Client.
114+
*/
115+
pal::AttClientToGattClientAdapter &BLE::getPalGattClient();
116+
110117
/**
111118
* @see BLEInstanceBase::getSecurityManager
112119
*/

features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ void CordioAttClient::att_client_handler(const attEvt_t* event)
2626
{
2727
if (event->hdr.status == ATT_SUCCESS && event->hdr.event == ATT_MTU_UPDATE_IND) {
2828
ble::vendor::cordio::BLE& ble = ble::vendor::cordio::BLE::deviceInstance();
29-
ble::pal::GattClient::EventHandler &handler = ble.getGattClient();
30-
handler.on_att_mtu_change(event->hdr.param, event->mtu);
29+
ble::pal::GattClient::EventHandler *handler = ble.getPalGattClient().get_event_handler();
30+
if (handler) {
31+
handler->on_att_mtu_change(event->hdr.param, event->mtu);
32+
}
3133
} else {
3234
// all handlers are stored in a static array
3335
static const event_handler_t handlers[] = {

features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,19 @@ const GattServer& BLE::getGattServer() const
199199
}
200200

201201
generic::GenericGattClient& BLE::getGattClient()
202+
{
203+
static generic::GenericGattClient gatt_client(&getPalGattClient());
204+
205+
return gatt_client;
206+
}
207+
208+
pal::AttClientToGattClientAdapter& BLE::getPalGattClient()
202209
{
203210
static pal::AttClientToGattClientAdapter pal_client(
204211
pal::vendor::cordio::CordioAttClient::get_client()
205212
);
206-
static generic::GenericGattClient client(&pal_client);
207213

208-
return client;
214+
return pal_client;
209215
}
210216

211217
SecurityManager& BLE::getSecurityManager()

0 commit comments

Comments
 (0)