diff --git a/include/btstack/run_loop.h b/include/btstack/run_loop.h index 26c52f628..bc6b90fc2 100644 --- a/include/btstack/run_loop.h +++ b/include/btstack/run_loop.h @@ -56,23 +56,23 @@ typedef struct timer { linked_item_t item; struct timeval timeout; // <-- next timeout void (*process)(struct timer *ts); // <-- do processing -} timer_t; +} timer_source_t; // init must be called before any other run_loop call void run_loop_init(RUN_LOOP_TYPE type); // set timer based on current time -void run_loop_set_timer(timer_t *a, int timeout_in_ms); +void run_loop_set_timer(timer_source_t *a, int timeout_in_ms); // compare timeval or timers - NULL is assumed to be before the Big Bang int run_loop_timeval_compare(struct timeval *a, struct timeval *b); -int run_loop_timer_compare(timer_t *a, timer_t *b); +int run_loop_timer_compare(timer_source_t *a, timer_source_t *b); void run_loop_add_data_source(data_source_t *dataSource); // <-- add DataSource to RunLoop int run_loop_remove_data_source(data_source_t *dataSource); // <-- remove DataSource from RunLoop -void run_loop_add_timer(timer_t *timer); // <-- add Timer to RunLoop -int run_loop_remove_timer(timer_t *timer); // <-- remove Timer from RunLoop +void run_loop_add_timer(timer_source_t *timer); // <-- add Timer to RunLoop +int run_loop_remove_timer(timer_source_t *timer); // <-- remove Timer from RunLoop void run_loop_execute(); // <-- execute configured RunLoop @@ -84,8 +84,8 @@ typedef struct { void (*init)(); void (*add_data_source)(data_source_t *dataSource); int (*remove_data_source)(data_source_t *dataSource); - void (*add_timer)(timer_t *timer); - int (*remove_timer)(timer_t *timer); + void (*add_timer)(timer_source_t *timer); + int (*remove_timer)(timer_source_t *timer); void (*execute)(); void (*dump_timer)(); } run_loop_t; diff --git a/src/daemon.c b/src/daemon.c index 645d6d514..d9b2e2a36 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -75,7 +75,7 @@ static hci_transport_t * transport; static hci_uart_config_t config; -static timer_t timeout; +static timer_source_t timeout; static void dummy_bluetooth_status_handler(BLUETOOTH_STATE state){ printf("Bluetooth status: %u\n", state); diff --git a/src/hci.c b/src/hci.c index f0106aa3d..82812bc96 100644 --- a/src/hci.c +++ b/src/hci.c @@ -66,7 +66,7 @@ static hci_connection_t * connection_for_handle(hci_con_handle_t con_handle){ return NULL; } -static void hci_connection_timeout_handler(timer_t *timer){ +static void hci_connection_timeout_handler(timer_source_t *timer){ hci_connection_t * connection = linked_item_get_user(&timer->item); struct timeval tv; gettimeofday(&tv, NULL); diff --git a/src/hci.h b/src/hci.h index 476a09534..4990fe539 100644 --- a/src/hci.h +++ b/src/hci.h @@ -126,7 +126,7 @@ typedef struct { hci_connection_flags_t flags; // timer - timer_t timeout; + timer_source_t timeout; struct timeval timestamp; } hci_connection_t; diff --git a/src/run_loop.c b/src/run_loop.c index c104ee7e3..aae903c85 100644 --- a/src/run_loop.c +++ b/src/run_loop.c @@ -78,7 +78,7 @@ int run_loop_remove_data_source(data_source_t *ds){ /** * Add timer to run_loop (keep list sorted) */ -void run_loop_add_timer(timer_t *ts){ +void run_loop_add_timer(timer_source_t *ts){ run_loop_assert(); the_run_loop->add_timer(ts); } @@ -86,7 +86,7 @@ void run_loop_add_timer(timer_t *ts){ /** * Remove timer from run loop */ -int run_loop_remove_timer(timer_t *ts){ +int run_loop_remove_timer(timer_source_t *ts){ run_loop_assert(); return the_run_loop->remove_timer(ts); } @@ -128,7 +128,7 @@ void run_loop_init(RUN_LOOP_TYPE type){ } // set timer -void run_loop_set_timer(timer_t *a, int timeout_in_ms){ +void run_loop_set_timer(timer_source_t *a, int timeout_in_ms){ gettimeofday(&a->timeout, NULL); a->timeout.tv_sec += timeout_in_ms / 1000; a->timeout.tv_usec += (timeout_in_ms % 1000) * 1000; @@ -165,7 +165,7 @@ int run_loop_timeval_compare(struct timeval *a, struct timeval *b){ // compare timers - NULL is assumed to be before the Big Bang // pre: 0 <= tv_usec < 1000000 -int run_loop_timer_compare(timer_t *a, timer_t *b){ +int run_loop_timer_compare(timer_source_t *a, timer_source_t *b){ if (!a && !b) return 0; if (!a) return -1; if (!b) return 1; diff --git a/src/run_loop_cocoa.m b/src/run_loop_cocoa.m index 123f9a0d1..41836c7e5 100644 --- a/src/run_loop_cocoa.m +++ b/src/run_loop_cocoa.m @@ -87,13 +87,13 @@ int cocoa_remove_data_source(data_source_t *dataSource){ return 0; } -void cocoa_add_timer(timer_t * ts){ +void cocoa_add_timer(timer_source_t * ts){ // not needed yet fprintf(stderr, "WARNING: run_loop_add_timer not implemented yet!"); // warning never the less } -int cocoa_remove_timer(timer_t * ts){ +int cocoa_remove_timer(timer_source_t * ts){ // not needed yet fprintf(stderr, "WARNING: run_loop_remove_timer not implemented yet!"); // warning never the less diff --git a/src/run_loop_posix.c b/src/run_loop_posix.c index f698ba683..0ff46b788 100644 --- a/src/run_loop_posix.c +++ b/src/run_loop_posix.c @@ -63,10 +63,10 @@ int posix_remove_data_source(data_source_t *ds){ /** * Add timer to run_loop (keep list sorted) */ -void posix_add_timer(timer_t *ts){ +void posix_add_timer(timer_source_t *ts){ linked_item_t *it; for (it = (linked_item_t *) &timers; it->next ; it = it->next){ - if (run_loop_timer_compare( (timer_t *) it->next, ts) >= 0) { + if (run_loop_timer_compare( (timer_source_t *) it->next, ts) >= 0) { break; } } @@ -79,7 +79,7 @@ void posix_add_timer(timer_t *ts){ /** * Remove timer from run loop */ -int posix_remove_timer(timer_t *ts){ +int posix_remove_timer(timer_source_t *ts){ // printf("Removed timer %x at %u\n", (int) ts, (unsigned int) ts->timeout.tv_sec); return linked_list_remove(&timers, (linked_item_t *) ts); } @@ -88,7 +88,7 @@ void posix_dump_timer(){ linked_item_t *it; int i = 0; for (it = (linked_item_t *) timers; it ; it = it->next){ - timer_t *ts = (timer_t*) it; + timer_source_t *ts = (timer_source_t*) it; printf("timer %u, timeout %u\n", i, (unsigned int) ts->timeout.tv_sec); } } @@ -99,7 +99,7 @@ void posix_dump_timer(){ void posix_execute() { fd_set descriptors; data_source_t *ds; - timer_t *ts; + timer_source_t *ts; struct timeval current_tv; struct timeval next_tv; struct timeval *timeout; @@ -122,7 +122,7 @@ void posix_execute() { timeout = NULL; if (timers) { gettimeofday(¤t_tv, NULL); - ts = (timer_t *) timers; + ts = (timer_source_t *) timers; next_tv.tv_usec = ts->timeout.tv_usec - current_tv.tv_usec; next_tv.tv_sec = ts->timeout.tv_sec - current_tv.tv_sec; while (next_tv.tv_usec < 0){ @@ -152,7 +152,7 @@ void posix_execute() { // pre: 0 <= tv_usec < 1000000 while (timers) { gettimeofday(¤t_tv, NULL); - ts = (timer_t *) timers; + ts = (timer_source_t *) timers; if (ts->timeout.tv_sec > current_tv.tv_sec) break; if (ts->timeout.tv_sec == current_tv.tv_sec && ts->timeout.tv_usec > current_tv.tv_usec) break; run_loop_remove_timer(ts);