From f399f7fbd7500ce38dbdebe25ff374624fc71cef Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Tue, 5 Jan 2021 16:38:44 +0100 Subject: [PATCH] hid_host: provide memory pool for hid_host_connection_t --- src/btstack_memory.c | 50 ++++++++++++++++++++++++++++++++ src/btstack_memory.h | 17 +++++++---- tool/btstack_memory_generator.py | 14 +++++---- 3 files changed, 69 insertions(+), 12 deletions(-) diff --git a/src/btstack_memory.c b/src/btstack_memory.c index bd5bab909..9c727b3b1 100644 --- a/src/btstack_memory.c +++ b/src/btstack_memory.c @@ -687,6 +687,53 @@ void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){ +// MARK: hid_host_connection_t +#if !defined(HAVE_MALLOC) && !defined(MAX_NR_HID_HOST_CONNECTIONS) + #if defined(MAX_NO_HID_HOST_CONNECTIONS) + #error "Deprecated MAX_NO_HID_HOST_CONNECTIONS defined instead of MAX_NR_HID_HOST_CONNECTIONS. Please update your btstack_config.h to use MAX_NR_HID_HOST_CONNECTIONS." + #else + #define MAX_NR_HID_HOST_CONNECTIONS 0 + #endif +#endif + +#ifdef MAX_NR_HID_HOST_CONNECTIONS +#if MAX_NR_HID_HOST_CONNECTIONS > 0 +static hid_host_connection_t hid_host_connection_storage[MAX_NR_HID_HOST_CONNECTIONS]; +static btstack_memory_pool_t hid_host_connection_pool; +hid_host_connection_t * btstack_memory_hid_host_connection_get(void){ + void * buffer = btstack_memory_pool_get(&hid_host_connection_pool); + if (buffer){ + memset(buffer, 0, sizeof(hid_host_connection_t)); + } + return (hid_host_connection_t *) buffer; +} +void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){ + btstack_memory_pool_free(&hid_host_connection_pool, hid_host_connection); +} +#else +hid_host_connection_t * btstack_memory_hid_host_connection_get(void){ + return NULL; +} +void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){ + // silence compiler warning about unused parameter in a portable way + (void) hid_host_connection; +}; +#endif +#elif defined(HAVE_MALLOC) +hid_host_connection_t * btstack_memory_hid_host_connection_get(void){ + void * buffer = malloc(sizeof(hid_host_connection_t)); + if (buffer){ + memset(buffer, 0, sizeof(hid_host_connection_t)); + } + return (hid_host_connection_t *) buffer; +} +void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection){ + free(hid_host_connection); +} +#endif + + + // MARK: service_record_item_t #if !defined(HAVE_MALLOC) && !defined(MAX_NR_SERVICE_RECORD_ITEMS) #if defined(MAX_NO_SERVICE_RECORD_ITEMS) @@ -1592,6 +1639,9 @@ void btstack_memory_init(void){ #if MAX_NR_HFP_CONNECTIONS > 0 btstack_memory_pool_create(&hfp_connection_pool, hfp_connection_storage, MAX_NR_HFP_CONNECTIONS, sizeof(hfp_connection_t)); #endif +#if MAX_NR_HID_HOST_CONNECTIONS > 0 + btstack_memory_pool_create(&hid_host_connection_pool, hid_host_connection_storage, MAX_NR_HID_HOST_CONNECTIONS, sizeof(hid_host_connection_t)); +#endif #if MAX_NR_SERVICE_RECORD_ITEMS > 0 btstack_memory_pool_create(&service_record_item_pool, service_record_item_storage, MAX_NR_SERVICE_RECORD_ITEMS, sizeof(service_record_item_t)); #endif diff --git a/src/btstack_memory.h b/src/btstack_memory.h index 4b2922776..063aa5d14 100644 --- a/src/btstack_memory.h +++ b/src/btstack_memory.h @@ -58,15 +58,16 @@ extern "C" { #include "l2cap.h" // Classic -#include "classic/bnep.h" -#include "classic/hfp.h" -#include "classic/btstack_link_key_db.h" -#include "classic/btstack_link_key_db_memory.h" -#include "classic/rfcomm.h" -#include "classic/sdp_server.h" #include "classic/avdtp_sink.h" #include "classic/avdtp_source.h" #include "classic/avrcp.h" +#include "classic/bnep.h" +#include "classic/btstack_link_key_db.h" +#include "classic/btstack_link_key_db_memory.h" +#include "classic/hfp.h" +#include "classic/hid_host.h" +#include "classic/rfcomm.h" +#include "classic/sdp_server.h" // BLE #ifdef ENABLE_BLE @@ -128,6 +129,10 @@ void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel); hfp_connection_t * btstack_memory_hfp_connection_get(void); void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection); +// hid_host_connection +hid_host_connection_t * btstack_memory_hid_host_connection_get(void); +void btstack_memory_hid_host_connection_free(hid_host_connection_t *hid_host_connection); + // service_record_item service_record_item_t * btstack_memory_service_record_item_get(void); void btstack_memory_service_record_item_free(service_record_item_t *service_record_item); diff --git a/tool/btstack_memory_generator.py b/tool/btstack_memory_generator.py index 27f54a2d9..c2b291c1b 100755 --- a/tool/btstack_memory_generator.py +++ b/tool/btstack_memory_generator.py @@ -66,15 +66,16 @@ extern "C" { #include "l2cap.h" // Classic -#include "classic/bnep.h" -#include "classic/hfp.h" -#include "classic/btstack_link_key_db.h" -#include "classic/btstack_link_key_db_memory.h" -#include "classic/rfcomm.h" -#include "classic/sdp_server.h" #include "classic/avdtp_sink.h" #include "classic/avdtp_source.h" #include "classic/avrcp.h" +#include "classic/bnep.h" +#include "classic/btstack_link_key_db.h" +#include "classic/btstack_link_key_db_memory.h" +#include "classic/hfp.h" +#include "classic/hid_host.h" +#include "classic/rfcomm.h" +#include "classic/sdp_server.h" // BLE #ifdef ENABLE_BLE @@ -283,6 +284,7 @@ list_of_classic_structs = [ ["btstack_link_key_db_memory_entry"], ["bnep_service", "bnep_channel"], ["hfp_connection"], + ["hid_host_connection"], ["service_record_item"], ["avdtp_stream_endpoint"], ["avdtp_connection"],