VirtualBox

Changeset 30345 in vbox


Ignore:
Timestamp:
Jun 21, 2010 4:49:59 PM (15 years ago)
Author:
vboxsync
Message:

Main: more events

Location:
trunk/src/VBox
Files:
10 edited

Legend:

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

    r30280 r30345  
    426426        pass
    427427    vbox.unregisterCallback(cb)
     428
     429def monitorVBox2(ctx, dur):
     430    vbox = ctx['vb']
     431    print vbox.eventSource
     432    listener = vbox.eventSource.createListener()
     433    if dur == -1:
     434        # not infinity, but close enough
     435        dur = 100000
     436    try:
     437        vbox.eventSource.registerListener(listener, [ctx['global'].constants.VBoxEventType_All], False)
     438        end = time.time() + dur
     439        while  time.time() < end:
     440            ev = vbox.eventSource.getEvent(500)
     441            if ev:
     442                print "got event: %s %s" %(ev, str(ev.type))
     443    # We need to catch all exceptions here, otherwise callback will never be unregistered
     444    except:
     445        traceback.print_exc()
     446        pass
     447    vbox.eventSource.unregisterListener(listener)
    428448
    429449
     
    13871407        dur = float(args[1])
    13881408    monitorVBox(ctx, dur)
     1409    return 0
     1410
     1411def monitorVBox2Cmd(ctx, args):
     1412    if (len(args) > 2):
     1413        print "usage: monitorVBox2 (duration)"
     1414        return 0
     1415    dur = 5
     1416    if len(args) > 1:
     1417        dur = float(args[1])
     1418    monitorVBox2(ctx, dur)
    13891419    return 0
    13901420
     
    28562886            'monitorGuest':['Monitor what happens with the guest for some time: monitorGuest Win32 10', monitorGuestCmd, 0],
    28572887            'monitorVBox':['Monitor what happens with Virtual Box for some time: monitorVBox 10', monitorVBoxCmd, 0],
     2888            'monitorVBox2':['(temp)Monitor what happens with Virtual Box for some time: monitorVBox2 10', monitorVBox2Cmd, 0],
    28582889            'portForward':['Setup permanent port forwarding for a VM, takes adapter number host port and guest port: portForward Win32 0 8080 80', portForwardCmd, 0],
    28592890            'showLog':['Show log file of the VM, : showLog Win32', showLogCmd, 0],
  • trunk/src/VBox/Main/EventImpl.cpp

    r30331 r30345  
    6161    HRESULT rc = S_OK;
    6262
     63    AssertReturn(aSource != NULL, E_INVALIDARG);
     64     
     65    AutoInitSpan autoInitSpan(this);
     66    AssertReturn(autoInitSpan.isOk(), E_FAIL);
     67
    6368    m->mSource = aSource;
    6469    m->mType = aType;
     
    7479            {
    7580                AssertFailed ();
    76                 rc = setError(E_FAIL,
    77                               tr("Internal error (%Rrc)"), vrc);
    78                 break;
     81                return setError(E_FAIL,
     82                                tr("Internal error (%Rrc)"), vrc);
    7983            }
    8084        }
    8185    } while (0);
     86
     87    /* Confirm a successful initialization */
     88    autoInitSpan.setSucceeded();
    8289
    8390    return rc;
     
    231238            return TRUE;
    232239        case VBoxEventType_MachineEvent:
    233             return (what == VBoxEventType_OnMachineStateChange) || (what == VBoxEventType_OnMachineDataChange);
     240            return     (what == VBoxEventType_OnMachineStateChange)
     241                    || (what == VBoxEventType_OnMachineDataChange)
     242                    || (what == VBoxEventType_OnMachineRegistered);
    234243        case VBoxEventType_Invalid:
    235244            return FALSE;
     
    262271    }
    263272
    264     ::RTCritSectInitEx(&mcsQLock, 0, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, NULL);
    265     ::RTSemEventCreate (&mQEvent);
     273    if (!mActive)
     274    {
     275        ::RTCritSectInitEx(&mcsQLock, 0, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, NULL);
     276        ::RTSemEventCreate (&mQEvent);
     277    }
    266278}
    267279
     
    275287    }
    276288
    277     ::RTCritSectDelete(&mcsQLock);
    278     ::RTSemEventDestroy(mQEvent);
     289    if (!mActive)
     290    {
     291        ::RTCritSectDelete(&mcsQLock);
     292        ::RTSemEventDestroy(mQEvent);
     293    }
    279294}
    280295
     
    343358}
    344359
     360
     361EventSource::EventSource()
     362{}
     363
     364EventSource::~EventSource()
     365{}
     366
    345367HRESULT EventSource::FinalConstruct()
    346368{
     
    355377}
    356378
    357 
    358 HRESULT EventSource::init()
     379HRESULT EventSource::init(IUnknown * aParent)
    359380{
    360381    HRESULT rc = S_OK;
     382
     383    AutoInitSpan autoInitSpan(this);
     384    AssertReturn(autoInitSpan.isOk(), E_FAIL);
     385
     386    /* Confirm a successful initialization */
     387    autoInitSpan.setSucceeded();
    361388    return rc;
    362389}
     
    366393    m->mListeners.clear();
    367394    // m->mEvMap shall be cleared at this point too by destructors
     395}
     396
     397STDMETHODIMP EventSource::CreateListener(IEventListener ** aListener)
     398{
     399    CheckComArgOutPointerValid(aListener);
     400
     401    AutoCaller autoCaller(this);
     402    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     403
     404    ComPtr<IEventListener> listener;
     405
     406    HRESULT rc = listener.createLocalObject(CLSID_CallbackWrapper);
     407    ComAssertMsgRet(SUCCEEDED(rc), ("Could not create wrapper object (%Rrc)", rc),
     408                    E_FAIL);
     409
     410    listener.queryInterfaceTo(aListener);
     411    return S_OK;
    368412}
    369413
     
    487531
    488532    if (it != m->mListeners.end())
    489     {
    490533        rc = it->second.dequeue(aEvent, aTimeout);
    491     }
    492     else
    493     {
     534    else
    494535        rc = setError(VBOX_E_OBJECT_NOT_FOUND,
    495536                      tr("Listener was never registered"));
    496     }
    497537
    498538    return rc;
  • trunk/src/VBox/Main/VirtualBoxCallbackImpl.cpp

    r29518 r30345  
    1818#include "VirtualBoxCallbackImpl.h"
    1919#include "Logging.h"
     20#include "AutoCaller.h"
    2021
    2122HRESULT CallbackWrapper::FinalConstruct()
     
    3132HRESULT CallbackWrapper::init()
    3233{
     34    AutoInitSpan autoInitSpan(this);
     35    AssertReturn(autoInitSpan.isOk(), E_FAIL);
     36    /* Confirm a successful initialization */
     37    autoInitSpan.setSucceeded();
    3338    return S_OK;
    3439}
     
    316321    return mConsoleCallback->OnShowWindow(winId);
    317322}
     323
     324STDMETHODIMP CallbackWrapper::HandleEvent(IEvent * aEvent)
     325{
     326    ComAssertMsgRet(false, ("HandleEvent() of wrapper shall never be called"),
     327                    E_FAIL);
     328}
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r30314 r30345  
    6767#include "PerformanceImpl.h"
    6868#endif /* VBOX_WITH_RESOURCE_USAGE_API */
     69#include "EventImpl.h"
    6970
    7071#include "AutoCaller.h"
     
    355356    ComEventsHelper                     mComEvHelper;
    356357#endif
     358    const ComObjPtr<EventSource>        pEventSource;
    357359};
    358360
     
    532534            if (FAILED(rc)) throw rc;
    533535        }
     536
     537        /* events */
     538        if (SUCCEEDED(rc = unconst(m->pEventSource).createObject()))
     539            rc = m->pEventSource->init(this);
     540        if (FAILED(rc)) throw rc;
     541
    534542    }
    535543    catch (HRESULT err)
     
    595603        rc = m->mComEvHelper.init(IID_IVirtualBoxCallback);
    596604#endif
    597 
    598605    /* Confirm a successful initialization when it's the case */
    599606    if (SUCCEEDED(rc))
     
    736743        m->pHost->uninit();
    737744        unconst(m->pHost).setNull();
     745    }
     746
     747    LogFlowThisFunc(("Releasing event source...\n"));
     748    if (m->pEventSource)
     749    {
     750        m->pEventSource->uninit();
     751        unconst(m->pEventSource).setNull();
    738752    }
    739753
     
    10411055    SafeIfaceArray<IDHCPServer> svrs(m->ollDHCPServers.getList());
    10421056    svrs.detachTo(ComSafeArrayOutArg(aDHCPServers));
     1057
     1058    return S_OK;
     1059}
     1060
     1061STDMETHODIMP
     1062VirtualBox::COMGETTER(EventSource)(IEventSource ** aEventSource)
     1063{
     1064    CheckComArgOutPointerValid(aEventSource);
     1065
     1066    AutoCaller autoCaller(this);
     1067    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     1068
     1069    /* event source is const, no need to lock */
     1070    m->pEventSource.queryInterfaceTo(aEventSource);
    10431071
    10441072    return S_OK;
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r30331 r30345  
    16051605  <interface
    16061606    name="IVirtualBox" extends="$unknown"
    1607     uuid="3f36e024-7fed-4f20-a02c-9158a82b44e6"
     1607    uuid="f0c2e058-8c72-4d56-95e7-3107627aba6e"
    16081608    wsmap="managed"
    16091609  >
     
    17381738      </desc>
    17391739    </attribute>
     1740
     1741    <attribute name="eventSource" type="IEventSource" readonly="yes">
     1742      <desc>
     1743        Event source for VirtualBox events.
     1744      </desc>
     1745    </attribute>
     1746
    17401747
    17411748    <method name="createMachine">
     
    1397913986      <param name="return" type="ISession" dir="return"/>
    1398013987    </method>
    13981 
     13988   
    1398213989    <method name="logoff">
    1398313990      <desc>
     
    1459514602      </desc>
    1459614603    </const>
    14597 
    14598     <const name="Last" value="35">
     14604    <const name="OnMediumRegistered" value="35">
     14605      <desc>
     14606        <see>IVirtualBoxCallback::onMediumRegistered</see>
     14607      </desc>
     14608    </const>
     14609    <const name="OnMachineRegistered" value="36">
     14610      <desc>
     14611        <see>IVirtualBoxCallback::onMachineRegistered</see>
     14612      </desc>
     14613    </const>
     14614    <const name="OnSessionStateChange" value="37">
     14615      <desc>
     14616        <see>IVirtualBoxCallback::onSessionStateChange</see>
     14617      </desc>
     14618    </const>
     14619    <const name="OnSnapshotTaken" value="38">
     14620      <desc>
     14621        <see>IVirtualBoxCallback::onSnapshotTaken</see>
     14622      </desc>
     14623    </const>
     14624    <const name="OnSnapshotDeleted" value="39">
     14625      <desc>
     14626        <see>IVirtualBoxCallback::onSnapshotDeleted</see>
     14627      </desc>
     14628    </const>
     14629    <const name="OnSnapshotChange" value="40">
     14630      <desc>
     14631        <see>IVirtualBoxCallback::onSnapshotChange</see>
     14632      </desc>
     14633    </const>
     14634    <const name="OnGuestPropertyChange" value="42">
     14635      <desc>
     14636        <see>IVirtualBoxCallback::onGuestPropertyChange</see>
     14637      </desc>
     14638    </const>
     14639
     14640    <const name="Last" value="43">
    1459914641      <desc>
    1460014642        Must be last event, used for iterations.
     
    1461714659    </desc>
    1461814660
     14661    <method name="createListener">
     14662      <desc>
     14663        Creates new listener object, useful for passive mode.
     14664        <see>IEventListener</see>
     14665      </desc>
     14666      <param name="listener" type="IEventListener" dir="return"/>
     14667    </method>
     14668
    1461914669    <method name="registerListener">
    1462014670      <desc>
     
    1464414694    <method name="unregisterListener">
    1464514695      <desc>
    14646         Unregister an event listener. If listener is passive, and some waitable events are still 
     14696        Unregister an event listener. If listener is passive, and some waitable events are still
    1464714697        in queue they are marked as processed automatically.
    1464814698      </desc>
     
    1468814738    <method name="eventProcessed">
    1468914739      <desc>
    14690         Must be called for waitable events when particular listener finished event processing. 
    14691         When all listeners who this event was aimed to call eventProcessed() event source 
     14740        Must be called for waitable events when particular listener finished event processing.
     14741        When all listeners who this event was aimed to call eventProcessed() event source
    1469214742        can call event's setProcessed().
    1469314743      </desc>
     
    1477314823  </interface>
    1477414824
     14825
    1477514826  <interface
    14776       name="IMachineStateChangeEvent" extends="IEvent"
     14827      name="IMachineEvent" extends="IEvent"
     14828      uuid="92ed7b1a-0d96-40ed-ae46-a564d484325e"
     14829      wsmap="managed"
     14830      >
     14831    <desc>Base interface for all machine events.</desc>
     14832
     14833    <attribute name="machineId" readonly="yes" type="uuid" mod="string">
     14834      <desc>ID of the machine this event relates to.</desc>
     14835    </attribute>
     14836
     14837  </interface>
     14838
     14839  <interface
     14840      name="IMachineStateChangeEvent" extends="IMachineEvent"
    1477714841      uuid="5748F794-48DF-438D-85EB-98FFD70D18C9"
    1477814842      wsmap="managed"
     
    1478014844    <desc>Machine state change event.</desc>
    1478114845
    14782     <attribute name="machineId" readonly="yes" type="uuid" mod="string">
    14783       <desc>ID of the machine this event relates to.</desc>
    14784     </attribute>
    14785 
    14786      <attribute name="state" readonly="yes" type="MachineState">
    14787        <desc>New execution state.</desc>
    14788      </attribute>
     14846    <attribute name="state" readonly="yes" type="MachineState">
     14847      <desc>New execution state.</desc>
     14848    </attribute>
    1478914849  </interface>
    1479014850
    1479114851  <interface
    14792       name="IMachineDataChangeEvent" extends="IEvent"
     14852      name="IMachineDataChangeEvent" extends="IMachineEvent"
    1479314853      uuid="6AA70A6C-0DCA-4810-8C5C-457B278E3D49"
    1479414854      wsmap="managed"
     
    1479714857      Any of the settings of the given machine has changed.
    1479814858    </desc>
    14799 
    14800     <attribute name="machineId" readonly="yes" type="uuid" mod="string">
    14801       <desc>ID of the machine this event relates to.</desc>
    14802     </attribute>
    14803 
     14859  </interface>
     14860
     14861  <interface
     14862      name="IMachineRegisteredEvent" extends="IMachineEvent"
     14863      uuid="c354a762-3ff2-4f2e-8f09-07382ee25088"
     14864      wsmap="managed"
     14865      >
     14866    <desc>
     14867      The given machine was registered or unregistered
     14868      within this VirtualBox installation.
     14869    </desc>
     14870
     14871    <attribute name="registered" type="boolean" readonly="yes">
     14872      <desc>
     14873        If @c true, the machine was registered, otherwise it was
     14874        unregistered.
     14875      </desc>
     14876    </attribute>
     14877  </interface>
     14878
     14879  <interface
     14880      name="IMachineSessionStateEvent" extends="IMachineEvent"
     14881      uuid="714a3eef-799a-4489-86cd-fe8e45b2ff8e"
     14882      wsmap="managed"
     14883      >
     14884    <desc>
     14885      The state of the session for the given machine was changed.
     14886      <see>IMachine::sessionState</see>
     14887    </desc>
     14888
     14889    <attribute name="state" type="SessionState" readonly="yes">
     14890      <desc>
     14891        New session state.
     14892      </desc>
     14893    </attribute>
     14894  </interface>
     14895
     14896  <interface
     14897      name="IGuestPropertyChangeEvent" extends="IMachineEvent"
     14898      uuid="3f63597a-26f1-4edb-8dd2-6bddd0912368"
     14899      wsmap="managed"
     14900      >
     14901    <desc>
     14902      Notification when a guest property has changed.
     14903    </desc>
     14904
     14905    <attribute name="name" readonly="yes" type="wstring">
     14906      <desc>
     14907        The name of the property that has changed.
     14908      </desc>
     14909    </attribute>
     14910
     14911    <attribute name="value" readonly="yes" type="wstring">
     14912      <desc>
     14913        The new property value.
     14914      </desc>
     14915    </attribute>
     14916
     14917     <attribute name="flags" readonly="yes" type="wstring">
     14918      <desc>
     14919        The new property flags.
     14920      </desc>
     14921    </attribute>
     14922
     14923  </interface>
     14924
     14925  <interface
     14926      name="ISnapshotEvent" extends="IMachineEvent"
     14927      uuid="21637b0e-34b8-42d3-acfb-7e96daf77c22"
     14928      wsmap="managed"
     14929      >
     14930    <desc>Base interface for all snapshot events.</desc>
     14931
     14932    <attribute name="snapshotId" readonly="yes" type="uuid" mod="string">
     14933      <desc>ID of the snapshot this event relates to.</desc>
     14934    </attribute>
     14935
     14936  </interface>
     14937
     14938  <interface
     14939     name="ISnapshotTakenEvent" extends="ISnapshotEvent"
     14940     uuid="d27c0b3d-6038-422c-b45e-6d4a0503d9f1"
     14941     wsmap="managed"
     14942     >
     14943    <desc>
     14944      A new snapshot of the machine has been taken.
     14945      <see>ISnapshot</see>
     14946    </desc>
     14947  </interface>
     14948
     14949  <interface
     14950     name="ISnapshotDeletedEvent" extends="ISnapshotEvent"
     14951     uuid="c48f3401-4a9e-43f4-b7a7-54bd285e22f4"
     14952     wsmap="managed"
     14953     >
     14954    <desc>
     14955      Snapshot of the given machine has been deleted.
     14956
     14957      <note>
     14958        This notification is delivered <b>after</b> the snapshot
     14959        object has been uninitialized on the server (so that any
     14960        attempt to call its methods will return an error).
     14961      </note>
     14962
     14963      <see>ISnapshot</see>
     14964    </desc>
     14965  </interface>
     14966
     14967   <interface
     14968     name="ISnapshotChangedEvent" extends="ISnapshotEvent"
     14969     uuid="07541941-8079-447a-a33e-47a69c7980db"
     14970     wsmap="managed"
     14971     >
     14972    <desc>
     14973      Snapshot properties (name and/or description) have been changed.
     14974      <see>ISnapshot</see>
     14975    </desc>
    1480414976  </interface>
    1480514977
     
    1485115023    </class>
    1485215024
    14853     <class name="CallbackWrapper" uuid="49EE8561-5563-4715-B18C-A4B1A490DAFE"
     15025    <class name="CallbackWrapper" uuid="bcacd681-7f53-4409-a2a5-8534911f9358"
    1485415026           namespace="virtualbox.org">
    1485515027      <interface name="ILocalOwner" default="yes"/>
    1485615028      <interface name="IVirtualBoxCallback"/>
    1485715029      <interface name="IConsoleCallback"/>
     15030      <interface name="IEventListener"/>
    1485815031    </class>
    1485915032  </module>
  • trunk/src/VBox/Main/include/EventImpl.h

    r30331 r30345  
    6969
    7070class ATL_NO_VTABLE EventSource :
     71    public VirtualBoxBase,
    7172    public VirtualBoxSupportErrorInfoImpl<EventSource, IEventSource>,
    7273    public VirtualBoxSupportTranslation<EventSource>,
    73     public VirtualBoxBase,
    7474    VBOX_SCRIPTABLE_IMPL(IEventSource)
    7575{
     
    8888    END_COM_MAP()
    8989
    90     EventSource() {}
    91     virtual ~EventSource() {}
     90    DECLARE_EMPTY_CTOR_DTOR (EventSource)
    9291
    9392    HRESULT FinalConstruct();
     
    9594
    9695    // public initializer/uninitializer for internal purposes only
    97     HRESULT init ();
     96    HRESULT init (IUnknown * aParent);
    9897    void uninit();
    9998
    10099    // IEventSource methods
     100    STDMETHOD(CreateListener)(IEventListener ** aListener);
    101101    STDMETHOD(RegisterListener)(IEventListener * aListener,
    102102                                ComSafeArrayIn(VBoxEventType_T, aInterested),
  • trunk/src/VBox/Main/include/VirtualBoxCallbackImpl.h

    r29519 r30345  
    2525    VBOX_SCRIPTABLE_IMPL(ILocalOwner),
    2626    VBOX_SCRIPTABLE_IMPL(IConsoleCallback),
    27     VBOX_SCRIPTABLE_IMPL(IVirtualBoxCallback)
     27    VBOX_SCRIPTABLE_IMPL(IVirtualBoxCallback),
     28    VBOX_SCRIPTABLE_IMPL(IEventListener)
    2829#ifdef RT_OS_WINDOWS
    2930    , public CComCoClass<CallbackWrapper, &CLSID_CallbackWrapper>
     
    4546        COM_INTERFACE_ENTRY(IVirtualBoxCallback)
    4647        COM_INTERFACE_ENTRY(IConsoleCallback)
     48        COM_INTERFACE_ENTRY(IEventListener)
    4749    END_COM_MAP()
    4850
     
    9597    STDMETHOD(OnShowWindow)(ULONG64 *winId);
    9698
     99    // IEventListener
     100    STDMETHOD(HandleEvent)(IEvent *aEvent);
     101
    97102    // for VirtualBoxSupportErrorInfoImpl
    98103    static const wchar_t *getComponentName() { return L"CallbackWrapper"; }
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r30207 r30345  
    9696         CONNECTION_POINT_ENTRY(IID_IVirtualBoxCallback)
    9797    END_CONNECTION_POINT_MAP()
    98    
     98
    9999    typedef CComDynamicUnkArray EventListenersList;
    100100#endif
     
    130130    STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
    131131    STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut (IDHCPServer *, aDHCPServers));
     132    STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
    132133
    133134    /* IVirtualBox methods */
  • trunk/src/VBox/Main/xpcom/module.cpp

    r28979 r30345  
    4646#include "ConsoleVRDPServer.h"
    4747#include "VirtualBoxCallbackImpl.h"
     48#include "EventImpl.h"
    4849
    4950#include "Logging.h"
     
    7374NS_DECL_CLASSINFO(RemoteDisplayInfo)
    7475NS_IMPL_THREADSAFE_ISUPPORTS1_CI(RemoteDisplayInfo, IRemoteDisplayInfo)
     76NS_DECL_CLASSINFO(EventSource)
     77NS_IMPL_THREADSAFE_ISUPPORTS1_CI(EventSource, IEventSource)
    7578
    7679NS_DECL_CLASSINFO(Session)
     
    8083NS_DECL_CLASSINFO(CallbackWrapper)
    8184NS_IMPL_THREADSAFE_ISUPPORTS3_CI(CallbackWrapper, IVirtualBoxCallback, IConsoleCallback, ILocalOwner)
     85
    8286/**
    8387 *  Singleton class factory that holds a reference to the created instance
  • trunk/src/VBox/Main/xpcom/server.cpp

    r29864 r30345  
    8787#include <AudioAdapterImpl.h>
    8888#include <SystemPropertiesImpl.h>
     89#include <EventImpl.h>
    8990
    9091/* implement nsISupports parts of our objects with support for nsIClassInfo */
     
    197198NS_DECL_CLASSINFO(BIOSSettings)
    198199NS_IMPL_THREADSAFE_ISUPPORTS1_CI(BIOSSettings, IBIOSSettings)
     200
     201NS_DECL_CLASSINFO(EventSource)
     202NS_IMPL_THREADSAFE_ISUPPORTS1_CI(EventSource, IEventSource)
    199203
    200204////////////////////////////////////////////////////////////////////////////////
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