VirtualBox

Changeset 85286 in vbox


Ignore:
Timestamp:
Jul 12, 2020 11:08:50 PM (4 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
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/comimpl.xsl

    r82972 r85286  
    127127      <xsl:choose>
    128128        <xsl:when test="$mod='ptr'">
    129           <xsl:value-of select="'BYTE*'" />
     129          <xsl:value-of select="'BYTE *'" />
    130130        </xsl:when>
    131131        <xsl:when test="(($type='wstring') or ($type='uuid'))">
     
    148148          <xsl:choose>
    149149            <xsl:when test="$param">
    150               <xsl:value-of select="concat($type,'*')"/>
     150              <xsl:value-of select="concat($type,' *')"/>
    151151            </xsl:when>
    152152            <xsl:otherwise>
     
    186186      </xsl:choose>
    187187      <xsl:if test="$dir='out'">
    188         <xsl:value-of select="'*'"/>
     188        <xsl:value-of select="' *'"/>
    189189      </xsl:if>
    190190      <xsl:if test="$param and not($param='_')">
     
    258258  <xsl:param name="name" />
    259259  <xsl:param name="obj" />
     260  <xsl:param name="va" select="true" />
    260261  <xsl:variable name="extends">
    261262    <xsl:value-of select="key('G_keyInterfacesByName', $name)/@extends" />
     
    271272        <xsl:with-param name="name" select="$extends" />
    272273        <xsl:with-param name="obj" select="$obj" />
     274        <xsl:with-param name="va" select="$va" />
    273275      </xsl:call-template>
    274276    </xsl:when>
     
    310312          </xsl:call-template>
    311313        </xsl:variable>
    312         <xsl:value-of select="       '#ifdef RT_OS_WINDOWS&#10;'"/>
    313         <xsl:value-of select="concat('              SAFEARRAY *aPtr_', @name, ' = va_arg(args, SAFEARRAY *);&#10;')"/>
    314         <xsl:value-of select="concat('              com::SafeArray&lt;', $elemtype,'&gt;   aArr_', @name, '(aPtr_', @name, ');&#10;')"/>
    315         <xsl:value-of select="       '#else&#10;'"/>
    316         <xsl:value-of select="concat('              PRUint32 aArrSize_', @name, ' = va_arg(args, PRUint32);&#10;')"/>
    317         <xsl:value-of select="concat('              void*    aPtr_', @name, ' = va_arg(args, void*);&#10;')"/>
    318         <xsl:value-of select="concat('              com::SafeArray&lt;', $elemtype,'&gt;   aArr_', @name, '(aArrSize_', @name, ', (', $elemtype,'*)aPtr_', @name, ');&#10;')"/>
    319         <xsl:value-of select="       '#endif&#10;'"/>
    320         <xsl:value-of select="concat('              ',$obj, '->set_', @name, '(ComSafeArrayAsInParam(aArr_', @name, '));&#10;')"/>
     314        <xsl:if test="$va">
     315          <xsl:value-of select="       '#ifdef RT_OS_WINDOWS&#10;'"/>
     316          <xsl:value-of select="concat('            SAFEARRAY *aPtr_', @name, ' = va_arg(args, SAFEARRAY *);&#10;')"/>
     317          <xsl:value-of select="concat('            com::SafeArray&lt;', $elemtype,'&gt;   aArr_', @name, '(aPtr_', @name, ');&#10;')"/>
     318          <xsl:value-of select="       '#else&#10;'"/>
     319          <xsl:value-of select="concat('            PRUint32 aArrSize_', @name, ' = va_arg(args, PRUint32);&#10;')"/>
     320          <xsl:value-of select="concat('            void*    aPtr_', @name, ' = va_arg(args, void*);&#10;')"/>
     321          <xsl:value-of select="concat('            com::SafeArray&lt;', $elemtype,'&gt;   aArr_', @name, '(aArrSize_', @name, ', (', $elemtype,'*)aPtr_', @name, ');&#10;')"/>
     322          <xsl:value-of select="       '#endif&#10;'"/>
     323          <xsl:value-of select="concat('            ',$obj, '->set_', @name, '(ComSafeArrayAsInParam(aArr_', @name, '));&#10;')"/>
     324        </xsl:if>
     325        <xsl:if test="not($va)">
     326          <xsl:value-of select="concat('            ',$obj, '->set_', @name, '(ComSafeArrayInArg(a_', @name, '));&#10;')"/>
     327        </xsl:if>
    321328      </xsl:when>
    322329      <xsl:when test="substring($aType, string-length($aType) - 1) = '_T'"> <!-- To avoid pedantic gcc warnings/errors. -->
    323         <xsl:value-of select="       '#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK&#10;'"/>
    324         <xsl:value-of select="concat('              ',$aTypeName, ' = (',$aType,')va_arg(args, int);&#10;')"/>
    325         <xsl:value-of select="       '#else&#10;'"/>
    326         <xsl:value-of select="concat('              ',$aTypeName, ' = va_arg(args, ',$aType,');&#10;')"/>
    327         <xsl:value-of select="       '#endif&#10;'"/>
    328         <xsl:value-of select="concat('              ',$obj, '->set_', @name, '(',$aName, ');&#10;')"/>
     330        <xsl:if test="$va">
     331          <xsl:value-of select="       '#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK&#10;'"/>
     332          <xsl:value-of select="concat('            ',$aTypeName, ' = (',$aType,')va_arg(args, int);&#10;')"/>
     333          <xsl:value-of select="       '#else&#10;'"/>
     334          <xsl:value-of select="concat('            ',$aTypeName, ' = va_arg(args, ',$aType,');&#10;')"/>
     335          <xsl:value-of select="       '#endif&#10;'"/>
     336        </xsl:if>
     337        <xsl:value-of select="concat('            ',$obj, '->set_', @name, '(',$aName, ');&#10;')"/>
    329338      </xsl:when>
    330339      <xsl:otherwise>
    331         <xsl:value-of select="concat('              ',$aTypeName, ' = va_arg(args, ',$aType,');&#10;')"/>
    332         <xsl:value-of select="concat('              ',$obj, '->set_', @name, '(',$aName, ');&#10;')"/>
     340        <xsl:if test="$va">
     341          <xsl:value-of select="concat('            ',$aTypeName, ' = va_arg(args, ',$aType,');&#10;')"/>
     342        </xsl:if>
     343        <xsl:value-of select="concat('            ',$obj, '->set_', @name, '(',$aName, ');&#10;')"/>
    333344      </xsl:otherwise>
    334345    </xsl:choose>
     
    489500
    490501  <xsl:value-of select="concat('class ATL_NO_VTABLE ',$implName,
    491                         '&#10;    : public VirtualBoxBase,&#10;      VBOX_SCRIPTABLE_IMPL(',
     502                        '&#10;    : public VirtualBoxBase&#10;    , VBOX_SCRIPTABLE_IMPL(',
    492503                        @name, ')&#10;{&#10;')" />
    493504  <xsl:value-of select="'public:&#10;'" />
     
    550561    <xsl:when test="$isVeto='yes'">
    551562<xsl:text><![CDATA[
    552     HRESULT init(IEventSource* aSource, VBoxEventType_T aType, BOOL aWaitable = TRUE)
     563    HRESULT init(IEventSource *aSource, VBoxEventType_T aType, BOOL aWaitable = TRUE)
    553564    {
    554565        NOREF(aWaitable);
     
    586597      <xsl:text>
    587598<![CDATA[
    588     HRESULT init(IEventSource* aSource, VBoxEventType_T aType, BOOL aWaitable = FALSE)
     599    HRESULT init(IEventSource *aSource, VBoxEventType_T aType, BOOL aWaitable = FALSE)
    589600    {
    590601        mGeneration = 1;
     
    593604    STDMETHOD(COMGETTER(Generation))(ULONG *aGeneration)
    594605    {
    595       *aGeneration = mGeneration;
    596       return S_OK;
     606        *aGeneration = mGeneration;
     607        return S_OK;
    597608    }
    598609    STDMETHOD(Reuse)()
    599610    {
    600        ASMAtomicIncU32((volatile uint32_t*)&mGeneration);
    601        return S_OK;
     611        ASMAtomicIncU32((volatile uint32_t *)&mGeneration);
     612        return S_OK;
    602613    }
    603614private:
     
    608619    <xsl:otherwise>
    609620<xsl:text><![CDATA[
    610     HRESULT init(IEventSource* aSource, VBoxEventType_T aType, BOOL aWaitable)
     621    HRESULT init(IEventSource *aSource, VBoxEventType_T aType, BOOL aWaitable)
    611622    {
    612623        return mEvent->init(aSource, aType, aWaitable);
     
    637648    <xsl:with-param name="parents" select="''" />
    638649  </xsl:call-template>
     650
     651  <!-- Split off the remainer into separate template? -->
     652  <xsl:variable name="evname">
     653    <xsl:value-of select="substring(@name, 2)" />
     654  </xsl:variable>
     655  <xsl:variable name="evid">
     656    <xsl:value-of select="concat('On', substring(@name, 2, string-length(@name)-6))" />
     657  </xsl:variable>
     658  <xsl:variable name="ifname">
     659    <xsl:value-of select="@name" />
     660  </xsl:variable>
     661  <xsl:variable name="waitable">
     662    <xsl:choose>
     663      <xsl:when test="@waitable='yes'">
     664        <xsl:value-of select="'TRUE'"/>
     665      </xsl:when>
     666      <xsl:otherwise>
     667        <xsl:value-of select="'FALSE'"/>
     668      </xsl:otherwise>
     669    </xsl:choose>
     670  </xsl:variable>
     671
     672  <!-- Generate ReinitXxxxEvent functions if reusable. -->
     673  <xsl:if test="$isReusable='yes'">
     674    <xsl:value-of select="concat('DECLHIDDEN(HRESULT) Reinit', $evname, '(IEvent *aEvent')"/>
     675    <xsl:call-template name="genFormalParams">
     676      <xsl:with-param name="name" select="$ifname" />
     677    </xsl:call-template>
     678    <xsl:text>)&#10;</xsl:text>
     679    <xsl:text>{&#10;</xsl:text>
     680    <xsl:text>    </xsl:text><xsl:value-of select="$implName"/><xsl:text> *pEvtImpl = dynamic_cast&lt;</xsl:text>
     681    <xsl:value-of select="$implName"/><xsl:text> *&gt;(aEvent);&#10;</xsl:text>
     682    <xsl:text>    if (pEvtImpl)&#10;</xsl:text>
     683    <xsl:text>    {&#10;</xsl:text>
     684    <xsl:text>        pEvtImpl->Reuse();&#10;</xsl:text>
     685    <xsl:text>        {&#10;</xsl:text>
     686    <xsl:call-template name="genAttrInitCode">
     687      <xsl:with-param name="name" select="@name" />
     688      <xsl:with-param name="obj" select="'pEvtImpl'" />
     689      <xsl:with-param name="va" select="false" />
     690    </xsl:call-template>
     691    <xsl:text>        }&#10;</xsl:text>
     692    <xsl:text>        return S_OK;&#10;</xsl:text>
     693    <xsl:text>    }&#10;</xsl:text>
     694    <xsl:text>    return E_INVALIDARG;&#10;</xsl:text>
     695    <xsl:text>}&#10;</xsl:text>
     696    <xsl:text>&#10;</xsl:text>
     697  </xsl:if>
     698
     699  <!-- Generate the CreateXxxxEvent function. -->
     700  <xsl:value-of select="concat('DECLHIDDEN(HRESULT) Create', $evname, '(IEvent **aEvent, IEventSource *aSource')"/>
     701  <xsl:call-template name="genFormalParams">
     702    <xsl:with-param name="name" select="$ifname" />
     703  </xsl:call-template>
     704  <xsl:text>)&#10;</xsl:text>
     705  <xsl:text>{&#10;</xsl:text>
     706  <xsl:text>    ComObjPtr&lt;</xsl:text><xsl:value-of select="$implName"/><xsl:text>&gt; EvtObj;&#10;</xsl:text>
     707  <xsl:text>    HRESULT hrc = EvtObj.createObject();&#10;</xsl:text>
     708  <xsl:text>    if (SUCCEEDED(hrc))&#10;</xsl:text>
     709  <xsl:text>    {&#10;</xsl:text>
     710  <xsl:text>        hrc = EvtObj-&gt;init(aSource, VBoxEventType_</xsl:text><xsl:value-of select="$evid"/>
     711  <xsl:text>, </xsl:text><xsl:value-of select="$waitable" /><xsl:text> /*waitable*/);&#10;</xsl:text>
     712  <xsl:text>        if (SUCCEEDED(hrc))&#10;</xsl:text>
     713  <xsl:text>        {&#10;</xsl:text>
     714  <xsl:call-template name="genAttrInitCode">
     715    <xsl:with-param name="name" select="@name" />
     716    <xsl:with-param name="obj" select="'EvtObj'" />
     717    <xsl:with-param name="va" select="false" />
     718  </xsl:call-template>
     719  <xsl:text>            hrc = EvtObj.queryInterfaceTo(aEvent);&#10;</xsl:text>
     720  <xsl:text>        }&#10;</xsl:text>
     721  <xsl:text>    }&#10;</xsl:text>
     722  <xsl:text>    return hrc;&#10;</xsl:text>
     723  <xsl:text>}&#10;</xsl:text>
     724  <xsl:text>&#10;</xsl:text>
     725
     726  <!-- Generate the fireXxxxEvent function. -->
     727  <xsl:value-of select="concat('DECLHIDDEN(HRESULT) fire', $evname, '(IEventSource *aSource')"/>
     728  <xsl:call-template name="genFormalParams">
     729    <xsl:with-param name="name" select="$ifname" />
     730  </xsl:call-template>
     731  <xsl:text>)&#10;</xsl:text>
     732  <xsl:text>{&#10;</xsl:text>
     733  <xsl:text>    ComPtr&lt;IEvent&gt; ptrEvent;&#10;</xsl:text>
     734  <xsl:text>    HRESULT hrc = </xsl:text>
     735  <xsl:value-of select="concat('Create', $evname, '(ptrEvent.asOutParam(), aSource')"/>
     736  <xsl:call-template name="genFactParams">
     737    <xsl:with-param name="name" select="$ifname" />
     738  </xsl:call-template>
     739  <xsl:text>);&#10;</xsl:text>
     740  <xsl:text>    if (SUCCEEDED(hrc))&#10;</xsl:text>
     741  <xsl:text>    {&#10;</xsl:text>
     742  <xsl:text>        VBoxEventDesc EvtDesc(ptrEvent, aSource);&#10;</xsl:text>
     743  <xsl:text>        EvtDesc.fire(/* do not wait for delivery */ 0);&#10;</xsl:text>
     744  <xsl:text>    }&#10;</xsl:text>
     745  <xsl:text>    return hrc;&#10;</xsl:text>
     746  <xsl:text>}&#10;</xsl:text>
     747  <xsl:text>&#10;</xsl:text>
    639748
    640749</xsl:template>
     
    691800#include <iprt/asm.h>
    692801#include "EventImpl.h"
     802#include "VBoxEvents.h"
    693803]]></xsl:text>
    694804
     
    723833
    724834  <xsl:text><![CDATA[
     835#if 0
    725836HRESULT VBoxEventDesc::init(IEventSource *aSource, VBoxEventType_T aType, ...)
    726837{
     
    752863    return S_OK;
    753864}
     865#endif
    754866]]></xsl:text>
    755867
    756868 <xsl:text><![CDATA[
     869#if 0
    757870HRESULT VBoxEventDesc::reinit(VBoxEventType_T aType, ...)
    758871{
     
    783896    return S_OK;
    784897}
     898#endif
    785899]]></xsl:text>
    786900
     
    868982<xsl:text><![CDATA[
    869983#include "EventImpl.h"
     984
    870985]]></xsl:text>
    871986
    872   <!-- Interfaces -->
     987  <!-- Simple methods for firing off events. -->
     988 <xsl:text>/** @name Fire off events&#10;</xsl:text>
     989 <xsl:text> * @{ */&#10;</xsl:text>
    873990  <xsl:for-each select="//interface[@autogen='VBoxEvent']">
    874     <xsl:value-of select="concat('// ', @name,  ' generation routine &#10;')" />
     991    <xsl:value-of select="concat('/** Fire an ', @name,  ' event. */&#10;')" />
    875992    <xsl:variable name="evname">
    876993      <xsl:value-of select="substring(@name, 2)" />
     
    8841001    </xsl:variable>
    8851002
    886     <xsl:value-of select="concat('DECLINLINE(void) fire', $evname, '(IEventSource* aSource')"/>
     1003    <!--
     1004    OLD:
     1005    <xsl:value-of select="concat('DECLINLINE(void) fire', $evname, '(IEventSource *aSource')"/>
    8871006    <xsl:call-template name="genFormalParams">
    8881007      <xsl:with-param name="name" select="$ifname" />
     
    8981017    <xsl:value-of select="       '    evDesc.fire(/* do not wait for delivery */ 0);&#10;'"/>
    8991018    <xsl:value-of select="       '}&#10;'"/>
     1019
     1020    NEW:
     1021    -->
     1022    <xsl:value-of select="concat('DECLHIDDEN(HRESULT) fire', $evname, '(IEventSource *aSource')"/>
     1023    <xsl:call-template name="genFormalParams">
     1024      <xsl:with-param name="name" select="$ifname" />
     1025    </xsl:call-template>
     1026    <xsl:text>);&#10;</xsl:text>
    9001027  </xsl:for-each>
     1028  <xsl:text>/** @} */&#10;&#10;</xsl:text>
     1029
     1030  <!-- Event instantiation methods. -->
     1031  <xsl:text>/** @name Instantiate events&#10;</xsl:text>
     1032  <xsl:text> * @{ */&#10;</xsl:text>
     1033  <xsl:for-each select="//interface[@autogen='VBoxEvent']">
     1034    <xsl:value-of select="concat('/** Create an ', @name,  ' event. */&#10;')" />
     1035    <xsl:variable name="evname">
     1036      <xsl:value-of select="substring(@name, 2)" />
     1037    </xsl:variable>
     1038    <xsl:variable name="evid">
     1039      <xsl:value-of select="concat('On', substring(@name, 2, string-length(@name)-6))" />
     1040    </xsl:variable>
     1041    <xsl:variable name="ifname">
     1042      <xsl:value-of select="@name" />
     1043    </xsl:variable>
     1044
     1045    <xsl:value-of select="concat('DECLHIDDEN(HRESULT) Create', $evname, '(IEvent **aEvent, IEventSource *aSource')"/>
     1046    <xsl:call-template name="genFormalParams">
     1047      <xsl:with-param name="name" select="$ifname" />
     1048    </xsl:call-template>
     1049    <xsl:text>);&#10;</xsl:text>
     1050  </xsl:for-each>
     1051  <xsl:text>/** @} */&#10;</xsl:text>
     1052  <xsl:text>&#10;</xsl:text>
     1053
     1054  <!-- Reinitialization methods for reusable events. -->
     1055  <xsl:text>/** @name Re-init reusable events&#10;</xsl:text>
     1056  <xsl:text> * @{ */&#10;</xsl:text>
     1057  <xsl:for-each select="//interface[@autogen='VBoxEvent']">
     1058    <xsl:if test="@extends='IReusableEvent'">
     1059      <xsl:value-of select="concat('/** Re-init an ', @name,  ' event. */&#10;')" />
     1060      <xsl:variable name="evname">
     1061        <xsl:value-of select="substring(@name, 2)" />
     1062      </xsl:variable>
     1063      <xsl:variable name="ifname">
     1064        <xsl:value-of select="@name" />
     1065      </xsl:variable>
     1066
     1067      <xsl:value-of select="concat('DECLHIDDEN(HRESULT) Reinit', $evname, '(IEvent *aEvent')"/>
     1068      <xsl:call-template name="genFormalParams">
     1069        <xsl:with-param name="name" select="$ifname" />
     1070      </xsl:call-template>
     1071      <xsl:text>);&#10;</xsl:text>
     1072    </xsl:if>
     1073  </xsl:for-each>
     1074  <xsl:text>/** @} */&#10;</xsl:text>
     1075
    9011076</xsl:template>
    9021077
  • trunk/src/VBox/Main/include/EventImpl.h

    r85240 r85286  
    2727
    2828
    29 class ATL_NO_VTABLE VBoxEvent :
    30     public EventWrap
     29class ATL_NO_VTABLE VBoxEvent
     30    : public EventWrap
    3131{
    3232public:
     
    5555
    5656
    57 class ATL_NO_VTABLE VBoxVetoEvent :
    58     public VetoEventWrap
     57class ATL_NO_VTABLE VBoxVetoEvent
     58    : public VetoEventWrap
    5959{
    6060public:
     
    123123
    124124    struct Data;
    125     Data* m;
     125    Data *m;
    126126
    127127    friend class ListenerRecord;
     
    134134    {}
    135135
     136    VBoxEventDesc(IEvent *aEvent, IEventSource *aSource)
     137        : mEvent(aEvent), mEventSource(aSource)
     138    {}
     139
    136140    ~VBoxEventDesc()
    137141    {}
    138142
     143
     144#if 0
    139145    /**
    140146     * This function to be used with some care, as arguments order must match
     
    150156    */
    151157    HRESULT reinit(VBoxEventType_T aType, ...);
     158#endif
     159
     160    void init(IEvent *aEvent, IEventSource *aSource)
     161    {
     162        mEvent       = aEvent;
     163        mEventSource = aSource;
     164    }
    152165
    153166    void uninit()
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r85121 r85286  
    9191    typedef ObjectsList<Machine> MachinesOList;
    9292
     93#if 0 /* obsoleted by AsyncEvent */
    9394    class CallbackEvent;
    9495    friend class CallbackEvent;
     96#endif
     97    class AsyncEvent;
     98    friend class AsyncEvent;
    9599
    96100#ifndef VBOX_WITH_XPCOM
  • trunk/src/VBox/Main/src-all/EventImpl.cpp

    r85239 r85286  
    5858#include "AutoCaller.h"
    5959#include "LoggingNew.h"
     60#include "VBoxEvents.h"
    6061
    6162#include <iprt/asm.h>
     
    10731074    m->mListeners.insert(Listeners::value_type((IEventListener *)aListener, lrh));
    10741075
    1075     VBoxEventDesc evDesc;
    1076     evDesc.init(this, VBoxEventType_OnEventSourceChanged, (IEventListener *)aListener, TRUE);
    1077     evDesc.fire(0);
     1076    fireEventSourceChangedEvent(this, (IEventListener *)aListener, TRUE /*add*/);
    10781077
    10791078    return S_OK;
     
    10931092        m->mListeners.erase(it);
    10941093        // destructor removes refs from the event map
     1094        fireEventSourceChangedEvent(this, (IEventListener *)aListener, FALSE /*add*/);
    10951095        rc = S_OK;
    10961096    }
    10971097    else
    1098     {
    10991098        rc = setError(VBOX_E_OBJECT_NOT_FOUND,
    11001099                      tr("Listener was never registered"));
    1101     }
    1102 
    1103     if (SUCCEEDED(rc))
    1104     {
    1105         VBoxEventDesc evDesc;
    1106         evDesc.init(this, VBoxEventType_OnEventSourceChanged, (IEventListener *)aListener, FALSE);
    1107         evDesc.fire(0);
    1108     }
    11091100
    11101101    return rc;
  • 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
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r85262 r85286  
    9090#include "CloudProviderManagerImpl.h"
    9191#include "ThreadTask.h"
     92#include "VBoxEvents.h"
    9293
    9394#include <QMTranslator.h>
     
    135136
    136137
     138#if 0 /* obsoleted by AsyncEvent */
    137139////////////////////////////////////////////////////////////////////////////////
    138140//
     
    173175protected:
    174176    VBoxEventType_T     mWhat;
     177};
     178#endif
     179
     180////////////////////////////////////////////////////////////////////////////////
     181//
     182// AsyncEvent class
     183//
     184////////////////////////////////////////////////////////////////////////////////
     185
     186/**
     187 * For firing off an event on asynchronously on an event thread.
     188 */
     189class VirtualBox::AsyncEvent : public Event
     190{
     191public:
     192    AsyncEvent(VirtualBox *a_pVirtualBox, ComPtr<IEvent> const &a_rEvent)
     193        : mVirtualBox(a_pVirtualBox), mEvent(a_rEvent)
     194    {
     195        Assert(a_pVirtualBox);
     196    }
     197
     198    void *handler() RT_OVERRIDE;
     199
     200private:
     201    /**
     202     * @note This is a weak ref -- the CallbackEvent handler thread is bound to the
     203     *       lifetime of the VirtualBox instance, so it's safe.
     204     */
     205    VirtualBox         *mVirtualBox;
     206    /** The event. */
     207    ComPtr<IEvent>      mEvent;
    175208};
    176209
     
    556589    try
    557590    {
     591        /* Create the event source early as we may fire async event during settings loading (media). */
     592        rc = unconst(m->pEventSource).createObject();
     593        if (FAILED(rc)) throw rc;
     594        rc = m->pEventSource->init();
     595        if (FAILED(rc)) throw rc;
     596
     597
    558598        /* Get the VirtualBox home directory. */
    559599        {
     
    718758        }
    719759#endif /* VBOX_WITH_CLOUD_NET */
    720 
    721         /* events */
    722         if (SUCCEEDED(rc = unconst(m->pEventSource).createObject()))
    723             rc = m->pEventSource->init();
    724         if (FAILED(rc)) throw rc;
    725760
    726761        /* cloud provider manager */
     
    31883223}
    31893224
    3190 /** Event for onMachineStateChange(), onMachineDataChange(), onMachineRegistered() */
    3191 struct MachineEvent : public VirtualBox::CallbackEvent
    3192 {
    3193     MachineEvent(VirtualBox *aVB, VBoxEventType_T aWhat, const Guid &aId, BOOL aBool)
    3194         : CallbackEvent(aVB, aWhat), id(aId.toUtf16())
    3195         , mBool(aBool)
    3196         { }
    3197 
    3198     MachineEvent(VirtualBox *aVB, VBoxEventType_T aWhat, const Guid &aId, MachineState_T aState)
    3199         : CallbackEvent(aVB, aWhat), id(aId.toUtf16())
    3200         , mState(aState)
    3201         {}
    3202 
    3203     virtual HRESULT prepareEventDesc(IEventSource* aSource, VBoxEventDesc& aEvDesc)
    3204     {
    3205         switch (mWhat)
    3206         {
    3207             case VBoxEventType_OnMachineDataChanged:
    3208                 aEvDesc.init(aSource, mWhat, id.raw(), mBool);
    3209                 break;
    3210 
    3211             case VBoxEventType_OnMachineStateChanged:
    3212                 aEvDesc.init(aSource, mWhat, id.raw(), mState);
    3213                 break;
    3214 
    3215             case VBoxEventType_OnMachineRegistered:
    3216                 aEvDesc.init(aSource, mWhat, id.raw(), mBool);
    3217                 break;
    3218 
    3219             default:
    3220                 AssertFailedReturn(S_OK);
    3221          }
    3222          return S_OK;
    3223     }
    3224 
    3225     Bstr id;
    3226     MachineState_T mState;
    3227     BOOL mBool;
    3228 };
    3229 
    3230 
    32313225/**
    32323226 * VD plugin load
     
    32453239}
    32463240
    3247 
    3248 /** Event for onMediumRegistered() */
    3249 struct MediumRegisteredEventStruct : public VirtualBox::CallbackEvent
    3250 {
    3251     MediumRegisteredEventStruct(VirtualBox *aVB, const Guid &aMediumId,
    3252                           const DeviceType_T aDevType, const BOOL aRegistered)
    3253         : CallbackEvent(aVB, VBoxEventType_OnMediumRegistered)
    3254         , mMediumId(aMediumId.toUtf16()), mDevType(aDevType), mRegistered(aRegistered)
    3255     {}
    3256 
    3257     virtual HRESULT prepareEventDesc(IEventSource *aSource, VBoxEventDesc &aEvDesc)
    3258     {
    3259         return aEvDesc.init(aSource, VBoxEventType_OnMediumRegistered, mMediumId.raw(), mDevType, mRegistered);
    3260     }
    3261 
    3262     Bstr mMediumId;
    3263     DeviceType_T mDevType;
    3264     BOOL mRegistered;
    3265 };
    3266 
    32673241/**
    32683242 *  @note Doesn't lock any object.
     
    32703244void VirtualBox::i_onMediumRegistered(const Guid &aMediumId, const DeviceType_T aDevType, const BOOL aRegistered)
    32713245{
    3272     i_postEvent(new MediumRegisteredEventStruct(this, aMediumId, aDevType, aRegistered));
    3273 }
    3274 
    3275 /** Event for onMediumConfigChanged() */
    3276 struct MediumConfigChangedEventStruct : public VirtualBox::CallbackEvent
    3277 {
    3278     MediumConfigChangedEventStruct(VirtualBox *aVB, IMedium *aMedium)
    3279         : CallbackEvent(aVB, VBoxEventType_OnMediumConfigChanged)
    3280         , mMedium(aMedium)
    3281     {}
    3282 
    3283     virtual HRESULT prepareEventDesc(IEventSource *aSource, VBoxEventDesc &aEvDesc)
    3284     {
    3285         return aEvDesc.init(aSource, VBoxEventType_OnMediumConfigChanged, mMedium);
    3286     }
    3287 
    3288     IMedium* mMedium;
    3289 };
     3246    ComPtr<IEvent> ptrEvent;
     3247    HRESULT hrc = CreateMediumRegisteredEvent(ptrEvent.asOutParam(), m->pEventSource,
     3248                                              aMediumId.toUtf16().raw(), aDevType, aRegistered);
     3249    AssertComRCReturnVoid(hrc);
     3250    i_postEvent(new AsyncEvent(this, ptrEvent));
     3251}
    32903252
    32913253void VirtualBox::i_onMediumConfigChanged(IMedium *aMedium)
    32923254{
    3293     i_postEvent(new MediumConfigChangedEventStruct(this, aMedium));
    3294 }
    3295 
    3296 /** Event for onMediumChanged() */
    3297 struct MediumChangedEventStruct : public VirtualBox::CallbackEvent
    3298 {
    3299     MediumChangedEventStruct(VirtualBox *aVB, IMediumAttachment *aMediumAttachment)
    3300         : CallbackEvent(aVB, VBoxEventType_OnMediumChanged)
    3301         , mMediumAttachment(aMediumAttachment)
    3302     {}
    3303 
    3304     virtual HRESULT prepareEventDesc(IEventSource *aSource, VBoxEventDesc &aEvDesc)
    3305     {
    3306         return aEvDesc.init(aSource, VBoxEventType_OnMediumChanged, mMediumAttachment);
    3307     }
    3308 
    3309     IMediumAttachment* mMediumAttachment;
    3310 };
     3255    ComPtr<IEvent> ptrEvent;
     3256    HRESULT hrc = CreateMediumConfigChangedEvent(ptrEvent.asOutParam(), m->pEventSource, aMedium);
     3257    AssertComRCReturnVoid(hrc);
     3258    i_postEvent(new AsyncEvent(this, ptrEvent));
     3259}
    33113260
    33123261void VirtualBox::i_onMediumChanged(IMediumAttachment *aMediumAttachment)
    33133262{
    3314     i_postEvent(new MediumChangedEventStruct(this, aMediumAttachment));
    3315 }
    3316 
    3317 /** Event for onStorageControllerChanged() */
    3318 struct StorageControllerChangedEventStruct : public VirtualBox::CallbackEvent
    3319 {
    3320     StorageControllerChangedEventStruct(VirtualBox *aVB, const Guid &aMachineId,
    3321                                         const com::Utf8Str &aControllerName)
    3322         : CallbackEvent(aVB, VBoxEventType_OnStorageControllerChanged)
    3323         , mMachineId(aMachineId.toUtf16()), mControllerName(aControllerName)
    3324     {}
    3325 
    3326     virtual HRESULT prepareEventDesc(IEventSource *aSource, VBoxEventDesc &aEvDesc)
    3327     {
    3328         return aEvDesc.init(aSource, VBoxEventType_OnStorageControllerChanged, mMachineId.raw(), mControllerName.raw());
    3329     }
    3330 
    3331     Bstr mMachineId;
    3332     Bstr mControllerName;
    3333 };
     3263    ComPtr<IEvent> ptrEvent;
     3264    HRESULT hrc = CreateMediumChangedEvent(ptrEvent.asOutParam(), m->pEventSource, aMediumAttachment);
     3265    AssertComRCReturnVoid(hrc);
     3266    i_postEvent(new AsyncEvent(this, ptrEvent));
     3267}
    33343268
    33353269/**
     
    33383272void VirtualBox::i_onStorageControllerChanged(const Guid &aMachineId, const com::Utf8Str &aControllerName)
    33393273{
    3340     i_postEvent(new StorageControllerChangedEventStruct(this, aMachineId, aControllerName));
    3341 }
    3342 
    3343 /** Event for onStorageDeviceChanged() */
    3344 struct StorageDeviceChangedEventStruct : public VirtualBox::CallbackEvent
    3345 {
    3346     StorageDeviceChangedEventStruct(VirtualBox *aVB, IMediumAttachment *aStorageDevice, BOOL fRemoved, BOOL fSilent)
    3347         : CallbackEvent(aVB, VBoxEventType_OnStorageDeviceChanged)
    3348         , mStorageDevice(aStorageDevice)
    3349         , mRemoved(fRemoved)
    3350         , mSilent(fSilent)
    3351     {}
    3352 
    3353     virtual HRESULT prepareEventDesc(IEventSource *aSource, VBoxEventDesc &aEvDesc)
    3354     {
    3355         return aEvDesc.init(aSource, VBoxEventType_OnStorageDeviceChanged, mStorageDevice, mRemoved, mSilent);
    3356     }
    3357 
    3358     IMediumAttachment* mStorageDevice;
    3359     BOOL mRemoved;
    3360     BOOL mSilent;
    3361 };
     3274    ComPtr<IEvent> ptrEvent;
     3275    HRESULT hrc = CreateStorageControllerChangedEvent(ptrEvent.asOutParam(), m->pEventSource,
     3276                                                      aMachineId.toUtf16().raw(), Bstr(aControllerName).raw());
     3277    AssertComRCReturnVoid(hrc);
     3278    i_postEvent(new AsyncEvent(this, ptrEvent));
     3279}
    33623280
    33633281void VirtualBox::i_onStorageDeviceChanged(IMediumAttachment *aStorageDevice, const BOOL fRemoved, const BOOL fSilent)
    33643282{
    3365     i_postEvent(new StorageDeviceChangedEventStruct(this, aStorageDevice, fRemoved, fSilent));
     3283    ComPtr<IEvent> ptrEvent;
     3284    HRESULT hrc = CreateStorageDeviceChangedEvent(ptrEvent.asOutParam(), m->pEventSource, aStorageDevice, fRemoved, fSilent);
     3285    AssertComRCReturnVoid(hrc);
     3286    i_postEvent(new AsyncEvent(this, ptrEvent));
    33663287}
    33673288
     
    33713292void VirtualBox::i_onMachineStateChange(const Guid &aId, MachineState_T aState)
    33723293{
    3373     i_postEvent(new MachineEvent(this, VBoxEventType_OnMachineStateChanged, aId, aState));
     3294    ComPtr<IEvent> ptrEvent;
     3295    HRESULT hrc = CreateMachineStateChangedEvent(ptrEvent.asOutParam(), m->pEventSource, aId.toUtf16().raw(), aState);
     3296    AssertComRCReturnVoid(hrc);
     3297    i_postEvent(new AsyncEvent(this, ptrEvent));
    33743298}
    33753299
     
    33793303void VirtualBox::i_onMachineDataChange(const Guid &aId, BOOL aTemporary)
    33803304{
    3381     i_postEvent(new MachineEvent(this, VBoxEventType_OnMachineDataChanged, aId, aTemporary));
     3305    ComPtr<IEvent> ptrEvent;
     3306    HRESULT hrc = CreateMachineDataChangedEvent(ptrEvent.asOutParam(), m->pEventSource, aId.toUtf16().raw(), aTemporary);
     3307    AssertComRCReturnVoid(hrc);
     3308    i_postEvent(new AsyncEvent(this, ptrEvent));
    33823309}
    33833310
     
    33883315                                        Bstr &aError)
    33893316{
    3390     LogFlowThisFunc(("machine={%s} aKey={%ls} aValue={%ls}\n",
    3391                       aId.toString().c_str(), aKey, aValue));
     3317    LogFlowThisFunc(("machine={%RTuuid} aKey={%ls} aValue={%ls}\n", aId.raw(), aKey, aValue));
    33923318
    33933319    AutoCaller autoCaller(this);
    33943320    AssertComRCReturn(autoCaller.rc(), FALSE);
    33953321
    3396     BOOL allowChange = TRUE;
    3397     Bstr id = aId.toUtf16();
    3398 
    3399     VBoxEventDesc evDesc;
    3400     evDesc.init(m->pEventSource, VBoxEventType_OnExtraDataCanChange, id.raw(), aKey, aValue);
    3401     BOOL fDelivered = evDesc.fire(3000); /* Wait up to 3 secs for delivery */
     3322    ComPtr<IEvent> ptrEvent;
     3323    HRESULT hrc = CreateExtraDataCanChangeEvent(ptrEvent.asOutParam(), m->pEventSource, aId.toUtf16().raw(), aKey, aValue);
     3324    AssertComRCReturn(hrc, TRUE);
     3325    i_postEvent(new AsyncEvent(this, ptrEvent));
     3326
     3327    VBoxEventDesc EvtDesc(ptrEvent, m->pEventSource);
     3328    BOOL fDelivered = EvtDesc.fire(3000); /* Wait up to 3 secs for delivery */
    34023329    //Assert(fDelivered);
     3330    BOOL fAllowChange = TRUE;
    34033331    if (fDelivered)
    34043332    {
    3405         ComPtr<IEvent> aEvent;
    3406         evDesc.getEvent(aEvent.asOutParam());
    3407         ComPtr<IExtraDataCanChangeEvent> aCanChangeEvent = aEvent;
    3408         Assert(aCanChangeEvent);
     3333        ComPtr<IExtraDataCanChangeEvent> ptrCanChangeEvent = ptrEvent;
     3334        Assert(ptrCanChangeEvent);
     3335
    34093336        BOOL fVetoed = FALSE;
    3410         aCanChangeEvent->IsVetoed(&fVetoed);
    3411         allowChange = !fVetoed;
    3412 
    3413         if (!allowChange)
     3337        ptrCanChangeEvent->IsVetoed(&fVetoed);
     3338        fAllowChange = !fVetoed;
     3339
     3340        if (!fAllowChange)
    34143341        {
    34153342            SafeArray<BSTR> aVetos;
    3416             aCanChangeEvent->GetVetos(ComSafeArrayAsOutParam(aVetos));
     3343            ptrCanChangeEvent->GetVetos(ComSafeArrayAsOutParam(aVetos));
    34173344            if (aVetos.size() > 0)
    34183345                aError = aVetos[0];
    34193346        }
    34203347    }
    3421     else
    3422         allowChange = TRUE;
    3423 
    3424     LogFlowThisFunc(("allowChange=%RTbool\n", allowChange));
    3425     return allowChange;
    3426 }
    3427 
    3428 /** Event for onExtraDataChange() */
    3429 struct ExtraDataEvent : public VirtualBox::CallbackEvent
    3430 {
    3431     ExtraDataEvent(VirtualBox *aVB, const Guid &aMachineId,
    3432                    IN_BSTR aKey, IN_BSTR aVal)
    3433         : CallbackEvent(aVB, VBoxEventType_OnExtraDataChanged)
    3434         , machineId(aMachineId.toUtf16()), key(aKey), val(aVal)
    3435     {}
    3436 
    3437     virtual HRESULT prepareEventDesc(IEventSource* aSource, VBoxEventDesc& aEvDesc)
    3438     {
    3439         return aEvDesc.init(aSource, VBoxEventType_OnExtraDataChanged, machineId.raw(), key.raw(), val.raw());
    3440     }
    3441 
    3442     Bstr machineId, key, val;
    3443 };
     3348
     3349    LogFlowThisFunc(("fAllowChange=%RTbool\n", fAllowChange));
     3350    return fAllowChange;
     3351}
    34443352
    34453353/**
    34463354 *  @note Doesn't lock any object.
     3355 *  @todo +d
    34473356 */
    34483357void VirtualBox::i_onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue)
    34493358{
    3450     i_postEvent(new ExtraDataEvent(this, aId, aKey, aValue));
     3359    ComPtr<IEvent> ptrEvent;
     3360    HRESULT hrc = CreateExtraDataChangedEvent(ptrEvent.asOutParam(), m->pEventSource, aId.toUtf16().raw(), aKey, aValue);
     3361    AssertComRCReturnVoid(hrc);
     3362    i_postEvent(new AsyncEvent(this, ptrEvent));
    34513363}
    34523364
     
    34563368void VirtualBox::i_onMachineRegistered(const Guid &aId, BOOL aRegistered)
    34573369{
    3458     i_postEvent(new MachineEvent(this, VBoxEventType_OnMachineRegistered, aId, aRegistered));
    3459 }
    3460 
    3461 /** Event for onSessionStateChange() */
    3462 struct SessionEvent : public VirtualBox::CallbackEvent
    3463 {
    3464     SessionEvent(VirtualBox *aVB, const Guid &aMachineId, SessionState_T aState)
    3465         : CallbackEvent(aVB, VBoxEventType_OnSessionStateChanged)
    3466         , machineId(aMachineId.toUtf16()), sessionState(aState)
    3467     {}
    3468 
    3469     virtual HRESULT prepareEventDesc(IEventSource* aSource, VBoxEventDesc& aEvDesc)
    3470     {
    3471         return aEvDesc.init(aSource, VBoxEventType_OnSessionStateChanged, machineId.raw(), sessionState);
    3472     }
    3473     Bstr machineId;
    3474     SessionState_T sessionState;
    3475 };
     3370    ComPtr<IEvent> ptrEvent;
     3371    HRESULT hrc = CreateMachineRegisteredEvent(ptrEvent.asOutParam(), m->pEventSource, aId.toUtf16().raw(), aRegistered);
     3372    AssertComRCReturnVoid(hrc);
     3373    i_postEvent(new AsyncEvent(this, ptrEvent));
     3374}
    34763375
    34773376/**
    34783377 *  @note Doesn't lock any object.
     3378 *  @todo +d
    34793379 */
    34803380void VirtualBox::i_onSessionStateChange(const Guid &aId, SessionState_T aState)
    34813381{
    3482     i_postEvent(new SessionEvent(this, aId, aState));
    3483 }
    3484 
    3485 /** Event for i_onSnapshotTaken(), i_onSnapshotDeleted(), i_onSnapshotRestored() and i_onSnapshotChange() */
    3486 struct SnapshotEvent : public VirtualBox::CallbackEvent
    3487 {
    3488     SnapshotEvent(VirtualBox *aVB, const Guid &aMachineId, const Guid &aSnapshotId,
    3489                   VBoxEventType_T aWhat)
    3490         : CallbackEvent(aVB, aWhat)
    3491         , machineId(aMachineId), snapshotId(aSnapshotId)
    3492         {}
    3493 
    3494     virtual HRESULT prepareEventDesc(IEventSource* aSource, VBoxEventDesc& aEvDesc)
    3495     {
    3496         return aEvDesc.init(aSource, mWhat, machineId.toUtf16().raw(),
    3497                             snapshotId.toUtf16().raw());
    3498     }
    3499 
    3500     Guid machineId;
    3501     Guid snapshotId;
    3502 };
     3382    ComPtr<IEvent> ptrEvent;
     3383    HRESULT hrc = CreateSessionStateChangedEvent(ptrEvent.asOutParam(), m->pEventSource, aId.toUtf16().raw(), aState);
     3384    AssertComRCReturnVoid(hrc);
     3385    i_postEvent(new AsyncEvent(this, ptrEvent));
     3386}
    35033387
    35043388/**
     
    35073391void VirtualBox::i_onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId)
    35083392{
    3509     i_postEvent(new SnapshotEvent(this, aMachineId, aSnapshotId,
    3510                                   VBoxEventType_OnSnapshotTaken));
     3393    ComPtr<IEvent> ptrEvent;
     3394    HRESULT hrc = CreateSnapshotTakenEvent(ptrEvent.asOutParam(), m->pEventSource,
     3395                                           aMachineId.toUtf16().raw(), aSnapshotId.toUtf16().raw());
     3396    AssertComRCReturnVoid(hrc);
     3397    i_postEvent(new AsyncEvent(this, ptrEvent));
    35113398}
    35123399
     
    35163403void VirtualBox::i_onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId)
    35173404{
    3518     i_postEvent(new SnapshotEvent(this, aMachineId, aSnapshotId,
    3519                                   VBoxEventType_OnSnapshotDeleted));
     3405    ComPtr<IEvent> ptrEvent;
     3406    HRESULT hrc = CreateSnapshotDeletedEvent(ptrEvent.asOutParam(), m->pEventSource,
     3407                                             aMachineId.toUtf16().raw(), aSnapshotId.toUtf16().raw());
     3408    AssertComRCReturnVoid(hrc);
     3409    i_postEvent(new AsyncEvent(this, ptrEvent));
    35203410}
    35213411
     
    35253415void VirtualBox::i_onSnapshotRestored(const Guid &aMachineId, const Guid &aSnapshotId)
    35263416{
    3527     i_postEvent(new SnapshotEvent(this, aMachineId, aSnapshotId,
    3528                                   VBoxEventType_OnSnapshotRestored));
     3417    ComPtr<IEvent> ptrEvent;
     3418    HRESULT hrc = CreateSnapshotRestoredEvent(ptrEvent.asOutParam(), m->pEventSource,
     3419                                              aMachineId.toUtf16().raw(), aSnapshotId.toUtf16().raw());
     3420    AssertComRCReturnVoid(hrc);
     3421    i_postEvent(new AsyncEvent(this, ptrEvent));
    35293422}
    35303423
    35313424/**
    35323425 *  @note Doesn't lock any object.
     3426 *  @todo +d
    35333427 */
    35343428void VirtualBox::i_onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId)
    35353429{
    3536     i_postEvent(new SnapshotEvent(this, aMachineId, aSnapshotId,
    3537                                   VBoxEventType_OnSnapshotChanged));
    3538 }
    3539 
    3540 /** Event for onGuestPropertyChange() */
    3541 struct GuestPropertyEvent : public VirtualBox::CallbackEvent
    3542 {
    3543     GuestPropertyEvent(VirtualBox *aVBox, const Guid &aMachineId,
    3544                        IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags)
    3545         : CallbackEvent(aVBox, VBoxEventType_OnGuestPropertyChanged),
    3546           machineId(aMachineId),
    3547           name(aName),
    3548           value(aValue),
    3549           flags(aFlags)
    3550     {}
    3551 
    3552     virtual HRESULT prepareEventDesc(IEventSource* aSource, VBoxEventDesc& aEvDesc)
    3553     {
    3554         return aEvDesc.init(aSource, VBoxEventType_OnGuestPropertyChanged,
    3555                             machineId.toUtf16().raw(), name.raw(), value.raw(), flags.raw());
    3556     }
    3557 
    3558     Guid machineId;
    3559     Bstr name, value, flags;
    3560 };
    3561 
    3562 #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
     3430    ComPtr<IEvent> ptrEvent;
     3431    HRESULT hrc = CreateSnapshotChangedEvent(ptrEvent.asOutParam(), m->pEventSource,
     3432                                             aMachineId.toUtf16().raw(), aSnapshotId.toUtf16().raw());
     3433    AssertComRCReturnVoid(hrc);
     3434    i_postEvent(new AsyncEvent(this, ptrEvent));
     3435}
     3436
     3437#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS /** @todo r=bird: Why is this still here?  */
     3438
    35633439/**
    35643440 * Generates a new clipboard area on the host by opening (and locking) a new, temporary directory.
     
    38333709    return cRefCount;
    38343710}
     3711
    38353712#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
    38363713
    38373714/**
    38383715 *  @note Doesn't lock any object.
     3716 *  @todo +d
    38393717 */
    38403718void VirtualBox::i_onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName,
    38413719                                         IN_BSTR aValue, IN_BSTR aFlags)
    38423720{
    3843     i_postEvent(new GuestPropertyEvent(this, aMachineId, aName, aValue, aFlags));
     3721    ComPtr<IEvent> ptrEvent;
     3722    HRESULT hrc = CreateGuestPropertyChangedEvent(ptrEvent.asOutParam(), m->pEventSource,
     3723                                                  aMachineId.toUtf16().raw(), aName, aValue, aFlags);
     3724    AssertComRCReturnVoid(hrc);
     3725    i_postEvent(new AsyncEvent(this, ptrEvent));
    38443726}
    38453727
    38463728/**
    38473729 *  @note Doesn't lock any object.
     3730 *  @todo +d
    38483731 */
    38493732void VirtualBox::i_onNatRedirectChange(const Guid &aMachineId, ULONG ulSlot, bool fRemove, IN_BSTR aName,
     
    38553738}
    38563739
     3740/**  @todo +d  */
    38573741void VirtualBox::i_onNATNetworkChange(IN_BSTR aName)
    38583742{
     
    58025686////////////////////////////////////////////////////////////////////////////////
    58035687
     5688#if 0 /* obsoleted by AsyncEvent */
    58045689/**
    58055690 * Prepare the event using the overwritten #prepareEventDesc method and fire.
     
    58315716
    58325717    mVirtualBox = NULL; /* Not needed any longer. Still make sense to do this? */
     5718    return NULL;
     5719}
     5720#endif
     5721
     5722/**
     5723 * Called on the event handler thread.
     5724 *
     5725 * @note Locks the managed VirtualBox object for reading but leaves the lock
     5726 *       before iterating over callbacks and calling their methods.
     5727 */
     5728void *VirtualBox::AsyncEvent::handler()
     5729{
     5730    if (mVirtualBox)
     5731    {
     5732        AutoCaller autoCaller(mVirtualBox);
     5733        if (autoCaller.isOk())
     5734        {
     5735            VBoxEventDesc EvtDesc(mEvent, mVirtualBox->m->pEventSource);
     5736            EvtDesc.fire(/* don't wait for delivery */0);
     5737        }
     5738        else
     5739            Log1WarningFunc(("VirtualBox has been uninitialized (state=%d), the callback event is discarded!\n",
     5740                             mVirtualBox->getObjectState().getState()));
     5741        mVirtualBox = NULL; /* Old code did this, not really necessary, but whatever. */
     5742    }
     5743    mEvent.setNull();
    58335744    return NULL;
    58345745}
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