Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbmouse/init.c

    r79ae36dd r4a4c8bcf  
    4343#include <errno.h>
    4444
    45 // FIXME: remove this header
    46 #include <kernel/ipc/ipc_methods.h>
    47 
    4845/** Mouse polling endpoint description for boot protocol subclass. */
    4946usb_endpoint_description_t poll_endpoint_description = {
     
    5653};
    5754
    58 static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
     55/** Default handler for IPC methods not handled by DDF.
     56 *
     57 * @param fun     Device function handling the call.
     58 * @param icallid Call ID.
     59 * @param icall   Call data.
     60 *
     61 */
     62static void default_connection_handler(ddf_fun_t *fun, ipc_callid_t icallid,
     63    ipc_call_t *icall)
     64{
     65        usb_mouse_t *mouse = (usb_mouse_t *) fun->driver_data;
     66        assert(mouse != NULL);
     67       
     68        async_sess_t *callback =
     69            async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
     70       
     71        if (callback) {
     72                if (mouse->console_sess == NULL) {
     73                        mouse->console_sess = callback;
     74                        async_answer_0(icallid, EOK);
     75                } else
     76                        async_answer_0(icallid, ELIMIT);
     77        } else
     78                async_answer_0(icallid, EINVAL);
     79}
     80
    5981/** Device ops for USB mouse. */
    6082static ddf_dev_ops_t mouse_ops = {
    6183        .default_handler = default_connection_handler
    6284};
    63 
    64 /** Default handler for IPC methods not handled by DDF.
    65  *
    66  * @param fun Device function handling the call.
    67  * @param icallid Call id.
    68  * @param icall Call data.
    69  */
    70 void default_connection_handler(ddf_fun_t *fun,
    71     ipc_callid_t icallid, ipc_call_t *icall)
    72 {
    73         sysarg_t method = IPC_GET_IMETHOD(*icall);
    74 
    75         usb_mouse_t *mouse = (usb_mouse_t *) fun->driver_data;
    76         assert(mouse != NULL);
    77 
    78         if (method == IPC_M_CONNECT_TO_ME) {
    79                 int callback = IPC_GET_ARG5(*icall);
    80 
    81                 if (mouse->console_phone != -1) {
    82                         async_answer_0(icallid, ELIMIT);
    83                         return;
    84                 }
    85 
    86                 mouse->console_phone = callback;
    87                 async_answer_0(icallid, EOK);
    88                 return;
    89         }
    90 
    91         async_answer_0(icallid, EINVAL);
    92 }
    9385
    9486/** Create USB mouse device.
     
    10294{
    10395        usb_mouse_t *mouse = malloc(sizeof(usb_mouse_t));
    104         if (mouse == NULL) {
     96        if (mouse == NULL)
    10597                return ENOMEM;
    106         }
     98       
    10799        mouse->dev = dev;
    108         mouse->console_phone = -1;
    109 
     100        mouse->console_sess = NULL;
     101       
    110102        int rc;
    111 
     103       
    112104        /* Create DDF function. */
    113105        mouse->mouse_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "mouse");
     
    116108                goto leave;
    117109        }
    118 
     110       
    119111        mouse->mouse_fun->ops = &mouse_ops;
    120 
     112       
    121113        rc = ddf_fun_bind(mouse->mouse_fun);
    122         if (rc != EOK) {
     114        if (rc != EOK)
    123115                goto leave;
    124         }
    125 
     116       
    126117        /* Add the function to mouse class. */
    127118        rc = ddf_fun_add_to_class(mouse->mouse_fun, "mouse");
    128         if (rc != EOK) {
     119        if (rc != EOK)
    129120                goto leave;
    130         }
    131121       
    132122        /* Set the boot protocol. */
    133123        rc = usbhid_req_set_protocol(&dev->ctrl_pipe, dev->interface_no,
    134124            USB_HID_PROTOCOL_BOOT);
    135         if (rc != EOK) {
     125        if (rc != EOK)
    136126                goto leave;
    137         }
    138127       
    139         /* Everything all right. */
     128        /* Everything allright. */
    140129        dev->driver_data = mouse;
    141130        mouse->mouse_fun->driver_data = mouse;
    142 
     131       
    143132        return EOK;
    144 
     133       
    145134leave:
    146135        free(mouse);
    147 
    148136        return rc;
    149137}
Note: See TracChangeset for help on using the changeset viewer.