Ignore:
File:
1 edited

Legend:

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

    r3e4f2e0 r563d9d0a  
    3535
    3636#include <assert.h>
     37#include <stdlib.h>
    3738#include <errno.h>
    3839#include <usb/host/endpoint.h>
    3940
    40 int endpoint_init(endpoint_t *instance, usb_address_t address,
    41     usb_endpoint_t endpoint, usb_direction_t direction,
    42     usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size)
     41endpoint_t * endpoint_get(usb_address_t address, usb_endpoint_t endpoint,
     42    usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed,
     43    size_t max_packet_size)
    4344{
    44         assert(instance);
    45         instance->address = address;
    46         instance->endpoint = endpoint;
    47         instance->direction = direction;
    48         instance->transfer_type = type;
    49         instance->speed = speed;
    50         instance->max_packet_size = max_packet_size;
    51         instance->toggle = 0;
    52         instance->active = false;
    53         fibril_mutex_initialize(&instance->guard);
    54         fibril_condvar_initialize(&instance->avail);
    55         endpoint_clear_hc_data(instance);
    56         return EOK;
     45        endpoint_t *instance = malloc(sizeof(endpoint_t));
     46        if (instance) {
     47                instance->address = address;
     48                instance->endpoint = endpoint;
     49                instance->direction = direction;
     50                instance->transfer_type = type;
     51                instance->speed = speed;
     52                instance->max_packet_size = max_packet_size;
     53                instance->toggle = 0;
     54                instance->active = false;
     55                instance->destroy_hook = NULL;
     56                instance->hc_data.data = NULL;
     57                instance->hc_data.toggle_get = NULL;
     58                instance->hc_data.toggle_set = NULL;
     59                fibril_mutex_initialize(&instance->guard);
     60                fibril_condvar_initialize(&instance->avail);
     61                endpoint_clear_hc_data(instance);
     62        }
     63        return instance;
    5764}
    5865/*----------------------------------------------------------------------------*/
     
    6168        assert(instance);
    6269        assert(!instance->active);
     70        if (instance->hc_data.data) {
     71                assert(instance->destroy_hook);
     72                instance->destroy_hook(instance);
     73        }
    6374        free(instance);
    6475}
    6576/*----------------------------------------------------------------------------*/
    6677void endpoint_set_hc_data(endpoint_t *instance,
    67     void *data, int (*toggle_get)(void *), void (*toggle_set)(void *, int))
     78    void *data, void (*destroy_hook)(endpoint_t *),
     79    int (*toggle_get)(void *), void (*toggle_set)(void *, int))
    6880{
    6981        assert(instance);
     82        instance->destroy_hook = destroy_hook;
    7083        instance->hc_data.data = data;
    7184        instance->hc_data.toggle_get = toggle_get;
     
    7689{
    7790        assert(instance);
     91        instance->destroy_hook = NULL;
    7892        instance->hc_data.data = NULL;
    7993        instance->hc_data.toggle_get = NULL;
Note: See TracChangeset for help on using the changeset viewer.