VirtualBox

Changeset 85286 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Jul 12, 2020 11:08:50 PM (5 years ago)
Author:
vboxsync
Message:

Main: Refactored the generated event code implementation as Clang 11 claims va_start() on an VBoxEventType_T may trigger undefined behaviour due to type promotion (or something to that effect), but also because that variadict approach was horrible from the start. Refactored code as a dedicated factory method for each event, removing a dependency on VBoxEventDesc in veto cases. The fireXxxxEvent functions now return a HRESULT are no longer DECLINLINE (no need to compile all of them all the time). Reusable events got a ReinitXxxxxEvent function for helping with that. The VirtualBox::CallbackEvent stuff was a horrid misdesign from the start, it could've been done with a single class carrying a VBoxEventDesc member that the i_onXxxx methods would init() with all the event specific parameters and stuff. Refactored code passes a IEvent around, as that's even easier. I've left much of the old code in place for reference, but will remove once I've had a chance to test it a bit more (still struggling building VBox on the mac). bugref:9790

Location:
trunk/src/VBox/Main/src-client
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r84618 r85286  
    73587358    AssertComRCReturnRC(autoCaller.rc());
    73597359
    7360     VBoxEventDesc evDesc;
     7360    ComPtr<IEvent> ptrEvent;
    73617361    if (aCheck)
    73627362    {
    7363         evDesc.init(mEventSource, VBoxEventType_OnCanShowWindow);
    7364         BOOL fDelivered = evDesc.fire(5000); /* Wait up to 5 secs for delivery */
    7365         //Assert(fDelivered);
    7366         if (fDelivered)
    7367         {
    7368             ComPtr<IEvent> pEvent;
    7369             evDesc.getEvent(pEvent.asOutParam());
    7370             // bit clumsy
    7371             ComPtr<ICanShowWindowEvent> pCanShowEvent = pEvent;
    7372             if (pCanShowEvent)
     7363        *aCanShow = TRUE;
     7364        HRESULT hrc = CreateCanShowWindowEvent(ptrEvent.asOutParam(), mEventSource);
     7365        if (SUCCEEDED(hrc))
     7366        {
     7367            VBoxEventDesc EvtDesc(ptrEvent, mEventSource);
     7368            BOOL fDelivered = EvtDesc.fire(5000); /* Wait up to 5 secs for delivery */
     7369            //Assert(fDelivered);
     7370            if (fDelivered)
    73737371            {
    7374                 BOOL fVetoed = FALSE;
    7375                 BOOL fApproved = FALSE;
    7376                 pCanShowEvent->IsVetoed(&fVetoed);
    7377                 pCanShowEvent->IsApproved(&fApproved);
    7378                 *aCanShow = fApproved || !fVetoed;
     7372                // bit clumsy
     7373                ComPtr<ICanShowWindowEvent> ptrCanShowEvent = ptrEvent;
     7374                if (ptrCanShowEvent)
     7375                {
     7376                    BOOL fVetoed   = FALSE;
     7377                    BOOL fApproved = FALSE;
     7378                    ptrCanShowEvent->IsVetoed(&fVetoed);
     7379                    ptrCanShowEvent->IsApproved(&fApproved);
     7380                    *aCanShow = fApproved || !fVetoed;
     7381                }
     7382                else
     7383                    AssertFailed();
    73797384            }
    7380             else
     7385        }
     7386    }
     7387    else
     7388    {
     7389        HRESULT hrc = CreateShowWindowEvent(ptrEvent.asOutParam(), mEventSource, 0);
     7390        if (SUCCEEDED(hrc))
     7391        {
     7392            VBoxEventDesc EvtDesc(ptrEvent, mEventSource);
     7393            BOOL fDelivered = EvtDesc.fire(5000); /* Wait up to 5 secs for delivery */
     7394            //Assert(fDelivered);
     7395            if (fDelivered)
    73817396            {
    7382                 AssertFailed();
    7383                 *aCanShow = TRUE;
     7397                ComPtr<IShowWindowEvent> ptrShowEvent = ptrEvent;
     7398                if (ptrShowEvent)
     7399                {
     7400                    LONG64 idWindow = 0;
     7401                    ptrShowEvent->COMGETTER(WinId)(&idWindow);
     7402                    if (idWindow != 0 && *aWinId == 0)
     7403                        *aWinId = idWindow;
     7404                }
     7405                else
     7406                    AssertFailed();
    73847407            }
    7385         }
    7386         else
    7387             *aCanShow = TRUE;
    7388     }
    7389     else
    7390     {
    7391         evDesc.init(mEventSource, VBoxEventType_OnShowWindow, INT64_C(0));
    7392         BOOL fDelivered = evDesc.fire(5000); /* Wait up to 5 secs for delivery */
    7393         //Assert(fDelivered);
    7394         if (fDelivered)
    7395         {
    7396             ComPtr<IEvent> pEvent;
    7397             evDesc.getEvent(pEvent.asOutParam());
    7398             ComPtr<IShowWindowEvent> pShowEvent = pEvent;
    7399             if (pShowEvent)
    7400             {
    7401                 LONG64 iEvWinId = 0;
    7402                 pShowEvent->COMGETTER(WinId)(&iEvWinId);
    7403                 if (iEvWinId != 0 && *aWinId == 0)
    7404                     *aWinId = iEvWinId;
    7405             }
    7406             else
    7407                 AssertFailed();
    74087408        }
    74097409    }
  • trunk/src/VBox/Main/src-client/KeyboardImpl.cpp

    r82968 r85286  
    2323
    2424#include "AutoCaller.h"
     25#include "VBoxEvents.h"
    2526
    2627#include <VBox/com/array.h>
     
    212213        keys[i] = aScancodes[i];
    213214
    214     VBoxEventDesc evDesc;
    215     evDesc.init(mEventSource, VBoxEventType_OnGuestKeyboard, ComSafeArrayAsInParam(keys));
    216     evDesc.fire(0);
     215    fireGuestKeyboardEvent(mEventSource, ComSafeArrayAsInParam(keys));
    217216
    218217    if (RT_FAILURE(vrc))
  • trunk/src/VBox/Main/src-client/MouseImpl.cpp

    r82968 r85286  
    2525#include "VMMDev.h"
    2626#include "MousePointerShapeWrap.h"
     27#include "VBoxEvents.h"
    2728
    2829#include <VBox/vmm/pdmdrv.h>
     
    266267    HRESULT rc = mEventSource->init();
    267268    AssertComRCReturnRC(rc);
    268     mMouseEvent.init(mEventSource, VBoxEventType_OnGuestMouse,
    269                      0, 0, 0, 0, 0, 0);
     269
     270    ComPtr<IEvent> ptrEvent;
     271    rc = CreateGuestMouseEvent(ptrEvent.asOutParam(), mEventSource,
     272                               (GuestMouseEventMode_T)0, 0 /*x*/, 0 /*y*/, 0 /*z*/, 0 /*w*/, 0 /*buttons*/);
     273    AssertComRCReturnRC(rc);
     274    mMouseEvent.init(ptrEvent, mEventSource);
    270275
    271276    /* Confirm a successful initialization */
     
    688693
    689694    if (fButtons != 0)
    690     {
    691         VBoxEventDesc evDesc;
    692         evDesc.init(mEventSource, VBoxEventType_OnGuestMouse, mode, x, y,
    693                     dz, dw, fButtons);
    694         evDesc.fire(0);
    695     }
     695        fireGuestMouseEvent(mEventSource, mode, x, y, dz, dw, fButtons);
    696696    else
    697697    {
    698         mMouseEvent.reinit(VBoxEventType_OnGuestMouse, mode, x, y, dz, dw,
    699                            fButtons);
     698        ComPtr<IEvent> ptrEvent;
     699        mMouseEvent.getEvent(ptrEvent.asOutParam());
     700        ReinitGuestMouseEvent(ptrEvent, mode, x, y, dz, dw, fButtons);
    700701        mMouseEvent.fire(0);
    701702    }
     
    722723    }
    723724
    724     VBoxEventDesc evDesc;
    725     evDesc.init(mEventSource, VBoxEventType_OnGuestMultiTouch,
    726                 cContacts, ComSafeArrayAsInParam(xPositions), ComSafeArrayAsInParam(yPositions),
    727                 ComSafeArrayAsInParam(contactIds), ComSafeArrayAsInParam(contactFlags), u32ScanTime);
    728     evDesc.fire(0);
     725    fireGuestMultiTouchEvent(mEventSource, cContacts, ComSafeArrayAsInParam(xPositions), ComSafeArrayAsInParam(yPositions),
     726                             ComSafeArrayAsInParam(contactIds), ComSafeArrayAsInParam(contactFlags), u32ScanTime);
    729727}
    730728
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