VirtualBox

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

Last change on this file since 32751 was 31772, checked in by vboxsync, 14 years ago

events: explicit uninit method

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 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(RegisterListener)(IEventListener * aListener,
158 ComSafeArrayIn(VBoxEventType_T, aInterested),
159 BOOL aActive);
160 STDMETHOD(UnregisterListener)(IEventListener * aListener);
161 STDMETHOD(FireEvent)(IEvent * aEvent,
162 LONG aTimeout,
163 BOOL *aProcessed);
164 STDMETHOD(GetEvent)(IEventListener * aListener,
165 LONG aTimeout,
166 IEvent * *aEvent);
167 STDMETHOD(EventProcessed)(IEventListener * aListener,
168 IEvent * aEvent);
169
170private:
171 struct Data;
172
173 Data* m;
174
175 friend class ListenerRecord;
176};
177
178class VBoxEventDesc
179{
180public:
181 VBoxEventDesc()
182 : mEvent(0), mEventSource(0)
183 {}
184 ~VBoxEventDesc()
185 {}
186
187 /**
188 * This function to be used with some care, as arguments order must match attribute declaration order
189 * event class and its superclasses up to IEvent. If unsure, consult implementation in
190 * generated VBoxEvents.cpp.
191 */
192 HRESULT init(IEventSource* aSource, VBoxEventType_T aType, ...);
193
194 /**
195 * Function similar to the above, but assumes that init() for this type already called once,
196 * so no need to allocate memory, and only reinit fields. Assumes event is subtype of
197 * IReusableEvent, asserts otherwise.
198 */
199 HRESULT reinit(VBoxEventType_T aType, ...);
200
201 void uninit()
202 {
203 mEvent.setNull();
204 mEventSource.setNull();
205 }
206
207 void getEvent(IEvent ** aEvent)
208 {
209 mEvent.queryInterfaceTo(aEvent);
210 }
211
212 BOOL fire(LONG aTimeout)
213 {
214 if (mEventSource && mEvent)
215 {
216 BOOL fDelivered = FALSE;
217 int rc = mEventSource->FireEvent(mEvent, aTimeout, &fDelivered);
218 AssertRCReturn(rc, FALSE);
219 return fDelivered;
220 }
221 return FALSE;
222 }
223
224private:
225 ComPtr<IEvent> mEvent;
226 ComPtr<IEventSource> mEventSource;
227};
228
229#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