mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-25 09:35:42 +00:00
runloop: add data source callback type to ds handler
This commit is contained in:
parent
f912b310ca
commit
896424b78e
@ -92,7 +92,7 @@ struct sockaddr_un {
|
||||
#define MAX_PENDING_CONNECTIONS 10
|
||||
|
||||
/** prototypes */
|
||||
static int socket_connection_hci_process(btstack_data_source_t *ds);
|
||||
static void socket_connection_hci_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type);
|
||||
static int socket_connection_dummy_handler(connection_t *connection, uint16_t packet_type, uint16_t channel, uint8_t *data, uint16_t length);
|
||||
|
||||
/** globals */
|
||||
@ -170,8 +170,8 @@ connection_t * socket_connection_register_new_connection(int fd){
|
||||
// store reference from linked item to base object
|
||||
conn->linked_connection.connection = conn;
|
||||
|
||||
conn->ds.fd = fd;
|
||||
conn->ds.process = socket_connection_hci_process;
|
||||
btstack_run_loop_set_data_source_handler(&conn->ds, &socket_connection_hci_process);
|
||||
btstack_run_loop_set_data_source_fd(&conn->ds, fd);
|
||||
|
||||
// prepare state machine and
|
||||
socket_connection_init_statemachine(conn);
|
||||
@ -197,7 +197,7 @@ void static socket_connection_emit_connection_closed(connection_t *connection){
|
||||
(*socket_connection_packet_callback)(connection, DAEMON_EVENT_PACKET, 0, (uint8_t *) &event, 1);
|
||||
}
|
||||
|
||||
int socket_connection_hci_process(btstack_data_source_t *ds) {
|
||||
void socket_connection_hci_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type) {
|
||||
connection_t *conn = (connection_t *) ds;
|
||||
int fd = btstack_run_loop_get_data_source_fd(ds);
|
||||
int bytes_read = read(fd, &conn->buffer[conn->bytes_read], conn->bytes_to_read);
|
||||
@ -208,13 +208,11 @@ int socket_connection_hci_process(btstack_data_source_t *ds) {
|
||||
// free connection
|
||||
socket_connection_free_connection(conn);
|
||||
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
conn->bytes_read += bytes_read;
|
||||
conn->bytes_to_read -= bytes_read;
|
||||
if (conn->bytes_to_read > 0) {
|
||||
return 0;
|
||||
}
|
||||
if (conn->bytes_to_read > 0) return;
|
||||
|
||||
int dispatch = 0;
|
||||
switch (conn->state){
|
||||
@ -247,7 +245,6 @@ int socket_connection_hci_process(btstack_data_source_t *ds) {
|
||||
btstack_linked_list_add_tail(&parked, (btstack_linked_item_t *) ds);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -285,13 +282,13 @@ int socket_connection_has_parked_connections(void){
|
||||
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);
|
||||
int socket_fd = btstack_run_loop_get_data_source_fd(socket_ds);
|
||||
|
||||
/* New connection coming in! */
|
||||
int fd = accept(socket_fd, (struct sockaddr *)&ss, &slen);
|
||||
if (fd < 0) {
|
||||
perror("accept");
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// no sigpipe
|
||||
@ -301,8 +298,6 @@ static void socket_connection_accept(btstack_data_source_t *socket_ds, btstack_d
|
||||
|
||||
connection_t * connection = socket_connection_register_new_connection(fd);
|
||||
socket_connection_emit_connection_opened(connection);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -461,7 +456,7 @@ int socket_connection_create_unix(char *path){
|
||||
btstack_run_loop_set_data_source_handler(ds, &socket_connection_accept);
|
||||
|
||||
// create unix socket
|
||||
int fd = socket (AF_UNIX, SOCK_STREAM, 0));
|
||||
int fd = socket (AF_UNIX, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
log_error( "Error creating socket ...(%s)", strerror(errno));
|
||||
free(ds);
|
||||
|
@ -67,7 +67,7 @@ void btstack_run_loop_set_timer_handler(btstack_timer_source_t *ts, void (*proce
|
||||
ts->process = process;
|
||||
};
|
||||
|
||||
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)){
|
||||
ds->process = process;
|
||||
};
|
||||
|
||||
@ -79,6 +79,11 @@ 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_disable_data_source_callback(btstack_data_source_t *data_source, uint16_t callbacks){
|
||||
}
|
||||
|
||||
/**
|
||||
* Add data_source to run_loop
|
||||
|
@ -118,32 +118,32 @@ void btstack_run_loop_init(const btstack_run_loop_t * run_loop);
|
||||
/**
|
||||
* @brief Set timer based on current time in milliseconds.
|
||||
*/
|
||||
void btstack_run_loop_set_timer(btstack_timer_source_t *a, uint32_t timeout_in_ms);
|
||||
void btstack_run_loop_set_timer(btstack_timer_source_t * ts, uint32_t timeout_in_ms);
|
||||
|
||||
/**
|
||||
* @brief Set callback that will be executed when timer expires.
|
||||
*/
|
||||
void btstack_run_loop_set_timer_handler(btstack_timer_source_t *ts, void (*process)(btstack_timer_source_t *_ts));
|
||||
void btstack_run_loop_set_timer_handler(btstack_timer_source_t * ts, void (*process)(btstack_timer_source_t *_ts));
|
||||
|
||||
/**
|
||||
* @brief Set context for this timer
|
||||
*/
|
||||
void btstack_run_loop_set_timer_context(btstack_timer_source_t *ts, void * context);
|
||||
void btstack_run_loop_set_timer_context(btstack_timer_source_t * ts, void * context);
|
||||
|
||||
/**
|
||||
* @brief Get context for this timer
|
||||
*/
|
||||
void * btstack_run_loop_get_timer_context(btstack_timer_source_t *ts);
|
||||
void * btstack_run_loop_get_timer_context(btstack_timer_source_t * ts);
|
||||
|
||||
/**
|
||||
* @brief Add timer source.
|
||||
*/
|
||||
void btstack_run_loop_add_timer(btstack_timer_source_t *timer);
|
||||
void btstack_run_loop_add_timer(btstack_timer_source_t * timer);
|
||||
|
||||
/**
|
||||
* @brief Remove timer source.
|
||||
*/
|
||||
int btstack_run_loop_remove_timer(btstack_timer_source_t *timer);
|
||||
int btstack_run_loop_remove_timer(btstack_timer_source_t * timer);
|
||||
|
||||
/**
|
||||
* @brief Get current time in ms
|
||||
@ -154,24 +154,47 @@ 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, void (*process)(btstack_data_source_t *_ds, btstack_data_source_callback_type_t callback_type));
|
||||
void btstack_run_loop_set_data_source_handler(btstack_data_source_t * data_source, void (*process)(btstack_data_source_t *_ds, btstack_data_source_callback_type_t callback_type));
|
||||
|
||||
/**
|
||||
* @brief Set data source file descriptor.
|
||||
* @param data_source
|
||||
* @param fd file descriptor
|
||||
* @note No effect if port doensn't have file descriptors
|
||||
*/
|
||||
void btstack_run_loop_set_data_source_fd(btstack_data_source_t *ds, int fd);
|
||||
void btstack_run_loop_set_data_source_fd(btstack_data_source_t * data_source, int fd);
|
||||
|
||||
/**
|
||||
* @brief Get data source file descriptor.
|
||||
* @param data_source
|
||||
*/
|
||||
int btstack_run_loop_get_data_source_fd(btstack_data_source_t *ds);
|
||||
int btstack_run_loop_get_data_source_fd(btstack_data_source_t * data_source);
|
||||
|
||||
/**
|
||||
* @brief Add/Remove data source.
|
||||
* @brief Enable callbacks for a data source
|
||||
* @param data_source to remove
|
||||
* @param callback types to enable
|
||||
*/
|
||||
void btstack_run_loop_add_data_source(btstack_data_source_t *dataSource);
|
||||
int btstack_run_loop_remove_data_source(btstack_data_source_t *dataSource);
|
||||
void btstack_run_loop_enable_data_source_callback(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);
|
||||
|
||||
/**
|
||||
* @brief Add data source to run loop
|
||||
* @param data_source to add
|
||||
*/
|
||||
void btstack_run_loop_add_data_source(btstack_data_source_t * data_source);
|
||||
|
||||
/**
|
||||
* @brief Remove data source from run loop
|
||||
* @param data_source to remove
|
||||
*/
|
||||
int btstack_run_loop_remove_data_source(btstack_data_source_t * data_source);
|
||||
|
||||
/**
|
||||
* @brief Execute configured run loop. This function does not return.
|
||||
|
Loading…
x
Reference in New Issue
Block a user