1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox COM IEvent implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010 Oracle Corporation
|
---|
8 | *
|
---|
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.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ____H_EVENTIMPL
|
---|
19 | #define ____H_EVENTIMPL
|
---|
20 |
|
---|
21 | #include "VirtualBoxBase.h"
|
---|
22 |
|
---|
23 |
|
---|
24 | class ATL_NO_VTABLE VBoxEvent :
|
---|
25 | public VirtualBoxBase,
|
---|
26 | VBOX_SCRIPTABLE_IMPL(IEvent)
|
---|
27 | {
|
---|
28 | public:
|
---|
29 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VBoxEvent, IEvent)
|
---|
30 |
|
---|
31 | DECLARE_NOT_AGGREGATABLE(VBoxEvent)
|
---|
32 |
|
---|
33 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
34 |
|
---|
35 | BEGIN_COM_MAP(VBoxEvent)
|
---|
36 | VBOX_DEFAULT_INTERFACE_ENTRIES(IEvent)
|
---|
37 | END_COM_MAP()
|
---|
38 |
|
---|
39 | VBoxEvent() {}
|
---|
40 | virtual ~VBoxEvent() {}
|
---|
41 |
|
---|
42 | HRESULT FinalConstruct();
|
---|
43 | void FinalRelease();
|
---|
44 |
|
---|
45 | // public initializer/uninitializer for internal purposes only
|
---|
46 | HRESULT init(IEventSource *aSource, VBoxEventType_T aType, BOOL aWaitable);
|
---|
47 | void uninit();
|
---|
48 |
|
---|
49 | // IEvent properties
|
---|
50 | STDMETHOD(COMGETTER(Type))(VBoxEventType_T *aType);
|
---|
51 | STDMETHOD(COMGETTER(Source))(IEventSource * *aSource);
|
---|
52 | STDMETHOD(COMGETTER(Waitable))(BOOL *aWaitable);
|
---|
53 |
|
---|
54 | // IEvent methods
|
---|
55 | STDMETHOD(SetProcessed)();
|
---|
56 | STDMETHOD(WaitProcessed)(LONG aTimeout, BOOL *aResult);
|
---|
57 |
|
---|
58 | private:
|
---|
59 | struct Data;
|
---|
60 |
|
---|
61 | Data* m;
|
---|
62 | };
|
---|
63 |
|
---|
64 | class ATL_NO_VTABLE VBoxVetoEvent :
|
---|
65 | public VBoxEvent,
|
---|
66 | VBOX_SCRIPTABLE_IMPL(IVetoEvent)
|
---|
67 | {
|
---|
68 | public:
|
---|
69 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VBoxVetoEvent, IVetoEvent)
|
---|
70 |
|
---|
71 | DECLARE_NOT_AGGREGATABLE(VBoxVetoEvent)
|
---|
72 |
|
---|
73 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
74 |
|
---|
75 | BEGIN_COM_MAP(VBoxVetoEvent)
|
---|
76 | COM_INTERFACE_ENTRY2(IEvent, IVetoEvent)
|
---|
77 | VBOX_DEFAULT_INTERFACE_ENTRIES(IVetoEvent)
|
---|
78 | END_COM_MAP()
|
---|
79 |
|
---|
80 | VBoxVetoEvent() {}
|
---|
81 | virtual ~VBoxVetoEvent() {}
|
---|
82 |
|
---|
83 | HRESULT FinalConstruct();
|
---|
84 | void FinalRelease();
|
---|
85 |
|
---|
86 | // public initializer/uninitializer for internal purposes only
|
---|
87 | HRESULT init(IEventSource *aSource, VBoxEventType_T aType);
|
---|
88 | void uninit();
|
---|
89 |
|
---|
90 | // IEvent properties
|
---|
91 | STDMETHOD(COMGETTER(Type))(VBoxEventType_T *aType)
|
---|
92 | {
|
---|
93 | return VBoxEvent::COMGETTER(Type)(aType);
|
---|
94 | }
|
---|
95 | STDMETHOD(COMGETTER(Source))(IEventSource * *aSource)
|
---|
96 | {
|
---|
97 | return VBoxEvent::COMGETTER(Source)(aSource);
|
---|
98 | }
|
---|
99 | STDMETHOD(COMGETTER(Waitable))(BOOL *aWaitable)
|
---|
100 | {
|
---|
101 | return VBoxEvent::COMGETTER(Waitable)(aWaitable);
|
---|
102 | }
|
---|
103 |
|
---|
104 | // IEvent methods
|
---|
105 | STDMETHOD(SetProcessed)()
|
---|
106 | {
|
---|
107 | return VBoxEvent::SetProcessed();
|
---|
108 | }
|
---|
109 | STDMETHOD(WaitProcessed)(LONG aTimeout, BOOL *aResult)
|
---|
110 | {
|
---|
111 | return VBoxEvent::WaitProcessed(aTimeout, aResult);
|
---|
112 | }
|
---|
113 |
|
---|
114 | // IVetoEvent methods
|
---|
115 | STDMETHOD(AddVeto)(IN_BSTR aVeto);
|
---|
116 | STDMETHOD(IsVetoed)(BOOL *aResult);
|
---|
117 | STDMETHOD(GetVetos)(ComSafeArrayOut(BSTR, aVetos));
|
---|
118 |
|
---|
119 | private:
|
---|
120 | struct Data;
|
---|
121 |
|
---|
122 | Data* m;
|
---|
123 | };
|
---|
124 |
|
---|
125 | class ATL_NO_VTABLE EventSource :
|
---|
126 | public VirtualBoxBase,
|
---|
127 | VBOX_SCRIPTABLE_IMPL(IEventSource)
|
---|
128 | {
|
---|
129 | public:
|
---|
130 |
|
---|
131 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(EventSource, IEventSource)
|
---|
132 |
|
---|
133 | DECLARE_NOT_AGGREGATABLE(EventSource)
|
---|
134 |
|
---|
135 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
136 |
|
---|
137 | BEGIN_COM_MAP(EventSource)
|
---|
138 | VBOX_DEFAULT_INTERFACE_ENTRIES(IEventSource)
|
---|
139 | END_COM_MAP()
|
---|
140 |
|
---|
141 | DECLARE_EMPTY_CTOR_DTOR(EventSource)
|
---|
142 |
|
---|
143 | HRESULT FinalConstruct();
|
---|
144 | void FinalRelease();
|
---|
145 |
|
---|
146 | // public initializer/uninitializer for internal purposes only
|
---|
147 | HRESULT init(IUnknown *aParent);
|
---|
148 | void uninit();
|
---|
149 |
|
---|
150 | // IEventSource methods
|
---|
151 | STDMETHOD(CreateListener)(IEventListener **aListener);
|
---|
152 | STDMETHOD(CreateAggregator)(ComSafeArrayIn(IEventSource *, aSubordinates),
|
---|
153 | IEventSource **aAggregator);
|
---|
154 | STDMETHOD(RegisterListener)(IEventListener *aListener,
|
---|
155 | ComSafeArrayIn(VBoxEventType_T, aInterested),
|
---|
156 | BOOL aActive);
|
---|
157 | STDMETHOD(UnregisterListener)(IEventListener *aListener);
|
---|
158 | STDMETHOD(FireEvent)(IEvent *aEvent, LONG aTimeout, BOOL *aProcessed);
|
---|
159 | STDMETHOD(GetEvent)(IEventListener *aListener, LONG aTimeout,
|
---|
160 | IEvent **aEvent);
|
---|
161 | STDMETHOD(EventProcessed)(IEventListener *aListener, IEvent *aEvent);
|
---|
162 |
|
---|
163 | private:
|
---|
164 | struct Data;
|
---|
165 |
|
---|
166 | Data* m;
|
---|
167 |
|
---|
168 | friend class ListenerRecord;
|
---|
169 | };
|
---|
170 |
|
---|
171 | class VBoxEventDesc
|
---|
172 | {
|
---|
173 | public:
|
---|
174 | VBoxEventDesc() : mEvent(0), mEventSource(0)
|
---|
175 | {}
|
---|
176 |
|
---|
177 | ~VBoxEventDesc()
|
---|
178 | {}
|
---|
179 |
|
---|
180 | /**
|
---|
181 | * This function to be used with some care, as arguments order must match
|
---|
182 | * attribute declaration order event class and its superclasses up to
|
---|
183 | * IEvent. If unsure, consult implementation in generated VBoxEvents.cpp.
|
---|
184 | */
|
---|
185 | HRESULT init(IEventSource* aSource, VBoxEventType_T aType, ...);
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * Function similar to the above, but assumes that init() for this type
|
---|
189 | * already called once, so no need to allocate memory, and only reinit
|
---|
190 | * fields. Assumes event is subtype of IReusableEvent, asserts otherwise.
|
---|
191 | */
|
---|
192 | HRESULT reinit(VBoxEventType_T aType, ...);
|
---|
193 |
|
---|
194 | void uninit()
|
---|
195 | {
|
---|
196 | mEvent.setNull();
|
---|
197 | mEventSource.setNull();
|
---|
198 | }
|
---|
199 |
|
---|
200 | void getEvent(IEvent **aEvent)
|
---|
201 | {
|
---|
202 | mEvent.queryInterfaceTo(aEvent);
|
---|
203 | }
|
---|
204 |
|
---|
205 | BOOL fire(LONG aTimeout)
|
---|
206 | {
|
---|
207 | if (mEventSource && mEvent)
|
---|
208 | {
|
---|
209 | BOOL fDelivered = FALSE;
|
---|
210 | int rc = mEventSource->FireEvent(mEvent, aTimeout, &fDelivered);
|
---|
211 | AssertRCReturn(rc, FALSE);
|
---|
212 | return fDelivered;
|
---|
213 | }
|
---|
214 | return FALSE;
|
---|
215 | }
|
---|
216 |
|
---|
217 | private:
|
---|
218 | ComPtr<IEvent> mEvent;
|
---|
219 | ComPtr<IEventSource> mEventSource;
|
---|
220 | };
|
---|
221 |
|
---|
222 | #endif // ____H_EVENTIMPL
|
---|