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; 61*6527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 62a3b02b71Smatthias.ringwald return memory_pool_get(&hci_connection_pool); 63a3b02b71Smatthias.ringwald } 64*6527a633S[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 68*6527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 69c4d3f927Smatthias.ringwald return NULL; 70c4d3f927Smatthias.ringwald } 71*6527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 72c4d3f927Smatthias.ringwald }; 73c4d3f927Smatthias.ringwald #endif 74a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 75*6527a633S[email protected] hci_connection_t * btstack_memory_hci_connection_get(void){ 76*6527a633S[email protected] return (hci_connection_t*) malloc(sizeof(hci_connection_t)); 77a3b02b71Smatthias.ringwald } 78*6527a633S[email protected] void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){ 79a3b02b71Smatthias.ringwald free(hci_connection); 80a3b02b71Smatthias.ringwald } 81e045abdeSmatthias.ringwald #else 82*6527a633S[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; 91*6527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 92a3b02b71Smatthias.ringwald return memory_pool_get(&l2cap_service_pool); 93a3b02b71Smatthias.ringwald } 94*6527a633S[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 98*6527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 99c4d3f927Smatthias.ringwald return NULL; 100c4d3f927Smatthias.ringwald } 101*6527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 102c4d3f927Smatthias.ringwald }; 103c4d3f927Smatthias.ringwald #endif 104a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 105*6527a633S[email protected] l2cap_service_t * btstack_memory_l2cap_service_get(void){ 106*6527a633S[email protected] return (l2cap_service_t*) malloc(sizeof(l2cap_service_t)); 107a3b02b71Smatthias.ringwald } 108*6527a633S[email protected] void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){ 109a3b02b71Smatthias.ringwald free(l2cap_service); 110a3b02b71Smatthias.ringwald } 111e045abdeSmatthias.ringwald #else 112*6527a633S[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; 121*6527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 122a3b02b71Smatthias.ringwald return memory_pool_get(&l2cap_channel_pool); 123a3b02b71Smatthias.ringwald } 124*6527a633S[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 128*6527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 129c4d3f927Smatthias.ringwald return NULL; 130c4d3f927Smatthias.ringwald } 131*6527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 132c4d3f927Smatthias.ringwald }; 133c4d3f927Smatthias.ringwald #endif 134a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 135*6527a633S[email protected] l2cap_channel_t * btstack_memory_l2cap_channel_get(void){ 136*6527a633S[email protected] return (l2cap_channel_t*) malloc(sizeof(l2cap_channel_t)); 137a3b02b71Smatthias.ringwald } 138*6527a633S[email protected] void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){ 139a3b02b71Smatthias.ringwald free(l2cap_channel); 140a3b02b71Smatthias.ringwald } 141e045abdeSmatthias.ringwald #else 142*6527a633S[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; 151*6527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 152a3b02b71Smatthias.ringwald return memory_pool_get(&rfcomm_multiplexer_pool); 153a3b02b71Smatthias.ringwald } 154*6527a633S[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 158*6527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 159c4d3f927Smatthias.ringwald return NULL; 160c4d3f927Smatthias.ringwald } 161*6527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 162c4d3f927Smatthias.ringwald }; 163c4d3f927Smatthias.ringwald #endif 164a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 165*6527a633S[email protected] rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){ 166*6527a633S[email protected] return (rfcomm_multiplexer_t*) malloc(sizeof(rfcomm_multiplexer_t)); 167a3b02b71Smatthias.ringwald } 168*6527a633S[email protected] void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){ 169a3b02b71Smatthias.ringwald free(rfcomm_multiplexer); 170a3b02b71Smatthias.ringwald } 171e045abdeSmatthias.ringwald #else 172*6527a633S[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; 181*6527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 182a3b02b71Smatthias.ringwald return memory_pool_get(&rfcomm_service_pool); 183a3b02b71Smatthias.ringwald } 184*6527a633S[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 188*6527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 189c4d3f927Smatthias.ringwald return NULL; 190c4d3f927Smatthias.ringwald } 191*6527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 192c4d3f927Smatthias.ringwald }; 193c4d3f927Smatthias.ringwald #endif 194a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 195*6527a633S[email protected] rfcomm_service_t * btstack_memory_rfcomm_service_get(void){ 196*6527a633S[email protected] return (rfcomm_service_t*) malloc(sizeof(rfcomm_service_t)); 197a3b02b71Smatthias.ringwald } 198*6527a633S[email protected] void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){ 199a3b02b71Smatthias.ringwald free(rfcomm_service); 200a3b02b71Smatthias.ringwald } 201e045abdeSmatthias.ringwald #else 202*6527a633S[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; 211*6527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 212a3b02b71Smatthias.ringwald return memory_pool_get(&rfcomm_channel_pool); 213a3b02b71Smatthias.ringwald } 214*6527a633S[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 218*6527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 219c4d3f927Smatthias.ringwald return NULL; 220c4d3f927Smatthias.ringwald } 221*6527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 222c4d3f927Smatthias.ringwald }; 223c4d3f927Smatthias.ringwald #endif 224a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC) 225*6527a633S[email protected] rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){ 226*6527a633S[email protected] return (rfcomm_channel_t*) malloc(sizeof(rfcomm_channel_t)); 227a3b02b71Smatthias.ringwald } 228*6527a633S[email protected] void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){ 229a3b02b71Smatthias.ringwald free(rfcomm_channel); 230a3b02b71Smatthias.ringwald } 231e045abdeSmatthias.ringwald #else 232*6527a633S[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; 241*6527a633S[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 } 244*6527a633S[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 248*6527a633S[email protected] db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){ 249c4d3f927Smatthias.ringwald return NULL; 250c4d3f927Smatthias.ringwald } 251*6527a633S[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) 255*6527a633S[email protected] db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){ 256*6527a633S[email protected] return (db_mem_device_name_t*) malloc(sizeof(db_mem_device_name_t)); 2571801b596Smatthias.ringwald } 258*6527a633S[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 262*6527a633S[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; 271*6527a633S[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 } 274*6527a633S[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 278*6527a633S[email protected] db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){ 279c4d3f927Smatthias.ringwald return NULL; 280c4d3f927Smatthias.ringwald } 281*6527a633S[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) 285*6527a633S[email protected] db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){ 286*6527a633S[email protected] return (db_mem_device_link_key_t*) malloc(sizeof(db_mem_device_link_key_t)); 287e0e5e285Smatthias.ringwald } 288*6527a633S[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 292*6527a633S[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; 301*6527a633S[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 } 304*6527a633S[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 308*6527a633S[email protected] db_mem_service_t * btstack_memory_db_mem_service_get(void){ 309c4d3f927Smatthias.ringwald return NULL; 310c4d3f927Smatthias.ringwald } 311*6527a633S[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) 315*6527a633S[email protected] db_mem_service_t * btstack_memory_db_mem_service_get(void){ 316*6527a633S[email protected] return (db_mem_service_t*) malloc(sizeof(db_mem_service_t)); 3171801b596Smatthias.ringwald } 318*6527a633S[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 322*6527a633S[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 325a3b02b71Smatthias.ringwald // init 326a3b02b71Smatthias.ringwald void btstack_memory_init(void){ 327c4d3f927Smatthias.ringwald #if MAX_NO_HCI_CONNECTIONS > 0 328a3b02b71Smatthias.ringwald memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NO_HCI_CONNECTIONS, sizeof(hci_connection_t)); 329a3b02b71Smatthias.ringwald #endif 330c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_SERVICES > 0 331a3b02b71Smatthias.ringwald memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NO_L2CAP_SERVICES, sizeof(l2cap_service_t)); 332a3b02b71Smatthias.ringwald #endif 333c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_CHANNELS > 0 334a3b02b71Smatthias.ringwald memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NO_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); 335a3b02b71Smatthias.ringwald #endif 336c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_MULTIPLEXERS > 0 337a3b02b71Smatthias.ringwald memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NO_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); 338a3b02b71Smatthias.ringwald #endif 339c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_SERVICES > 0 340a3b02b71Smatthias.ringwald memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NO_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); 341a3b02b71Smatthias.ringwald #endif 342c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_CHANNELS > 0 343a3b02b71Smatthias.ringwald memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NO_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); 344a3b02b71Smatthias.ringwald #endif 345c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_NAMES > 0 346e0e5e285Smatthias.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)); 347e0e5e285Smatthias.ringwald #endif 348c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0 349e0e5e285Smatthias.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)); 3501801b596Smatthias.ringwald #endif 351c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_SERVICES > 0 3521801b596Smatthias.ringwald memory_pool_create(&db_mem_service_pool, db_mem_service_storage, MAX_NO_DB_MEM_SERVICES, sizeof(db_mem_service_t)); 3531801b596Smatthias.ringwald #endif 354a3b02b71Smatthias.ringwald } 355e045abdeSmatthias.ringwald 356