Пример #1
0
static void hfp_run(){
    linked_list_iterator_t it;    
    linked_list_iterator_init(&it, hfp_get_connections());
    while (linked_list_iterator_has_next(&it)){
        hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
        hfp_run_for_context(connection);
    }
}
Пример #2
0
static hfp_connection_t * get_hfp_connection_context_for_handle(uint16_t handle){
    linked_list_iterator_t it;    
    linked_list_iterator_init(&it, hfp_get_connections());
    while (linked_list_iterator_has_next(&it)){
        hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
        if (connection->con_handle == handle){
            return connection;
        }
    }
    return NULL;
}
Пример #3
0
hfp_connection_t * get_hfp_connection_context_for_bd_addr(bd_addr_t bd_addr){
    linked_list_iterator_t it;  
    linked_list_iterator_init(&it, hfp_get_connections());
    while (linked_list_iterator_has_next(&it)){
        hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
        if (memcmp(connection->remote_addr, bd_addr, 6) == 0) {
            return connection;
        }
    }
    return NULL;
}
Пример #4
0
hfp_connection_t * get_hfp_connection_context_for_rfcomm_cid(uint16_t cid){
    linked_list_iterator_t it;    
    linked_list_iterator_init(&it, hfp_get_connections());
    while (linked_list_iterator_has_next(&it)){
        hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
        if (connection->rfcomm_cid == cid){
            return connection;
        }
    }
    return NULL;
}
Пример #5
0
/**
 * @brief 
 */
void hfp_ag_terminate_call(void){

    linked_list_iterator_t it;    
    linked_list_iterator_init(&it, hfp_get_connections());
    while (linked_list_iterator_has_next(&it)){
        hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
        hfp_ag_establish_service_level_connection(connection->remote_addr);
        connection->terminate_call = 1;
        hfp_run_for_context(connection);
    }
}
Пример #6
0
/**
 * @brief 
 */
void hfp_ag_incoming_call(void){
    linked_list_iterator_t it;    
    linked_list_iterator_init(&it, hfp_get_connections());
    while (linked_list_iterator_has_next(&it)){
        hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
        hfp_ag_establish_service_level_connection(connection->remote_addr);
        connection->use_in_band_ring_tone = hfp_ag_use_in_band_ring_tone;
        connection->run_call_state_machine = 1;
        hfp_run_for_context(connection);
    }
}
Пример #7
0
/**
 * Execute run_loop
 */
static void posix_execute(void) {
    fd_set descriptors;
    
    timer_source_t       *ts;
    struct timeval current_tv;
    struct timeval next_tv;
    struct timeval *timeout;
    linked_list_iterator_t it;
    
    while (1) {
        // collect FDs
        FD_ZERO(&descriptors);
        int highest_fd = 0;
        linked_list_iterator_init(&it, &data_sources);
        while (linked_list_iterator_has_next(&it)){
            data_source_t *ds = (data_source_t*) linked_list_iterator_next(&it);
            if (ds->fd >= 0) {
                FD_SET(ds->fd, &descriptors);
                if (ds->fd > highest_fd) {
                    highest_fd = ds->fd;
                }
            }
        }
        
        // get next timeout
        // pre: 0 <= tv_usec < 1000000
        timeout = NULL;
        if (timers) {
            gettimeofday(&current_tv, NULL);
            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){
                next_tv.tv_usec += 1000000;
                next_tv.tv_sec--;
            }
            if (next_tv.tv_sec < 0){
                next_tv.tv_sec  = 0; 
                next_tv.tv_usec = 0;
            }
            timeout = &next_tv;
        }
                
        // wait for ready FDs
        select( highest_fd+1 , &descriptors, NULL, NULL, timeout);
        
        // process data sources very carefully
        // bt_control.close() triggered from a client can remove a different data source
        
        // log_info("posix_execute: before ds check\n");
        data_sources_modified = 0;
        linked_list_iterator_init(&it, &data_sources);
        while (linked_list_iterator_has_next(&it) && !data_sources_modified){
            data_source_t *ds = (data_source_t*) linked_list_iterator_next(&it);
            // log_info("posix_execute: check %x with fd %u\n", (int) ds, ds->fd);
            if (FD_ISSET(ds->fd, &descriptors)) {
                // log_info("posix_execute: process %x with fd %u\n", (int) ds, ds->fd);
                ds->process(ds);
            }
        }
        // log_info("posix_execute: after ds check\n");
        
        // process timers
        // pre: 0 <= tv_usec < 1000000
        while (timers) {
            gettimeofday(&current_tv, NULL);
            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;
            // log_info("posix_execute: process times %x\n", (int) ts);
            
            // remove timer before processing it to allow handler to re-register with run loop
            run_loop_remove_timer(ts);
            ts->process(ts);
        }
    }
}