hid_host: provide memory pool for hid_host_connection_t

This commit is contained in:
Milanka Ringwald 2021-01-05 16:38:44 +01:00 committed by Matthias Ringwald
parent 63bf37cdf2
commit f399f7fbd7
3 changed files with 69 additions and 12 deletions

View File

@ -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

View File

@ -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);

View File

@ -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"],