mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-28 08:37:22 +00:00
runloop: pass callback type to data source process functions
This commit is contained in:
parent
c4ae7169b8
commit
7cd5ef9557
@ -72,7 +72,7 @@ static void socketDataCallback (
|
||||
if (callbackType == kCFSocketReadCallBack && info){
|
||||
btstack_data_source_t *dataSource = (btstack_data_source_t *) info;
|
||||
// printf("btstack_run_loop_cocoa_data_source %x - fd %u, CFSocket %x, CFRunLoopSource %x\n", (int) dataSource, dataSource->fd, (int) s, (int) dataSource->item.next);
|
||||
dataSource->process(dataSource);
|
||||
dataSource->process(dataSource, DATA_SOURCE_CALLBACK_READ);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ int socket_connection_has_parked_connections(void){
|
||||
return parked != NULL;
|
||||
}
|
||||
|
||||
static int socket_connection_accept(btstack_data_source_t *socket_ds) {
|
||||
static void socket_connection_accept(btstack_data_source_t *socket_ds, btstack_data_source_callback_type_t callback_type) {
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t slen = sizeof(ss);
|
||||
int socket_fd = btstack_run_loop_get_data_source_fd(ds);
|
||||
|
@ -187,7 +187,7 @@ void btstack_run_loop_embedded_execute_once(void) {
|
||||
btstack_timer_source_t *ts = (btstack_timer_source_t *) timers;
|
||||
if (ts->timeout > now) break;
|
||||
btstack_run_loop_remove_timer(ts);
|
||||
ts->process(ts);
|
||||
ts->process(ts, DATA_SOURCE_CALLBACK_POLL);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -102,7 +102,7 @@ typedef struct hci_transport_h4 {
|
||||
} hci_transport_h4_t;
|
||||
|
||||
// prototypes
|
||||
static int h4_process(btstack_data_source_t *ds);
|
||||
static void h4_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type);
|
||||
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||
static void h4_block_received(void);
|
||||
static void h4_block_sent(void);
|
||||
@ -387,7 +387,7 @@ static void h4_block_sent(void){
|
||||
}
|
||||
}
|
||||
|
||||
static int h4_process(btstack_data_source_t *ds) {
|
||||
static void h4_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type) {
|
||||
|
||||
// reset tx state before emitting packet sent event
|
||||
// to allow for positive can_send_now
|
||||
|
@ -83,7 +83,7 @@ typedef struct hci_transport_h4 {
|
||||
} hci_transport_h4_t;
|
||||
|
||||
// prototypes
|
||||
static int h4_process(btstack_data_source_t *ds);
|
||||
static void h4_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type);
|
||||
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||
static void h4_block_received(void);
|
||||
static void h4_block_sent(void);
|
||||
@ -243,7 +243,7 @@ static void h4_register_packet_handler(void (*handler)(uint8_t packet_type, uint
|
||||
packet_handler = handler;
|
||||
}
|
||||
|
||||
static int h4_process(btstack_data_source_t *ds) {
|
||||
static void h4_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type) {
|
||||
|
||||
// notify about packet sent
|
||||
if (tx_state == TX_DONE){
|
||||
|
@ -180,7 +180,7 @@ static void btstack_run_loop_posix_execute(void) {
|
||||
// log_info("btstack_run_loop_posix_execute: check %x with fd %u\n", (int) ds, ds->fd);
|
||||
if (FD_ISSET(ds->fd, &descriptors)) {
|
||||
// log_info("btstack_run_loop_posix_execute: process %x with fd %u\n", (int) ds, ds->fd);
|
||||
ds->process(ds);
|
||||
ds->process(ds, DATA_SOURCE_CALLBACK_READ);
|
||||
}
|
||||
}
|
||||
// log_info("btstack_run_loop_posix_execute: after ds check\n");
|
||||
|
@ -65,7 +65,7 @@
|
||||
#error HCI_OUTGOING_PRE_BUFFER_SIZE not defined. Please update hci.h
|
||||
#endif
|
||||
|
||||
static int h4_process(btstack_data_source_t *ds);
|
||||
static void h4_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type);
|
||||
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||
|
||||
typedef enum {
|
||||
@ -342,8 +342,8 @@ static void h4_statemachine(void){
|
||||
}
|
||||
}
|
||||
|
||||
static int h4_process(btstack_data_source_t *ds) {
|
||||
if (hci_transport_h4->uart_fd == 0) return -1;
|
||||
static void h4_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type) {
|
||||
if (hci_transport_h4->uart_fd == 0) return;
|
||||
|
||||
int read_now = bytes_to_read;
|
||||
|
||||
@ -352,9 +352,7 @@ static int h4_process(btstack_data_source_t *ds) {
|
||||
// read up to bytes_to_read data in
|
||||
ssize_t bytes_read = read(hci_transport_h4->uart_fd, &hci_packet[read_pos], read_now);
|
||||
// log_info("h4_process: bytes read %u", bytes_read);
|
||||
if (bytes_read < 0) {
|
||||
return bytes_read;
|
||||
}
|
||||
if (bytes_read < 0) return;
|
||||
|
||||
uint32_t end = btstack_run_loop_get_time_ms();
|
||||
if (end - start > 10){
|
||||
@ -363,12 +361,9 @@ static int h4_process(btstack_data_source_t *ds) {
|
||||
|
||||
bytes_to_read -= bytes_read;
|
||||
read_pos += bytes_read;
|
||||
if (bytes_to_read > 0) {
|
||||
return 0;
|
||||
}
|
||||
if (bytes_to_read > 0) return;
|
||||
|
||||
h4_statemachine();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||
|
@ -83,7 +83,7 @@
|
||||
#include "hci.h"
|
||||
#include "hci_transport.h"
|
||||
|
||||
static int h4_process(btstack_data_source_t *ds);
|
||||
static void h4_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type);
|
||||
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||
static hci_transport_config_uart_t *hci_transport_config_uart;
|
||||
|
||||
@ -336,7 +336,7 @@ static void h4_statemachine(void){
|
||||
}
|
||||
}
|
||||
|
||||
static int h4_process(btstack_data_source_t *ds) {
|
||||
static void h4_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type) {
|
||||
if (hci_transport_h4->uart_fd == 0) return -1;
|
||||
|
||||
int read_now = bytes_to_read;
|
||||
|
@ -400,7 +400,7 @@ static void handle_completed_transfer(struct libusb_transfer *transfer){
|
||||
}
|
||||
}
|
||||
|
||||
static int usb_process_ds(btstack_data_source_t *ds) {
|
||||
static void usb_process_ds(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type) {
|
||||
if (libusb_state != LIB_USB_TRANSFERS_ALLOCATED) return -1;
|
||||
|
||||
// log_info("begin usb_process_ds");
|
||||
|
@ -54,7 +54,7 @@
|
||||
#include "hci.h"
|
||||
#include "hci_transport.h"
|
||||
|
||||
static int h4_process(btstack_data_source_t *ds);
|
||||
static void h4_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type);
|
||||
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||
|
||||
typedef struct hci_transport_h4 {
|
||||
@ -122,7 +122,7 @@ static void h4_register_packet_handler(void (*handler)(uint8_t packet_type, ui
|
||||
packet_handler = handler;
|
||||
}
|
||||
|
||||
static int h4_process(btstack_data_source_t *ds) {
|
||||
static void h4_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type) {
|
||||
if (hci_transport_h4->ds->fd == 0) return -1;
|
||||
|
||||
// read up to bytes_to_read data in
|
||||
|
@ -368,7 +368,7 @@ uint8_t ll_set_scan_enable(uint8_t le_scan_enable, uint8_t filter_duplicates){
|
||||
}
|
||||
}
|
||||
|
||||
static int transport_run(btstack_data_source_t * ds){
|
||||
static void transport_run(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
|
||||
// deliver hci packet on main thread
|
||||
if (hci_outgoing_event_ready){
|
||||
hci_outgoing_event_ready = 0;
|
||||
|
@ -58,13 +58,23 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Callback types for run loop data sources
|
||||
*/
|
||||
typedef enum {
|
||||
DATA_SOURCE_CALLBACK_POLL = 1 << 0,
|
||||
DATA_SOURCE_CALLBACK_READ = 1 << 1,
|
||||
DATA_SOURCE_CALLBACK_WRITE = 1 << 2,
|
||||
} btstack_data_source_callback_type_t;
|
||||
|
||||
typedef struct btstack_data_source {
|
||||
//
|
||||
btstack_linked_item_t item;
|
||||
// file descriptor to watch for run loops that support file descriptors
|
||||
int fd;
|
||||
// callback to call for enabled callback types
|
||||
int (*process)(struct btstack_data_source *ds);
|
||||
void (*process)(struct btstack_data_source *ds, btstack_data_source_callback_type_t callback_type);
|
||||
// flags storing enabled callback types
|
||||
uint16_t flags;
|
||||
} btstack_data_source_t;
|
||||
@ -82,7 +92,6 @@ typedef struct btstack_timer_source {
|
||||
void * context;
|
||||
} btstack_timer_source_t;
|
||||
|
||||
//
|
||||
typedef struct btstack_run_loop {
|
||||
void (*init)(void);
|
||||
void (*add_data_source)(btstack_data_source_t *dataSource);
|
||||
@ -99,15 +108,6 @@ void btstack_run_loop_timer_dump(void);
|
||||
|
||||
/* API_START */
|
||||
|
||||
/**
|
||||
* possible callback types for run loop data sources
|
||||
*/
|
||||
typedef enum {
|
||||
DATA_SOURCE_CALLBACK_POLL = 1 << 0,
|
||||
DATA_SOURCE_CALLBACK_READ = 1 << 1,
|
||||
DATA_SOURCE_CALLBACK_WRITE = 1 << 2,
|
||||
} btstack_data_source_callback_type_t;
|
||||
|
||||
/**
|
||||
* @brief Init main run loop. Must be called before any other run loop call.
|
||||
*
|
||||
@ -154,7 +154,7 @@ uint32_t btstack_run_loop_get_time_ms(void);
|
||||
/**
|
||||
* @brief Set data source callback.
|
||||
*/
|
||||
void btstack_run_loop_set_data_source_handler(btstack_data_source_t *ds, int (*process)(btstack_data_source_t *_ds));
|
||||
void btstack_run_loop_set_data_source_handler(btstack_data_source_t *ds, void (*process)(btstack_data_source_t *_ds, btstack_data_source_callback_type_t callback_type));
|
||||
|
||||
/**
|
||||
* @brief Set data source file descriptor.
|
||||
|
Loading…
x
Reference in New Issue
Block a user