diff --git a/src/btstack_memory.c b/src/btstack_memory.c index 3f34a6da1..65f2920bb 100644 --- a/src/btstack_memory.c +++ b/src/btstack_memory.c @@ -322,6 +322,36 @@ void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){ #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_SERVICES for struct db_mem_service is defined. Please, edit the config file." #endif +// MARK: gatt_client_t +#ifdef HAVE_BLE +#ifdef MAX_NO_GATT_CLIENTS +#if MAX_NO_GATT_CLIENTS > 0 +static gatt_client_t gatt_client_storage[MAX_NO_GATT_CLIENTS]; +static memory_pool_t gatt_client_pool; +gatt_client_t * btstack_memory_gatt_client_get(void){ + return memory_pool_get(&gatt_client_pool); +} +void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ + memory_pool_free(&gatt_client_pool, gatt_client); +} +#else +gatt_client_t * btstack_memory_gatt_client_get(void){ + return NULL; +} +void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ +}; +#endif +#elif defined(HAVE_MALLOC) +gatt_client_t * btstack_memory_gatt_client_get(void){ + return (gatt_client_t*) malloc(sizeof(gatt_client_t)); +} +void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ + free(gatt_client); +} +#else +#error "Neither HAVE_MALLOC nor MAX_NO_GATT_CLIENTS for struct gatt_client is defined. Please, edit the config file." +#endif +#endif // init void btstack_memory_init(void){ #if MAX_NO_HCI_CONNECTIONS > 0 @@ -351,5 +381,8 @@ void btstack_memory_init(void){ #if MAX_NO_DB_MEM_SERVICES > 0 memory_pool_create(&db_mem_service_pool, db_mem_service_storage, MAX_NO_DB_MEM_SERVICES, sizeof(db_mem_service_t)); #endif +#if MAX_NO_GATT_CLIENTS > 0 + memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NO_GATT_CLIENTS, sizeof(gatt_client_t)); +#endif } diff --git a/src/btstack_memory.h b/src/btstack_memory.h index c23e0b489..85bd1c26e 100644 --- a/src/btstack_memory.h +++ b/src/btstack_memory.h @@ -47,13 +47,19 @@ #if defined __cplusplus extern "C" { #endif + +#include "btstack-config.h" #include "hci.h" #include "l2cap.h" #include "rfcomm.h" #include "rfcomm.h" #include "remote_device_db.h" - + +#ifdef HAVE_BLE +#include "gatt_client.h" +#endif + void btstack_memory_init(void); hci_connection_t * btstack_memory_hci_connection_get(void); @@ -75,6 +81,11 @@ void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_m db_mem_service_t * btstack_memory_db_mem_service_get(void); void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service); +#ifdef HAVE_BLE +gatt_client_t * btstack_memory_gatt_client_get(void); +void btstack_memory_gatt_client_free(gatt_client_t *gatt_client); +#endif + #if defined __cplusplus } #endif diff --git a/tools/btstack_memory_generator.py b/tools/btstack_memory_generator.py index 2e7969e61..246ad9e89 100755 --- a/tools/btstack_memory_generator.py +++ b/tools/btstack_memory_generator.py @@ -45,7 +45,7 @@ def replacePlaceholder(template, struct_name): snippet = template.replace("STRUCT_TYPE", struct_type).replace("STRUCT_NAME", struct_name).replace("POOL_COUNT", pool_count) return snippet -list_of_structs = [ "hci_connection", "l2cap_service", "l2cap_channel", "rfcomm_multiplexer", "rfcomm_service", "rfcomm_channel", "db_mem_device_name", "db_mem_device_link_key", "db_mem_service"] +list_of_structs = [ "hci_connection", "l2cap_service", "l2cap_channel", "rfcomm_multiplexer", "rfcomm_service", "rfcomm_channel", "db_mem_device_name", "db_mem_device_link_key", "db_mem_service", "gatt_client"] print "// header file" for struct_name in list_of_structs: