3
* VirtualBox COM IEvent implementation
7
* Copyright (C) 2010 Oracle Corporation
9
* This file is part of VirtualBox Open Source Edition (OSE), as
10
* available from http://www.virtualbox.org. This file is free software;
11
* you can redistribute it and/or modify it under the terms of the GNU
12
* General Public License (GPL) as published by the Free Software
13
* Foundation, in version 2 as it comes in the "COPYING" file of the
14
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18
#ifndef ____H_EVENTIMPL
19
#define ____H_EVENTIMPL
21
#include "VirtualBoxBase.h"
24
class ATL_NO_VTABLE VBoxEvent :
25
public VirtualBoxBase,
26
VBOX_SCRIPTABLE_IMPL(IEvent)
29
VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VBoxEvent, IEvent)
31
DECLARE_NOT_AGGREGATABLE(VBoxEvent)
33
DECLARE_PROTECT_FINAL_CONSTRUCT()
35
BEGIN_COM_MAP(VBoxEvent)
36
COM_INTERFACE_ENTRY(ISupportErrorInfo)
37
COM_INTERFACE_ENTRY(IEvent)
38
COM_INTERFACE_ENTRY(IDispatch)
42
virtual ~VBoxEvent() {}
44
HRESULT FinalConstruct();
47
// public initializer/uninitializer for internal purposes only
48
HRESULT init(IEventSource *aSource, VBoxEventType_T aType, BOOL aWaitable);
52
STDMETHOD(COMGETTER(Type))(VBoxEventType_T *aType);
53
STDMETHOD(COMGETTER(Source))(IEventSource * *aSource);
54
STDMETHOD(COMGETTER(Waitable))(BOOL *aWaitable);
57
STDMETHOD(SetProcessed)();
58
STDMETHOD(WaitProcessed)(LONG aTimeout, BOOL *aResult);
66
class ATL_NO_VTABLE VBoxVetoEvent :
68
VBOX_SCRIPTABLE_IMPL(IVetoEvent)
71
VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VBoxVetoEvent, IVetoEvent)
73
DECLARE_NOT_AGGREGATABLE(VBoxVetoEvent)
75
DECLARE_PROTECT_FINAL_CONSTRUCT()
77
BEGIN_COM_MAP(VBoxVetoEvent)
78
COM_INTERFACE_ENTRY(ISupportErrorInfo)
79
COM_INTERFACE_ENTRY2(IEvent, IVetoEvent)
80
COM_INTERFACE_ENTRY(IVetoEvent)
81
COM_INTERFACE_ENTRY2(IDispatch, IVetoEvent)
85
virtual ~VBoxVetoEvent() {}
87
HRESULT FinalConstruct();
90
// public initializer/uninitializer for internal purposes only
91
HRESULT init(IEventSource *aSource, VBoxEventType_T aType);
95
STDMETHOD(COMGETTER(Type))(VBoxEventType_T *aType)
97
return VBoxEvent::COMGETTER(Type)(aType);
99
STDMETHOD(COMGETTER(Source))(IEventSource * *aSource)
101
return VBoxEvent::COMGETTER(Source)(aSource);
103
STDMETHOD(COMGETTER(Waitable))(BOOL *aWaitable)
105
return VBoxEvent::COMGETTER(Waitable)(aWaitable);
109
STDMETHOD(SetProcessed)()
111
return VBoxEvent::SetProcessed();
113
STDMETHOD(WaitProcessed)(LONG aTimeout, BOOL *aResult)
115
return VBoxEvent::WaitProcessed(aTimeout, aResult);
118
// IVetoEvent methods
119
STDMETHOD(AddVeto)(IN_BSTR aVeto);
120
STDMETHOD(IsVetoed)(BOOL *aResult);
121
STDMETHOD(GetVetos)(ComSafeArrayOut(BSTR, aVetos));
129
class ATL_NO_VTABLE EventSource :
130
public VirtualBoxBase,
131
VBOX_SCRIPTABLE_IMPL(IEventSource)
135
VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(EventSource, IEventSource)
137
DECLARE_NOT_AGGREGATABLE(EventSource)
139
DECLARE_PROTECT_FINAL_CONSTRUCT()
141
BEGIN_COM_MAP(EventSource)
142
COM_INTERFACE_ENTRY(ISupportErrorInfo)
143
COM_INTERFACE_ENTRY(IEventSource)
144
COM_INTERFACE_ENTRY(IDispatch)
147
DECLARE_EMPTY_CTOR_DTOR(EventSource)
149
HRESULT FinalConstruct();
152
// public initializer/uninitializer for internal purposes only
153
HRESULT init(IUnknown *aParent);
156
// IEventSource methods
157
STDMETHOD(CreateListener)(IEventListener **aListener);
158
STDMETHOD(CreateAggregator)(ComSafeArrayIn(IEventSource *, aSubordinates),
159
IEventSource **aAggregator);
160
STDMETHOD(RegisterListener)(IEventListener *aListener,
161
ComSafeArrayIn(VBoxEventType_T, aInterested),
163
STDMETHOD(UnregisterListener)(IEventListener *aListener);
164
STDMETHOD(FireEvent)(IEvent *aEvent, LONG aTimeout, BOOL *aProcessed);
165
STDMETHOD(GetEvent)(IEventListener *aListener, LONG aTimeout,
167
STDMETHOD(EventProcessed)(IEventListener *aListener, IEvent *aEvent);
174
friend class ListenerRecord;
180
VBoxEventDesc() : mEvent(0), mEventSource(0)
187
* This function to be used with some care, as arguments order must match
188
* attribute declaration order event class and its superclasses up to
189
* IEvent. If unsure, consult implementation in generated VBoxEvents.cpp.
191
HRESULT init(IEventSource* aSource, VBoxEventType_T aType, ...);
194
* Function similar to the above, but assumes that init() for this type
195
* already called once, so no need to allocate memory, and only reinit
196
* fields. Assumes event is subtype of IReusableEvent, asserts otherwise.
198
HRESULT reinit(VBoxEventType_T aType, ...);
203
mEventSource.setNull();
206
void getEvent(IEvent **aEvent)
208
mEvent.queryInterfaceTo(aEvent);
211
BOOL fire(LONG aTimeout)
213
if (mEventSource && mEvent)
215
BOOL fDelivered = FALSE;
216
int rc = mEventSource->FireEvent(mEvent, aTimeout, &fDelivered);
217
AssertRCReturn(rc, FALSE);
224
ComPtr<IEvent> mEvent;
225
ComPtr<IEventSource> mEventSource;
228
#endif // ____H_EVENTIMPL