Ignore:
Timestamp:
2011-10-15T20:05:00Z (13 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
22ceff3a
Parents:
1ccc32f (diff), 721d4b6e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.c

    r1ccc32f r25696fea  
    124124{
    125125        usb_mouse_t *mouse_dev = (usb_mouse_t *) fun->driver_data;
    126        
     126
    127127        if (mouse_dev == NULL) {
    128128                usb_log_debug("default_connection_handler: Missing "
     
    131131                return;
    132132        }
    133        
     133
    134134        usb_log_debug("default_connection_handler: fun->name: %s\n",
    135135                      fun->name);
    136136        usb_log_debug("default_connection_handler: mouse_sess: %p, "
    137137            "wheel_sess: %p\n", mouse_dev->mouse_sess, mouse_dev->wheel_sess);
    138        
     138
    139139        async_sess_t **sess_ptr =
    140140            (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0) ?
    141141            &mouse_dev->mouse_sess : &mouse_dev->wheel_sess;
    142        
     142
    143143        async_sess_t *sess =
    144144            async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
     
    170170        mouse->mouse_sess = NULL;
    171171        mouse->wheel_sess = NULL;
    172        
     172
    173173        return mouse;
    174174}
     
    179179{
    180180        assert(mouse_dev != NULL);
    181        
     181
    182182        // hangup session to the console
    183183        if (mouse_dev->mouse_sess != NULL)
    184184                async_hangup(mouse_dev->mouse_sess);
    185        
     185
    186186        if (mouse_dev->wheel_sess != NULL)
    187187                async_hangup(mouse_dev->wheel_sess);
     188        int ret = ddf_fun_unbind(mouse_dev->mouse_fun);
     189        if (ret != EOK) {
     190                usb_log_error("Failed to unbind mouse function.\n");
     191        } else {
     192                ddf_fun_destroy(mouse_dev->mouse_fun);
     193                /* Prevent double free */
     194                mouse_dev->wheel_fun->driver_data = NULL;
     195        }
     196
     197        ret = ddf_fun_unbind(mouse_dev->wheel_fun);
     198        if (ret != EOK) {
     199                usb_log_error("Failed to unbind wheel function.\n");
     200        } else {
     201                ddf_fun_destroy(mouse_dev->wheel_fun);
     202        }
    188203}
    189204
     
    199214                return;
    200215        }
    201        
     216
    202217        int count = ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL;
    203218        int i;
    204        
     219
    205220        for (i = 0; i < count; i++) {
    206221                /* Send arrow press and release. */
     
    246261{
    247262        assert(mouse_dev != NULL);
    248        
     263
    249264        if (mouse_dev->mouse_sess == NULL) {
    250265                usb_log_warning(NAME " No console session.\n");
     
    264279                async_exchange_end(exch);
    265280        }
    266        
     281
    267282        if (wheel != 0)
    268283                usb_mouse_send_wheel(mouse_dev, wheel);
    269        
     284
    270285        /*
    271286         * Buttons
     
    274289        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
    275290        usb_hid_report_path_set_report_id(path, hid_dev->report_id);
    276        
     291
    277292        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    278293            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
     
    309324                    USB_HID_REPORT_TYPE_INPUT);
    310325        }
    311        
     326
    312327        usb_hid_report_path_free(path);
    313328
     
    321336        assert(hid_dev != NULL);
    322337        assert(mouse != NULL);
    323        
     338
    324339        /* Create the exposed function. */
    325340        usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
     
    330345                return ENOMEM;
    331346        }
    332        
     347
    333348        fun->ops = &mouse->ops;
    334349        fun->driver_data = mouse;
     
    338353                usb_log_error("Could not bind DDF function: %s.\n",
    339354                    str_error(rc));
    340                 ddf_fun_destroy(fun);
    341                 return rc;
    342         }
    343        
     355                return rc;
     356        }
     357
    344358        usb_log_debug("Adding DDF function to category %s...\n",
    345359            HID_MOUSE_CATEGORY);
     
    349363                    "Could not add DDF function to category %s: %s.\n",
    350364                    HID_MOUSE_CATEGORY, str_error(rc));
    351                 ddf_fun_destroy(fun);
    352                 return rc;
    353         }
    354        
     365                return rc;
     366        }
     367        mouse->mouse_fun = fun;
     368
    355369        /*
    356370         * Special function for acting as keyboard (wheel)
     
    364378                return ENOMEM;
    365379        }
    366        
     380
    367381        /*
    368382         * Store the initialized HID device and HID ops
     
    376390                usb_log_error("Could not bind DDF function: %s.\n",
    377391                    str_error(rc));
    378                 ddf_fun_destroy(fun);
    379                 return rc;
    380         }
    381        
     392                return rc;
     393        }
     394
    382395        usb_log_debug("Adding DDF function to category %s...\n",
    383396            HID_MOUSE_WHEEL_CATEGORY);
     
    387400                    "Could not add DDF function to category %s: %s.\n",
    388401                    HID_MOUSE_WHEEL_CATEGORY, str_error(rc));
    389                 ddf_fun_destroy(fun);
    390                 return rc;
    391         }
    392        
     402                return rc;
     403        }
     404        mouse->wheel_fun = fun;
     405
    393406        return EOK;
    394407}
     
    441454{
    442455        usb_log_debug("Initializing HID/Mouse structure...\n");
    443        
     456
    444457        if (hid_dev == NULL) {
    445458                usb_log_error("Failed to init keyboard structure: no structure"
     
    447460                return EINVAL;
    448461        }
    449        
     462
    450463        usb_mouse_t *mouse_dev = usb_mouse_new();
    451464        if (mouse_dev == NULL) {
     
    454467                return ENOMEM;
    455468        }
    456        
     469
    457470        // FIXME: This may not be optimal since stupid hardware vendor may
    458471        // use buttons 1, 2, 3 and 6000 and we would allocate array of
     
    464477            hid_dev->report_id) + 1;
    465478        mouse_dev->buttons = calloc(mouse_dev->buttons_count, sizeof(int32_t));
    466        
     479
    467480        if (mouse_dev->buttons == NULL) {
    468481                usb_log_error(NAME ": out of memory, giving up on device!\n");
     
    474487        // save the Mouse device structure into the HID device structure
    475488        *data = mouse_dev;
    476        
     489
    477490        // set handler for incoming calls
    478491        mouse_dev->ops.default_handler = default_connection_handler;
    479        
     492
    480493        // TODO: how to know if the device supports the request???
    481494        usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,
    482495            hid_dev->usb_dev->interface_no, IDLE_RATE);
    483        
     496
    484497        int rc = usb_mouse_create_function(hid_dev, mouse_dev);
    485498        if (rc != EOK) {
     
    487500                return rc;
    488501        }
    489        
     502
    490503        return EOK;
    491504}
     
    500513                return false;
    501514        }
    502        
     515
    503516        usb_mouse_t *mouse_dev = (usb_mouse_t *)data;
    504517               
     
    511524{
    512525        if (data != NULL) {
    513                 usb_mouse_destroy((usb_mouse_t *)data);
     526                usb_mouse_destroy(data);
    514527        }
    515528}
     
    522535            USB_MOUSE_BOOT_REPORT_DESCRIPTOR,
    523536            USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE);
    524        
     537
    525538        if (rc != EOK) {
    526539                usb_log_error("Failed to parse boot report descriptor: %s\n",
     
    528541                return rc;
    529542        }
    530        
     543
    531544        rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe,
    532545            hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT);
    533        
     546
    534547        if (rc != EOK) {
    535548                usb_log_warning("Failed to set boot protocol to the device: "
     
    537550                return rc;
    538551        }
    539        
     552
    540553        return EOK;
    541554}
Note: See TracChangeset for help on using the changeset viewer.