From fdb398c2d333d32dd9293f9d014bdb0811e3f5ae Mon Sep 17 00:00:00 2001 From: "ole.reinhardt@googlemail.com" Date: Wed, 8 Oct 2014 13:21:55 +0000 Subject: [PATCH] Added bnep memory structs --- src/btstack_memory.c | 60 +++++++++++++++++++++++++++++++ src/btstack_memory.h | 12 +++++-- tools/btstack_memory_generator.py | 4 +-- 3 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/btstack_memory.c b/src/btstack_memory.c index 08698a1ce..61b1fa83a 100644 --- a/src/btstack_memory.c +++ b/src/btstack_memory.c @@ -244,6 +244,65 @@ void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_CHANNELS for struct rfcomm_channel is defined. Please, edit the config file." #endif +// MARK: bnepservice_t +#ifdef MAX_NO_BNEP_SERVICES +#if MAX_NO_BNEP_SERVICES > 0 +static bnep_service_t bnep_service_storage[MAX_NO_BNEP_SERVICES]; +static memory_pool_t bnep_service_pool; +bnep_service_t * btstack_memory_bnep_service_get(void){ + return memory_pool_get(&bnep_service_pool); +} +void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ + memory_pool_free(&bnep_service_pool, bnep_service); +} +#else +bnep_service_t * btstack_memory_bnep_service_get(void){ + return NULL; +} +void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ +}; +#endif +#elif defined(HAVE_MALLOC) +bnep_service_t * btstack_memory_bnep_service_get(void){ + return (bnep_service_t*) malloc(sizeof(bnep_service_t)); +} +void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){ + free(bnep_service); +} +#else +#error "Neither HAVE_MALLOC nor MAX_NO_BNEP_SERVICES for struct bnep_service is defined. Please, edit the config file." +#endif + + +// MARK: bnep_channel_t +#ifdef MAX_NO_BNEP_CHANNELS +#if MAX_NO_BNEP_CHANNELS > 0 +static bnep_channel_t bnep_channel_storage[MAX_NO_BNEP_CHANNELS]; +static memory_pool_t bnep_channel_pool; +bnep_channel_t * btstack_memory_bnep_channel_get(void){ + return memory_pool_get(&bnep_channel_pool); +} +void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ + memory_pool_free(&bnep_channel_pool, bnep_channel); +} +#else +bnep_channel_t * btstack_memory_bnep_channel_get(void){ + return NULL; +} +void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ +}; +#endif +#elif defined(HAVE_MALLOC) +bnep_channel_t * btstack_memory_bnep_channel_get(void){ + return (bnep_channel_t*) malloc(sizeof(bnep_channel_t)); +} +void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){ + free(bnep_channel); +} +#else +#error "Neither HAVE_MALLOC nor MAX_NO_BNEP_CHANNELS for struct bnep_channel is defined. Please, edit the config file." +#endif + // MARK: db_mem_device_name_t #ifdef MAX_NO_DB_MEM_DEVICE_NAMES @@ -372,6 +431,7 @@ void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ #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 diff --git a/src/btstack_memory.h b/src/btstack_memory.h index 85bd1c26e..b82fd338b 100644 --- a/src/btstack_memory.h +++ b/src/btstack_memory.h @@ -53,7 +53,7 @@ extern "C" { #include "hci.h" #include "l2cap.h" #include "rfcomm.h" -#include "rfcomm.h" +#include "bnep.h" #include "remote_device_db.h" #ifdef HAVE_BLE @@ -64,23 +64,31 @@ void btstack_memory_init(void); hci_connection_t * btstack_memory_hci_connection_get(void); void btstack_memory_hci_connection_free(hci_connection_t *hci_connection); + l2cap_service_t * btstack_memory_l2cap_service_get(void); void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service); l2cap_channel_t * btstack_memory_l2cap_channel_get(void); void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel); + rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void); void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer); rfcomm_service_t * btstack_memory_rfcomm_service_get(void); void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service); rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void); void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel); + +bnep_service_t * btstack_memory_bnep_service_get(void); +void btstack_memory_bnep_service_free(bnep_service_t *bnep_service); +bnep_channel_t * btstack_memory_bnep_channel_get(void); +void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel); + db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void); void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name); db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void); void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key); 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); diff --git a/tools/btstack_memory_generator.py b/tools/btstack_memory_generator.py index f8681b6ec..45116c386 100755 --- a/tools/btstack_memory_generator.py +++ b/tools/btstack_memory_generator.py @@ -47,7 +47,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", "gatt_client"] +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", "bnep_service", "bnep_channel"] print "// header file" for struct_name in list_of_structs: @@ -63,4 +63,4 @@ for struct_name in list_of_structs: print replacePlaceholder(init_template, struct_name) print "}" - \ No newline at end of file +