Esempio n. 1
0
void test_linked_list(){
    linked_list_t testList = 0;
    linked_item_t itemA;
    linked_item_t itemB;
    linked_item_t itemC;
    linked_item_set_user(&itemA, (void *) 0);
    linked_item_set_user(&itemB, (void *) 0);
    linked_list_add(&testList, &itemA);
    linked_list_add(&testList, &itemB);
    linked_list_add_tail(&testList, &itemC);
    // linked_list_remove(&testList, &itemB);
    linked_item_t *it;
    for (it = (linked_item_t *) &testList; it ; it = it->next){
        if (it->next == &itemA) printf("Item A\n");
        if (it->next == &itemB) printf("Item B\n");
        if (it->next == &itemC) printf("Item C\n");
        /* if (it->next == &itemB){
            it->next =  it->next;
            printf(" remove\n");
        } else {
            printf(" keep\n");
        
         */
    }
}
Esempio n. 2
0
File: hci.c Progetto: ajsb85/ioio
/**
 * create connection for given address
 *
 * @return connection OR NULL, if no memory left
 */
static hci_connection_t * create_connection_for_addr(bd_addr_t addr){
    hci_connection_t * conn = btstack_memory_hci_connection_get();
    if (!conn) return NULL;
    BD_ADDR_COPY(conn->address, addr);
    conn->con_handle = 0xffff;
    conn->authentication_flags = AUTH_FLAGS_NONE;
    linked_item_set_user(&conn->timeout.item, conn);
    conn->timeout.process = hci_connection_timeout_handler;
    hci_connection_timestamp(conn);
    conn->acl_recombination_length = 0;
    conn->acl_recombination_pos = 0;
    conn->num_acl_packets_sent = 0;
    linked_list_add(&hci_stack.connections, (linked_item_t *) conn);
    return conn;
}
connection_t * socket_connection_register_new_connection(int fd){
    // create connection objec 
    connection_t * conn = malloc( sizeof(connection_t));
    if (conn == NULL) return 0;
    linked_item_set_user( &conn->item, conn);
    conn->ds.fd = fd;
    conn->ds.process = socket_connection_hci_process;
    
    // prepare state machine and
    socket_connection_init_statemachine(conn);
    
    // add this socket to the run_loop
    run_loop_add_data_source( &conn->ds );
    
    // and the connection list
    linked_list_add( &connections, &conn->item);
    
    return conn;
}