Ignore:
File:
1 edited

Legend:

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

    r4a4c8bcf r79ae36dd  
    4343#include <errno.h>
    4444
     45// FIXME: remove this header
     46#include <kernel/ipc/ipc_methods.h>
     47
    4548/** Mouse polling endpoint description for boot protocol subclass. */
    4649usb_endpoint_description_t poll_endpoint_description = {
     
    5356};
    5457
    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  */
    62 static 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 
     58static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
    8159/** Device ops for USB mouse. */
    8260static ddf_dev_ops_t mouse_ops = {
    8361        .default_handler = default_connection_handler
    8462};
     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 */
     70void 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}
    8593
    8694/** Create USB mouse device.
     
    94102{
    95103        usb_mouse_t *mouse = malloc(sizeof(usb_mouse_t));
    96         if (mouse == NULL)
     104        if (mouse == NULL) {
    97105                return ENOMEM;
    98        
     106        }
    99107        mouse->dev = dev;
    100         mouse->console_sess = NULL;
    101        
     108        mouse->console_phone = -1;
     109
    102110        int rc;
    103        
     111
    104112        /* Create DDF function. */
    105113        mouse->mouse_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "mouse");
     
    108116                goto leave;
    109117        }
    110        
     118
    111119        mouse->mouse_fun->ops = &mouse_ops;
    112        
     120
    113121        rc = ddf_fun_bind(mouse->mouse_fun);
    114         if (rc != EOK)
     122        if (rc != EOK) {
    115123                goto leave;
    116        
     124        }
     125
    117126        /* Add the function to mouse class. */
    118127        rc = ddf_fun_add_to_class(mouse->mouse_fun, "mouse");
    119         if (rc != EOK)
     128        if (rc != EOK) {
    120129                goto leave;
     130        }
    121131       
    122132        /* Set the boot protocol. */
    123133        rc = usbhid_req_set_protocol(&dev->ctrl_pipe, dev->interface_no,
    124134            USB_HID_PROTOCOL_BOOT);
    125         if (rc != EOK)
     135        if (rc != EOK) {
    126136                goto leave;
     137        }
    127138       
    128         /* Everything allright. */
     139        /* Everything all right. */
    129140        dev->driver_data = mouse;
    130141        mouse->mouse_fun->driver_data = mouse;
    131        
     142
    132143        return EOK;
    133        
     144
    134145leave:
    135146        free(mouse);
     147
    136148        return rc;
    137149}
Note: See TracChangeset for help on using the changeset viewer.