mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-28 08:37:22 +00:00
linked list/run loop: return true if item/data source/timer was removed
This commit is contained in:
parent
c9a4f43caa
commit
d58a1b5f11
@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
- bluetooth.h: extract internal defintitions to respective protocol layers
|
||||
- Updated CC256x initscripts (CC256xB v1.8, CC256xC v1.2)
|
||||
- libusb and posix ports: store bonding information in TLV
|
||||
- Linked List: return bool true if item was removed
|
||||
- btstack_run_loop_remove: return bool true if timer/data source was removed
|
||||
|
||||
## Changes August 2019
|
||||
|
||||
|
@ -158,7 +158,7 @@ static void btstack_run_loop_embedded_disable_data_source_callbacks(btstack_data
|
||||
CFSocketDisableCallBacks(references->socket, option_flags);
|
||||
}
|
||||
|
||||
static int btstack_run_loop_corefoundation_remove_data_source(btstack_data_source_t *ds){
|
||||
static bool btstack_run_loop_corefoundation_remove_data_source(btstack_data_source_t *ds){
|
||||
btstack_corefoundation_data_source_helper_t * references = (btstack_corefoundation_data_source_helper_t *) ds->item.next;
|
||||
// printf("btstack_run_loop_corefoundation_remove_data_source %x - fd %u, CFSocket %x, CFRunLoopSource %x\n", (int) dataSource, dataSource->source.fd, (int) dataSource->item.next, (int) dataSource->item.user_data);
|
||||
CFRunLoopRemoveSource( CFRunLoopGetCurrent(), references->socket_run_loop, kCFRunLoopCommonModes);
|
||||
@ -168,7 +168,7 @@ static int btstack_run_loop_corefoundation_remove_data_source(btstack_data_sour
|
||||
CFRelease(references->socket);
|
||||
|
||||
free(references);
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void btstack_run_loop_corefoundation_add_timer(btstack_timer_source_t * ts)
|
||||
@ -189,8 +189,9 @@ static int btstack_run_loop_corefoundation_remove_timer(btstack_timer_source_t *
|
||||
if (ts->item.next != NULL) {
|
||||
CFRunLoopTimerInvalidate((CFRunLoopTimerRef) ts->item.next); // also removes timer from run loops + releases it
|
||||
CFRelease((CFRunLoopTimerRef) ts->item.next);
|
||||
return true;
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,7 +101,7 @@ static void btstack_run_loop_embedded_add_data_source(btstack_data_source_t *ds)
|
||||
/**
|
||||
* Remove data_source from run loop
|
||||
*/
|
||||
static int btstack_run_loop_embedded_remove_data_source(btstack_data_source_t *ds){
|
||||
static bool btstack_run_loop_embedded_remove_data_source(btstack_data_source_t *ds){
|
||||
return btstack_linked_list_remove(&data_sources, (btstack_linked_item_t *) ds);
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ static void btstack_run_loop_embedded_add_timer(btstack_timer_source_t *ts){
|
||||
/**
|
||||
* Remove timer from run loop
|
||||
*/
|
||||
static int btstack_run_loop_embedded_remove_timer(btstack_timer_source_t *ts){
|
||||
static bool btstack_run_loop_embedded_remove_timer(btstack_timer_source_t *ts){
|
||||
#ifdef TIMER_SUPPORT
|
||||
return btstack_linked_list_remove(&timers, (btstack_linked_item_t *) ts);
|
||||
#else
|
||||
|
@ -138,7 +138,7 @@ static void btstack_run_loop_freertos_add_timer(btstack_timer_source_t *ts){
|
||||
/**
|
||||
* Remove timer from run loop
|
||||
*/
|
||||
static int btstack_run_loop_freertos_remove_timer(btstack_timer_source_t *ts){
|
||||
static bool btstack_run_loop_freertos_remove_timer(btstack_timer_source_t *ts){
|
||||
return btstack_linked_list_remove(&timers, (btstack_linked_item_t *) ts);
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ static void btstack_run_loop_freertos_add_data_source(btstack_data_source_t *ds)
|
||||
btstack_linked_list_add(&data_sources, (btstack_linked_item_t *) ds);
|
||||
}
|
||||
|
||||
static int btstack_run_loop_freertos_remove_data_source(btstack_data_source_t *ds){
|
||||
static bool btstack_run_loop_freertos_remove_data_source(btstack_data_source_t *ds){
|
||||
return btstack_linked_list_remove(&data_sources, (btstack_linked_item_t *) ds);
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ static void btstack_run_loop_posix_add_data_source(btstack_data_source_t *ds){
|
||||
/**
|
||||
* Remove data_source from run loop
|
||||
*/
|
||||
static int btstack_run_loop_posix_remove_data_source(btstack_data_source_t *ds){
|
||||
static bool btstack_run_loop_posix_remove_data_source(btstack_data_source_t *ds){
|
||||
data_sources_modified = 1;
|
||||
log_debug("btstack_run_loop_posix_remove_data_source %p\n", ds);
|
||||
return btstack_linked_list_remove(&data_sources, (btstack_linked_item_t *) ds);
|
||||
@ -115,7 +115,7 @@ static void btstack_run_loop_posix_add_timer(btstack_timer_source_t *ts){
|
||||
/**
|
||||
* Remove timer from run loop
|
||||
*/
|
||||
static int btstack_run_loop_posix_remove_timer(btstack_timer_source_t *ts){
|
||||
static bool btstack_run_loop_posix_remove_timer(btstack_timer_source_t *ts){
|
||||
// log_info("Removed timer %x at %u\n", (int) ts, (unsigned int) ts->timeout.tv_sec);
|
||||
// btstack_run_loop_posix_dump_timer();
|
||||
return btstack_linked_list_remove(&timers, (btstack_linked_item_t *) ts);
|
||||
|
@ -101,7 +101,7 @@ static void btstack_run_loop_wiced_add_timer(btstack_timer_source_t *ts){
|
||||
/**
|
||||
* Remove timer from run loop
|
||||
*/
|
||||
static int btstack_run_loop_wiced_remove_timer(btstack_timer_source_t *ts){
|
||||
static bool btstack_run_loop_wiced_remove_timer(btstack_timer_source_t *ts){
|
||||
return btstack_linked_list_remove(&timers, (btstack_linked_item_t *) ts);
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ static void btstack_run_loop_windows_add_data_source(btstack_data_source_t *ds){
|
||||
/**
|
||||
* Remove data_source from run loop
|
||||
*/
|
||||
static int btstack_run_loop_windows_remove_data_source(btstack_data_source_t *ds){
|
||||
static bool btstack_run_loop_windows_remove_data_source(btstack_data_source_t *ds){
|
||||
data_sources_modified = 1;
|
||||
// log_info("btstack_run_loop_windows_remove_data_source %x\n", (int) ds);
|
||||
return btstack_linked_list_remove(&data_sources, (btstack_linked_item_t *) ds);
|
||||
@ -104,7 +104,7 @@ static void btstack_run_loop_windows_add_timer(btstack_timer_source_t *ts){
|
||||
/**
|
||||
* Remove timer from run loop
|
||||
*/
|
||||
static int btstack_run_loop_windows_remove_timer(btstack_timer_source_t *ts){
|
||||
static bool btstack_run_loop_windows_remove_timer(btstack_timer_source_t *ts){
|
||||
// log_info("Removed timer %x at %u\n", (int) ts, (unsigned int) ts->timeout.tv_sec);
|
||||
// btstack_run_loop_windows_dump_timer();
|
||||
return btstack_linked_list_remove(&timers, (btstack_linked_item_t *) ts);
|
||||
|
@ -100,16 +100,16 @@ bool btstack_linked_list_add_tail(btstack_linked_list_t * list, btstack_linked_i
|
||||
return true;
|
||||
}
|
||||
|
||||
int btstack_linked_list_remove(btstack_linked_list_t * list, btstack_linked_item_t *item){ // <-- remove item from list
|
||||
if (!item) return -1;
|
||||
bool btstack_linked_list_remove(btstack_linked_list_t * list, btstack_linked_item_t *item){ // <-- remove item from list
|
||||
if (!item) return false;
|
||||
btstack_linked_item_t *it;
|
||||
for (it = (btstack_linked_item_t *) list; it ; it = it->next){
|
||||
if (it->next == item){
|
||||
it->next = item->next;
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,9 +97,9 @@ btstack_linked_item_t * btstack_linked_list_pop(btstack_linked_list_t * list);
|
||||
* @brief Remove item from list
|
||||
* @param list
|
||||
* @param item
|
||||
* @returns 0 if item was found in list, -1 if item was not in list
|
||||
* @returns true if item was removed, false if it is no't in list
|
||||
*/
|
||||
int btstack_linked_list_remove(btstack_linked_list_t * list, btstack_linked_item_t *item);
|
||||
bool btstack_linked_list_remove(btstack_linked_list_t * list, btstack_linked_item_t *item);
|
||||
|
||||
/**
|
||||
* @brief Get first element.
|
||||
|
@ -46,6 +46,7 @@
|
||||
|
||||
#include "btstack_config.h"
|
||||
|
||||
#include "btstack_bool.h"
|
||||
#include "btstack_linked_list.h"
|
||||
|
||||
#include <stdint.h>
|
||||
@ -96,12 +97,12 @@ typedef struct btstack_timer_source {
|
||||
typedef struct btstack_run_loop {
|
||||
void (*init)(void);
|
||||
void (*add_data_source)(btstack_data_source_t * data_source);
|
||||
int (*remove_data_source)(btstack_data_source_t * data_source);
|
||||
bool (*remove_data_source)(btstack_data_source_t * data_source);
|
||||
void (*enable_data_source_callbacks)(btstack_data_source_t * data_source, uint16_t callbacks);
|
||||
void (*disable_data_source_callbacks)(btstack_data_source_t * data_source, uint16_t callbacks);
|
||||
void (*set_timer)(btstack_timer_source_t * timer, uint32_t timeout_in_ms);
|
||||
void (*add_timer)(btstack_timer_source_t *timer);
|
||||
int (*remove_timer)(btstack_timer_source_t *timer);
|
||||
bool (*remove_timer)(btstack_timer_source_t *timer);
|
||||
void (*execute)(void);
|
||||
void (*dump_timer)(void);
|
||||
uint32_t (*get_time_ms)(void);
|
||||
|
@ -62,7 +62,7 @@ void btstack_run_loop_base_add_data_source(btstack_data_source_t *ds){
|
||||
btstack_linked_list_add(&btstack_run_loop_base_data_sources, (btstack_linked_item_t *) ds);
|
||||
}
|
||||
|
||||
int btstack_run_loop_base_remove_data_source(btstack_data_source_t *ds){
|
||||
bool btstack_run_loop_base_remove_data_source(btstack_data_source_t *ds){
|
||||
return btstack_linked_list_remove(&btstack_run_loop_base_data_sources, (btstack_linked_item_t *) ds);
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ void btstack_run_loop_base_disable_data_source_callbacks(btstack_data_source_t *
|
||||
}
|
||||
|
||||
|
||||
int btstack_run_loop_base_remove_timer(btstack_timer_source_t *ts){
|
||||
bool btstack_run_loop_base_remove_timer(btstack_timer_source_t *ts){
|
||||
return btstack_linked_list_remove(&btstack_run_loop_base_timers, (btstack_linked_item_t *) ts);
|
||||
}
|
||||
|
||||
|
@ -65,13 +65,16 @@ void btstack_run_loop_base_init(void);
|
||||
|
||||
/**
|
||||
* @brief Add timer source.
|
||||
* @param timer to add
|
||||
*/
|
||||
void btstack_run_loop_base_add_timer(btstack_timer_source_t * timer);
|
||||
|
||||
/**
|
||||
* @brief Remove timer source.
|
||||
* @param timer to remove
|
||||
* @returns true if timer was removed
|
||||
*/
|
||||
int btstack_run_loop_base_remove_timer(btstack_timer_source_t * timer);
|
||||
bool btstack_run_loop_base_remove_timer(btstack_timer_source_t * timer);
|
||||
|
||||
/**
|
||||
* @brief Process timers: remove expired timers from list and call their process function
|
||||
@ -94,8 +97,9 @@ void btstack_run_loop_base_add_data_source(btstack_data_source_t * data_source);
|
||||
/**
|
||||
* @brief Remove data source from run loop
|
||||
* @param data_source to remove
|
||||
* @returns true if data srouce was removed
|
||||
*/
|
||||
int btstack_run_loop_base_remove_data_source(btstack_data_source_t * data_source);
|
||||
bool btstack_run_loop_base_remove_data_source(btstack_data_source_t * data_source);
|
||||
|
||||
/**
|
||||
* @brief Enable callbacks for a data source
|
||||
|
@ -69,7 +69,7 @@ void mesh_network_key_add(mesh_network_key_t * network_key){
|
||||
btstack_linked_list_add_tail(&network_keys, (btstack_linked_item_t *) network_key);
|
||||
}
|
||||
|
||||
int mesh_network_key_remove(mesh_network_key_t * network_key){
|
||||
bool mesh_network_key_remove(mesh_network_key_t * network_key){
|
||||
mesh_network_key_used[network_key->internal_index] = 0;
|
||||
return btstack_linked_list_remove(&network_keys, (btstack_linked_item_t *) network_key);
|
||||
}
|
||||
@ -161,7 +161,7 @@ void mesh_transport_key_add(mesh_transport_key_t * transport_key){
|
||||
btstack_linked_list_add_tail(&application_keys, (btstack_linked_item_t *) transport_key);
|
||||
}
|
||||
|
||||
int mesh_transport_key_remove(mesh_transport_key_t * transport_key){
|
||||
bool mesh_transport_key_remove(mesh_transport_key_t * transport_key){
|
||||
mesh_transport_key_used[transport_key->internal_index] = 0;
|
||||
return btstack_linked_list_remove(&application_keys, (btstack_linked_item_t *) transport_key);
|
||||
}
|
||||
|
@ -150,10 +150,10 @@ void mesh_network_key_add(mesh_network_key_t * network_key);
|
||||
/**
|
||||
* @brief Remove network key from list
|
||||
* @param network_key
|
||||
* @return 0 if removed
|
||||
* @return true if removed
|
||||
* @note key is only removed from list, memory is not released
|
||||
*/
|
||||
int mesh_network_key_remove(mesh_network_key_t * network_key);
|
||||
bool mesh_network_key_remove(mesh_network_key_t * network_key);
|
||||
|
||||
/**
|
||||
* @brief Get network_key for netkey_index
|
||||
@ -239,7 +239,7 @@ void mesh_transport_key_add(mesh_transport_key_t * transport_key);
|
||||
* @return 0 if removed
|
||||
* @note key is only removed from list, memory is not released
|
||||
*/
|
||||
int mesh_transport_key_remove(mesh_transport_key_t * transport_key);
|
||||
bool mesh_transport_key_remove(mesh_transport_key_t * transport_key);
|
||||
|
||||
/**
|
||||
* Get transport key for appkey_index
|
||||
|
Loading…
x
Reference in New Issue
Block a user