VirtualBox

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

最後變更 在這個檔案從85286是 85286,由 vboxsync 提交於 5 年 前

Main: Refactored the generated event code implementation as Clang 11 claims va_start() on an VBoxEventType_T may trigger undefined behaviour due to type promotion (or something to that effect), but also because that variadict approach was horrible from the start. Refactored code as a dedicated factory method for each event, removing a dependency on VBoxEventDesc in veto cases. The fireXxxxEvent functions now return a HRESULT are no longer DECLINLINE (no need to compile all of them all the time). Reusable events got a ReinitXxxxxEvent function for helping with that. The VirtualBox::CallbackEvent stuff was a horrid misdesign from the start, it could've been done with a single class carrying a VBoxEventDesc member that the i_onXxxx methods would init() with all the event specific parameters and stuff. Refactored code passes a IEvent around, as that's even easier. I've left much of the old code in place for reference, but will remove once I've had a chance to test it a bit more (still struggling building VBox on the mac). bugref:9790

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 5.2 KB
 
1/* $Id: EventImpl.h 85286 2020-07-12 23:08:50Z vboxsync $ */
2/** @file
3 * VirtualBox COM IEvent implementation
4 */
5
6/*
7 * Copyright (C) 2010-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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 MAIN_INCLUDED_EventImpl_h
19#define MAIN_INCLUDED_EventImpl_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "EventWrap.h"
25#include "EventSourceWrap.h"
26#include "VetoEventWrap.h"
27
28
29class ATL_NO_VTABLE VBoxEvent
30 : public EventWrap
31{
32public:
33 DECLARE_EMPTY_CTOR_DTOR(VBoxEvent)
34
35 HRESULT FinalConstruct();
36 void FinalRelease();
37
38 // public initializer/uninitializer for internal purposes only
39 HRESULT init(IEventSource *aSource, VBoxEventType_T aType, BOOL aWaitable);
40 void uninit();
41
42private:
43 // wrapped IEvent properties
44 HRESULT getType(VBoxEventType_T *aType);
45 HRESULT getSource(ComPtr<IEventSource> &aSource);
46 HRESULT getWaitable(BOOL *aWaitable);
47
48 // wrapped IEvent methods
49 HRESULT setProcessed();
50 HRESULT waitProcessed(LONG aTimeout, BOOL *aResult);
51
52 struct Data;
53 Data* m;
54};
55
56
57class ATL_NO_VTABLE VBoxVetoEvent
58 : public VetoEventWrap
59{
60public:
61 DECLARE_EMPTY_CTOR_DTOR(VBoxVetoEvent)
62
63 HRESULT FinalConstruct();
64 void FinalRelease();
65
66 // public initializer/uninitializer for internal purposes only
67 HRESULT init(IEventSource *aSource, VBoxEventType_T aType);
68 void uninit();
69
70private:
71 // wrapped IEvent properties
72 HRESULT getType(VBoxEventType_T *aType);
73 HRESULT getSource(ComPtr<IEventSource> &aSource);
74 HRESULT getWaitable(BOOL *aWaitable);
75
76 // wrapped IEvent methods
77 HRESULT setProcessed();
78 HRESULT waitProcessed(LONG aTimeout, BOOL *aResult);
79
80 // wrapped IVetoEvent methods
81 HRESULT addVeto(const com::Utf8Str &aReason);
82 HRESULT isVetoed(BOOL *aResult);
83 HRESULT getVetos(std::vector<com::Utf8Str> &aResult);
84 HRESULT addApproval(const com::Utf8Str &aReason);
85 HRESULT isApproved(BOOL *aResult);
86 HRESULT getApprovals(std::vector<com::Utf8Str> &aResult);
87
88 struct Data;
89 Data* m;
90};
91
92class ATL_NO_VTABLE EventSource :
93 public EventSourceWrap
94{
95public:
96 DECLARE_EMPTY_CTOR_DTOR(EventSource)
97
98 HRESULT FinalConstruct();
99 void FinalRelease();
100
101 // public initializer/uninitializer for internal purposes only
102 HRESULT init();
103 void uninit();
104
105private:
106 // wrapped IEventSource methods
107 HRESULT createListener(ComPtr<IEventListener> &aListener);
108 HRESULT createAggregator(const std::vector<ComPtr<IEventSource> > &aSubordinates,
109 ComPtr<IEventSource> &aResult);
110 HRESULT registerListener(const ComPtr<IEventListener> &aListener,
111 const std::vector<VBoxEventType_T> &aInteresting,
112 BOOL aActive);
113 HRESULT unregisterListener(const ComPtr<IEventListener> &aListener);
114 HRESULT fireEvent(const ComPtr<IEvent> &aEvent,
115 LONG aTimeout,
116 BOOL *aResult);
117 HRESULT getEvent(const ComPtr<IEventListener> &aListener,
118 LONG aTimeout,
119 ComPtr<IEvent> &aEvent);
120 HRESULT eventProcessed(const ComPtr<IEventListener> &aListener,
121 const ComPtr<IEvent> &aEvent);
122
123
124 struct Data;
125 Data *m;
126
127 friend class ListenerRecord;
128};
129
130class VBoxEventDesc
131{
132public:
133 VBoxEventDesc() : mEvent(0), mEventSource(0)
134 {}
135
136 VBoxEventDesc(IEvent *aEvent, IEventSource *aSource)
137 : mEvent(aEvent), mEventSource(aSource)
138 {}
139
140 ~VBoxEventDesc()
141 {}
142
143
144#if 0
145 /**
146 * This function to be used with some care, as arguments order must match
147 * attribute declaration order event class and its superclasses up to
148 * IEvent. If unsure, consult implementation in generated VBoxEvents.cpp.
149 */
150 HRESULT init(IEventSource* aSource, VBoxEventType_T aType, ...);
151
152 /**
153 * Function similar to the above, but assumes that init() for this type
154 * already called once, so no need to allocate memory, and only reinit
155 * fields. Assumes event is subtype of IReusableEvent, asserts otherwise.
156 */
157 HRESULT reinit(VBoxEventType_T aType, ...);
158#endif
159
160 void init(IEvent *aEvent, IEventSource *aSource)
161 {
162 mEvent = aEvent;
163 mEventSource = aSource;
164 }
165
166 void uninit()
167 {
168 mEvent.setNull();
169 mEventSource.setNull();
170 }
171
172 void getEvent(IEvent **aEvent)
173 {
174 mEvent.queryInterfaceTo(aEvent);
175 }
176
177 BOOL fire(LONG aTimeout)
178 {
179 if (mEventSource && mEvent)
180 {
181 BOOL fDelivered = FALSE;
182 HRESULT hrc = mEventSource->FireEvent(mEvent, aTimeout, &fDelivered);
183 AssertComRCReturn(hrc, FALSE);
184 return fDelivered;
185 }
186 return FALSE;
187 }
188
189private:
190 ComPtr<IEvent> mEvent;
191 ComPtr<IEventSource> mEventSource;
192};
193
194
195#endif /* !MAIN_INCLUDED_EventImpl_h */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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