1a3b02b71Smatthias.ringwald /* 26b64433eSmatthias.ringwald * Copyright (C) 2009-2012 by Matthias Ringwald 3a3b02b71Smatthias.ringwald * 4a3b02b71Smatthias.ringwald * Redistribution and use in source and binary forms, with or without 5a3b02b71Smatthias.ringwald * modification, are permitted provided that the following conditions 6a3b02b71Smatthias.ringwald * are met: 7a3b02b71Smatthias.ringwald * 8a3b02b71Smatthias.ringwald * 1. Redistributions of source code must retain the above copyright 9a3b02b71Smatthias.ringwald * notice, this list of conditions and the following disclaimer. 10a3b02b71Smatthias.ringwald * 2. Redistributions in binary form must reproduce the above copyright 11a3b02b71Smatthias.ringwald * notice, this list of conditions and the following disclaimer in the 12a3b02b71Smatthias.ringwald * documentation and/or other materials provided with the distribution. 13a3b02b71Smatthias.ringwald * 3. Neither the name of the copyright holders nor the names of 14a3b02b71Smatthias.ringwald * contributors may be used to endorse or promote products derived 15a3b02b71Smatthias.ringwald * from this software without specific prior written permission. 166b64433eSmatthias.ringwald * 4. Any redistribution, use, or modification is done solely for 176b64433eSmatthias.ringwald * personal benefit and not for any commercial purpose or for 186b64433eSmatthias.ringwald * monetary gain. 19a3b02b71Smatthias.ringwald * 20a3b02b71Smatthias.ringwald * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS 21a3b02b71Smatthias.ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22a3b02b71Smatthias.ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23a3b02b71Smatthias.ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24a3b02b71Smatthias.ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25a3b02b71Smatthias.ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26a3b02b71Smatthias.ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27a3b02b71Smatthias.ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28a3b02b71Smatthias.ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29a3b02b71Smatthias.ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30a3b02b71Smatthias.ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31a3b02b71Smatthias.ringwald * SUCH DAMAGE. 32a3b02b71Smatthias.ringwald * 336b64433eSmatthias.ringwald * Please inquire about commercial licensing options at [email protected] 346b64433eSmatthias.ringwald * 35a3b02b71Smatthias.ringwald */ 36a3b02b71Smatthias.ringwald 37a3b02b71Smatthias.ringwald /* 38a3b02b71Smatthias.ringwald * btstsack_memory.h 39a3b02b71Smatthias.ringwald * 40a3b02b71Smatthias.ringwald * @brief BTstack memory management via configurable memory pools 41a3b02b71Smatthias.ringwald * 42e0e5e285Smatthias.ringwald * @note code semi-atuomatically generated by btstack_memory_generator.py 43a3b02b71Smatthias.ringwald * 44a3b02b71Smatthias.ringwald */ 45a3b02b71Smatthias.ringwald 46a3b02b71Smatthias.ringwald #include "btstack_memory.h" 47a3b02b71Smatthias.ringwald #include <btstack/memory_pool.h> 48a3b02b71Smatthias.ringwald 49a3b02b71Smatthias.ringwald #include <stdlib.h> 50a3b02b71Smatthias.ringwald 51bde315ceS[email protected] #include "btstack-config.h" 52a3b02b71Smatthias.ringwald #include "hci.h" 53a3b02b71Smatthias.ringwald #include "l2cap.h" 54a3b02b71Smatthias.ringwald #include "rfcomm.h" 55a3b02b71Smatthias.ringwald 56a3b02b71Smatthias.ringwald // MARK: hci_connection_t 57a3b02b71Smatthias.ringwald #ifdef MAX_NO_HCI_CONNECTIONS 58c4d3f927Smatthias.ringwald #if MAX_NO_HCI_CONNECTIONS > 0 59a3b02b71Smatthias.ringwald static hci_connection_t hci_connection_storage[MAX_NO_HCI_CONNECTIONS]; 60a3b02b71Smatthias.ringwald static memory_pool_t hci_connection_pool; 616527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 62a3b02b71Smatthias.ringwald return memory_pool_get(&hci_connection_pool); 63a3b02b71Smatthias.ringwald } 646527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 65a3b02b71Smatthias.ringwald memory_pool_free(&hci_connection_pool, hci_connection); 66a3b02b71Smatthias.ringwald } 67c4d3f927Smatthias.ringwald #else 686527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 69c4d3f927Smatthias.ringwald return NULL; 70c4d3f927Smatthias.ringwald } 716527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 72c4d3f927Smatthias.ringwald }; 73c4d3f927Smatthias.ringwald #endif 74a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 756527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 766527a633S[email protected] return (hci_connection_t*) malloc(sizeof(hci_connection_t)); 77a3b02b71Smatthias.ringwald } 786527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 79a3b02b71Smatthias.ringwald free(hci_connection); 80a3b02b71Smatthias.ringwald } 81e045abdeSmatthias.ringwald #else 826527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_HCI_CONNECTIONS for struct hci_connection is defined. Please, edit the config file." 83a3b02b71Smatthias.ringwald #endif 84a3b02b71Smatthias.ringwald 85a3b02b71Smatthias.ringwald 86a3b02b71Smatthias.ringwald // MARK: l2cap_service_t 87a3b02b71Smatthias.ringwald #ifdef MAX_NO_L2CAP_SERVICES 88c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_SERVICES > 0 89a3b02b71Smatthias.ringwald static l2cap_service_t l2cap_service_storage[MAX_NO_L2CAP_SERVICES]; 90a3b02b71Smatthias.ringwald static memory_pool_t l2cap_service_pool; 916527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 92a3b02b71Smatthias.ringwald return memory_pool_get(&l2cap_service_pool); 93a3b02b71Smatthias.ringwald } 946527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 95a3b02b71Smatthias.ringwald memory_pool_free(&l2cap_service_pool, l2cap_service); 96a3b02b71Smatthias.ringwald } 97c4d3f927Smatthias.ringwald #else 986527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 99c4d3f927Smatthias.ringwald return NULL; 100c4d3f927Smatthias.ringwald } 1016527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 102c4d3f927Smatthias.ringwald }; 103c4d3f927Smatthias.ringwald #endif 104a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 1056527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 1066527a633S[email protected] return (l2cap_service_t*) malloc(sizeof(l2cap_service_t)); 107a3b02b71Smatthias.ringwald } 1086527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 109a3b02b71Smatthias.ringwald free(l2cap_service); 110a3b02b71Smatthias.ringwald } 111e045abdeSmatthias.ringwald #else 1126527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_L2CAP_SERVICES for struct l2cap_service is defined. Please, edit the config file." 113a3b02b71Smatthias.ringwald #endif 114a3b02b71Smatthias.ringwald 115a3b02b71Smatthias.ringwald 116a3b02b71Smatthias.ringwald // MARK: l2cap_channel_t 117a3b02b71Smatthias.ringwald #ifdef MAX_NO_L2CAP_CHANNELS 118c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_CHANNELS > 0 119a3b02b71Smatthias.ringwald static l2cap_channel_t l2cap_channel_storage[MAX_NO_L2CAP_CHANNELS]; 120a3b02b71Smatthias.ringwald static memory_pool_t l2cap_channel_pool; 1216527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 122a3b02b71Smatthias.ringwald return memory_pool_get(&l2cap_channel_pool); 123a3b02b71Smatthias.ringwald } 1246527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 125a3b02b71Smatthias.ringwald memory_pool_free(&l2cap_channel_pool, l2cap_channel); 126a3b02b71Smatthias.ringwald } 127c4d3f927Smatthias.ringwald #else 1286527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 129c4d3f927Smatthias.ringwald return NULL; 130c4d3f927Smatthias.ringwald } 1316527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 132c4d3f927Smatthias.ringwald }; 133c4d3f927Smatthias.ringwald #endif 134a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 1356527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 1366527a633S[email protected] return (l2cap_channel_t*) malloc(sizeof(l2cap_channel_t)); 137a3b02b71Smatthias.ringwald } 1386527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 139a3b02b71Smatthias.ringwald free(l2cap_channel); 140a3b02b71Smatthias.ringwald } 141e045abdeSmatthias.ringwald #else 1426527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_L2CAP_CHANNELS for struct l2cap_channel is defined. Please, edit the config file." 143a3b02b71Smatthias.ringwald #endif 144a3b02b71Smatthias.ringwald 145a3b02b71Smatthias.ringwald 146a3b02b71Smatthias.ringwald // MARK: rfcomm_multiplexer_t 147a3b02b71Smatthias.ringwald #ifdef MAX_NO_RFCOMM_MULTIPLEXERS 148c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_MULTIPLEXERS > 0 149a3b02b71Smatthias.ringwald static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NO_RFCOMM_MULTIPLEXERS]; 150a3b02b71Smatthias.ringwald static memory_pool_t rfcomm_multiplexer_pool; 1516527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 152a3b02b71Smatthias.ringwald return memory_pool_get(&rfcomm_multiplexer_pool); 153a3b02b71Smatthias.ringwald } 1546527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 155a3b02b71Smatthias.ringwald memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer); 156a3b02b71Smatthias.ringwald } 157c4d3f927Smatthias.ringwald #else 1586527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 159c4d3f927Smatthias.ringwald return NULL; 160c4d3f927Smatthias.ringwald } 1616527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 162c4d3f927Smatthias.ringwald }; 163c4d3f927Smatthias.ringwald #endif 164a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 1656527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 1666527a633S[email protected] return (rfcomm_multiplexer_t*) malloc(sizeof(rfcomm_multiplexer_t)); 167a3b02b71Smatthias.ringwald } 1686527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 169a3b02b71Smatthias.ringwald free(rfcomm_multiplexer); 170a3b02b71Smatthias.ringwald } 171e045abdeSmatthias.ringwald #else 1726527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_MULTIPLEXERS for struct rfcomm_multiplexer is defined. Please, edit the config file." 173a3b02b71Smatthias.ringwald #endif 174a3b02b71Smatthias.ringwald 175a3b02b71Smatthias.ringwald 176a3b02b71Smatthias.ringwald // MARK: rfcomm_service_t 177a3b02b71Smatthias.ringwald #ifdef MAX_NO_RFCOMM_SERVICES 178c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_SERVICES > 0 179a3b02b71Smatthias.ringwald static rfcomm_service_t rfcomm_service_storage[MAX_NO_RFCOMM_SERVICES]; 180a3b02b71Smatthias.ringwald static memory_pool_t rfcomm_service_pool; 1816527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 182a3b02b71Smatthias.ringwald return memory_pool_get(&rfcomm_service_pool); 183a3b02b71Smatthias.ringwald } 1846527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 185a3b02b71Smatthias.ringwald memory_pool_free(&rfcomm_service_pool, rfcomm_service); 186a3b02b71Smatthias.ringwald } 187c4d3f927Smatthias.ringwald #else 1886527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 189c4d3f927Smatthias.ringwald return NULL; 190c4d3f927Smatthias.ringwald } 1916527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 192c4d3f927Smatthias.ringwald }; 193c4d3f927Smatthias.ringwald #endif 194a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 1956527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 1966527a633S[email protected] return (rfcomm_service_t*) malloc(sizeof(rfcomm_service_t)); 197a3b02b71Smatthias.ringwald } 1986527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 199a3b02b71Smatthias.ringwald free(rfcomm_service); 200a3b02b71Smatthias.ringwald } 201e045abdeSmatthias.ringwald #else 2026527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_SERVICES for struct rfcomm_service is defined. Please, edit the config file." 203a3b02b71Smatthias.ringwald #endif 204a3b02b71Smatthias.ringwald 205a3b02b71Smatthias.ringwald 206a3b02b71Smatthias.ringwald // MARK: rfcomm_channel_t 207a3b02b71Smatthias.ringwald #ifdef MAX_NO_RFCOMM_CHANNELS 208c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_CHANNELS > 0 209a3b02b71Smatthias.ringwald static rfcomm_channel_t rfcomm_channel_storage[MAX_NO_RFCOMM_CHANNELS]; 210a3b02b71Smatthias.ringwald static memory_pool_t rfcomm_channel_pool; 2116527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 212a3b02b71Smatthias.ringwald return memory_pool_get(&rfcomm_channel_pool); 213a3b02b71Smatthias.ringwald } 2146527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 215a3b02b71Smatthias.ringwald memory_pool_free(&rfcomm_channel_pool, rfcomm_channel); 216a3b02b71Smatthias.ringwald } 217c4d3f927Smatthias.ringwald #else 2186527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 219c4d3f927Smatthias.ringwald return NULL; 220c4d3f927Smatthias.ringwald } 2216527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 222c4d3f927Smatthias.ringwald }; 223c4d3f927Smatthias.ringwald #endif 224a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 2256527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 2266527a633S[email protected] return (rfcomm_channel_t*) malloc(sizeof(rfcomm_channel_t)); 227a3b02b71Smatthias.ringwald } 2286527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 229a3b02b71Smatthias.ringwald free(rfcomm_channel); 230a3b02b71Smatthias.ringwald } 231e045abdeSmatthias.ringwald #else 2326527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_CHANNELS for struct rfcomm_channel is defined. Please, edit the config file." 233a3b02b71Smatthias.ringwald #endif 234a3b02b71Smatthias.ringwald 235e0e5e285Smatthias.ringwald 236e0e5e285Smatthias.ringwald // MARK: db_mem_device_name_t 237e0e5e285Smatthias.ringwald #ifdef MAX_NO_DB_MEM_DEVICE_NAMES 238c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_NAMES > 0 239e0e5e285Smatthias.ringwald static db_mem_device_name_t db_mem_device_name_storage[MAX_NO_DB_MEM_DEVICE_NAMES]; 240e0e5e285Smatthias.ringwald static memory_pool_t db_mem_device_name_pool; 2416527a633S[email protected] db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){ 242e0e5e285Smatthias.ringwald return memory_pool_get(&db_mem_device_name_pool); 2431801b596Smatthias.ringwald } 2446527a633S[email protected] void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name){ 245e0e5e285Smatthias.ringwald memory_pool_free(&db_mem_device_name_pool, db_mem_device_name); 2461801b596Smatthias.ringwald } 247c4d3f927Smatthias.ringwald #else 2486527a633S[email protected] db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){ 249c4d3f927Smatthias.ringwald return NULL; 250c4d3f927Smatthias.ringwald } 2516527a633S[email protected] void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name){ 252c4d3f927Smatthias.ringwald }; 253c4d3f927Smatthias.ringwald #endif 2541801b596Smatthias.ringwald #elif defined(HAVE_MALLOC) 2556527a633S[email protected] db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){ 2566527a633S[email protected] return (db_mem_device_name_t*) malloc(sizeof(db_mem_device_name_t)); 2571801b596Smatthias.ringwald } 2586527a633S[email protected] void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name){ 259e0e5e285Smatthias.ringwald free(db_mem_device_name); 260e0e5e285Smatthias.ringwald } 261e045abdeSmatthias.ringwald #else 2626527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_DEVICE_NAMES for struct db_mem_device_name is defined. Please, edit the config file." 263e0e5e285Smatthias.ringwald #endif 264e0e5e285Smatthias.ringwald 265e0e5e285Smatthias.ringwald 266e0e5e285Smatthias.ringwald // MARK: db_mem_device_link_key_t 267e0e5e285Smatthias.ringwald #ifdef MAX_NO_DB_MEM_DEVICE_LINK_KEYS 268c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0 269e0e5e285Smatthias.ringwald static db_mem_device_link_key_t db_mem_device_link_key_storage[MAX_NO_DB_MEM_DEVICE_LINK_KEYS]; 270e0e5e285Smatthias.ringwald static memory_pool_t db_mem_device_link_key_pool; 2716527a633S[email protected] db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){ 272e0e5e285Smatthias.ringwald return memory_pool_get(&db_mem_device_link_key_pool); 273e0e5e285Smatthias.ringwald } 2746527a633S[email protected] void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){ 275e0e5e285Smatthias.ringwald memory_pool_free(&db_mem_device_link_key_pool, db_mem_device_link_key); 276e0e5e285Smatthias.ringwald } 277c4d3f927Smatthias.ringwald #else 2786527a633S[email protected] db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){ 279c4d3f927Smatthias.ringwald return NULL; 280c4d3f927Smatthias.ringwald } 2816527a633S[email protected] void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){ 282c4d3f927Smatthias.ringwald }; 283c4d3f927Smatthias.ringwald #endif 284e0e5e285Smatthias.ringwald #elif defined(HAVE_MALLOC) 2856527a633S[email protected] db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){ 2866527a633S[email protected] return (db_mem_device_link_key_t*) malloc(sizeof(db_mem_device_link_key_t)); 287e0e5e285Smatthias.ringwald } 2886527a633S[email protected] void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){ 289e0e5e285Smatthias.ringwald free(db_mem_device_link_key); 2901801b596Smatthias.ringwald } 291e045abdeSmatthias.ringwald #else 2926527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_DEVICE_LINK_KEYS for struct db_mem_device_link_key is defined. Please, edit the config file." 2931801b596Smatthias.ringwald #endif 2941801b596Smatthias.ringwald 2951801b596Smatthias.ringwald 2961801b596Smatthias.ringwald // MARK: db_mem_service_t 2971801b596Smatthias.ringwald #ifdef MAX_NO_DB_MEM_SERVICES 298c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_SERVICES > 0 2991801b596Smatthias.ringwald static db_mem_service_t db_mem_service_storage[MAX_NO_DB_MEM_SERVICES]; 3001801b596Smatthias.ringwald static memory_pool_t db_mem_service_pool; 3016527a633S[email protected] db_mem_service_t * btstack_memory_db_mem_service_get(void){ 3021801b596Smatthias.ringwald return memory_pool_get(&db_mem_service_pool); 3031801b596Smatthias.ringwald } 3046527a633S[email protected] void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){ 3051801b596Smatthias.ringwald memory_pool_free(&db_mem_service_pool, db_mem_service); 3061801b596Smatthias.ringwald } 307c4d3f927Smatthias.ringwald #else 3086527a633S[email protected] db_mem_service_t * btstack_memory_db_mem_service_get(void){ 309c4d3f927Smatthias.ringwald return NULL; 310c4d3f927Smatthias.ringwald } 3116527a633S[email protected] void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){ 312c4d3f927Smatthias.ringwald }; 313c4d3f927Smatthias.ringwald #endif 3141801b596Smatthias.ringwald #elif defined(HAVE_MALLOC) 3156527a633S[email protected] db_mem_service_t * btstack_memory_db_mem_service_get(void){ 3166527a633S[email protected] return (db_mem_service_t*) malloc(sizeof(db_mem_service_t)); 3171801b596Smatthias.ringwald } 3186527a633S[email protected] void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){ 3191801b596Smatthias.ringwald free(db_mem_service); 3201801b596Smatthias.ringwald } 321e045abdeSmatthias.ringwald #else 3226527a633S[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_SERVICES for struct db_mem_service is defined. Please, edit the config file." 3231801b596Smatthias.ringwald #endif 3241801b596Smatthias.ringwald 325*d0fdae3cS[email protected] // MARK: gatt_client_t 326*d0fdae3cS[email protected] #ifdef HAVE_BLE 327*d0fdae3cS[email protected] #ifdef MAX_NO_GATT_CLIENTS 328*d0fdae3cS[email protected] #if MAX_NO_GATT_CLIENTS > 0 329*d0fdae3cS[email protected] static gatt_client_t gatt_client_storage[MAX_NO_GATT_CLIENTS]; 330*d0fdae3cS[email protected] static memory_pool_t gatt_client_pool; 331*d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 332*d0fdae3cS[email protected] return memory_pool_get(&gatt_client_pool); 333*d0fdae3cS[email protected] } 334*d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 335*d0fdae3cS[email protected] memory_pool_free(&gatt_client_pool, gatt_client); 336*d0fdae3cS[email protected] } 337*d0fdae3cS[email protected] #else 338*d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 339*d0fdae3cS[email protected] return NULL; 340*d0fdae3cS[email protected] } 341*d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 342*d0fdae3cS[email protected] }; 343*d0fdae3cS[email protected] #endif 344*d0fdae3cS[email protected] #elif defined(HAVE_MALLOC) 345*d0fdae3cS[email protected] gatt_client_t * btstack_memory_gatt_client_get(void){ 346*d0fdae3cS[email protected] return (gatt_client_t*) malloc(sizeof(gatt_client_t)); 347*d0fdae3cS[email protected] } 348*d0fdae3cS[email protected] void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){ 349*d0fdae3cS[email protected] free(gatt_client); 350*d0fdae3cS[email protected] } 351*d0fdae3cS[email protected] #else 352*d0fdae3cS[email protected] #error "Neither HAVE_MALLOC nor MAX_NO_GATT_CLIENTS for struct gatt_client is defined. Please, edit the config file." 353*d0fdae3cS[email protected] #endif 354*d0fdae3cS[email protected] #endif 355a3b02b71Smatthias.ringwald // init 356a3b02b71Smatthias.ringwald void btstack_memory_init(void){ 357c4d3f927Smatthias.ringwald #if MAX_NO_HCI_CONNECTIONS > 0 358a3b02b71Smatthias.ringwald memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NO_HCI_CONNECTIONS, sizeof(hci_connection_t)); 359a3b02b71Smatthias.ringwald #endif 360c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_SERVICES > 0 361a3b02b71Smatthias.ringwald memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NO_L2CAP_SERVICES, sizeof(l2cap_service_t)); 362a3b02b71Smatthias.ringwald #endif 363c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_CHANNELS > 0 364a3b02b71Smatthias.ringwald memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NO_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); 365a3b02b71Smatthias.ringwald #endif 366c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_MULTIPLEXERS > 0 367a3b02b71Smatthias.ringwald memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NO_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); 368a3b02b71Smatthias.ringwald #endif 369c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_SERVICES > 0 370a3b02b71Smatthias.ringwald memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NO_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); 371a3b02b71Smatthias.ringwald #endif 372c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_CHANNELS > 0 373a3b02b71Smatthias.ringwald memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NO_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); 374a3b02b71Smatthias.ringwald #endif 375c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_NAMES > 0 376e0e5e285Smatthias.ringwald memory_pool_create(&db_mem_device_name_pool, db_mem_device_name_storage, MAX_NO_DB_MEM_DEVICE_NAMES, sizeof(db_mem_device_name_t)); 377e0e5e285Smatthias.ringwald #endif 378c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0 379e0e5e285Smatthias.ringwald memory_pool_create(&db_mem_device_link_key_pool, db_mem_device_link_key_storage, MAX_NO_DB_MEM_DEVICE_LINK_KEYS, sizeof(db_mem_device_link_key_t)); 3801801b596Smatthias.ringwald #endif 381c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_SERVICES > 0 3821801b596Smatthias.ringwald memory_pool_create(&db_mem_service_pool, db_mem_service_storage, MAX_NO_DB_MEM_SERVICES, sizeof(db_mem_service_t)); 3831801b596Smatthias.ringwald #endif 384*d0fdae3cS[email protected] #if MAX_NO_GATT_CLIENTS > 0 385*d0fdae3cS[email protected] memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NO_GATT_CLIENTS, sizeof(gatt_client_t)); 386*d0fdae3cS[email protected] #endif 387a3b02b71Smatthias.ringwald } 388e045abdeSmatthias.ringwald 389