BLE: Prevent code generation from GattClient when not used.

pull/13811/head
Vincent Coubard 2020-10-23 10:37:28 +01:00
parent 8ef0a435b2
commit 26300912d3
3 changed files with 17 additions and 2 deletions

View File

@ -304,12 +304,14 @@ ble_error_t PalAttClient::terminate()
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#if BLE_FEATURE_GATT_CLIENT
// singleton of the ARM Cordio client // singleton of the ARM Cordio client
PalAttClient &PalAttClient::get_client() PalAttClient &PalAttClient::get_client()
{ {
static PalAttClient _client; static PalAttClient _client;
return _client; return _client;
} }
#endif
void PalAttClient::when_server_message_received( void PalAttClient::when_server_message_received(
mbed::Callback<void(connection_handle_t, const AttServerMessage &)> cb mbed::Callback<void(connection_handle_t, const AttServerMessage &)> cb
@ -345,12 +347,17 @@ bool PalAttClient::event_handler(const attEvt_t *event)
bool PalAttClient::timeout_event_handler(const attEvt_t *event) bool PalAttClient::timeout_event_handler(const attEvt_t *event)
{ {
#if BLE_FEATURE_GATT_CLIENT
if (event->hdr.status != ATT_ERR_TIMEOUT) { if (event->hdr.status != ATT_ERR_TIMEOUT) {
return false; return false;
} }
get_client().on_transaction_timeout(event->hdr.param); get_client().on_transaction_timeout(event->hdr.param);
return true; return true;
#else
return false;
#endif
} }
@ -359,10 +366,12 @@ void PalAttClient::generated_handler(
const attEvt_t *event, ResultType (*convert)(const attEvt_t *) const attEvt_t *event, ResultType (*convert)(const attEvt_t *)
) )
{ {
#if BLE_FEATURE_GATT_CLIENT
get_client().on_server_event( get_client().on_server_event(
event->hdr.param, event->hdr.param,
convert(event) convert(event)
); );
#endif
} }
void PalAttClient::on_server_event( void PalAttClient::on_server_event(
@ -392,9 +401,9 @@ void PalAttClient::on_transaction_timeout(
} }
} }
#if BLE_FEATURE_GATT_CLIENT
void PalAttClient::att_client_handler(const attEvt_t *event) void PalAttClient::att_client_handler(const attEvt_t *event)
{ {
#if BLE_FEATURE_GATT_CLIENT
if (event->hdr.status == ATT_SUCCESS && event->hdr.event == ATT_MTU_UPDATE_IND) { if (event->hdr.status == ATT_SUCCESS && event->hdr.event == ATT_MTU_UPDATE_IND) {
ble::impl::BLEInstanceBase &ble = BLEInstanceBase::deviceInstance(); ble::impl::BLEInstanceBase &ble = BLEInstanceBase::deviceInstance();
PalGattClientEventHandler *handler = ble.getPalGattClient().get_event_handler(); PalGattClientEventHandler *handler = ble.getPalGattClient().get_event_handler();
@ -444,13 +453,13 @@ void PalAttClient::att_client_handler(const attEvt_t *event)
} }
} }
} }
#endif // BLE_FEATURE_GATT_CLIENT
#if BLE_FEATURE_GATT_SERVER #if BLE_FEATURE_GATT_SERVER
// pass events not handled to the server side // pass events not handled to the server side
ble::impl::GattServer::att_cb(event); ble::impl::GattServer::att_cb(event);
#endif // BLE_FEATURE_GATT_SERVER #endif // BLE_FEATURE_GATT_SERVER
} }
#endif // BLE_FEATURE_GATT_CLIENT
} // namespace impl } // namespace impl
} // ble } // ble

View File

@ -173,8 +173,10 @@ public:
*/ */
ble_error_t terminate() final; ble_error_t terminate() final;
#if BLE_FEATURE_GATT_CLIENT
// singleton of the ARM Cordio client // singleton of the ARM Cordio client
static PalAttClient &get_client(); static PalAttClient &get_client();
#endif
void when_server_message_received( void when_server_message_received(
mbed::Callback<void(connection_handle_t, const AttServerMessage &)> cb mbed::Callback<void(connection_handle_t, const AttServerMessage &)> cb
@ -199,7 +201,9 @@ public:
/** /**
* Callback which handle attEvt_t and forward them to on_server_event. * Callback which handle attEvt_t and forward them to on_server_event.
*/ */
#if BLE_FEATURE_GATT_CLIENT
static void att_client_handler(const attEvt_t *event); static void att_client_handler(const attEvt_t *event);
#endif
private: private:
/** /**

View File

@ -282,8 +282,10 @@ ble_error_t PalSecurityManager::set_csrk(
{ {
_csrk = csrk; _csrk = csrk;
DmSecSetLocalCsrk(_csrk.data()); DmSecSetLocalCsrk(_csrk.data());
#if BLE_FEATURE_GATT_CLIENT
// extra set the sign counter used by the client // extra set the sign counter used by the client
impl::PalAttClient::get_client().set_sign_counter(sign_counter); impl::PalAttClient::get_client().set_sign_counter(sign_counter);
#endif
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }