VirtualBox

Changeset 11661 in vbox for trunk/src/VBox/Frontends/VBoxBFE


Ignore:
Timestamp:
Aug 26, 2008 1:49:29 PM (16 years ago)
Author:
vboxsync
Message:

Modified IKeyboard::PutScancodes to use SafeArray (including webservice)

Location:
trunk/src/VBox/Frontends/VBoxBFE
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxBFE/COMDefs.h

    r11659 r11661  
    7474#endif /* !RT_OS_WINDOWS */
    7575
     76#define ComSafeArrayIn(aType, aArg)         unsigned aArg##Size, aType *aArg
     77#define ComSafeArrayInIsNull(aArg)          (aArg == NULL)
     78#define ComSafeArrayInArg(aArg)             aArg##Size, aArg
     79#define ComSafeArrayAsInParam(aArray)   \
     80    (aArray).size(), aArray.raw()
     81
     82
     83namespace com
     84{
     85    template<class T> class SafeArray {
     86        T t;
     87    public:
     88        SafeArray (size_t aSize) {}
     89        SafeArray (ComSafeArrayIn (T, aArg)) {}
     90        T &operator[] (size_t aIdx) { return t; }
     91        size_t size() const { return 0; }
     92        T *raw() { return &t; }
     93    };
     94}
    7695#endif
  • trunk/src/VBox/Frontends/VBoxBFE/KeyboardImpl.cpp

    r11659 r11661  
    2525#else
    2626# include <VBox/com/defs.h>
     27//# include <VBox/com/array.h>
    2728#endif
    2829#include <VBox/pdm.h>
     
    99100 *
    100101 * @returns COM status code
    101  * @param scancodes   Pointer to the first scancode
    102  * @param count       Number of scancodes
     102 * @param scancodes   Safe array of scancodes
    103103 * @param codesStored Address of variable to store the number
    104104 *                    of scancodes that were sent to the keyboard.
    105105                      This value can be NULL.
    106106 */
    107 STDMETHODIMP Keyboard::PutScancodes(LONG *scancodes,
    108                                     ULONG count,
     107STDMETHODIMP Keyboard::PutScancodes(ComSafeArrayIn (LONG, scancodes),
    109108                                    ULONG *codesStored)
    110109{
    111     if (!scancodes)
     110    if (ComSafeArrayInIsNull(scancodes))
    112111        return E_INVALIDARG;
    113112    if (!mpDrv)
    114113        return S_OK;
    115114
    116     LONG *currentScancode = scancodes;
     115    com::SafeArray <LONG> keys(ComSafeArrayInArg(scancodes));
    117116    int rcVBox = VINF_SUCCESS;
    118117
    119     for (uint32_t i = 0; (i < count) && VBOX_SUCCESS(rcVBox); i++, currentScancode++)
    120     {
    121         rcVBox = mpDrv->pUpPort->pfnPutEvent(mpDrv->pUpPort, *(uint8_t*)currentScancode);
     118    for (uint32_t i = 0; (i < keys.size()) && VBOX_SUCCESS(rcVBox); i++)
     119    {
     120        rcVBox = mpDrv->pUpPort->pfnPutEvent(mpDrv->pUpPort, (uint8_t)keys[i]);
    122121    }
    123122
     
    127126    /// @todo is it actually possible that not all scancodes can be transmitted?
    128127    if (codesStored)
    129         *codesStored = count;
     128        *codesStored = keys.size();
    130129
    131130    return S_OK;
     
    141140STDMETHODIMP Keyboard::PutCAD()
    142141{
    143     static LONG cadSequence[] = {
    144         0x1d, // Ctrl down
    145         0x38, // Alt down
    146         0x53, // Del down
    147         0xd3, // Del up
    148         0xb8, // Alt up
    149         0x9d  // Ctrl up
    150     };
    151 
    152     return PutScancodes (cadSequence, ELEMENTS (cadSequence), NULL);
     142    static com::SafeArray<LONG> cadSequence(6);
     143   
     144    cadSequence[0] = 0x1d; // Ctrl down
     145    cadSequence[1] = 0x38; // Alt down
     146    cadSequence[2] = 0x53; // Del down
     147    cadSequence[3] = 0xd3; // Del up
     148    cadSequence[4] = 0xb8; // Alt up
     149    cadSequence[5] = 0x9d; // Ctrl up
     150
     151    return PutScancodes (ComSafeArrayAsInParam(cadSequence), NULL);
    153152}
    154153
  • trunk/src/VBox/Frontends/VBoxBFE/KeyboardImpl.h

    r11659 r11661  
    4848
    4949    STDMETHOD(PutScancode)(LONG scancode);
    50     STDMETHOD(PutScancodes)(LONG *scancodes,
    51                             ULONG count,
     50    STDMETHOD(PutScancodes)(ComSafeArrayIn (LONG, scancodes),
    5251                            ULONG *codesStored);
    5352    STDMETHOD(PutCAD)();
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