VirtualBox

Changeset 27969 in vbox for trunk/src/VBox/Devices/Input


Ignore:
Timestamp:
Apr 2, 2010 9:32:57 PM (15 years ago)
Author:
vboxsync
Message:

UsbKbd.cpp: Use doxygen comment where applicable; hungarian typos; don't wrap RTCritSectEnter/Leave or the lock validator doesn't get the best data to work on.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Input/UsbKbd.cpp

    r27917 r27969  
     1/* $Id$ */
    12/** @file
    2  * UsbKbd - USB Human Interface Device Emulation (Keyboard).
     3 * UsbKbd - USB Human Interface Device Emulation, Keyboard.
    34 */
    45
     
    117118typedef struct USBHIDK_REPORT
    118119{
    119     uint8_t     ShiftState;     /* Modifier keys bitfield */
    120     uint8_t     Reserved;       /* Currently unused */
    121     uint8_t     aKeys[6];       /* Normal keys */
     120    uint8_t     ShiftState;     /**< Modifier keys bitfield */
     121    uint8_t     Reserved;       /**< Currently unused */
     122    uint8_t     aKeys[6];       /**< Normal keys */
    122123} USBHIDK_REPORT, *PUSBHIDK_REPORT;
    123124
    124 /* Scancode translator state.  */
     125/** Scancode translator state.  */
    125126typedef enum {
    126     SS_IDLE,    /* Starting state. */
    127     SS_EXT,     /* E0 byte was received. */
    128     SS_EXT1     /* E1 byte was received. */
     127    SS_IDLE,    /**< Starting state. */
     128    SS_EXT,     /**< E0 byte was received. */
     129    SS_EXT1     /**< E1 byte was received. */
    129130} scan_state_t;
    130131
     
    137138    PPDMUSBINS          pUsbIns;
    138139    /** Critical section protecting the device state. */
    139     RTCRITSECT          csLock;
     140    RTCRITSECT          CritSect;
    140141
    141142    /** The current configuration.
     
    169170    /** Someone is waiting on the done queue. */
    170171    bool                fHaveDoneQueueWaiter;
    171     /** If no URB since last key press */
     172    /** If no URB since last key press. */
    172173    bool                fNoUrbSinceLastPress;
    173     /* If device has pending changes */
     174    /** If device has pending changes. */
    174175    bool                fHasPendingChanges;
    175     /* Keys released since last URB */
    176     uint8_t             aReleasedKeys[6];
     176    /** Keys released since last URB. */
     177    uint8_t             abReleasedKeys[6];
    177178
    178179    /**
     
    229230};
    230231
    231 /* HID report descriptor. */
     232/** HID report descriptor. */
    232233static const uint8_t g_UsbHidReportDesc[] =
    233234{
     
    266267};
    267268
    268 /* Additional HID class interface descriptor. */
     269/** Additional HID class interface descriptor. */
    269270static const uint8_t g_UsbHidIfHidDesc[] =
    270271{
     
    357358 */
    358359
    359 /* Lookup table for converting PC/XT scan codes to USB HID usage codes. */
     360/** Lookup table for converting PC/XT scan codes to USB HID usage codes. */
    360361static uint8_t aScancode2Hid[] =
    361362{
     
    378379};
    379380
    380 /* Lookup table for extended scancodes (arrow keys etc.). */
     381/** Lookup table for extended scancodes (arrow keys etc.). */
    381382static uint8_t aExtScan2Hid[] =
    382383{
     
    449450*******************************************************************************/
    450451
    451 /* Everything happens in R3 */
    452 /**
    453  * Lock device state mutex.
    454  */
    455 DECLINLINE(int) usbKbdLock(PUSBHID pThis)
    456 {
    457     return RTCritSectEnter(&pThis->csLock);
    458 }
    459 
    460 /**
    461  * Unlock device state mutex.
    462  */
    463 DECLINLINE(void) usbKbdUnlock(PUSBHID pThis)
    464 {
    465     RTCritSectLeave(&pThis->csLock);
    466 }
    467452
    468453/**
     
    635620    pThis->fNoUrbSinceLastPress = false;
    636621    pThis->fHasPendingChanges = false;
    637     memset(&pThis->aReleasedKeys[0], 0, sizeof(pThis->aReleasedKeys));
     622    memset(&pThis->abReleasedKeys[0], 0, sizeof(pThis->abReleasedKeys));
    638623
    639624    for (unsigned i = 0; i < RT_ELEMENTS(pThis->aEps); i++)
     
    682667{
    683668    unsigned i;
    684     for (i=0; i < RT_ELEMENTS(pThis->aReleasedKeys); ++i)
    685     {
    686         if (pThis->aReleasedKeys[i] != 0)
     669    for (i = 0; i < RT_ELEMENTS(pThis->abReleasedKeys); ++i)
     670    {
     671        if (pThis->abReleasedKeys[i] != 0)
    687672        {
    688             usbHidUpdateReportReleased(pThis, pThis->aReleasedKeys[i]);
    689             pThis->aReleasedKeys[i] = 0;
     673            usbHidUpdateReportReleased(pThis, pThis->abReleasedKeys[i]);
     674            pThis->abReleasedKeys[i] = 0;
    690675        }
    691676    }
     
    693678
    694679#ifdef DEBUG
    695 #define HEX_DIGIT(x) (((x) < 0xa) ? ((x) + '0') : ((x) - 0xa + 'a'))
    696 static void usbHidComputePressed(PUSBHIDK_REPORT pReport, char* pszBuf, unsigned uBufLen)
    697 {
    698     unsigned i, uBufPos = 0;
    699     for (i=0; i < RT_ELEMENTS(pReport->aKeys); ++i)
     680# define HEX_DIGIT(x) (((x) < 0xa) ? ((x) + '0') : ((x) - 0xa + 'a'))
     681static void usbHidComputePressed(PUSBHIDK_REPORT pReport, char* pszBuf, unsigned cbBuf)
     682{
     683    unsigned offBuf = 0;
     684    unsigned i;
     685    for (i = 0; i < RT_ELEMENTS(pReport->aKeys); ++i)
    700686    {
    701687        uint8_t uCode = pReport->aKeys[i];
    702688        if (uCode != 0)
    703689        {
    704             if (uBufPos + 4 >= uBufLen)
     690            if (offBuf + 4 >= cbBuf)
    705691                break;
    706             pszBuf[uBufPos++] = HEX_DIGIT(uCode >> 4);
    707             pszBuf[uBufPos++] = HEX_DIGIT(uCode & 0xf);
    708             pszBuf[uBufPos++] = ' ';
     692            pszBuf[offBuf++] = HEX_DIGIT(uCode >> 4);
     693            pszBuf[offBuf++] = HEX_DIGIT(uCode & 0xf);
     694            pszBuf[offBuf++] = ' ';
    709695        }
    710696    }
    711     pszBuf[uBufPos++] = '\0';
    712 }
    713 #undef HEX_DIGIT
     697    pszBuf[offBuf++] = '\0';
     698}
     699# undef HEX_DIGIT
    714700#endif
    715701
     
    778764    unsigned    i;
    779765
    780     usbKbdLock(pThis);
     766    RTCritSectEnter(&pThis->CritSect);
    781767
    782768    pThis->XlatState = ScancodeToHidUsage(pThis->XlatState, u8KeyCode, &u32Usage);
     
    799785                    /* Skip repeat events. */
    800786                    fHaveEvent = false;
    801                     break;                             
     787                    break;
    802788                }
    803789            }
     
    813799                    }
    814800                }
    815                
     801
    816802                pThis->fNoUrbSinceLastPress = true;
    817                
     803
    818804                if (i == RT_ELEMENTS(pReport->aKeys))
    819805                {
    820806                    /* We ran out of room. Report error. */
    821807                    Log(("no more room in usbHidKeyboardPutEvent\n"));
    822                     // @todo!!
     808                    /// @todo!!
    823809                }
    824810            }
     
    833819            if (pThis->fNoUrbSinceLastPress)
    834820            {
    835                 for (i = 0; i < RT_ELEMENTS(pThis->aReleasedKeys); ++i)
     821                for (i = 0; i < RT_ELEMENTS(pThis->abReleasedKeys); ++i)
    836822                {
    837                     if (pThis->aReleasedKeys[i] == u8HidCode)
     823                    if (pThis->abReleasedKeys[i] == u8HidCode)
    838824                        break;
    839825
    840                     if (pThis->aReleasedKeys[i] == 0)
     826                    if (pThis->abReleasedKeys[i] == 0)
    841827                    {
    842                         pThis->aReleasedKeys[i] = u8HidCode;
     828                        pThis->abReleasedKeys[i] = u8HidCode;
    843829                        break;
    844830                    }
     
    854840    }
    855841
    856     usbKbdUnlock(pThis);
     842    RTCritSectLeave(&pThis->CritSect);
    857843
    858844    return VINF_SUCCESS;
     
    867853    //LogFlow(("usbHidUrbReap/#%u: cMillies=%u\n", pUsbIns->iInstance, cMillies));
    868854
    869     usbKbdLock(pThis);
     855    RTCritSectEnter(&pThis->CritSect);
    870856
    871857    PVUSBURB pUrb = usbHidQueueRemoveHead(&pThis->DoneQueue);
     
    874860        /* Wait */
    875861        pThis->fHaveDoneQueueWaiter = true;
    876         usbKbdUnlock(pThis);
     862        RTCritSectLeave(&pThis->CritSect);
    877863
    878864        RTSemEventWait(pThis->hEvtDoneQueue, cMillies);
    879865
    880         usbKbdLock(pThis);
     866        RTCritSectEnter(&pThis->CritSect);
    881867        pThis->fHaveDoneQueueWaiter = false;
    882868
     
    884870    }
    885871
    886     usbKbdUnlock(pThis);
     872    RTCritSectLeave(&pThis->CritSect);
    887873
    888874    if (pUrb)
     
    899885    PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID);
    900886    LogFlow(("usbHidUrbCancel/#%u: pUrb=%p:%s\n", pUsbIns->iInstance, pUrb, pUrb->pszDesc));
    901     usbKbdLock(pThis);
     887    RTCritSectEnter(&pThis->CritSect);
    902888
    903889    /*
     
    907893        usbHidLinkDone(pThis, pUrb);
    908894
    909     usbKbdUnlock(pThis);
     895    RTCritSectLeave(&pThis->CritSect);
    910896    return VINF_SUCCESS;
    911897}
     
    11531139    PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID);
    11541140    LogFlow(("usbHidQueue/#%u: pUrb=%p:%s EndPt=%#x\n", pUsbIns->iInstance, pUrb, pUrb->pszDesc, pUrb->EndPt));
    1155     usbKbdLock(pThis);
     1141    RTCritSectEnter(&pThis->CritSect);
    11561142
    11571143    /*
     
    11771163    }
    11781164
    1179     usbKbdUnlock(pThis);
     1165    RTCritSectLeave(&pThis->CritSect);
    11801166    return rc;
    11811167}
     
    11921178    if ((uEndpoint & ~0x80) < RT_ELEMENTS(pThis->aEps))
    11931179    {
    1194         usbKbdLock(pThis);
     1180        RTCritSectEnter(&pThis->CritSect);
    11951181        pThis->aEps[(uEndpoint & ~0x80)].fHalted = false;
    1196         usbKbdUnlock(pThis);
     1182        RTCritSectLeave(&pThis->CritSect);
    11971183    }
    11981184
     
    12211207    LogFlow(("usbHidUsbSetConfiguration/#%u: bConfigurationValue=%u\n", pUsbIns->iInstance, bConfigurationValue));
    12221208    Assert(bConfigurationValue == 1);
    1223     usbKbdLock(pThis);
     1209    RTCritSectEnter(&pThis->CritSect);
    12241210
    12251211    /*
     
    12301216    pThis->bConfigurationValue = bConfigurationValue;
    12311217
    1232     usbKbdUnlock(pThis);
     1218    RTCritSectLeave(&pThis->CritSect);
    12331219    return VINF_SUCCESS;
    12341220}
     
    12531239    PUSBHID pThis = PDMINS_2_DATA(pUsbIns, PUSBHID);
    12541240    LogFlow(("usbHidUsbReset/#%u:\n", pUsbIns->iInstance));
    1255     usbKbdLock(pThis);
     1241    RTCritSectEnter(&pThis->CritSect);
    12561242
    12571243    int rc = usbHidResetWorker(pThis, NULL, false /*fSetConfig*/);
    12581244
    1259     usbKbdUnlock(pThis);
     1245    RTCritSectLeave(&pThis->CritSect);
    12601246    return rc;
    12611247}
     
    12701256    LogFlow(("usbHidDestruct/#%u:\n", pUsbIns->iInstance));
    12711257
    1272     if (RTCritSectIsInitialized(&pThis->csLock))
    1273     {
    1274         /* Let whoever runs in this critical section complete */
    1275         usbKbdLock(pThis);
    1276         usbKbdUnlock(pThis);
    1277         RTCritSectDelete(&pThis->csLock);
     1258    if (RTCritSectIsInitialized(&pThis->CritSect))
     1259    {
     1260        /* Let whoever runs in this critical section complete. */
     1261        RTCritSectEnter(&pThis->CritSect);
     1262        RTCritSectLeave(&pThis->CritSect);
     1263        RTCritSectDelete(&pThis->CritSect);
    12781264    }
    12791265
     
    13041290    usbHidQueueInit(&pThis->DoneQueue);
    13051291
    1306     int rc = RTCritSectInit(&pThis->csLock);
     1292    int rc = RTCritSectInit(&pThis->CritSect);
    13071293    AssertRCReturn(rc, rc);
    13081294
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette