VirtualBox

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

Last change on this file since 35164 was 34402, checked in by vboxsync, 14 years ago

whitespace

  • 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
23
24class ATL_NO_VTABLE VBoxEvent :
25 public VirtualBoxBase,
26 VBOX_SCRIPTABLE_IMPL(IEvent)
27{
28public:
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 COM_INTERFACE_ENTRY(ISupportErrorInfo)
37 COM_INTERFACE_ENTRY(IEvent)
38 COM_INTERFACE_ENTRY(IDispatch)
39 END_COM_MAP()
40
41 VBoxEvent() {}
42 virtual ~VBoxEvent() {}
43
44 HRESULT FinalConstruct();
45 void FinalRelease();
46
47 // public initializer/uninitializer for internal purposes only
48 HRESULT init(IEventSource *aSource, VBoxEventType_T aType, BOOL aWaitable);
49 void uninit();
50
51 // IEvent properties
52 STDMETHOD(COMGETTER(Type))(VBoxEventType_T *aType);
53 STDMETHOD(COMGETTER(Source))(IEventSource * *aSource);
54 STDMETHOD(COMGETTER(Waitable))(BOOL *aWaitable);
55
56 // IEvent methods
57 STDMETHOD(SetProcessed)();
58 STDMETHOD(WaitProcessed)(LONG aTimeout, BOOL *aResult);
59
60private:
61 struct Data;
62
63 Data* m;
64};
65
66class ATL_NO_VTABLE VBoxVetoEvent :
67 public VBoxEvent,
68 VBOX_SCRIPTABLE_IMPL(IVetoEvent)
69{
70public:
71 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VBoxVetoEvent, IVetoEvent)
72
73 DECLARE_NOT_AGGREGATABLE(VBoxVetoEvent)
74
75 DECLARE_PROTECT_FINAL_CONSTRUCT()
76
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)
82 END_COM_MAP()
83
84 VBoxVetoEvent() {}
85 virtual ~VBoxVetoEvent() {}
86
87 HRESULT FinalConstruct();
88 void FinalRelease();
89
90 // public initializer/uninitializer for internal purposes only
91 HRESULT init(IEventSource *aSource, VBoxEventType_T aType);
92 void uninit();
93
94 // IEvent properties
95 STDMETHOD(COMGETTER(Type))(VBoxEventType_T *aType)
96 {
97 return VBoxEvent::COMGETTER(Type)(aType);
98 }
99 STDMETHOD(COMGETTER(Source))(IEventSource * *aSource)
100 {
101 return VBoxEvent::COMGETTER(Source)(aSource);
102 }
103 STDMETHOD(COMGETTER(Waitable))(BOOL *aWaitable)
104 {
105 return VBoxEvent::COMGETTER(Waitable)(aWaitable);
106 }
107
108 // IEvent methods
109 STDMETHOD(SetProcessed)()
110 {
111 return VBoxEvent::SetProcessed();
112 }
113 STDMETHOD(WaitProcessed)(LONG aTimeout, BOOL *aResult)
114 {
115 return VBoxEvent::WaitProcessed(aTimeout, aResult);
116 }
117
118 // IVetoEvent methods
119 STDMETHOD(AddVeto)(IN_BSTR aVeto);
120 STDMETHOD(IsVetoed)(BOOL *aResult);
121 STDMETHOD(GetVetos)(ComSafeArrayOut(BSTR, aVetos));
122
123private:
124 struct Data;
125
126 Data* m;
127};
128
129class ATL_NO_VTABLE EventSource :
130 public VirtualBoxBase,
131 VBOX_SCRIPTABLE_IMPL(IEventSource)
132{
133public:
134
135 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(EventSource, IEventSource)
136
137 DECLARE_NOT_AGGREGATABLE(EventSource)
138
139 DECLARE_PROTECT_FINAL_CONSTRUCT()
140
141 BEGIN_COM_MAP(EventSource)
142 COM_INTERFACE_ENTRY(ISupportErrorInfo)
143 COM_INTERFACE_ENTRY(IEventSource)
144 COM_INTERFACE_ENTRY(IDispatch)
145 END_COM_MAP()
146
147 DECLARE_EMPTY_CTOR_DTOR(EventSource)
148
149 HRESULT FinalConstruct();
150 void FinalRelease();
151
152 // public initializer/uninitializer for internal purposes only
153 HRESULT init(IUnknown *aParent);
154 void uninit();
155
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),
162 BOOL aActive);
163 STDMETHOD(UnregisterListener)(IEventListener *aListener);
164 STDMETHOD(FireEvent)(IEvent *aEvent, LONG aTimeout, BOOL *aProcessed);
165 STDMETHOD(GetEvent)(IEventListener *aListener, LONG aTimeout,
166 IEvent **aEvent);
167 STDMETHOD(EventProcessed)(IEventListener *aListener, IEvent *aEvent);
168
169private:
170 struct Data;
171
172 Data* m;
173
174 friend class ListenerRecord;
175};
176
177class VBoxEventDesc
178{
179public:
180 VBoxEventDesc() : mEvent(0), mEventSource(0)
181 {}
182
183 ~VBoxEventDesc()
184 {}
185
186 /**
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.
190 */
191 HRESULT init(IEventSource* aSource, VBoxEventType_T aType, ...);
192
193 /**
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.
197 */
198 HRESULT reinit(VBoxEventType_T aType, ...);
199
200 void uninit()
201 {
202 mEvent.setNull();
203 mEventSource.setNull();
204 }
205
206 void getEvent(IEvent **aEvent)
207 {
208 mEvent.queryInterfaceTo(aEvent);
209 }
210
211 BOOL fire(LONG aTimeout)
212 {
213 if (mEventSource && mEvent)
214 {
215 BOOL fDelivered = FALSE;
216 int rc = mEventSource->FireEvent(mEvent, aTimeout, &fDelivered);
217 AssertRCReturn(rc, FALSE);
218 return fDelivered;
219 }
220 return FALSE;
221 }
222
223private:
224 ComPtr<IEvent> mEvent;
225 ComPtr<IEventSource> mEventSource;
226};
227
228#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