VirtualBox

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

Last change on this file since 30604 was 30553, checked in by vboxsync, 15 years ago

Main: console events, sample of veto events use (enabled by default, could be pretty dangerous, report issues into 4975)

  • 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 public VirtualBoxSupportErrorInfoImpl<VBoxEvent, IEvent>,
26 public VirtualBoxSupportTranslation<VBoxEvent>,
27 VBOX_SCRIPTABLE_IMPL(IEvent)
28{
29public:
30 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VBoxEvent)
31
32 DECLARE_NOT_AGGREGATABLE(VBoxEvent)
33
34 DECLARE_PROTECT_FINAL_CONSTRUCT()
35
36 BEGIN_COM_MAP(VBoxEvent)
37 COM_INTERFACE_ENTRY(ISupportErrorInfo)
38 COM_INTERFACE_ENTRY(IEvent)
39 COM_INTERFACE_ENTRY(IDispatch)
40 END_COM_MAP()
41
42 VBoxEvent() {}
43 virtual ~VBoxEvent() {}
44
45 HRESULT FinalConstruct();
46 void FinalRelease();
47
48 // public initializer/uninitializer for internal purposes only
49 HRESULT init (IEventSource *aSource, VBoxEventType_T aType, BOOL aWaitable);
50 void uninit();
51
52 // IEvent properties
53 STDMETHOD(COMGETTER(Type)) (VBoxEventType_T *aType);
54 STDMETHOD(COMGETTER(Source)) (IEventSource * *aSource);
55 STDMETHOD(COMGETTER(Waitable)) (BOOL *aWaitable);
56
57 // IEvent methods
58 STDMETHOD(SetProcessed)();
59 STDMETHOD(WaitProcessed)(LONG aTimeout, BOOL *aResult);
60
61 // for VirtualBoxSupportErrorInfoImpl
62 static const wchar_t *getComponentName() { return L"Event"; }
63
64private:
65 struct Data;
66
67 Data* m;
68};
69
70class ATL_NO_VTABLE VBoxVetoEvent :
71 public VBoxEvent,
72 VBOX_SCRIPTABLE_IMPL(IVetoEvent)
73{
74public:
75 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VBoxVetoEvent)
76
77 DECLARE_NOT_AGGREGATABLE(VBoxVetoEvent)
78
79 DECLARE_PROTECT_FINAL_CONSTRUCT()
80
81 BEGIN_COM_MAP(VBoxVetoEvent)
82 COM_INTERFACE_ENTRY(ISupportErrorInfo)
83 COM_INTERFACE_ENTRY2(IEvent, IVetoEvent)
84 COM_INTERFACE_ENTRY(IVetoEvent)
85 COM_INTERFACE_ENTRY2(IDispatch, IVetoEvent)
86 END_COM_MAP()
87
88 VBoxVetoEvent() {}
89 virtual ~VBoxVetoEvent() {}
90
91 HRESULT FinalConstruct();
92 void FinalRelease();
93
94 // public initializer/uninitializer for internal purposes only
95 HRESULT init (IEventSource *aSource, VBoxEventType_T aType);
96 void uninit();
97
98 // IEvent properties
99 STDMETHOD(COMGETTER(Type)) (VBoxEventType_T *aType)
100 {
101 return VBoxEvent::COMGETTER(Type)(aType);
102 }
103 STDMETHOD(COMGETTER(Source)) (IEventSource * *aSource)
104 {
105 return VBoxEvent::COMGETTER(Source)(aSource);
106 }
107 STDMETHOD(COMGETTER(Waitable)) (BOOL *aWaitable)
108 {
109 return VBoxEvent::COMGETTER(Waitable)(aWaitable);
110 }
111
112 // IEvent methods
113 STDMETHOD(SetProcessed)()
114 {
115 return VBoxEvent::SetProcessed();
116 }
117 STDMETHOD(WaitProcessed)(LONG aTimeout, BOOL *aResult)
118 {
119 return VBoxEvent::WaitProcessed(aTimeout, aResult);
120 }
121
122 // IVetoEvent methods
123 STDMETHOD(AddVeto)(IN_BSTR aVeto);
124 STDMETHOD(IsVetoed)(BOOL *aResult);
125 STDMETHOD(GetVetos)(ComSafeArrayOut(BSTR, aVetos));
126
127 // for VirtualBoxSupportErrorInfoImpl
128 static const wchar_t *getComponentName() { return L"VetoEvent"; }
129
130private:
131 struct Data;
132
133 Data* m;
134};
135
136class ATL_NO_VTABLE EventSource :
137 public VirtualBoxBase,
138 public VirtualBoxSupportErrorInfoImpl<EventSource, IEventSource>,
139 public VirtualBoxSupportTranslation<EventSource>,
140 VBOX_SCRIPTABLE_IMPL(IEventSource)
141{
142public:
143
144 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(EventSource)
145
146 DECLARE_NOT_AGGREGATABLE(EventSource)
147
148 DECLARE_PROTECT_FINAL_CONSTRUCT()
149
150 BEGIN_COM_MAP(EventSource)
151 COM_INTERFACE_ENTRY(ISupportErrorInfo)
152 COM_INTERFACE_ENTRY(IEventSource)
153 COM_INTERFACE_ENTRY(IDispatch)
154 END_COM_MAP()
155
156 DECLARE_EMPTY_CTOR_DTOR (EventSource)
157
158 HRESULT FinalConstruct();
159 void FinalRelease();
160
161 // public initializer/uninitializer for internal purposes only
162 HRESULT init (IUnknown * aParent);
163 void uninit();
164
165 // IEventSource methods
166 STDMETHOD(CreateListener)(IEventListener ** aListener);
167 STDMETHOD(RegisterListener)(IEventListener * aListener,
168 ComSafeArrayIn(VBoxEventType_T, aInterested),
169 BOOL aActive);
170 STDMETHOD(UnregisterListener)(IEventListener * aListener);
171 STDMETHOD(FireEvent)(IEvent * aEvent,
172 LONG aTimeout,
173 BOOL *aProcessed);
174 STDMETHOD(GetEvent)(IEventListener * aListener,
175 LONG aTimeout,
176 IEvent * *aEvent);
177 STDMETHOD(EventProcessed)(IEventListener * aListener,
178 IEvent * aEvent);
179
180 // for VirtualBoxSupportErrorInfoImpl
181 static const wchar_t *getComponentName() { return L"EventSource"; }
182
183private:
184 struct Data;
185
186 Data* m;
187
188 friend class ListenerRecord;
189};
190
191class VBoxEventDesc
192{
193public:
194 VBoxEventDesc()
195 : mEvent(0)
196 {}
197 ~VBoxEventDesc()
198 {}
199
200 /**
201 * This function to be used with some care, as arguments order must match attribute declaration order
202 * event class and its superclasses up to IEvent. If unsure, consult implementation in
203 * generated VBoxEvents.cpp.
204 */
205 HRESULT init(IEventSource* aSource, VBoxEventType_T aType, ...);
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.

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