Changeset 48ae3ef in mainline for uspace/lib/usbhost/src/iface.c


Ignore:
Timestamp:
2011-10-28T21:52:15Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
57e06ef
Parents:
7265558
Message:

libusbhost: Make interfaces more symmetric.

Make usb_endpoint_manager interface easier to use and understand.
Move ep removal hook pointer from endpoint_t to hcd_t.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/iface.c

    r7265558 r48ae3ef  
    4949        assert(hcd);
    5050
    51         endpoint_t *ep = usb_endpoint_manager_get_ep(&hcd->ep_manager,
     51        endpoint_t *ep = usb_endpoint_manager_find_ep(&hcd->ep_manager,
    5252            target.address, target.endpoint, direction);
    5353        if (ep == NULL) {
     
    165165}
    166166/*----------------------------------------------------------------------------*/
     167static int register_helper(endpoint_t *ep, void *arg)
     168{
     169        hcd_t *hcd = arg;
     170        assert(ep);
     171        assert(hcd);
     172        if (hcd->ep_add_hook)
     173                return hcd->ep_add_hook(hcd, ep);
     174        return EOK;
     175}
     176/*----------------------------------------------------------------------------*/
     177static void unregister_helper(endpoint_t *ep, void *arg)
     178{
     179        hcd_t *hcd = arg;
     180        assert(ep);
     181        assert(hcd);
     182        if (hcd->ep_remove_hook)
     183                hcd->ep_remove_hook(hcd, ep);
     184}
     185/*----------------------------------------------------------------------------*/
    167186static int register_endpoint(
    168187    ddf_fun_t *fun, usb_address_t address, usb_speed_t ep_speed,
     
    188207            max_packet_size, interval);
    189208
    190         endpoint_t *ep =
    191             endpoint_create(address, endpoint, direction, transfer_type,
    192                 speed, max_packet_size, 0);
    193         if (!ep)
    194                 return ENOMEM;
    195 
    196         if (hcd->ep_add_hook) {
    197                 const int ret = hcd->ep_add_hook(hcd, ep);
    198                 if (ret != EOK) {
    199                         endpoint_destroy(ep);
    200                         return ret;
    201                 }
    202         }
    203 
    204         const int ret =
    205             usb_endpoint_manager_register_ep(&hcd->ep_manager, ep, size);
    206         if (ret != EOK) {
    207                 endpoint_destroy(ep);
    208         }
    209         return ret;
     209        return usb_endpoint_manager_add_ep(&hcd->ep_manager, address, endpoint,
     210            direction, transfer_type, speed, max_packet_size, size,
     211            register_helper, hcd);
    210212}
    211213/*----------------------------------------------------------------------------*/
     
    219221        usb_log_debug("Unregister endpoint %d:%d %s.\n",
    220222            address, endpoint, usb_str_direction(direction));
    221         return usb_endpoint_manager_unregister_ep(&hcd->ep_manager, address,
    222             endpoint, direction);
     223        return usb_endpoint_manager_remove_ep(&hcd->ep_manager, address,
     224            endpoint, direction, unregister_helper, hcd);
    223225}
    224226/*----------------------------------------------------------------------------*/
Note: See TracChangeset for help on using the changeset viewer.