VirtualBox

Changeset 34288 in vbox for trunk


Ignore:
Timestamp:
Nov 23, 2010 4:02:26 PM (14 years ago)
Author:
vboxsync
Message:

Main/Keyboard: eliminate code duplication, handle keyboard queue overflow correctly and send only actually processed keycodes in the event

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/KeyboardImpl.cpp

    r34012 r34288  
    156156STDMETHODIMP Keyboard::PutScancode(LONG scancode)
    157157{
    158     HRESULT rc = S_OK;
    159 
    160     AutoCaller autoCaller(this);
    161     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    162 
    163     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    164 
    165     CHECK_CONSOLE_DRV(mpDrv[0]);
    166 
    167     PPDMIKEYBOARDPORT pUpPort = NULL;
    168     for (int i = KEYBOARD_MAX_DEVICES - 1; i >= 0 ; --i)
    169     {
    170         if (mpDrv[i] && (mpDrv[i]->u32DevCaps & KEYBOARD_DEVCAP_ENABLED))
    171         {
    172             pUpPort = mpDrv[i]->pUpPort;
    173             break;
    174         }
    175     }
    176     /* No enabled keyboard - throw the input away. */
    177     if (!pUpPort)
    178         return rc;
    179 
    180     int vrc = pUpPort->pfnPutEvent(pUpPort, (uint8_t)scancode);
    181 
    182     if (RT_FAILURE(vrc))
    183         rc = setError(VBOX_E_IPRT_ERROR,
    184                       tr("Could not send scan code 0x%08X to the virtual keyboard (%Rrc)"),
    185                       scancode, vrc);
    186 
    187     VBoxEventDesc evDesc;
    188158    com::SafeArray<LONG> scancodes(1);
    189159    scancodes[0] = scancode;
    190     evDesc.init(mEventSource, VBoxEventType_OnGuestKeyboardEvent, ComSafeArrayAsInParam(scancodes));
    191     evDesc.fire(0);
    192     return rc;
     160    return PutScancodes(ComSafeArrayAsInParam(scancodes), NULL);
    193161}
    194162
     
    206174                                    ULONG *codesStored)
    207175{
    208     HRESULT rc = S_OK;
    209 
    210176    if (ComSafeArrayInIsNull(scancodes))
    211177        return E_INVALIDARG;
     
    213179    AutoCaller autoCaller(this);
    214180    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     181
     182    com::SafeArray<LONG> keys(ComSafeArrayInArg(scancodes));
    215183
    216184    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    232200    /* No enabled keyboard - throw the input away. */
    233201    if (!pUpPort)
    234         return rc;
    235 
    236     com::SafeArray<LONG> keys(ComSafeArrayInArg(scancodes));
     202    {
     203        if (codesStored)
     204            *codesStored = (uint32_t)keys.size();
     205        return S_OK;
     206    }
     207
    237208    int vrc = VINF_SUCCESS;
    238209
    239     for (uint32_t i = 0; (i < keys.size()) && RT_SUCCESS(vrc); i++)
    240         vrc = pUpPort->pfnPutEvent(pUpPort, (uint8_t)keys[i]);
     210    uint32_t sent;
     211    for (sent = 0; (sent < keys.size()) && RT_SUCCESS(vrc); sent++)
     212        vrc = pUpPort->pfnPutEvent(pUpPort, (uint8_t)keys[sent]);
     213
     214    if (codesStored)
     215        *codesStored = sent;
     216
     217    /* Only signal the keys in the event which have been actually sent. */
     218    keys.resize(sent);
     219    VBoxEventDesc evDesc;
     220    evDesc.init(mEventSource, VBoxEventType_OnGuestKeyboardEvent, ComSafeArrayAsInParam(keys));
     221    evDesc.fire(0);
    241222
    242223    if (RT_FAILURE(vrc))
     
    245226                        vrc);
    246227
    247     /// @todo is it actually possible that not all scancodes can be transmitted?
    248     if (codesStored)
    249         *codesStored = (uint32_t)keys.size();
    250 
    251     VBoxEventDesc evDesc;
    252     evDesc.init(mEventSource, VBoxEventType_OnGuestKeyboardEvent, ComSafeArrayAsInParam(keys));
    253     evDesc.fire(0);
    254 
    255     return rc;
     228    return S_OK;
    256229}
    257230
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