Ignore:
Timestamp:
2011-04-06T21:12:41Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade
Children:
f567bcf
Parents:
1e70157
Message:

Move endpoint_t to libusb

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/host/usb_endpoint_manager.c

    r1e70157 r8dc762e0  
    4848        link_t link;
    4949        size_t bw;
    50         void *data;
    51         void (*data_remove_callback)(void* data);
    52 } ep_t;
    53 /*----------------------------------------------------------------------------*/
    54 static hash_index_t ep_hash(unsigned long key[])
     50        endpoint_t *ep;
     51} node_t;
     52/*----------------------------------------------------------------------------*/
     53static hash_index_t node_hash(unsigned long key[])
    5554{
    5655        hash_index_t hash = 0;
     
    6362}
    6463/*----------------------------------------------------------------------------*/
    65 static int ep_compare(unsigned long key[], hash_count_t keys, link_t *item)
     64static int node_compare(unsigned long key[], hash_count_t keys, link_t *item)
    6665{
    6766        assert(item);
    68         ep_t *ep = hash_table_get_instance(item, ep_t, link);
     67        node_t *node = hash_table_get_instance(item, node_t, link);
    6968        hash_count_t i = 0;
    7069        for (; i < keys; ++i) {
    71                 if (key[i] != ep->key[i])
     70                if (key[i] != node->key[i])
    7271                        return false;
    7372        }
     
    7574}
    7675/*----------------------------------------------------------------------------*/
    77 static void ep_remove(link_t *item)
     76static void node_remove(link_t *item)
    7877{
    7978        assert(item);
    80         ep_t *ep =
    81             hash_table_get_instance(item, ep_t, link);
    82         ep->data_remove_callback(ep->data);
    83         free(ep);
     79        node_t *node = hash_table_get_instance(item, node_t, link);
     80        endpoint_destroy(node->ep);
     81        free(node);
    8482}
    8583/*----------------------------------------------------------------------------*/
    8684static hash_table_operations_t op = {
    87         .hash = ep_hash,
    88         .compare = ep_compare,
    89         .remove_callback = ep_remove,
     85        .hash = node_hash,
     86        .compare = node_compare,
     87        .remove_callback = node_remove,
    9088};
    9189/*----------------------------------------------------------------------------*/
     
    145143int usb_endpoint_manager_register_ep(usb_endpoint_manager_t *instance,
    146144    usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
    147     void *data, void (*data_remove_callback)(void* data), size_t bw)
    148 {
     145    endpoint_t *ep, size_t data_size)
     146{
     147        assert(ep);
     148        size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
     149            data_size, ep->max_packet_size);
    149150        assert(instance);
    150151
     
    168169        }
    169170
    170         ep_t *ep = malloc(sizeof(ep_t));
    171         if (ep == NULL) {
     171        node_t *node = malloc(sizeof(node_t));
     172        if (node == NULL) {
    172173                fibril_mutex_unlock(&instance->guard);
    173174                return ENOMEM;
    174175        }
    175176
    176         ep->id = id;
    177         ep->bw = bw;
    178         ep->data = data;
    179         link_initialize(&ep->link);
    180 
    181         hash_table_insert(&instance->ep_table, (unsigned long*)&id, &ep->link);
     177        node->id = id;
     178        node->bw = bw;
     179        node->ep = ep;
     180        link_initialize(&node->link);
     181
     182        hash_table_insert(&instance->ep_table,
     183            (unsigned long*)&id, &node->link);
    182184        instance->free_bw -= bw;
    183185        fibril_mutex_unlock(&instance->guard);
     
    203205        }
    204206
    205         ep_t *ep = hash_table_get_instance(item, ep_t, link);
    206         instance->free_bw += ep->bw;
     207        node_t *node = hash_table_get_instance(item, node_t, link);
     208        instance->free_bw += node->bw;
    207209        hash_table_remove(&instance->ep_table, (unsigned long*)&id, MAX_KEYS);
    208210
     
    212214}
    213215/*----------------------------------------------------------------------------*/
    214 void * usb_endpoint_manager_get_ep_data(usb_endpoint_manager_t *instance,
     216endpoint_t * usb_endpoint_manager_get_ep(usb_endpoint_manager_t *instance,
    215217    usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
    216218    size_t *bw)
     
    229231                return NULL;
    230232        }
    231         ep_t *ep = hash_table_get_instance(item, ep_t, link);
     233        node_t *node = hash_table_get_instance(item, node_t, link);
    232234        if (bw)
    233                 *bw = ep->bw;
     235                *bw = node->bw;
    234236
    235237        fibril_mutex_unlock(&instance->guard);
    236         return ep->data;
    237 }
     238        return node->ep;
     239}
Note: See TracChangeset for help on using the changeset viewer.