Changeset 30345 in vbox
- Timestamp:
- Jun 21, 2010 4:49:59 PM (15 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
r30280 r30345 426 426 pass 427 427 vbox.unregisterCallback(cb) 428 429 def 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) 428 448 429 449 … … 1387 1407 dur = float(args[1]) 1388 1408 monitorVBox(ctx, dur) 1409 return 0 1410 1411 def 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) 1389 1419 return 0 1390 1420 … … 2856 2886 'monitorGuest':['Monitor what happens with the guest for some time: monitorGuest Win32 10', monitorGuestCmd, 0], 2857 2887 '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], 2858 2889 'portForward':['Setup permanent port forwarding for a VM, takes adapter number host port and guest port: portForward Win32 0 8080 80', portForwardCmd, 0], 2859 2890 'showLog':['Show log file of the VM, : showLog Win32', showLogCmd, 0], -
trunk/src/VBox/Main/EventImpl.cpp
r30331 r30345 61 61 HRESULT rc = S_OK; 62 62 63 AssertReturn(aSource != NULL, E_INVALIDARG); 64 65 AutoInitSpan autoInitSpan(this); 66 AssertReturn(autoInitSpan.isOk(), E_FAIL); 67 63 68 m->mSource = aSource; 64 69 m->mType = aType; … … 74 79 { 75 80 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); 79 83 } 80 84 } 81 85 } while (0); 86 87 /* Confirm a successful initialization */ 88 autoInitSpan.setSucceeded(); 82 89 83 90 return rc; … … 231 238 return TRUE; 232 239 case VBoxEventType_MachineEvent: 233 return (what == VBoxEventType_OnMachineStateChange) || (what == VBoxEventType_OnMachineDataChange); 240 return (what == VBoxEventType_OnMachineStateChange) 241 || (what == VBoxEventType_OnMachineDataChange) 242 || (what == VBoxEventType_OnMachineRegistered); 234 243 case VBoxEventType_Invalid: 235 244 return FALSE; … … 262 271 } 263 272 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 } 266 278 } 267 279 … … 275 287 } 276 288 277 ::RTCritSectDelete(&mcsQLock); 278 ::RTSemEventDestroy(mQEvent); 289 if (!mActive) 290 { 291 ::RTCritSectDelete(&mcsQLock); 292 ::RTSemEventDestroy(mQEvent); 293 } 279 294 } 280 295 … … 343 358 } 344 359 360 361 EventSource::EventSource() 362 {} 363 364 EventSource::~EventSource() 365 {} 366 345 367 HRESULT EventSource::FinalConstruct() 346 368 { … … 355 377 } 356 378 357 358 HRESULT EventSource::init() 379 HRESULT EventSource::init(IUnknown * aParent) 359 380 { 360 381 HRESULT rc = S_OK; 382 383 AutoInitSpan autoInitSpan(this); 384 AssertReturn(autoInitSpan.isOk(), E_FAIL); 385 386 /* Confirm a successful initialization */ 387 autoInitSpan.setSucceeded(); 361 388 return rc; 362 389 } … … 366 393 m->mListeners.clear(); 367 394 // m->mEvMap shall be cleared at this point too by destructors 395 } 396 397 STDMETHODIMP 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; 368 412 } 369 413 … … 487 531 488 532 if (it != m->mListeners.end()) 489 {490 533 rc = it->second.dequeue(aEvent, aTimeout); 491 } 492 else 493 { 534 else 494 535 rc = setError(VBOX_E_OBJECT_NOT_FOUND, 495 536 tr("Listener was never registered")); 496 }497 537 498 538 return rc; -
trunk/src/VBox/Main/VirtualBoxCallbackImpl.cpp
r29518 r30345 18 18 #include "VirtualBoxCallbackImpl.h" 19 19 #include "Logging.h" 20 #include "AutoCaller.h" 20 21 21 22 HRESULT CallbackWrapper::FinalConstruct() … … 31 32 HRESULT CallbackWrapper::init() 32 33 { 34 AutoInitSpan autoInitSpan(this); 35 AssertReturn(autoInitSpan.isOk(), E_FAIL); 36 /* Confirm a successful initialization */ 37 autoInitSpan.setSucceeded(); 33 38 return S_OK; 34 39 } … … 316 321 return mConsoleCallback->OnShowWindow(winId); 317 322 } 323 324 STDMETHODIMP 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 67 67 #include "PerformanceImpl.h" 68 68 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 69 #include "EventImpl.h" 69 70 70 71 #include "AutoCaller.h" … … 355 356 ComEventsHelper mComEvHelper; 356 357 #endif 358 const ComObjPtr<EventSource> pEventSource; 357 359 }; 358 360 … … 532 534 if (FAILED(rc)) throw rc; 533 535 } 536 537 /* events */ 538 if (SUCCEEDED(rc = unconst(m->pEventSource).createObject())) 539 rc = m->pEventSource->init(this); 540 if (FAILED(rc)) throw rc; 541 534 542 } 535 543 catch (HRESULT err) … … 595 603 rc = m->mComEvHelper.init(IID_IVirtualBoxCallback); 596 604 #endif 597 598 605 /* Confirm a successful initialization when it's the case */ 599 606 if (SUCCEEDED(rc)) … … 736 743 m->pHost->uninit(); 737 744 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(); 738 752 } 739 753 … … 1041 1055 SafeIfaceArray<IDHCPServer> svrs(m->ollDHCPServers.getList()); 1042 1056 svrs.detachTo(ComSafeArrayOutArg(aDHCPServers)); 1057 1058 return S_OK; 1059 } 1060 1061 STDMETHODIMP 1062 VirtualBox::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); 1043 1071 1044 1072 return S_OK; -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r30331 r30345 1605 1605 <interface 1606 1606 name="IVirtualBox" extends="$unknown" 1607 uuid=" 3f36e024-7fed-4f20-a02c-9158a82b44e6"1607 uuid="f0c2e058-8c72-4d56-95e7-3107627aba6e" 1608 1608 wsmap="managed" 1609 1609 > … … 1738 1738 </desc> 1739 1739 </attribute> 1740 1741 <attribute name="eventSource" type="IEventSource" readonly="yes"> 1742 <desc> 1743 Event source for VirtualBox events. 1744 </desc> 1745 </attribute> 1746 1740 1747 1741 1748 <method name="createMachine"> … … 13979 13986 <param name="return" type="ISession" dir="return"/> 13980 13987 </method> 13981 13988 13982 13989 <method name="logoff"> 13983 13990 <desc> … … 14595 14602 </desc> 14596 14603 </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"> 14599 14641 <desc> 14600 14642 Must be last event, used for iterations. … … 14617 14659 </desc> 14618 14660 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 14619 14669 <method name="registerListener"> 14620 14670 <desc> … … 14644 14694 <method name="unregisterListener"> 14645 14695 <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 14647 14697 in queue they are marked as processed automatically. 14648 14698 </desc> … … 14688 14738 <method name="eventProcessed"> 14689 14739 <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 14692 14742 can call event's setProcessed(). 14693 14743 </desc> … … 14773 14823 </interface> 14774 14824 14825 14775 14826 <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" 14777 14841 uuid="5748F794-48DF-438D-85EB-98FFD70D18C9" 14778 14842 wsmap="managed" … … 14780 14844 <desc>Machine state change event.</desc> 14781 14845 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> 14789 14849 </interface> 14790 14850 14791 14851 <interface 14792 name="IMachineDataChangeEvent" extends="I Event"14852 name="IMachineDataChangeEvent" extends="IMachineEvent" 14793 14853 uuid="6AA70A6C-0DCA-4810-8C5C-457B278E3D49" 14794 14854 wsmap="managed" … … 14797 14857 Any of the settings of the given machine has changed. 14798 14858 </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> 14804 14976 </interface> 14805 14977 … … 14851 15023 </class> 14852 15024 14853 <class name="CallbackWrapper" uuid=" 49EE8561-5563-4715-B18C-A4B1A490DAFE"15025 <class name="CallbackWrapper" uuid="bcacd681-7f53-4409-a2a5-8534911f9358" 14854 15026 namespace="virtualbox.org"> 14855 15027 <interface name="ILocalOwner" default="yes"/> 14856 15028 <interface name="IVirtualBoxCallback"/> 14857 15029 <interface name="IConsoleCallback"/> 15030 <interface name="IEventListener"/> 14858 15031 </class> 14859 15032 </module> -
trunk/src/VBox/Main/include/EventImpl.h
r30331 r30345 69 69 70 70 class ATL_NO_VTABLE EventSource : 71 public VirtualBoxBase, 71 72 public VirtualBoxSupportErrorInfoImpl<EventSource, IEventSource>, 72 73 public VirtualBoxSupportTranslation<EventSource>, 73 public VirtualBoxBase,74 74 VBOX_SCRIPTABLE_IMPL(IEventSource) 75 75 { … … 88 88 END_COM_MAP() 89 89 90 EventSource() {} 91 virtual ~EventSource() {} 90 DECLARE_EMPTY_CTOR_DTOR (EventSource) 92 91 93 92 HRESULT FinalConstruct(); … … 95 94 96 95 // public initializer/uninitializer for internal purposes only 97 HRESULT init ( );96 HRESULT init (IUnknown * aParent); 98 97 void uninit(); 99 98 100 99 // IEventSource methods 100 STDMETHOD(CreateListener)(IEventListener ** aListener); 101 101 STDMETHOD(RegisterListener)(IEventListener * aListener, 102 102 ComSafeArrayIn(VBoxEventType_T, aInterested), -
trunk/src/VBox/Main/include/VirtualBoxCallbackImpl.h
r29519 r30345 25 25 VBOX_SCRIPTABLE_IMPL(ILocalOwner), 26 26 VBOX_SCRIPTABLE_IMPL(IConsoleCallback), 27 VBOX_SCRIPTABLE_IMPL(IVirtualBoxCallback) 27 VBOX_SCRIPTABLE_IMPL(IVirtualBoxCallback), 28 VBOX_SCRIPTABLE_IMPL(IEventListener) 28 29 #ifdef RT_OS_WINDOWS 29 30 , public CComCoClass<CallbackWrapper, &CLSID_CallbackWrapper> … … 45 46 COM_INTERFACE_ENTRY(IVirtualBoxCallback) 46 47 COM_INTERFACE_ENTRY(IConsoleCallback) 48 COM_INTERFACE_ENTRY(IEventListener) 47 49 END_COM_MAP() 48 50 … … 95 97 STDMETHOD(OnShowWindow)(ULONG64 *winId); 96 98 99 // IEventListener 100 STDMETHOD(HandleEvent)(IEvent *aEvent); 101 97 102 // for VirtualBoxSupportErrorInfoImpl 98 103 static const wchar_t *getComponentName() { return L"CallbackWrapper"; } -
trunk/src/VBox/Main/include/VirtualBoxImpl.h
r30207 r30345 96 96 CONNECTION_POINT_ENTRY(IID_IVirtualBoxCallback) 97 97 END_CONNECTION_POINT_MAP() 98 98 99 99 typedef CComDynamicUnkArray EventListenersList; 100 100 #endif … … 130 130 STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector); 131 131 STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut (IDHCPServer *, aDHCPServers)); 132 STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource); 132 133 133 134 /* IVirtualBox methods */ -
trunk/src/VBox/Main/xpcom/module.cpp
r28979 r30345 46 46 #include "ConsoleVRDPServer.h" 47 47 #include "VirtualBoxCallbackImpl.h" 48 #include "EventImpl.h" 48 49 49 50 #include "Logging.h" … … 73 74 NS_DECL_CLASSINFO(RemoteDisplayInfo) 74 75 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(RemoteDisplayInfo, IRemoteDisplayInfo) 76 NS_DECL_CLASSINFO(EventSource) 77 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(EventSource, IEventSource) 75 78 76 79 NS_DECL_CLASSINFO(Session) … … 80 83 NS_DECL_CLASSINFO(CallbackWrapper) 81 84 NS_IMPL_THREADSAFE_ISUPPORTS3_CI(CallbackWrapper, IVirtualBoxCallback, IConsoleCallback, ILocalOwner) 85 82 86 /** 83 87 * Singleton class factory that holds a reference to the created instance -
trunk/src/VBox/Main/xpcom/server.cpp
r29864 r30345 87 87 #include <AudioAdapterImpl.h> 88 88 #include <SystemPropertiesImpl.h> 89 #include <EventImpl.h> 89 90 90 91 /* implement nsISupports parts of our objects with support for nsIClassInfo */ … … 197 198 NS_DECL_CLASSINFO(BIOSSettings) 198 199 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(BIOSSettings, IBIOSSettings) 200 201 NS_DECL_CLASSINFO(EventSource) 202 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(EventSource, IEventSource) 199 203 200 204 ////////////////////////////////////////////////////////////////////////////////
Note:
See TracChangeset
for help on using the changeset viewer.