VirtualBox

Changeset 30698 in vbox


Ignore:
Timestamp:
Jul 7, 2010 9:47:45 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63459
Message:

Events: docs, properly cleanup queue in passive mode

Location:
trunk/src/VBox
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxShell/vboxshell.py

    r30627 r30698  
    310310             psev = ctx['global'].queryInterface(ev, 'IMousePointerShapeChangeEvent')
    311311             if psev:
    312                  print "pointer shape event: w=%d h=%d" %(psev.width, psev.height)
    313312                 shape = ctx['global'].getArray(psev, 'shape')
    314313                 if shape is None:
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMainEventListener.cpp

    r30680 r30698  
    5050}
    5151
     52
     53/**
     54 * @todo: instead of double wrapping of events into signals maybe it
     55 * make sense to use passive listeners, and peek up events in main thread.
     56 */
    5257STDMETHODIMP UIMainEventListener::HandleEvent(IEvent *pEvent)
    5358{
     
    217222    return S_OK;
    218223}
    219 
  • trunk/src/VBox/Main/EventImpl.cpp

    r30591 r30698  
    1414 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
    1515 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
     16 */
     17
     18/**
     19 * Theory of operations.
     20 *
     21 * This code implements easily extensible event mechanism, letting us
     22 * to make any VirtualBox object an event source (by aggregating an EventSource instance).
     23 * Another entity could subscribe to the event source for events it is interested in.
     24 * If an event is waitable, it's possible to wait until all listeners
     25 * registered at the moment of firing event as ones interested in this
     26 * event acknowledged that they finished event processing (thus allowing
     27 * vetoable events).
     28 *
     29 * Listeners can be registered as active or passive ones, defining policy of delivery.
     30 * For *active* listeners, their HandleEvent() method is invoked when event is fired by
     31 * the event source (pretty much callbacks).
     32 * For *passive* listeners, it's up to an event consumer to perform GetEvent() operation
     33 * with given listener, and then perform desired operation with returned event, if any.
     34 * For passive listeners case, listener instance serves as merely a key referring to
     35 * particular event consumer, thus HandleEvent() implementation isn't that important.
     36 * IEventSource's CreateListener() could be used to create such a listener.
     37 * Passive mode is designed for transports not allowing callbacks, such as webservices
     38 * running on top of HTTP, and for situations where consumer wants exact control on
     39 * context where event handler is executed (such as GUI thread for some toolkits).
     40 *
     41 * Internal EventSource data structures are optimized for fast event delivery, while
     42 * listener registration/unregistration operations are expected being pretty rare.
     43 * Passive mode listeners keep an internal event queue for all events they receive,
     44 * and all waitable events are addded to the pending events map. This map keeps track
     45 * of how many listeners are still not acknowledged their event, and once this counter
     46 * reach zero, element is removed from pending events map, and event is marked as processed.
     47 * Thus if passive listener's user forgets to call IEventSource's EventProcessed()
     48 * waiters may never know that event processing finished.
    1649 */
    1750
     
    191224    }
    192225
     226    /* @todo: maybe while loop for spurious wakeups? */
    193227    int vrc = ::RTSemEventWait(m->mWaitEvent, aTimeout);
    194228    AssertMsg(RT_SUCCESS(vrc) || vrc == VERR_TIMEOUT || vrc == VERR_INTERRUPTED,
     
    498532    if (!mActive)
    499533    {
     534        // at this moment nobody could add elements to our queue, so we can safely
     535        // clean it up, otherwise there will be pending events map elements
     536        PendingEventsMap* aPem = &mOwner->m->mPendingMap;
     537        while (true)
     538        {
     539            ComPtr<IEvent> aEvent;
     540
     541            if (mQueue.empty())
     542                break;
     543
     544            mQueue.front().queryInterfaceTo(aEvent.asOutParam());
     545            mQueue.pop_front();
     546
     547            BOOL aWaitable = FALSE;
     548            aEvent->COMGETTER(Waitable)(&aWaitable);
     549            if (aWaitable)
     550            {
     551                PendingEventsMap::iterator pit = aPem->find(aEvent);
     552                if (pit != aPem->end())
     553                    eventProcessed(aEvent, pit);
     554            }
     555        }
     556
    500557        ::RTCritSectDelete(&mcsQLock);
    501558        ::RTSemEventDestroy(mQEvent);
     
    847904 * This class serves as feasible listener implementation
    848905 * which could be used by clients not able to create local
    849  * COM objects, but still willing to recieve event
     906 * COM objects, but still willing to receive event
    850907 * notifications in passive mode, such as webservices.
    851908 */
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r30633 r30698  
    1461914619    <const name="OnMachineStateChange" value="32">
    1462014620      <desc>
    14621         <see>IVirtualBoxCallback::onMachineStateChange</see>
     14621        <see>IMachineStateChangeEvent</see>
    1462214622      </desc>
    1462314623    </const>
    1462414624    <const name="OnMachineDataChange" value="33">
    1462514625      <desc>
    14626         <see>IVirtualBoxCallback::onMachineDataChange</see>
     14626        <see>IMachineDataChangeEvent</see>
    1462714627      </desc>
    1462814628    </const>
    1462914629    <const name="OnExtraDataChange" value="34">
    1463014630      <desc>
    14631         <see>IVirtualBoxCallback::onExtraDataChange</see>
     14631        <see>IExtraDataChangeEvent</see>
    1463214632      </desc>
    1463314633    </const>
    1463414634     <const name="OnExtraDataCanChange" value="35">
    1463514635      <desc>
    14636         <see>IVirtualBoxCallback::onExtraDataChange</see>
     14636        <see>IExtraDataCanChangeEvent</see>
    1463714637      </desc>
    1463814638    </const>
    1463914639    <const name="OnMediumRegistered" value="36">
    1464014640      <desc>
    14641         <see>IVirtualBoxCallback::onMediumRegistered</see>
     14641        <see>IMediumRegistered</see>
    1464214642      </desc>
    1464314643    </const>
    1464414644    <const name="OnMachineRegistered" value="37">
    1464514645      <desc>
    14646         <see>IVirtualBoxCallback::onMachineRegistered</see>
     14646        <see>IMachineRegisteredEvent</see>
    1464714647      </desc>
    1464814648    </const>
    1464914649    <const name="OnSessionStateChange" value="38">
    1465014650      <desc>
    14651         <see>IVirtualBoxCallback::onSessionStateChange</see>
     14651        <see>ISessionStateChangeEvent</see>
    1465214652      </desc>
    1465314653    </const>
    1465414654    <const name="OnSnapshotTaken" value="39">
    1465514655      <desc>
    14656         <see>IVirtualBoxCallback::onSnapshotTaken</see>
     14656        <see>ISnapshotTakenEvent</see>
    1465714657      </desc>
    1465814658    </const>
    1465914659    <const name="OnSnapshotDeleted" value="40">
    1466014660      <desc>
    14661         <see>IVirtualBoxCallback::onSnapshotDeleted</see>
     14661        <see>ISnapshotDeletedEvent</see>
    1466214662      </desc>
    1466314663    </const>
    1466414664    <const name="OnSnapshotChange" value="41">
    1466514665      <desc>
    14666         <see>IVirtualBoxCallback::onSnapshotChange</see>
     14666        <see>ISnapshotChangeEvent</see>
    1466714667      </desc>
    1466814668    </const>
    1466914669    <const name="OnGuestPropertyChange" value="42">
    1467014670      <desc>
    14671         <see>IVirtualBoxCallback::onGuestPropertyChange</see>
     14671        <see>IGuestPropertyChangeEvent</see>
    1467214672      </desc>
    1467314673    </const>
     
    1467514675    <const name="OnMousePointerShapeChange" value="43">
    1467614676      <desc>
    14677         <see>IConsoleCallback::onMousePointerShapeChange</see>
     14677        <see>IMousePointerShapeChangeEvent</see>
    1467814678      </desc>
    1467914679    </const>
    1468014680    <const name="OnMouseCapabilityChange" value="44">
    1468114681      <desc>
    14682         <see>IConsoleCallback::onMouseCapabilityChange</see>
     14682        <see>IMouseCapabilityChangeEvent</see>
    1468314683      </desc>
    1468414684    </const>
    1468514685    <const name="OnKeyboardLedsChange" value="45">
    1468614686      <desc>
    14687         <see>IConsoleCallback::onKeyboardLedsChange</see>
     14687        <see>IKeyboardLedsChangeEvent</see>
    1468814688      </desc>
    1468914689    </const>
    1469014690    <const name="OnStateChange" value="46">
    1469114691      <desc>
    14692         <see>IConsoleCallback::onStateChange</see>
     14692        <see>IStateChangeEvent</see>
    1469314693      </desc>
    1469414694    </const>
    1469514695    <const name="OnAdditionsStateChange" value="47">
    1469614696      <desc>
    14697         <see>IConsoleCallback::onAdditionsStateChange</see>
     14697        <see>IAdditionsStateChangeEvent</see>
    1469814698      </desc>
    1469914699    </const>
    1470014700    <const name="OnNetworkAdapterChange" value="48">
    1470114701      <desc>
    14702         <see>IConsoleCallback::onNetworkAdapterChange</see>
     14702        <see>INetworkAdapterChangeEvent</see>
    1470314703      </desc>
    1470414704    </const>
    1470514705    <const name="OnSerialPortChange" value="49">
    1470614706      <desc>
    14707         <see>IConsoleCallback::onSerialPortChange</see>
     14707        <see>ISerialPortChangeEvent</see>
    1470814708      </desc>
    1470914709    </const>
    1471014710    <const name="OnParallelPortChange" value="50">
    1471114711      <desc>
    14712         <see>IConsoleCallback::onParallelPortChange</see>
     14712        <see>IParallelPortChangeEvent</see>
    1471314713      </desc>
    1471414714    </const>
    1471514715    <const name="OnStorageControllerChange" value="51">
    1471614716      <desc>
    14717         <see>IConsoleCallback::onStorageControllerChange</see>
     14717        <see>IStorageControllerChangeEvent</see>
    1471814718      </desc>
    1471914719    </const>
    1472014720    <const name="OnMediumChange" value="52">
    1472114721      <desc>
    14722         <see>IConsoleCallback::onMediumChange</see>
     14722        <see>IMediumChangeEvent</see>
    1472314723      </desc>
    1472414724    </const>
    1472514725    <const name="OnVRDPServerChange" value="53">
    1472614726      <desc>
    14727         <see>IConsoleCallback::onVRDPServerChange</see>
     14727        <see>IVRDPServerChangeEvent</see>
    1472814728      </desc>
    1472914729    </const>
    1473014730    <const name="OnUSBControllerChange" value="54">
    1473114731      <desc>
    14732         <see>IConsoleCallback::onUSBControllerChange</see>
     14732        <see>IUSBControllerChangeEvent</see>
    1473314733      </desc>
    1473414734    </const>
    1473514735    <const name="OnUSBDeviceStateChange" value="55">
    1473614736      <desc>
    14737         <see>IConsoleCallback::onUSBDeviceStateChange</see>
     14737        <see>IUSBDeviceStateChangeEvent</see>
    1473814738      </desc>
    1473914739    </const>
    1474014740    <const name="OnSharedFolderChange" value="56">
    1474114741      <desc>
    14742         <see>IConsoleCallback::onSharedFolderChange</see>
     14742        <see>ISharedFolderChangeEvent</see>
    1474314743      </desc>
    1474414744    </const>
    1474514745    <const name="OnRuntimeError" value="57">
    1474614746      <desc>
    14747         <see>IConsoleCallback::onRuntimeError</see>
     14747        <see>IRuntimeErrorEvent</see>
    1474814748      </desc>
    1474914749    </const>
    1475014750    <const name="OnCanShowWindow" value="58">
    1475114751      <desc>
    14752         <see>IConsoleCallback::onCanShowWindow</see>
     14752        <see>ICanShowWindowEvent</see>
    1475314753      </desc>
    1475414754    </const>
    1475514755    <const name="OnShowWindow" value="59">
    1475614756      <desc>
    14757         <see>IConsoleCallback::onShowWindow</see>
     14757        <see>IShowWindowEvent</see>
    1475814758      </desc>
    1475914759    </const>
    1476014760    <const name="OnCPUChange" value="60">
    1476114761      <desc>
    14762         <see>IConsoleCallback::onCPUChange</see>
     14762        <see>ICPUChangeEvent</see>
    1476314763      </desc>
    1476414764    </const>
    1476514765    <const name="OnRemoteDisplayInfoChange" value="61">
    1476614766      <desc>
    14767         <see>IConsoleCallback::onRemoteDisplayInfoChange</see>
     14767        <see>IRemoteDisplayInfoChangeEvent</see>
    1476814768      </desc>
    1476914769    </const>
     
    1489414894    <method name="handleEvent">
    1489514895      <desc>
    14896         Handle event callback (called directly by IEventSource in active mode, or by event processor thread
    14897         in passive mode).
     14896        Handle event callback (called directly by IEventSource in active mode, or could be
     14897        called by event processor thread in passive mode).
    1489814898      </desc>
    1489914899      <param name="event" type="IEvent" dir="in">
     
    1490914909     wsmap="managed"
    1491014910     >
    14911     <desc>Generic event, aiming to replace callbacks mechanism.</desc>
     14911    <desc>
     14912      Generic event. Usually events implements some of IEvent subinterfaces, so
     14913      standard use pattern is to check 'type' attribute and downcast (with QueryInterface())
     14914      appropraitely.
     14915    </desc>
    1491214916
    1491314917    <attribute name="type" readonly="yes" type="VBoxEventType">
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette