Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/kbddev.c

    r00b13408 rfc5ed5d  
    9494        .flags = 0
    9595};
    96 
    97 typedef enum usbhid_kbd_flags {
    98         USBHID_KBD_STATUS_UNINITIALIZED = 0,
    99         USBHID_KBD_STATUS_INITIALIZED = 1,
    100         USBHID_KBD_STATUS_TO_DESTROY = -1
    101 } usbhid_kbd_flags;
    10296
    10397/*----------------------------------------------------------------------------*/
     
    238232       
    239233        assert(kbd_dev->hid_dev != NULL);
    240         assert(kbd_dev->hid_dev->initialized == USBHID_KBD_STATUS_INITIALIZED);
     234        assert(kbd_dev->hid_dev->initialized);
    241235        usbhid_req_set_report(kbd_dev->hid_dev, USB_HID_REPORT_TYPE_OUTPUT,
    242236            buffer, BOOTP_BUFFER_OUT_SIZE);
     
    571565                                    uint8_t *buffer, size_t actual_size)
    572566{
    573         assert(kbd_dev->initialized == USBHID_KBD_STATUS_INITIALIZED);
     567        assert(kbd_dev->initialized);
    574568        assert(kbd_dev->hid_dev->parser != NULL);
    575569       
     
    625619       
    626620        kbd_dev->console_phone = -1;
    627         kbd_dev->initialized = USBHID_KBD_STATUS_UNINITIALIZED;
     621        kbd_dev->initialized = 0;
    628622       
    629623        return kbd_dev;
     
    631625
    632626/*----------------------------------------------------------------------------*/
    633 
    634 static void usbhid_kbd_mark_unusable(usbhid_kbd_t *kbd_dev)
    635 {
    636         kbd_dev->initialized = USBHID_KBD_STATUS_TO_DESTROY;
     627/**
     628 * Properly destroys the USB/HID keyboard structure.
     629 *
     630 * @param kbd_dev Pointer to the structure to be destroyed.
     631 */
     632static void usbhid_kbd_free(usbhid_kbd_t **kbd_dev)
     633{
     634        if (kbd_dev == NULL || *kbd_dev == NULL) {
     635                return;
     636        }
     637       
     638        // hangup phone to the console
     639        async_hangup((*kbd_dev)->console_phone);
     640       
     641        if ((*kbd_dev)->hid_dev != NULL) {
     642                usbhid_dev_free(&(*kbd_dev)->hid_dev);
     643                assert((*kbd_dev)->hid_dev == NULL);
     644        }
     645       
     646        if ((*kbd_dev)->repeat_mtx != NULL) {
     647                /* TODO: replace by some check and wait */
     648                assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
     649                free((*kbd_dev)->repeat_mtx);
     650        }
     651
     652        free(*kbd_dev);
     653        *kbd_dev = NULL;
    637654}
    638655
     
    676693        }
    677694       
    678         if (kbd_dev->initialized == USBHID_KBD_STATUS_INITIALIZED) {
     695        if (kbd_dev->initialized) {
    679696                usb_log_warning("Keyboard structure already initialized.\n");
    680697                return EINVAL;
     
    689706        }
    690707       
    691         assert(kbd_dev->hid_dev->initialized == USBHID_KBD_STATUS_INITIALIZED);
     708        assert(kbd_dev->hid_dev->initialized);
    692709       
    693710        // save the size of the report (boot protocol report by default)
     
    741758        usbhid_req_set_idle(kbd_dev->hid_dev, IDLE_RATE);
    742759       
    743         kbd_dev->initialized = USBHID_KBD_STATUS_INITIALIZED;
     760        kbd_dev->initialized = 1;
    744761        usb_log_info("HID/KBD device structure initialized.\n");
    745762       
     
    855872        usbhid_kbd_poll(kbd_dev);
    856873       
    857         // as there is another fibril using this device, so we must leave the
    858         // structure to it, but mark it for destroying.
    859         usbhid_kbd_mark_unusable(kbd_dev);
    860874        // at the end, properly destroy the KBD structure
    861 //      usbhid_kbd_free(&kbd_dev);
    862 //      assert(kbd_dev == NULL);
     875        usbhid_kbd_free(&kbd_dev);
     876        assert(kbd_dev == NULL);
    863877
    864878        return EOK;
     
    982996}
    983997
    984 /*----------------------------------------------------------------------------*/
    985 
    986 int usbhid_kbd_is_usable(const usbhid_kbd_t *kbd_dev)
    987 {
    988         return (kbd_dev->initialized == USBHID_KBD_STATUS_INITIALIZED);
    989 }
    990 
    991 /*----------------------------------------------------------------------------*/
    992 /**
    993  * Properly destroys the USB/HID keyboard structure.
    994  *
    995  * @param kbd_dev Pointer to the structure to be destroyed.
    996  */
    997 void usbhid_kbd_free(usbhid_kbd_t **kbd_dev)
    998 {
    999         if (kbd_dev == NULL || *kbd_dev == NULL) {
    1000                 return;
    1001         }
    1002        
    1003         // hangup phone to the console
    1004         async_hangup((*kbd_dev)->console_phone);
    1005        
    1006         if ((*kbd_dev)->hid_dev != NULL) {
    1007                 usbhid_dev_free(&(*kbd_dev)->hid_dev);
    1008                 assert((*kbd_dev)->hid_dev == NULL);
    1009         }
    1010        
    1011         if ((*kbd_dev)->repeat_mtx != NULL) {
    1012                 /* TODO: replace by some check and wait */
    1013                 assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
    1014                 free((*kbd_dev)->repeat_mtx);
    1015         }
    1016 
    1017         free(*kbd_dev);
    1018         *kbd_dev = NULL;
    1019 }
    1020 
    1021998/**
    1022999 * @}
Note: See TracChangeset for help on using the changeset viewer.