Fork us on GitHub Follow us on Facebook Follow us on Twitter

Ignore:
Timestamp:
2012-08-17T11:37:03Z (9 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
1d5a540
Parents:
be2a38ad
Message:

Make ddf_dev_t and ddf_fun_t opaque. This further tighthens the DDF interface.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhid/generic/hiddev.c

    rbe2a38ad r56fd7cf  
    3535 */
    3636
     37/* XXX Fix this */
     38#define _DDF_DATA_IMPLANT
     39
    3740#include <usb/debug.h>
    3841#include <usb/classes/classes.h>
     
    8184};
    8285
     86/** Return hid_dev_t * for generic HID function node.
     87 *
     88 * For the generic HID subdriver the 'hid' function has usb_hid_gen_fun_t
     89 * as soft state. Through that we can get to the usb_hid_dev_t.
     90 */
     91static usb_hid_dev_t *fun_hid_dev(ddf_fun_t *fun)
     92{
     93        return ((usb_hid_gen_fun_t *)ddf_fun_data_get(fun))->hid_dev;
     94}
     95
    8396static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun)
    8497{
    8598        usb_log_debug2("Generic HID: Get event length (fun: %p, "
    86             "fun->driver_data: %p.\n", fun, fun->driver_data);
    87 
    88         if (fun == NULL || fun->driver_data == NULL) {
    89                 return 0;
    90         }
    91 
    92         const usb_hid_dev_t *hid_dev = fun->driver_data;
     99            "fun->driver_data: %p.\n", fun, ddf_fun_data_get(fun));
     100
     101        const usb_hid_dev_t *hid_dev = fun_hid_dev(fun);
    93102
    94103        usb_log_debug2("hid_dev: %p, Max input report size (%zu).\n",
     
    103112        usb_log_debug2("Generic HID: Get event.\n");
    104113
    105         if (fun == NULL || fun->driver_data == NULL || buffer == NULL
    106             || act_size == NULL || event_nr == NULL) {
     114        if (buffer == NULL || act_size == NULL || event_nr == NULL) {
    107115                usb_log_debug("No function");
    108116                return EINVAL;
    109117        }
    110118
    111         const usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     119        const usb_hid_dev_t *hid_dev = fun_hid_dev(fun);
    112120
    113121        if (hid_dev->input_report_size > size) {
     
    132140        usb_log_debug("Generic HID: Get report descriptor length.\n");
    133141
    134         if (fun == NULL || fun->driver_data == NULL) {
    135                 usb_log_debug("No function");
    136                 return EINVAL;
    137         }
    138 
    139         const usb_hid_dev_t *hid_dev = fun->driver_data;
     142        const usb_hid_dev_t *hid_dev = fun_hid_dev(fun);
    140143
    141144        usb_log_debug2("hid_dev->report_desc_size = %zu\n",
     
    150153        usb_log_debug2("Generic HID: Get report descriptor.\n");
    151154
    152         if (fun == NULL || fun->driver_data == NULL) {
    153                 usb_log_debug("No function");
    154                 return EINVAL;
    155         }
    156 
    157         const usb_hid_dev_t *hid_dev = fun->driver_data;
     155        const usb_hid_dev_t *hid_dev = fun_hid_dev(fun);
    158156
    159157        if (hid_dev->report_desc_size > size) {
     
    183181                return;
    184182        }
    185         usb_log_debug2("%s unbound.\n", fun->name);
    186         /* We did not allocate this, so leave this alone
    187          * the device would take care of it */
    188         fun->driver_data = NULL;
     183        usb_log_debug2("%s unbound.\n", ddf_fun_get_name(fun));
    189184        ddf_fun_destroy(fun);
    190185}
     
    192187int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data)
    193188{
     189        usb_hid_gen_fun_t *hid_fun;
     190
    194191        if (hid_dev == NULL) {
    195192                return EINVAL;
     
    205202        }
    206203
    207         /* This is nasty, both device and this function have the same
    208          * driver data, thus destruction causes to double free */
    209         fun->driver_data = hid_dev;
    210         fun->ops = &usb_generic_hid_ops;
     204        /* Create softstate */
     205        hid_fun = ddf_fun_data_alloc(fun, sizeof(usb_hid_gen_fun_t));
     206        hid_fun->hid_dev = hid_dev;
     207        ddf_fun_set_ops(fun, &usb_generic_hid_ops);
    211208
    212209        int rc = ddf_fun_bind(fun);
     
    214211                usb_log_error("Could not bind DDF function: %s.\n",
    215212                    str_error(rc));
    216                 fun->driver_data = NULL;
    217213                ddf_fun_destroy(fun);
    218214                return rc;
    219215        }
    220216
    221         usb_log_debug("HID function created. Handle: %" PRIun "\n", fun->handle);
     217        usb_log_debug("HID function created. Handle: %" PRIun "\n",
     218            ddf_fun_get_handle(fun));
    222219        *data = fun;
    223220
Note: See TracChangeset for help on using the changeset viewer.