runloop: enable callback for all data sources

This commit is contained in:
Matthias Ringwald 2016-03-24 22:12:50 +01:00
parent 80edae71fb
commit 24ced5a6f6
14 changed files with 35 additions and 19 deletions

View File

@ -172,6 +172,7 @@ connection_t * socket_connection_register_new_connection(int fd){
btstack_run_loop_set_data_source_handler(&conn->ds, &socket_connection_hci_process);
btstack_run_loop_set_data_source_fd(&conn->ds, fd);
btstack_run_loop_enable_data_source_callbacks(&conn->ds, DATA_SOURCE_CALLBACK_READ);
// prepare state machine and
socket_connection_init_statemachine(conn);
@ -311,10 +312,10 @@ int socket_connection_create_tcp(int port){
btstack_data_source_t *ds = malloc( sizeof(btstack_data_source_t));
if (ds == NULL) return -1;
memset(ds, 0, sizeof(btstack_data_source_t));
btstack_run_loop_set_data_source_handler(ds, &socket_connection_accept);
// create tcp socket
if ((ds->fd = socket (PF_INET, SOCK_STREAM, 0)) < 0) {
int fd = socket (PF_INET, SOCK_STREAM, 0);
if (fd < 0) {
log_error("Error creating socket ...(%s)", strerror(errno));
free(ds);
return -1;
@ -328,20 +329,23 @@ int socket_connection_create_tcp(int port){
memset (&addr.sin_addr, 0, sizeof (addr.sin_addr));
const int y = 1;
setsockopt(ds->fd, SOL_SOCKET, SO_REUSEADDR, (void*) &y, sizeof(int));
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void*) &y, sizeof(int));
if (bind ( ds->fd, (struct sockaddr *) &addr, sizeof (addr) ) ) {
if (bind ( fd, (struct sockaddr *) &addr, sizeof (addr) ) ) {
log_error("Error on bind() ...(%s)", strerror(errno));
free(ds);
return -1;
}
if (listen (ds->fd, MAX_PENDING_CONNECTIONS)) {
if (listen (fd, MAX_PENDING_CONNECTIONS)) {
log_error("Error on listen() ...(%s)", strerror(errno));
free(ds);
return -1;
}
btstack_run_loop_set_data_source_fd(ds, fd);
btstack_run_loop_set_data_source_handler(ds, &socket_connection_accept);
btstack_run_loop_enable_data_source_callbacks(ds, DATA_SOURCE_CALLBACK_READ);
btstack_run_loop_add_data_source(ds);
log_info ("Server up and running ...");
@ -366,8 +370,9 @@ void socket_connection_launchd_register_fd_array(launch_data_t listening_fd_arra
btstack_data_source_t *ds = malloc( sizeof(btstack_data_source_t));
if (ds == NULL) return;
memset(ds, 0, sizeof(btstack_data_source_t));
btstack_run_loop_set_data_source_handler(ds, &socket_connection_accept);
btstack_run_loop_set_data_source_fd(ds, listening_fd);
btstack_run_loop_set_data_source_handler(ds, &socket_connection_accept);
btstack_run_loop_enable_data_source_callbacks(ds, DATA_SOURCE_CALLBACK_READ);
btstack_run_loop_add_data_source(ds);
}
}
@ -453,7 +458,6 @@ int socket_connection_create_unix(char *path){
btstack_data_source_t *ds = malloc( sizeof(btstack_data_source_t));
if (ds == NULL) return -1;
memset(ds, 0, sizeof(btstack_data_source_t));
btstack_run_loop_set_data_source_handler(ds, &socket_connection_accept);
// create unix socket
int fd = socket (AF_UNIX, SOCK_STREAM, 0);
@ -462,7 +466,6 @@ int socket_connection_create_unix(char *path){
free(ds);
return -1;
}
btstack_run_loop_set_data_source_fd(ds, fd);
log_info ("Socket created at %s", path);
struct sockaddr_un addr;
@ -491,6 +494,9 @@ int socket_connection_create_unix(char *path){
return -1;
}
btstack_run_loop_set_data_source_fd(ds, fd);
btstack_run_loop_set_data_source_handler(ds, &socket_connection_accept);
btstack_run_loop_enable_data_source_callbacks(ds, DATA_SOURCE_CALLBACK_READ);
btstack_run_loop_add_data_source(ds);
log_info ("Server up and running ...");

View File

@ -192,6 +192,7 @@ static int h4_open(void){
// set up data_source
btstack_run_loop_set_data_source_handler(&hci_transport_h4_dma_ds, &h4_process);
btstack_run_loop_enable_data_source_callbacks(&hci_transport_h4_dma_ds, DATA_SOURCE_CALLBACK_POLL);
btstack_run_loop_add_data_source(&hci_transport_h4_dma_ds);
// init state machines

View File

@ -144,6 +144,7 @@ static int h4_open(void){
// set up data_source
btstack_run_loop_set_data_source_handler(&hci_transport_h4_dma_ds, &h4_process);
btstack_run_loop_enable_data_source_callbacks(&hci_transport_h4_dma_ds, DATA_SOURCE_CALLBACK_POLL);
btstack_run_loop_add_data_source(&hci_transport_h4_dma_ds);
//

View File

@ -214,6 +214,7 @@ static int h4_open(void){
hci_transport_h4->uart_fd = fd;
btstack_run_loop_set_data_source_fd(hci_transport_h4->ds, fd);
btstack_run_loop_set_data_source_handler(hci_transport_h4->ds, &h4_process);
btstack_run_loop_enable_data_source_callbacks(hci_transport_h4->ds, DATA_SOURCE_CALLBACK_READ);
btstack_run_loop_add_data_source(hci_transport_h4->ds);
// also set baudrate

View File

@ -610,8 +610,9 @@ static int hci_transport_h5_open(void){
}
// set up data_source
hci_transport_h5_data_source.fd = fd;
hci_transport_h5_data_source.process = &hci_transport_h5_process;
btstack_run_loop_set_data_source_fd(&hci_transport_h5_data_source, fd);
btstack_run_loop_set_data_source_handler(&hci_transport_h5_data_source, &hci_transport_h5_process);
btstack_run_loop_enable_data_source_callbacks(&hci_transport_h5_data_source, DATA_SOURCE_CALLBACK_READ);
btstack_run_loop_add_data_source(&hci_transport_h5_data_source);
// also set baudrate
@ -652,8 +653,8 @@ static int hci_transport_h5_close(void){
return 0;
}
static int hci_transport_h5_process(btstack_data_source_t *ds) {
if (hci_transport_h5_data_source.fd < 0) return -1;
static void hci_transport_h5_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type) {
if (hci_transport_h5_data_source.fd < 0) return;
// process data byte by byte
uint8_t data;
@ -668,8 +669,8 @@ static int hci_transport_h5_process(btstack_data_source_t *ds) {
hci_transport_slip_init();
}
};
return 0;
}
// get h5 singleton
const hci_transport_t * hci_transport_h5_instance() {
if (hci_transport_h5 == NULL) {

View File

@ -49,7 +49,7 @@
static btstack_data_source_t stdin_source;
static int activated = 0;
void btstack_stdin_setup(int (*stdin_process)(btstack_data_source_t *_ds)){
void btstack_stdin_setup(void (*stdin_process)(btstack_data_source_t *_ds, btstack_data_source_callback_type_t callback_type)){
#ifndef _WIN32
struct termios term = {0};
@ -64,6 +64,7 @@ void btstack_stdin_setup(int (*stdin_process)(btstack_data_source_t *_ds)){
btstack_run_loop_set_data_source_fd(&stdin_source, 0); // stdin
btstack_run_loop_set_data_source_handler(&stdin_source, stdin_process);
btstack_run_loop_enable_data_source_callbacks(&stdin_source, DATA_SOURCE_CALLBACK_READ);
btstack_run_loop_add_data_source(&stdin_source);
activated = 1;

View File

@ -45,7 +45,7 @@ extern "C" {
#endif
// setup handler for command line interface
void btstack_stdin_setup(int (*stdin_handler)(btstack_data_source_t *_ds));
void btstack_stdin_setup(void (*stdin_handler)(btstack_data_source_t *_ds, btstack_data_source_callback_type_t callback_type));
// gets called by main.c
void btstack_stdin_reset(void);

View File

@ -746,6 +746,7 @@ void iphone_register_for_power_notifications(void (*cb)(POWER_NOTIFICATION_t eve
// set up data source handler
btstack_run_loop_set_data_source_fd(&power_notification_ds, power_notification_pipe_fds[0]); // stdin
btstack_run_loop_set_data_source_handler(&power_notification_ds, &power_notification_process);
btstack_run_loop_enable_data_source_callbacks(&power_notification_ds, DATA_SOURCE_CALLBACK_READ);
btstack_run_loop_add_data_source(&power_notification_ds);
}

View File

@ -227,6 +227,7 @@ static int h4_open(void)
memset(hci_transport_h4->ds, 0, sizeof(btstack_data_source_t));
btstack_run_loop_set_data_source_fd(hci_transport_h4->ds, fd);
btstack_run_loop_set_data_source_handler(hci_transport_h4->ds, &h4_process);
btstack_run_loop_enable_data_source_callbacks(hci_transport_h4->ds, DATA_SOURCE_CALLBACK_READ);
btstack_run_loop_add_data_source(hci_transport_h4->ds);
// init state machine

View File

@ -844,6 +844,7 @@ static int usb_open(void){
btstack_data_source_t *ds = &pollfd_data_sources[r];
btstack_run_loop_set_data_source_fd(ds, pollfd[r]->fd);
btstack_run_loop_set_data_source_handler(ds, &usb_process_ds);
btstack_run_loop_enable_data_source_callbacks(ds, DATA_SOURCE_CALLBACK_READ);
btstack_run_loop_add_data_source(ds);
log_info("%u: %p fd: %u, events %x", r, pollfd[r], pollfd[r]->fd, pollfd[r]->events);
}

View File

@ -87,6 +87,7 @@ static int h4_open(void){
memset(hci_transport_h4->ds, 0, sizeof(btstack_data_source_t));
btstack_run_loop_set_data_source_fd(hci_transport_h4->ds, fd);
btstack_run_loop_set_data_source_handler(hci_transport_h4->ds, &h4_process);
btstack_run_loop_enable_data_source_callbacks(hci_transport_h4->ds, DATA_SOURCE_CALLBACK_READ);
btstack_run_loop_add_data_source(hci_transport_h4->ds);
return 0;
}

View File

@ -392,6 +392,7 @@ void transport_init(const void *transport_config){
*/
static int transport_open(void){
btstack_run_loop_set_data_source_handler(&hci_transport_data_source, &transport_run);
btstack_run_loop_enable_data_source_callbacks(&hci_transport_data_source, DATA_SOURCE_CALLBACK_POLL);
btstack_run_loop_add_data_source(&hci_transport_data_source);
return 0;
}

View File

@ -79,10 +79,10 @@ int btstack_run_loop_get_data_source_fd(btstack_data_source_t *ds){
return ds->fd;
}
void btstack_run_loop_enable_data_source_callback(btstack_data_source_t *data_source, uint16_t callbacks){
void btstack_run_loop_enable_data_source_callbacks(btstack_data_source_t *data_source, uint16_t callbacks){
}
void btstack_run_loop_disable_data_source_callback(btstack_data_source_t *data_source, uint16_t callbacks){
void btstack_run_loop_disable_data_source_callbacks(btstack_data_source_t *data_source, uint16_t callbacks){
}
/**

View File

@ -175,14 +175,14 @@ int btstack_run_loop_get_data_source_fd(btstack_data_source_t * data_source);
* @param data_source to remove
* @param callback types to enable
*/
void btstack_run_loop_enable_data_source_callback(btstack_data_source_t * data_source, uint16_t callbacks);
void btstack_run_loop_enable_data_source_callbacks(btstack_data_source_t * data_source, uint16_t callbacks);
/**
* @brief Enable callbacks for a data source
* @param data_source to remove
* @param callback types to disable
*/
void btstack_run_loop_disable_data_source_callback(btstack_data_source_t * data_source, uint16_t callbacks);
void btstack_run_loop_disable_data_source_callbacks(btstack_data_source_t * data_source, uint16_t callbacks);
/**
* @brief Add data source to run loop