VirtualBox

source: vbox/trunk/src/VBox/Main/include/EventImpl.h@ 33451

Last change on this file since 33451 was 33298, checked in by vboxsync, 14 years ago

Main: fix docs for aggregator API, burn fix

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

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