VirtualBox

Changeset 31572 in vbox


Ignore:
Timestamp:
Aug 11, 2010 2:08:41 PM (14 years ago)
Author:
vboxsync
Message:

events: vacation-time idea of reusable events (for perfomance-critical operations)

Location:
trunk/src/VBox/Main
Files:
4 edited

Legend:

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

    r31269 r31572  
    684684        case VBoxEventType_Any:
    685685            return TRUE;
     686        case VBoxEventType_Vetoable:
     687            return     (what == VBoxEventType_OnExtraDataCanChange)
     688                    || (what == VBoxEventType_OnCanShowWindow);
    686689        case VBoxEventType_MachineEvent:
    687690            return     (what == VBoxEventType_OnMachineStateChanged)
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r31568 r31572  
    1367113671    <const name="Any" value="1">
    1367213672      <desc>
    13673         Wildcard for all events. Events of this type are never delivered, and only used in
     13673        Wildcard for all events.
     13674        Events of this type are never delivered, and only used in
    1367413675        registerListener() call to simplify registration.
    1367513676      </desc>
    1367613677    </const>
    1367713678
    13678     <const name="MachineEvent" value="2">
     13679    <const name="Vetoable" value="2">
     13680      <desc>
     13681        Wildcard for all vetoable events. Events of this type are never delivered, and only
     13682        used in registerListener() call to simplify registration.
     13683      </desc>
     13684    </const>
     13685
     13686    <const name="MachineEvent" value="3">
    1367913687      <desc>
    1368013688        Wildcard for all machine events. Events of this type are never delivered, and only used in
     
    1368313691    </const>
    1368413692
    13685     <const name="SnapshotEvent" value="3">
     13693    <const name="SnapshotEvent" value="4">
    1368613694      <desc>
    1368713695        Wildcard for all snapshot events. Events of this type are never delivered, and only used in
     
    1369013698    </const>
    1369113699
    13692     <const name="InputEvent" value="4">
     13700    <const name="InputEvent" value="5">
    1369313701      <desc>
    1369413702        Wildcard for all input device (keyboard, mouse) events.
  • trunk/src/VBox/Main/idl/comimpl.xsl

    r31501 r31572  
    240240  <xsl:choose>
    241241    <xsl:when test="$extends='IEvent'">
     242    </xsl:when>
     243    <xsl:when test="$extends='IReusableEvent'">
    242244    </xsl:when>
    243245    <xsl:when test="//interface[@name=$extends]">
     
    428430      <xsl:value-of select="   '    // skipping IEvent attributes &#10;'" />
    429431    </xsl:when>
     432    <xsl:when test="$extends='IReusableEvent'">
     433      <xsl:value-of select="   '    // skipping IReusableEvent attributes &#10;'" />
     434    </xsl:when>
     435     <xsl:when test="$extends='IVetoEvent'">
     436      <xsl:value-of select="   '    // skipping IVetoEvent attributes &#10;'" />
     437    </xsl:when>
    430438    <xsl:when test="//interface[@name=$extends]">
    431439      <xsl:call-template name="genAttrCode">
     
    446454  <xsl:param name="implName" />
    447455  <xsl:param name="isVeto" />
     456  <xsl:param name="isReusable" />
    448457
    449458  <xsl:value-of select="concat('class ATL_NO_VTABLE ',$implName,
     
    519528]]></xsl:text>
    520529    </xsl:when>
     530    <xsl:when test="$isReusable='yes'">
     531      <xsl:text>
     532<![CDATA[
     533    HRESULT init(IEventSource* aSource, VBoxEventType_T aType, BOOL aWaitable = FALSE)
     534    {
     535        mGeneration = 1;
     536        return mEvent->init(aSource, aType, aWaitable);
     537    }
     538    STDMETHOD(COMGETTER(Generation)) (ULONG *aGeneration)
     539    {
     540      *aGeneration = mGeneration;
     541      return S_OK;
     542    }
     543    STDMETHOD(Reuse) ()
     544    {
     545       ASMAtomicIncU32(&mGeneration);
     546       return S_OK;
     547    }
     548private:
     549    volatile ULONG              mGeneration;
     550    ComObjPtr<VBoxEvent>        mEvent;
     551]]></xsl:text>
     552    </xsl:when>
    521553    <xsl:otherwise>
    522554<xsl:text><![CDATA[
     
    548580<xsl:template name="genSwitchCase">
    549581  <xsl:param name="implName" />
     582  <xsl:param name="reinit" />
    550583  <xsl:variable name="waitable">
    551584    <xsl:choose>
     
    560593  <xsl:value-of select="concat('         case VBoxEventType_', @id, ':&#10;')"/>
    561594  <xsl:value-of select="       '         {&#10;'"/>
    562   <xsl:value-of select="concat('              ComObjPtr&lt;', $implName, '&gt; obj;&#10;')"/>
    563   <xsl:value-of select="       '              obj.createObject();&#10;'"/>
    564   <xsl:value-of select="concat('              obj->init(aSource, aType, ', $waitable, ');&#10;')"/>
     595  <xsl:choose>
     596    <xsl:when test="$reinit='yes'">
     597      <xsl:value-of select="concat('              ComPtr&lt;', $implName, '&gt; obj;&#10;')"/>
     598      <xsl:value-of select="       '              obj = mEvent;&#10;'"/>
     599      <xsl:value-of select="       '              Assert(obj);&#10;'"/>
     600      <xsl:value-of select="       '              obj->Reuse();&#10;'"/>
     601    </xsl:when>
     602    <xsl:otherwise>
     603      <xsl:value-of select="concat('              ComObjPtr&lt;', $implName, '&gt; obj;&#10;')"/>
     604      <xsl:value-of select="       '              obj.createObject();&#10;'"/>
     605      <xsl:value-of select="concat('              obj->init(aSource, aType, ', $waitable, ');&#10;')"/>
     606    </xsl:otherwise>
     607  </xsl:choose>
    565608  <xsl:call-template name="genAttrInitCode">
    566609    <xsl:with-param name="name" select="@name" />
    567610    <xsl:with-param name="obj" select="'obj'" />
    568611  </xsl:call-template>
    569   <xsl:value-of select="       '              obj.queryInterfaceTo(mEvent.asOutParam());&#10;'"/>
     612  <xsl:if test="not($reinit='yes')">
     613    <xsl:value-of select="       '              obj.queryInterfaceTo(mEvent.asOutParam());&#10;'"/>
     614  </xsl:if>
    570615  <xsl:value-of select="       '              break;&#10;'"/>
    571616  <xsl:value-of select="       '         }&#10;'"/>
     
    590635    <xsl:call-template name="genSwitchCase">
    591636      <xsl:with-param name="implName" select="$implName" />
     637      <xsl:with-param name="reinit" select="'no'" />
    592638    </xsl:call-template>
    593639  </xsl:for-each>
     
    595641  <xsl:text><![CDATA[
    596642         default:
    597             if (1) AssertFailed();
     643            AssertFailed();
     644    }
     645    va_end(args);
     646
     647    return S_OK;
     648}
     649]]></xsl:text>
     650
     651 <xsl:text><![CDATA[
     652HRESULT VBoxEventDesc::reinit(VBoxEventType_T aType, ...)
     653{
     654    va_list args;
     655
     656    va_start(args, aType);
     657    switch (aType)
     658    {
     659]]></xsl:text>
     660
     661  <xsl:for-each select="//interface[@autogen=$G_kind and @extends='IReusableEvent']">
     662    <xsl:variable name="implName">
     663      <xsl:value-of select="substring(@name, 2)" />
     664    </xsl:variable>
     665    <xsl:call-template name="genSwitchCase">
     666      <xsl:with-param name="implName" select="$implName" />
     667      <xsl:with-param name="reinit" select="'yes'" />
     668    </xsl:call-template>
     669  </xsl:for-each>
     670
     671  <xsl:text><![CDATA[
     672         default:
     673            AssertFailed();
    598674    }
    599675    va_end(args);
     
    613689<xsl:text><![CDATA[
    614690  #include <VBox/com/array.h>
     691  #include <iprt/asm.h>
    615692  #include "EventImpl.h"
    616693]]></xsl:text>
     
    631708          </xsl:if>
    632709        </xsl:variable>
     710        <xsl:variable name="isReusable">
     711          <xsl:if test="@extends='IReusableEvent'">
     712            <xsl:value-of select="'yes'" />
     713          </xsl:if>
     714        </xsl:variable>
    633715        <xsl:call-template name="genEventImpl">
    634716          <xsl:with-param name="implName" select="$implName" />
    635717          <xsl:with-param name="isVeto" select="$isVeto" />
     718          <xsl:with-param name="isReusable" select="$isReusable" />
    636719        </xsl:call-template>
    637720      </xsl:when>
  • trunk/src/VBox/Main/include/EventImpl.h

    r30739 r31572  
    180180public:
    181181 VBoxEventDesc()
    182  : mEvent(0)
     182 : mEvent(0), mEventSource(0)
    183183 {}
    184184 ~VBoxEventDesc()
     
    191191  */
    192192 HRESULT init(IEventSource* aSource, VBoxEventType_T aType, ...);
     193
     194 /**
     195  * Function similar to the above, but assumes that init() for this type already called once,
     196  * so no need to allocate memory, and only reinit fields. Assumes event is subtype of
     197  * IReusableEvent, asserts otherwise.
     198  */
     199 HRESULT reinit(VBoxEventType_T aType, ...);
     200
    193201
    194202 void getEvent(IEvent ** aEvent)
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