VirtualBox

source: vbox/trunk/src/VBox/Main/idl/comimpl.xsl@ 66891

Last change on this file since 66891 was 60977, checked in by vboxsync, 9 years ago

Main/VirtualBoxBase: Add code for collecting information about how many API objects of each component type are currently around and how many have been created ever. While working on this the tiny bug in the event code was found (harmless, as before VirtualBoxBase::BaseFinalRelease was idempotent, but now no longer acceptable)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 33.0 KB
Line 
1<xsl:stylesheet version = '1.0'
2 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
3 xmlns:vbox="http://www.virtualbox.org/"
4 xmlns:exsl="http://exslt.org/common"
5 extension-element-prefixes="exsl">
6
7<!--
8
9 comimpl.xsl:
10 XSLT stylesheet that generates COM C++ classes implementing
11 interfaces described in VirtualBox.xidl.
12 For now we generate implementation for events, as they are
13 rather trivial container classes for their read-only attributes.
14 Further extension to other interfaces is possible and anticipated.
15
16 Copyright (C) 2010-2016 Oracle Corporation
17
18 This file is part of VirtualBox Open Source Edition (OSE), as
19 available from http://www.virtualbox.org. This file is free software;
20 you can redistribute it and/or modify it under the terms of the GNU
21 General Public License (GPL) as published by the Free Software
22 Foundation, in version 2 as it comes in the "COPYING" file of the
23 VirtualBox OSE distribution. VirtualBox OSE is distributed in the
24 hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
25-->
26
27<xsl:output
28 method="text"
29 version="1.0"
30 encoding="utf-8"
31 indent="no"/>
32
33<xsl:include href="typemap-shared.inc.xsl" />
34
35<!-- $G_kind contains what kind of COM class implementation we generate -->
36<xsl:variable name="G_xsltFilename" select="'autogen.xsl'" />
37
38
39<!-- - - - - - - - - - - - - - - - - - - - - - -
40 Keys for more efficiently looking up of types.
41 - - - - - - - - - - - - - - - - - - - - - - -->
42
43<xsl:key name="G_keyEnumsByName" match="//enum[@name]" use="@name"/>
44<xsl:key name="G_keyInterfacesByName" match="//interface[@name]" use="@name"/>
45
46<!-- - - - - - - - - - - - - - - - - - - - - - -
47 - - - - - - - - - - - - - - - - - - - - - - -->
48
49<xsl:template name="fileheader">
50 <xsl:param name="name" />
51 <xsl:text>/** @file </xsl:text>
52 <xsl:value-of select="$name"/>
53 <xsl:text>
54 * DO NOT EDIT! This is a generated file.
55 * Generated from: src/VBox/Main/idl/VirtualBox.xidl (VirtualBox's interface definitions in XML)
56 * Generator: src/VBox/Main/idl/comimpl.xsl
57 */
58
59/*
60 * Copyright (C) 2010-2016 Oracle Corporation
61 *
62 * This file is part of VirtualBox Open Source Edition (OSE), as
63 * available from http://www.virtualbox.org. This file is free software;
64 * you can redistribute it and/or modify it under the terms of the GNU
65 * General Public License (GPL) as published by the Free Software
66 * Foundation, in version 2 as it comes in the "COPYING" file of the
67 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
68 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
69 */
70
71</xsl:text>
72</xsl:template>
73
74<xsl:template name="genComEntry">
75 <xsl:param name="name" />
76 <xsl:variable name="extends">
77 <xsl:value-of select="key('G_keyInterfacesByName', $name)/@extends" />
78 </xsl:variable>
79
80 <xsl:value-of select="concat(' COM_INTERFACE_ENTRY(', $name, ')&#10;')" />
81 <xsl:choose>
82 <xsl:when test="$extends='$unknown'">
83 <!-- Reached base -->
84 </xsl:when>
85 <xsl:when test="count(key('G_keyInterfacesByName', $extends)) > 0">
86 <xsl:call-template name="genComEntry">
87 <xsl:with-param name="name" select="$extends" />
88 </xsl:call-template>
89 </xsl:when>
90 <xsl:otherwise>
91 <xsl:call-template name="fatalError">
92 <xsl:with-param name="msg" select="concat('No idea how to process it: ', $extends)" />
93 </xsl:call-template>
94 </xsl:otherwise>
95 </xsl:choose>
96</xsl:template>
97
98<xsl:template name="typeIdl2Back">
99 <xsl:param name="type" />
100 <xsl:param name="safearray" />
101 <xsl:param name="param" />
102 <xsl:param name="dir" />
103 <xsl:param name="mod" />
104
105 <xsl:choose>
106 <xsl:when test="$safearray='yes'">
107 <xsl:variable name="elemtype">
108 <xsl:call-template name="typeIdl2Back">
109 <xsl:with-param name="type" select="$type" />
110 <xsl:with-param name="safearray" select="''" />
111 <xsl:with-param name="dir" select="'in'" />
112 </xsl:call-template>
113 </xsl:variable>
114 <xsl:choose>
115 <xsl:when test="$param and ($dir='in')">
116 <xsl:value-of select="concat('ComSafeArrayIn(',$elemtype,',', $param,')')"/>
117 </xsl:when>
118 <xsl:when test="$param and ($dir='out')">
119 <xsl:value-of select="concat('ComSafeArrayOut(',$elemtype,', ', $param, ')')"/>
120 </xsl:when>
121 <xsl:otherwise>
122 <xsl:value-of select="concat('com::SafeArray&lt;',$elemtype,'&gt;')"/>
123 </xsl:otherwise>
124 </xsl:choose>
125 </xsl:when>
126 <xsl:otherwise>
127 <xsl:choose>
128 <xsl:when test="$mod='ptr'">
129 <xsl:value-of select="'BYTE*'" />
130 </xsl:when>
131 <xsl:when test="(($type='wstring') or ($type='uuid'))">
132 <xsl:choose>
133 <xsl:when test="$param and ($dir='in')">
134 <xsl:value-of select="'CBSTR'"/>
135 </xsl:when>
136 <xsl:when test="$param and ($dir='out')">
137 <xsl:value-of select="'BSTR'"/>
138 </xsl:when>
139 <xsl:otherwise>
140 <xsl:value-of select="'Bstr'"/>
141 </xsl:otherwise>
142 </xsl:choose>
143 </xsl:when>
144 <xsl:when test="count(key('G_keyEnumsByName', $type)) > 0">
145 <xsl:value-of select="concat($type,'_T')"/>
146 </xsl:when>
147 <xsl:when test="count(key('G_keyInterfacesByName', $type)) > 0">
148 <xsl:choose>
149 <xsl:when test="$param">
150 <xsl:value-of select="concat($type,'*')"/>
151 </xsl:when>
152 <xsl:otherwise>
153 <xsl:value-of select="concat('ComPtr&lt;',$type,'&gt;')"/>
154 </xsl:otherwise>
155 </xsl:choose>
156 </xsl:when>
157 <xsl:when test="$type='boolean'">
158 <xsl:value-of select="'BOOL'" />
159 </xsl:when>
160 <xsl:when test="$type='octet'">
161 <xsl:value-of select="'BYTE'" />
162 </xsl:when>
163 <xsl:when test="$type='unsigned short'">
164 <xsl:value-of select="'USHORT'" />
165 </xsl:when>
166 <xsl:when test="$type='short'">
167 <xsl:value-of select="'SHORT'" />
168 </xsl:when>
169 <xsl:when test="$type='unsigned long'">
170 <xsl:value-of select="'ULONG'" />
171 </xsl:when>
172 <xsl:when test="$type='long'">
173 <xsl:value-of select="'LONG'" />
174 </xsl:when>
175 <xsl:when test="$type='unsigned long long'">
176 <xsl:value-of select="'ULONG64'" />
177 </xsl:when>
178 <xsl:when test="$type='long long'">
179 <xsl:value-of select="'LONG64'" />
180 </xsl:when>
181 <xsl:otherwise>
182 <xsl:call-template name="fatalError">
183 <xsl:with-param name="msg" select="concat('Unhandled type: ', $type)" />
184 </xsl:call-template>
185 </xsl:otherwise>
186 </xsl:choose>
187 <xsl:if test="$dir='out'">
188 <xsl:value-of select="'*'"/>
189 </xsl:if>
190 <xsl:if test="$param and not($param='_')">
191 <xsl:value-of select="concat(' ', $param)"/>
192 </xsl:if>
193 </xsl:otherwise>
194 </xsl:choose>
195
196</xsl:template>
197
198
199<xsl:template name="genSetParam">
200 <xsl:param name="member"/>
201 <xsl:param name="param"/>
202 <xsl:param name="type"/>
203 <xsl:param name="safearray"/>
204
205 <xsl:choose>
206 <xsl:when test="$safearray='yes'">
207 <xsl:variable name="elemtype">
208 <xsl:call-template name="typeIdl2Back">
209 <xsl:with-param name="type" select="$type" />
210 <xsl:with-param name="safearray" select="''" />
211 <xsl:with-param name="dir" select="'in'" />
212 </xsl:call-template>
213 </xsl:variable>
214 <xsl:value-of select="concat(' SafeArray&lt;', $elemtype, '&gt; aArr(ComSafeArrayInArg(',$param,'));&#10;')"/>
215 <xsl:value-of select="concat(' ',$member, '.initFrom(aArr);&#10;')"/>
216 </xsl:when>
217 <xsl:otherwise>
218 <xsl:value-of select="concat(' ', $member, ' = ', $param, ';&#10;')"/>
219 </xsl:otherwise>
220 </xsl:choose>
221</xsl:template>
222
223<xsl:template name="genRetParam">
224 <xsl:param name="member"/>
225 <xsl:param name="param"/>
226 <xsl:param name="type"/>
227 <xsl:param name="safearray"/>
228 <xsl:choose>
229 <xsl:when test="$safearray='yes'">
230 <xsl:variable name="elemtype">
231 <xsl:call-template name="typeIdl2Back">
232 <xsl:with-param name="type" select="$type" />
233 <xsl:with-param name="safearray" select="''" />
234 <xsl:with-param name="dir" select="'in'" />
235 </xsl:call-template>
236 </xsl:variable>
237 <xsl:value-of select="concat(' SafeArray&lt;', $elemtype,'&gt; result;&#10;')"/>
238 <xsl:value-of select="concat(' ', $member, '.cloneTo(result);&#10;')"/>
239 <xsl:value-of select="concat(' result.detachTo(ComSafeArrayOutArg(', $param, '));&#10;')"/>
240 </xsl:when>
241 <xsl:otherwise>
242 <xsl:choose>
243 <xsl:when test="($type='wstring') or ($type = 'uuid')">
244 <xsl:value-of select="concat(' ', $member, '.cloneTo(', $param, ');&#10;')"/>
245 </xsl:when>
246 <xsl:when test="count(key('G_keyInterfacesByName', $type)) > 0">
247 <xsl:value-of select="concat(' ', $member, '.queryInterfaceTo(', $param, ');&#10;')"/>
248 </xsl:when>
249 <xsl:otherwise>
250 <xsl:value-of select="concat(' *', $param, ' = ', $member, ';&#10;')"/>
251 </xsl:otherwise>
252 </xsl:choose>
253 </xsl:otherwise>
254 </xsl:choose>
255</xsl:template>
256
257<xsl:template name="genAttrInitCode">
258 <xsl:param name="name" />
259 <xsl:param name="obj" />
260 <xsl:variable name="extends">
261 <xsl:value-of select="key('G_keyInterfacesByName', $name)/@extends" />
262 </xsl:variable>
263
264 <xsl:choose>
265 <xsl:when test="$extends='IEvent'">
266 </xsl:when>
267 <xsl:when test="$extends='IReusableEvent'">
268 </xsl:when>
269 <xsl:when test="count(key('G_keyInterfacesByName', $extends)) > 0">
270 <xsl:call-template name="genAttrInitCode">
271 <xsl:with-param name="name" select="$extends" />
272 <xsl:with-param name="obj" select="$obj" />
273 </xsl:call-template>
274 </xsl:when>
275 <xsl:otherwise>
276 <xsl:call-template name="fatalError">
277 <xsl:with-param name="msg" select="concat('No idea how to process it: ', $name)" />
278 </xsl:call-template>
279 </xsl:otherwise>
280 </xsl:choose>
281
282 <xsl:for-each select="key('G_keyInterfacesByName', $name)/attribute[@name != 'midlDoesNotLikeEmptyInterfaces']">
283 <xsl:variable name="aName" select="concat('a_',@name)"/>
284 <xsl:variable name="aTypeName">
285 <xsl:call-template name="typeIdl2Back">
286 <xsl:with-param name="type" select="@type" />
287 <xsl:with-param name="safearray" select="@safearray" />
288 <xsl:with-param name="param" select="$aName" />
289 <xsl:with-param name="dir" select="'in'" />
290 <xsl:with-param name="mod" select="@mod" />
291 </xsl:call-template>
292 </xsl:variable>
293 <xsl:variable name="aType">
294 <xsl:call-template name="typeIdl2Back">
295 <xsl:with-param name="type" select="@type" />
296 <xsl:with-param name="safearray" select="@safearray" />
297 <xsl:with-param name="param" select="'_'" />
298 <xsl:with-param name="dir" select="'in'" />
299 <xsl:with-param name="mod" select="@mod" />
300 </xsl:call-template>
301 </xsl:variable>
302
303 <xsl:choose>
304 <xsl:when test="@safearray='yes'">
305 <xsl:variable name="elemtype">
306 <xsl:call-template name="typeIdl2Back">
307 <xsl:with-param name="type" select="@type" />
308 <xsl:with-param name="safearray" select="''" />
309 <xsl:with-param name="dir" select="'in'" />
310 </xsl:call-template>
311 </xsl:variable>
312 <xsl:value-of select=" '#ifdef RT_OS_WINDOWS&#10;'"/>
313 <xsl:value-of select="concat(' SAFEARRAY *aPtr_', @name, ' = va_arg(args, SAFEARRAY *);&#10;')"/>
314 <xsl:value-of select="concat(' com::SafeArray&lt;', $elemtype,'&gt; aArr_', @name, '(aPtr_', @name, ');&#10;')"/>
315 <xsl:value-of select=" '#else&#10;'"/>
316 <xsl:value-of select="concat(' PRUint32 aArrSize_', @name, ' = va_arg(args, PRUint32);&#10;')"/>
317 <xsl:value-of select="concat(' void* aPtr_', @name, ' = va_arg(args, void*);&#10;')"/>
318 <xsl:value-of select="concat(' com::SafeArray&lt;', $elemtype,'&gt; aArr_', @name, '(aArrSize_', @name, ', (', $elemtype,'*)aPtr_', @name, ');&#10;')"/>
319 <xsl:value-of select=" '#endif&#10;'"/>
320 <xsl:value-of select="concat(' ',$obj, '->set_', @name, '(ComSafeArrayAsInParam(aArr_', @name, '));&#10;')"/>
321 </xsl:when>
322 <xsl:otherwise>
323 <xsl:value-of select="concat(' ',$aTypeName, ' = va_arg(args, ',$aType,');&#10;')"/>
324 <xsl:value-of select="concat(' ',$obj, '->set_', @name, '(',$aName, ');&#10;')"/>
325 </xsl:otherwise>
326 </xsl:choose>
327 </xsl:for-each>
328</xsl:template>
329
330<xsl:template name="genImplList">
331 <xsl:param name="impl" />
332 <xsl:param name="name" />
333 <xsl:param name="depth" />
334 <xsl:param name="parents" />
335
336 <xsl:variable name="extends">
337 <xsl:value-of select="key('G_keyInterfacesByName', $name)/@extends" />
338 </xsl:variable>
339
340 <xsl:choose>
341 <xsl:when test="$name='IEvent'">
342 <xsl:value-of select=" '#ifdef VBOX_WITH_XPCOM&#10;'" />
343 <xsl:value-of select="concat('NS_DECL_CLASSINFO(', $impl, ')&#10;')" />
344 <xsl:value-of select="concat('NS_IMPL_THREADSAFE_ISUPPORTS',$depth,'_CI(', $impl, $parents, ', IEvent)&#10;')" />
345 <xsl:value-of select=" '#endif&#10;&#10;'"/>
346 </xsl:when>
347 <xsl:when test="count(key('G_keyInterfacesByName', $extends)) > 0">
348 <xsl:call-template name="genImplList">
349 <xsl:with-param name="impl" select="$impl" />
350 <xsl:with-param name="name" select="$extends" />
351 <xsl:with-param name="depth" select="$depth+1" />
352 <xsl:with-param name="parents" select="concat($parents, ', ', $name)" />
353 </xsl:call-template>
354 </xsl:when>
355 <xsl:otherwise>
356 <xsl:call-template name="fatalError">
357 <xsl:with-param name="msg" select="concat('No idea how to process it: ', $name)" />
358 </xsl:call-template>
359 </xsl:otherwise>
360 </xsl:choose>
361</xsl:template>
362
363<xsl:template name="genAttrCode">
364 <xsl:param name="name" />
365 <xsl:param name="depth" />
366 <xsl:param name="parents" />
367
368 <xsl:variable name="extends">
369 <xsl:value-of select="key('G_keyInterfacesByName', $name)/@extends" />
370 </xsl:variable>
371
372 <xsl:for-each select="key('G_keyInterfacesByName', $name)/attribute">
373 <xsl:variable name="mName">
374 <xsl:value-of select="concat('m_', @name)" />
375 </xsl:variable>
376 <xsl:variable name="mType">
377 <xsl:call-template name="typeIdl2Back">
378 <xsl:with-param name="type" select="@type" />
379 <xsl:with-param name="safearray" select="@safearray" />
380 <xsl:with-param name="dir" select="'in'" />
381 <xsl:with-param name="mod" select="@mod" />
382 </xsl:call-template>
383 </xsl:variable>
384 <xsl:variable name="pName">
385 <xsl:value-of select="concat('a_', @name)" />
386 </xsl:variable>
387 <xsl:variable name="pTypeNameOut">
388 <xsl:call-template name="typeIdl2Back">
389 <xsl:with-param name="type" select="@type" />
390 <xsl:with-param name="safearray" select="@safearray" />
391 <xsl:with-param name="param" select="$pName" />
392 <xsl:with-param name="dir" select="'out'" />
393 <xsl:with-param name="mod" select="@mod" />
394 </xsl:call-template>
395 </xsl:variable>
396
397 <xsl:variable name="pTypeNameIn">
398 <xsl:call-template name="typeIdl2Back">
399 <xsl:with-param name="type" select="@type" />
400 <xsl:with-param name="safearray" select="@safearray" />
401 <xsl:with-param name="param" select="$pName" />
402 <xsl:with-param name="dir" select="'in'" />
403 <xsl:with-param name="mod" select="@mod" />
404 </xsl:call-template>
405 </xsl:variable>
406
407 <xsl:variable name="capsName">
408 <xsl:call-template name="capitalize">
409 <xsl:with-param name="str" select="@name" />
410 </xsl:call-template>
411 </xsl:variable>
412
413 <xsl:value-of select=" '&#10;'" />
414 <xsl:value-of select="concat(' // attribute ', @name,'&#10;')" />
415 <xsl:value-of select=" 'private:&#10;'" />
416 <xsl:value-of select="concat(' ', $mType, ' ', $mName,';&#10;')" />
417 <xsl:value-of select=" 'public:&#10;'" />
418 <xsl:value-of select="concat(' STDMETHOD(COMGETTER(', $capsName,'))(',$pTypeNameOut,')&#10; {&#10;')" />
419 <xsl:call-template name="genRetParam">
420 <xsl:with-param name="type" select="@type" />
421 <xsl:with-param name="member" select="$mName" />
422 <xsl:with-param name="param" select="$pName" />
423 <xsl:with-param name="safearray" select="@safearray" />
424 </xsl:call-template>
425 <xsl:value-of select=" ' return S_OK;&#10;'" />
426 <xsl:value-of select=" ' }&#10;'" />
427
428 <xsl:if test="not(@readonly='yes')">
429 <xsl:value-of select="concat(' STDMETHOD(COMSETTER(', $capsName,'))(',$pTypeNameIn,')&#10; {&#10;')" />
430 <xsl:call-template name="genSetParam">
431 <xsl:with-param name="type" select="@type" />
432 <xsl:with-param name="member" select="$mName" />
433 <xsl:with-param name="param" select="$pName" />
434 <xsl:with-param name="safearray" select="@safearray" />
435 </xsl:call-template>
436 <xsl:value-of select=" ' return S_OK;&#10;'" />
437 <xsl:value-of select=" ' }&#10;'" />
438 </xsl:if>
439
440 <xsl:value-of select=" ' // purely internal setter&#10;'" />
441 <xsl:value-of select="concat(' HRESULT set_', @name,'(',$pTypeNameIn, ')&#10; {&#10;')" />
442 <xsl:call-template name="genSetParam">
443 <xsl:with-param name="type" select="@type" />
444 <xsl:with-param name="member" select="$mName" />
445 <xsl:with-param name="param" select="$pName" />
446 <xsl:with-param name="safearray" select="@safearray" />
447 </xsl:call-template>
448 <xsl:value-of select=" ' return S_OK;&#10;'" />
449 <xsl:value-of select=" ' }&#10;'" />
450 </xsl:for-each>
451
452 <xsl:choose>
453 <xsl:when test="$extends='IEvent'">
454 <xsl:value-of select=" ' // skipping IEvent attributes &#10;'" />
455 </xsl:when>
456 <xsl:when test="$extends='IReusableEvent'">
457 <xsl:value-of select=" ' // skipping IReusableEvent attributes &#10;'" />
458 </xsl:when>
459 <xsl:when test="$extends='IVetoEvent'">
460 <xsl:value-of select=" ' // skipping IVetoEvent attributes &#10;'" />
461 </xsl:when>
462 <xsl:when test="count(key('G_keyInterfacesByName', $extends)) > 0">
463 <xsl:call-template name="genAttrCode">
464 <xsl:with-param name="name" select="$extends" />
465 <xsl:with-param name="depth" select="$depth+1" />
466 <xsl:with-param name="parents" select="concat($parents, ', ', @name)" />
467 </xsl:call-template>
468 </xsl:when>
469 <xsl:otherwise>
470 <xsl:call-template name="fatalError">
471 <xsl:with-param name="msg" select="concat('No idea how to process it: ', $extends)" />
472 </xsl:call-template>
473 </xsl:otherwise>
474 </xsl:choose>
475</xsl:template>
476
477<xsl:template name="genEventImpl">
478 <xsl:param name="implName" />
479 <xsl:param name="isVeto" />
480 <xsl:param name="isReusable" />
481
482 <xsl:value-of select="concat('class ATL_NO_VTABLE ',$implName,
483 '&#10; : public VirtualBoxBase,&#10; VBOX_SCRIPTABLE_IMPL(',
484 @name, ')&#10;{&#10;')" />
485 <xsl:value-of select="'public:&#10;'" />
486 <xsl:value-of select="concat(' VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(', $implName, ', ', @name, ')&#10;')" />
487 <xsl:value-of select="concat(' DECLARE_NOT_AGGREGATABLE(', $implName, ')&#10;')" />
488 <xsl:value-of select=" ' DECLARE_PROTECT_FINAL_CONSTRUCT()&#10;'" />
489 <xsl:value-of select="concat(' BEGIN_COM_MAP(', $implName, ')&#10;')" />
490 <xsl:value-of select=" ' COM_INTERFACE_ENTRY(ISupportErrorInfo)&#10;'" />
491 <xsl:value-of select="concat(' COM_INTERFACE_ENTRY(', @name, ')&#10;')" />
492 <xsl:value-of select="concat(' COM_INTERFACE_ENTRY2(IDispatch, ', @name, ')&#10;')" />
493 <xsl:value-of select="concat(' VBOX_TWEAK_INTERFACE_ENTRY(', @name, ')&#10;')" />
494
495 <xsl:call-template name="genComEntry">
496 <xsl:with-param name="name" select="@name" />
497 </xsl:call-template>
498 <xsl:value-of select=" ' END_COM_MAP()&#10;'" />
499 <xsl:value-of select="concat(' ',$implName,'() { /*printf(&quot;',$implName,'\n&quot;)*/;}&#10;')" />
500 <xsl:value-of select="concat(' virtual ~',$implName,'() { /*printf(&quot;~',$implName,'\n&quot;)*/; uninit(); }&#10;')" />
501 <xsl:text><![CDATA[
502 HRESULT FinalConstruct()
503 {
504 BaseFinalConstruct();
505 return mEvent.createObject();
506 }
507 void FinalRelease()
508 {
509 uninit();
510 BaseFinalRelease();
511 }
512 STDMETHOD(COMGETTER(Type))(VBoxEventType_T *aType)
513 {
514 return mEvent->COMGETTER(Type)(aType);
515 }
516 STDMETHOD(COMGETTER(Source))(IEventSource * *aSource)
517 {
518 return mEvent->COMGETTER(Source)(aSource);
519 }
520 STDMETHOD(COMGETTER(Waitable))(BOOL *aWaitable)
521 {
522 return mEvent->COMGETTER(Waitable)(aWaitable);
523 }
524 STDMETHOD(SetProcessed)()
525 {
526 return mEvent->SetProcessed();
527 }
528 STDMETHOD(WaitProcessed)(LONG aTimeout, BOOL *aResult)
529 {
530 return mEvent->WaitProcessed(aTimeout, aResult);
531 }
532 void uninit()
533 {
534 if (!mEvent.isNull())
535 {
536 mEvent->uninit();
537 mEvent.setNull();
538 }
539 }
540]]></xsl:text>
541 <xsl:choose>
542 <xsl:when test="$isVeto='yes'">
543<xsl:text><![CDATA[
544 HRESULT init(IEventSource* aSource, VBoxEventType_T aType, BOOL aWaitable = TRUE)
545 {
546 NOREF(aWaitable);
547 return mEvent->init(aSource, aType);
548 }
549 STDMETHOD(AddVeto)(IN_BSTR aVeto)
550 {
551 return mEvent->AddVeto(aVeto);
552 }
553 STDMETHOD(IsVetoed)(BOOL *aResult)
554 {
555 return mEvent->IsVetoed(aResult);
556 }
557 STDMETHOD(GetVetos)(ComSafeArrayOut(BSTR, aVetos))
558 {
559 return mEvent->GetVetos(ComSafeArrayOutArg(aVetos));
560 }
561 STDMETHOD(AddApproval)(IN_BSTR aReason)
562 {
563 return mEvent->AddApproval(aReason);
564 }
565 STDMETHOD(IsApproved)(BOOL *aResult)
566 {
567 return mEvent->IsApproved(aResult);
568 }
569 STDMETHOD(GetApprovals)(ComSafeArrayOut(BSTR, aReasons))
570 {
571 return mEvent->GetApprovals(ComSafeArrayOutArg(aReasons));
572 }
573private:
574 ComObjPtr<VBoxVetoEvent> mEvent;
575]]></xsl:text>
576 </xsl:when>
577 <xsl:when test="$isReusable='yes'">
578 <xsl:text>
579<![CDATA[
580 HRESULT init(IEventSource* aSource, VBoxEventType_T aType, BOOL aWaitable = FALSE)
581 {
582 mGeneration = 1;
583 return mEvent->init(aSource, aType, aWaitable);
584 }
585 STDMETHOD(COMGETTER(Generation))(ULONG *aGeneration)
586 {
587 *aGeneration = mGeneration;
588 return S_OK;
589 }
590 STDMETHOD(Reuse)()
591 {
592 ASMAtomicIncU32((volatile uint32_t*)&mGeneration);
593 return S_OK;
594 }
595private:
596 volatile ULONG mGeneration;
597 ComObjPtr<VBoxEvent> mEvent;
598]]></xsl:text>
599 </xsl:when>
600 <xsl:otherwise>
601<xsl:text><![CDATA[
602 HRESULT init(IEventSource* aSource, VBoxEventType_T aType, BOOL aWaitable)
603 {
604 return mEvent->init(aSource, aType, aWaitable);
605 }
606private:
607 ComObjPtr<VBoxEvent> mEvent;
608]]></xsl:text>
609 </xsl:otherwise>
610 </xsl:choose>
611
612 <!-- Before we generate attribute code, we check and make sure there are attributes here. -->
613 <xsl:if test="count(attribute) = 0 and @name != 'INATNetworkAlterEvent'">
614 <xsl:call-template name="fatalError">
615 <xsl:with-param name="msg">error: <xsl:value-of select="@name"/> has no attributes</xsl:with-param>
616 </xsl:call-template>
617 </xsl:if>
618
619 <xsl:call-template name="genAttrCode">
620 <xsl:with-param name="name" select="@name" />
621 </xsl:call-template>
622 <xsl:value-of select="'};&#10;'" />
623
624
625 <xsl:call-template name="genImplList">
626 <xsl:with-param name="impl" select="$implName" />
627 <xsl:with-param name="name" select="@name" />
628 <xsl:with-param name="depth" select="'1'" />
629 <xsl:with-param name="parents" select="''" />
630 </xsl:call-template>
631
632</xsl:template>
633
634
635<xsl:template name="genSwitchCase">
636 <xsl:param name="ifaceName" />
637 <xsl:param name="implName" />
638 <xsl:param name="reinit" />
639 <xsl:variable name="waitable">
640 <xsl:choose>
641 <xsl:when test="@waitable='yes'">
642 <xsl:value-of select="'TRUE'"/>
643 </xsl:when>
644 <xsl:otherwise>
645 <xsl:value-of select="'FALSE'"/>
646 </xsl:otherwise>
647 </xsl:choose>
648 </xsl:variable>
649 <xsl:value-of select="concat(' case VBoxEventType_', @id, ':&#10;')"/>
650 <xsl:value-of select=" ' {&#10;'"/>
651 <xsl:choose>
652 <xsl:when test="$reinit='yes'">
653 <xsl:value-of select="concat(' ComPtr&lt;', $ifaceName, '&gt; iobj;&#10;')"/>
654 <xsl:value-of select=" ' iobj = mEvent;&#10;'"/>
655 <xsl:value-of select=" ' Assert(!iobj.isNull());&#10;'"/>
656 <xsl:value-of select="concat(' ',$implName, '* obj = (', $implName, '*)(', $ifaceName, '*)iobj;&#10;')"/>
657 <xsl:value-of select=" ' obj->Reuse();&#10;'"/>
658 </xsl:when>
659 <xsl:otherwise>
660 <xsl:value-of select="concat(' ComObjPtr&lt;', $implName, '&gt; obj;&#10;')"/>
661 <xsl:value-of select=" ' obj.createObject();&#10;'"/>
662 <xsl:value-of select="concat(' obj->init(aSource, aType, ', $waitable, ');&#10;')"/>
663 </xsl:otherwise>
664 </xsl:choose>
665 <xsl:call-template name="genAttrInitCode">
666 <xsl:with-param name="name" select="@name" />
667 <xsl:with-param name="obj" select="'obj'" />
668 </xsl:call-template>
669 <xsl:if test="not($reinit='yes')">
670 <xsl:value-of select=" ' obj.queryInterfaceTo(mEvent.asOutParam());&#10;'"/>
671 </xsl:if>
672 <xsl:value-of select=" ' break;&#10;'"/>
673 <xsl:value-of select=" ' }&#10;'"/>
674</xsl:template>
675
676<xsl:template name="genCommonEventCode">
677 <xsl:call-template name="fileheader">
678 <xsl:with-param name="name" select="'VBoxEvents.cpp'" />
679 </xsl:call-template>
680
681<xsl:text><![CDATA[
682#include <VBox/com/array.h>
683#include <iprt/asm.h>
684#include "EventImpl.h"
685]]></xsl:text>
686
687 <!-- Interfaces -->
688 <xsl:for-each select="//interface[@autogen=$G_kind]">
689 <xsl:value-of select="concat('// ', @name, ' implementation code')" />
690 <xsl:call-template name="xsltprocNewlineOutputHack"/>
691 <xsl:variable name="implName">
692 <xsl:value-of select="substring(@name, 2)" />
693 </xsl:variable>
694
695 <xsl:choose>
696 <xsl:when test="$G_kind='VBoxEvent'">
697 <xsl:variable name="isVeto">
698 <xsl:if test="@extends='IVetoEvent'">
699 <xsl:value-of select="'yes'" />
700 </xsl:if>
701 </xsl:variable>
702 <xsl:variable name="isReusable">
703 <xsl:if test="@extends='IReusableEvent'">
704 <xsl:value-of select="'yes'" />
705 </xsl:if>
706 </xsl:variable>
707 <xsl:call-template name="genEventImpl">
708 <xsl:with-param name="implName" select="$implName" />
709 <xsl:with-param name="isVeto" select="$isVeto" />
710 <xsl:with-param name="isReusable" select="$isReusable" />
711 </xsl:call-template>
712 </xsl:when>
713 </xsl:choose>
714 </xsl:for-each>
715
716 <xsl:text><![CDATA[
717HRESULT VBoxEventDesc::init(IEventSource *aSource, VBoxEventType_T aType, ...)
718{
719 va_list args;
720
721 mEventSource = aSource;
722 va_start(args, aType);
723 switch (aType)
724 {
725]]></xsl:text>
726
727 <xsl:for-each select="//interface[@autogen=$G_kind]">
728 <xsl:variable name="implName">
729 <xsl:value-of select="substring(@name, 2)" />
730 </xsl:variable>
731 <xsl:call-template name="genSwitchCase">
732 <xsl:with-param name="ifaceName" select="@name" />
733 <xsl:with-param name="implName" select="$implName" />
734 <xsl:with-param name="reinit" select="'no'" />
735 </xsl:call-template>
736 </xsl:for-each>
737
738 <xsl:text><![CDATA[
739 default:
740 AssertFailed();
741 }
742 va_end(args);
743
744 return S_OK;
745}
746]]></xsl:text>
747
748 <xsl:text><![CDATA[
749HRESULT VBoxEventDesc::reinit(VBoxEventType_T aType, ...)
750{
751 va_list args;
752
753 va_start(args, aType);
754 switch (aType)
755 {
756]]></xsl:text>
757
758 <xsl:for-each select="//interface[@autogen=$G_kind and @extends='IReusableEvent']">
759 <xsl:variable name="implName">
760 <xsl:value-of select="substring(@name, 2)" />
761 </xsl:variable>
762 <xsl:call-template name="genSwitchCase">
763 <xsl:with-param name="ifaceName" select="@name" />
764 <xsl:with-param name="implName" select="$implName" />
765 <xsl:with-param name="reinit" select="'yes'" />
766 </xsl:call-template>
767 </xsl:for-each>
768
769 <xsl:text><![CDATA[
770 default:
771 AssertFailed();
772 }
773 va_end(args);
774
775 return S_OK;
776}
777]]></xsl:text>
778
779</xsl:template>
780
781<xsl:template name="genFormalParams">
782 <xsl:param name="name" />
783 <xsl:variable name="extends">
784 <xsl:value-of select="key('G_keyInterfacesByName', $name)/@extends" />
785 </xsl:variable>
786
787 <xsl:choose>
788 <xsl:when test="$extends='IEvent'">
789 </xsl:when>
790 <xsl:when test="$extends='IReusableEvent'">
791 </xsl:when>
792 <xsl:when test="count(key('G_keyInterfacesByName', $extends)) > 0">
793 <xsl:call-template name="genFormalParams">
794 <xsl:with-param name="name" select="$extends" />
795 </xsl:call-template>
796 </xsl:when>
797 <xsl:otherwise>
798 <xsl:call-template name="fatalError">
799 <xsl:with-param name="msg" select="concat('No idea how to process it: ', $name)" />
800 </xsl:call-template>
801 </xsl:otherwise>
802 </xsl:choose>
803
804 <xsl:for-each select="key('G_keyInterfacesByName', $name)/attribute[@name != 'midlDoesNotLikeEmptyInterfaces']">
805 <xsl:variable name="aName" select="concat('a_',@name)"/>
806 <xsl:variable name="aTypeName">
807 <xsl:call-template name="typeIdl2Back">
808 <xsl:with-param name="type" select="@type" />
809 <xsl:with-param name="safearray" select="@safearray" />
810 <xsl:with-param name="param" select="$aName" />
811 <xsl:with-param name="dir" select="'in'" />
812 <xsl:with-param name="mod" select="@mod" />
813 </xsl:call-template>
814 </xsl:variable>
815 <xsl:value-of select="concat(', ',$aTypeName)"/>
816 </xsl:for-each>
817</xsl:template>
818
819<xsl:template name="genFactParams">
820 <xsl:param name="name" />
821 <xsl:variable name="extends">
822 <xsl:value-of select="key('G_keyInterfacesByName', $name)/@extends" />
823 </xsl:variable>
824
825 <xsl:choose>
826 <xsl:when test="$extends='IEvent'">
827 </xsl:when>
828 <xsl:when test="$extends='IReusableEvent'">
829 </xsl:when>
830 <xsl:when test="count(key('G_keyInterfacesByName', $extends)) > 0">
831 <xsl:call-template name="genFactParams">
832 <xsl:with-param name="name" select="$extends" />
833 </xsl:call-template>
834 </xsl:when>
835 <xsl:otherwise>
836 <xsl:call-template name="fatalError">
837 <xsl:with-param name="msg" select="concat('No idea how to process it: ', $name)" />
838 </xsl:call-template>
839 </xsl:otherwise>
840 </xsl:choose>
841
842 <xsl:for-each select="key('G_keyInterfacesByName', $name)/attribute[@name != 'midlDoesNotLikeEmptyInterfaces']">
843 <xsl:variable name="aName" select="concat('a_',@name)"/>
844 <xsl:choose>
845 <xsl:when test="@safearray='yes'">
846 <xsl:value-of select="concat(', ComSafeArrayInArg(',$aName,')')"/>
847 </xsl:when>
848 <xsl:otherwise>
849 <xsl:value-of select="concat(', ',$aName)"/>
850 </xsl:otherwise>
851 </xsl:choose>
852 </xsl:for-each>
853</xsl:template>
854
855<xsl:template name="genCommonEventHeader">
856 <xsl:call-template name="fileheader">
857 <xsl:with-param name="name" select="'VBoxEvents.h'" />
858 </xsl:call-template>
859
860<xsl:text><![CDATA[
861#include "EventImpl.h"
862]]></xsl:text>
863
864 <!-- Interfaces -->
865 <xsl:for-each select="//interface[@autogen='VBoxEvent']">
866 <xsl:value-of select="concat('// ', @name, ' generation routine &#10;')" />
867 <xsl:variable name="evname">
868 <xsl:value-of select="substring(@name, 2)" />
869 </xsl:variable>
870 <xsl:variable name="evid">
871 <xsl:value-of select="concat('On', substring(@name, 2, string-length(@name)-6))" />
872 </xsl:variable>
873
874 <xsl:variable name="ifname">
875 <xsl:value-of select="@name" />
876 </xsl:variable>
877
878 <xsl:value-of select="concat('DECLINLINE(void) fire', $evname, '(IEventSource* aSource')"/>
879 <xsl:call-template name="genFormalParams">
880 <xsl:with-param name="name" select="$ifname" />
881 </xsl:call-template>
882 <xsl:value-of select=" ')&#10;{&#10;'"/>
883
884 <xsl:value-of select=" ' VBoxEventDesc evDesc;&#10;'"/>
885 <xsl:value-of select="concat(' evDesc.init(aSource, VBoxEventType_',$evid)"/>
886 <xsl:call-template name="genFactParams">
887 <xsl:with-param name="name" select="$ifname" />
888 </xsl:call-template>
889 <xsl:value-of select="');&#10;'"/>
890 <xsl:value-of select=" ' evDesc.fire(/* do not wait for delivery */ 0);&#10;'"/>
891 <xsl:value-of select=" '}&#10;'"/>
892 </xsl:for-each>
893</xsl:template>
894
895<xsl:template match="/">
896 <!-- Global code -->
897 <xsl:choose>
898 <xsl:when test="$G_kind='VBoxEvent'">
899 <xsl:call-template name="genCommonEventCode">
900 </xsl:call-template>
901 </xsl:when>
902 <xsl:when test="$G_kind='VBoxEventHeader'">
903 <xsl:call-template name="genCommonEventHeader">
904 </xsl:call-template>
905 </xsl:when>
906 <xsl:otherwise>
907 <xsl:call-template name="fatalError">
908 <xsl:with-param name="msg" select="concat('Request unsupported: ', $G_kind)" />
909 </xsl:call-template>
910 </xsl:otherwise>
911 </xsl:choose>
912</xsl:template>
913
914</xsl:stylesheet>
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