VirtualBox

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

Last change on this file since 55068 was 53917, checked in by vboxsync, 10 years ago

comimpl.xsl: Use xsl:key + key() to access interfaces[@name=?] and enum[@name=?]. Also, inserted a new-output-buffer command.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 32.4 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-2014 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-2015 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 != 'midlDoesNotLikEmptyInterfaces']">
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="concat(' VBOX_DEFAULT_INTERFACE_ENTRIES(', @name, ')&#10;')" />
491
492 <xsl:call-template name="genComEntry">
493 <xsl:with-param name="name" select="@name" />
494 </xsl:call-template>
495 <xsl:value-of select=" ' END_COM_MAP()&#10;'" />
496 <xsl:value-of select="concat(' ',$implName,'() { /*printf(&quot;',$implName,'\n&quot;)*/;}&#10;')" />
497 <xsl:value-of select="concat(' virtual ~',$implName,'() { /*printf(&quot;~',$implName,'\n&quot;)*/; uninit(); }&#10;')" />
498 <xsl:text><![CDATA[
499 HRESULT FinalConstruct()
500 {
501 BaseFinalConstruct();
502 return mEvent.createObject();
503 }
504 void FinalRelease()
505 {
506 mEvent->FinalRelease();
507 BaseFinalRelease();
508 }
509 STDMETHOD(COMGETTER(Type))(VBoxEventType_T *aType)
510 {
511 return mEvent->COMGETTER(Type)(aType);
512 }
513 STDMETHOD(COMGETTER(Source))(IEventSource * *aSource)
514 {
515 return mEvent->COMGETTER(Source)(aSource);
516 }
517 STDMETHOD(COMGETTER(Waitable))(BOOL *aWaitable)
518 {
519 return mEvent->COMGETTER(Waitable)(aWaitable);
520 }
521 STDMETHOD(SetProcessed)()
522 {
523 return mEvent->SetProcessed();
524 }
525 STDMETHOD(WaitProcessed)(LONG aTimeout, BOOL *aResult)
526 {
527 return mEvent->WaitProcessed(aTimeout, aResult);
528 }
529 void uninit()
530 {
531 if (!mEvent.isNull())
532 {
533 mEvent->uninit();
534 mEvent.setNull();
535 }
536 }
537]]></xsl:text>
538 <xsl:choose>
539 <xsl:when test="$isVeto='yes'">
540<xsl:text><![CDATA[
541 HRESULT init(IEventSource* aSource, VBoxEventType_T aType, BOOL aWaitable = TRUE)
542 {
543 NOREF(aWaitable);
544 return mEvent->init(aSource, aType);
545 }
546 STDMETHOD(AddVeto)(IN_BSTR aVeto)
547 {
548 return mEvent->AddVeto(aVeto);
549 }
550 STDMETHOD(IsVetoed)(BOOL *aResult)
551 {
552 return mEvent->IsVetoed(aResult);
553 }
554 STDMETHOD(GetVetos)(ComSafeArrayOut(BSTR, aVetos))
555 {
556 return mEvent->GetVetos(ComSafeArrayOutArg(aVetos));
557 }
558private:
559 ComObjPtr<VBoxVetoEvent> mEvent;
560]]></xsl:text>
561 </xsl:when>
562 <xsl:when test="$isReusable='yes'">
563 <xsl:text>
564<![CDATA[
565 HRESULT init(IEventSource* aSource, VBoxEventType_T aType, BOOL aWaitable = FALSE)
566 {
567 mGeneration = 1;
568 return mEvent->init(aSource, aType, aWaitable);
569 }
570 STDMETHOD(COMGETTER(Generation))(ULONG *aGeneration)
571 {
572 *aGeneration = mGeneration;
573 return S_OK;
574 }
575 STDMETHOD(Reuse)()
576 {
577 ASMAtomicIncU32((volatile uint32_t*)&mGeneration);
578 return S_OK;
579 }
580private:
581 volatile ULONG mGeneration;
582 ComObjPtr<VBoxEvent> mEvent;
583]]></xsl:text>
584 </xsl:when>
585 <xsl:otherwise>
586<xsl:text><![CDATA[
587 HRESULT init(IEventSource* aSource, VBoxEventType_T aType, BOOL aWaitable)
588 {
589 return mEvent->init(aSource, aType, aWaitable);
590 }
591private:
592 ComObjPtr<VBoxEvent> mEvent;
593]]></xsl:text>
594 </xsl:otherwise>
595 </xsl:choose>
596
597 <!-- Before we generate attribute code, we check and make sure there are attributes here. -->
598 <xsl:if test="count(attribute) = 0 and @name != 'INATNetworkAlterEvent'">
599 <xsl:call-template name="fatalError">
600 <xsl:with-param name="msg">error: <xsl:value-of select="@name"/> has no attributes</xsl:with-param>
601 </xsl:call-template>
602 </xsl:if>
603
604 <xsl:call-template name="genAttrCode">
605 <xsl:with-param name="name" select="@name" />
606 </xsl:call-template>
607 <xsl:value-of select="'};&#10;'" />
608
609
610 <xsl:call-template name="genImplList">
611 <xsl:with-param name="impl" select="$implName" />
612 <xsl:with-param name="name" select="@name" />
613 <xsl:with-param name="depth" select="'1'" />
614 <xsl:with-param name="parents" select="''" />
615 </xsl:call-template>
616
617</xsl:template>
618
619
620<xsl:template name="genSwitchCase">
621 <xsl:param name="ifaceName" />
622 <xsl:param name="implName" />
623 <xsl:param name="reinit" />
624 <xsl:variable name="waitable">
625 <xsl:choose>
626 <xsl:when test="@waitable='yes'">
627 <xsl:value-of select="'TRUE'"/>
628 </xsl:when>
629 <xsl:otherwise>
630 <xsl:value-of select="'FALSE'"/>
631 </xsl:otherwise>
632 </xsl:choose>
633 </xsl:variable>
634 <xsl:value-of select="concat(' case VBoxEventType_', @id, ':&#10;')"/>
635 <xsl:value-of select=" ' {&#10;'"/>
636 <xsl:choose>
637 <xsl:when test="$reinit='yes'">
638 <xsl:value-of select="concat(' ComPtr&lt;', $ifaceName, '&gt; iobj;&#10;')"/>
639 <xsl:value-of select=" ' iobj = mEvent;&#10;'"/>
640 <xsl:value-of select=" ' Assert(!iobj.isNull());&#10;'"/>
641 <xsl:value-of select="concat(' ',$implName, '* obj = (', $implName, '*)(', $ifaceName, '*)iobj;&#10;')"/>
642 <xsl:value-of select=" ' obj->Reuse();&#10;'"/>
643 </xsl:when>
644 <xsl:otherwise>
645 <xsl:value-of select="concat(' ComObjPtr&lt;', $implName, '&gt; obj;&#10;')"/>
646 <xsl:value-of select=" ' obj.createObject();&#10;'"/>
647 <xsl:value-of select="concat(' obj->init(aSource, aType, ', $waitable, ');&#10;')"/>
648 </xsl:otherwise>
649 </xsl:choose>
650 <xsl:call-template name="genAttrInitCode">
651 <xsl:with-param name="name" select="@name" />
652 <xsl:with-param name="obj" select="'obj'" />
653 </xsl:call-template>
654 <xsl:if test="not($reinit='yes')">
655 <xsl:value-of select=" ' obj.queryInterfaceTo(mEvent.asOutParam());&#10;'"/>
656 </xsl:if>
657 <xsl:value-of select=" ' break;&#10;'"/>
658 <xsl:value-of select=" ' }&#10;'"/>
659</xsl:template>
660
661<xsl:template name="genCommonEventCode">
662 <xsl:call-template name="fileheader">
663 <xsl:with-param name="name" select="'VBoxEvents.cpp'" />
664 </xsl:call-template>
665
666<xsl:text><![CDATA[
667#include <VBox/com/array.h>
668#include <iprt/asm.h>
669#include "EventImpl.h"
670]]></xsl:text>
671
672 <!-- Interfaces -->
673 <xsl:for-each select="//interface[@autogen=$G_kind]">
674 <xsl:value-of select="concat('// ', @name, ' implementation code')" />
675 <xsl:call-template name="xsltprocNewlineOutputHack"/>
676 <xsl:variable name="implName">
677 <xsl:value-of select="substring(@name, 2)" />
678 </xsl:variable>
679
680 <xsl:choose>
681 <xsl:when test="$G_kind='VBoxEvent'">
682 <xsl:variable name="isVeto">
683 <xsl:if test="@extends='IVetoEvent'">
684 <xsl:value-of select="'yes'" />
685 </xsl:if>
686 </xsl:variable>
687 <xsl:variable name="isReusable">
688 <xsl:if test="@extends='IReusableEvent'">
689 <xsl:value-of select="'yes'" />
690 </xsl:if>
691 </xsl:variable>
692 <xsl:call-template name="genEventImpl">
693 <xsl:with-param name="implName" select="$implName" />
694 <xsl:with-param name="isVeto" select="$isVeto" />
695 <xsl:with-param name="isReusable" select="$isReusable" />
696 </xsl:call-template>
697 </xsl:when>
698 </xsl:choose>
699 </xsl:for-each>
700
701 <xsl:text><![CDATA[
702HRESULT VBoxEventDesc::init(IEventSource *aSource, VBoxEventType_T aType, ...)
703{
704 va_list args;
705
706 mEventSource = aSource;
707 va_start(args, aType);
708 switch (aType)
709 {
710]]></xsl:text>
711
712 <xsl:for-each select="//interface[@autogen=$G_kind]">
713 <xsl:variable name="implName">
714 <xsl:value-of select="substring(@name, 2)" />
715 </xsl:variable>
716 <xsl:call-template name="genSwitchCase">
717 <xsl:with-param name="ifaceName" select="@name" />
718 <xsl:with-param name="implName" select="$implName" />
719 <xsl:with-param name="reinit" select="'no'" />
720 </xsl:call-template>
721 </xsl:for-each>
722
723 <xsl:text><![CDATA[
724 default:
725 AssertFailed();
726 }
727 va_end(args);
728
729 return S_OK;
730}
731]]></xsl:text>
732
733 <xsl:text><![CDATA[
734HRESULT VBoxEventDesc::reinit(VBoxEventType_T aType, ...)
735{
736 va_list args;
737
738 va_start(args, aType);
739 switch (aType)
740 {
741]]></xsl:text>
742
743 <xsl:for-each select="//interface[@autogen=$G_kind and @extends='IReusableEvent']">
744 <xsl:variable name="implName">
745 <xsl:value-of select="substring(@name, 2)" />
746 </xsl:variable>
747 <xsl:call-template name="genSwitchCase">
748 <xsl:with-param name="ifaceName" select="@name" />
749 <xsl:with-param name="implName" select="$implName" />
750 <xsl:with-param name="reinit" select="'yes'" />
751 </xsl:call-template>
752 </xsl:for-each>
753
754 <xsl:text><![CDATA[
755 default:
756 AssertFailed();
757 }
758 va_end(args);
759
760 return S_OK;
761}
762]]></xsl:text>
763
764</xsl:template>
765
766<xsl:template name="genFormalParams">
767 <xsl:param name="name" />
768 <xsl:variable name="extends">
769 <xsl:value-of select="key('G_keyInterfacesByName', $name)/@extends" />
770 </xsl:variable>
771
772 <xsl:choose>
773 <xsl:when test="$extends='IEvent'">
774 </xsl:when>
775 <xsl:when test="$extends='IReusableEvent'">
776 </xsl:when>
777 <xsl:when test="count(key('G_keyInterfacesByName', $extends)) > 0">
778 <xsl:call-template name="genFormalParams">
779 <xsl:with-param name="name" select="$extends" />
780 </xsl:call-template>
781 </xsl:when>
782 <xsl:otherwise>
783 <xsl:call-template name="fatalError">
784 <xsl:with-param name="msg" select="concat('No idea how to process it: ', $name)" />
785 </xsl:call-template>
786 </xsl:otherwise>
787 </xsl:choose>
788
789 <xsl:for-each select="key('G_keyInterfacesByName', $name)/attribute[@name != 'midlDoesNotLikEmptyInterfaces']">
790 <xsl:variable name="aName" select="concat('a_',@name)"/>
791 <xsl:variable name="aTypeName">
792 <xsl:call-template name="typeIdl2Back">
793 <xsl:with-param name="type" select="@type" />
794 <xsl:with-param name="safearray" select="@safearray" />
795 <xsl:with-param name="param" select="$aName" />
796 <xsl:with-param name="dir" select="'in'" />
797 <xsl:with-param name="mod" select="@mod" />
798 </xsl:call-template>
799 </xsl:variable>
800 <xsl:value-of select="concat(', ',$aTypeName)"/>
801 </xsl:for-each>
802</xsl:template>
803
804<xsl:template name="genFactParams">
805 <xsl:param name="name" />
806 <xsl:variable name="extends">
807 <xsl:value-of select="key('G_keyInterfacesByName', $name)/@extends" />
808 </xsl:variable>
809
810 <xsl:choose>
811 <xsl:when test="$extends='IEvent'">
812 </xsl:when>
813 <xsl:when test="$extends='IReusableEvent'">
814 </xsl:when>
815 <xsl:when test="count(key('G_keyInterfacesByName', $extends)) > 0">
816 <xsl:call-template name="genFactParams">
817 <xsl:with-param name="name" select="$extends" />
818 </xsl:call-template>
819 </xsl:when>
820 <xsl:otherwise>
821 <xsl:call-template name="fatalError">
822 <xsl:with-param name="msg" select="concat('No idea how to process it: ', $name)" />
823 </xsl:call-template>
824 </xsl:otherwise>
825 </xsl:choose>
826
827 <xsl:for-each select="key('G_keyInterfacesByName', $name)/attribute[@name != 'midlDoesNotLikEmptyInterfaces']">
828 <xsl:variable name="aName" select="concat('a_',@name)"/>
829 <xsl:choose>
830 <xsl:when test="@safearray='yes'">
831 <xsl:value-of select="concat(', ComSafeArrayInArg(',$aName,')')"/>
832 </xsl:when>
833 <xsl:otherwise>
834 <xsl:value-of select="concat(', ',$aName)"/>
835 </xsl:otherwise>
836 </xsl:choose>
837 </xsl:for-each>
838</xsl:template>
839
840<xsl:template name="genCommonEventHeader">
841 <xsl:call-template name="fileheader">
842 <xsl:with-param name="name" select="'VBoxEvents.h'" />
843 </xsl:call-template>
844
845<xsl:text><![CDATA[
846#include "EventImpl.h"
847]]></xsl:text>
848
849 <!-- Interfaces -->
850 <xsl:for-each select="//interface[@autogen='VBoxEvent']">
851 <xsl:value-of select="concat('// ', @name, ' generation routine &#10;')" />
852 <xsl:variable name="evname">
853 <xsl:value-of select="substring(@name, 2)" />
854 </xsl:variable>
855 <xsl:variable name="evid">
856 <xsl:value-of select="concat('On', substring(@name, 2, string-length(@name)-6))" />
857 </xsl:variable>
858
859 <xsl:variable name="ifname">
860 <xsl:value-of select="@name" />
861 </xsl:variable>
862
863 <xsl:value-of select="concat('DECLINLINE(void) fire', $evname, '(IEventSource* aSource')"/>
864 <xsl:call-template name="genFormalParams">
865 <xsl:with-param name="name" select="$ifname" />
866 </xsl:call-template>
867 <xsl:value-of select=" ')&#10;{&#10;'"/>
868
869 <xsl:value-of select=" ' VBoxEventDesc evDesc;&#10;'"/>
870 <xsl:value-of select="concat(' evDesc.init(aSource, VBoxEventType_',$evid)"/>
871 <xsl:call-template name="genFactParams">
872 <xsl:with-param name="name" select="$ifname" />
873 </xsl:call-template>
874 <xsl:value-of select="');&#10;'"/>
875 <xsl:value-of select=" ' evDesc.fire(/* do not wait for delivery */ 0);&#10;'"/>
876 <xsl:value-of select=" '}&#10;'"/>
877 </xsl:for-each>
878</xsl:template>
879
880<xsl:template match="/">
881 <!-- Global code -->
882 <xsl:choose>
883 <xsl:when test="$G_kind='VBoxEvent'">
884 <xsl:call-template name="genCommonEventCode">
885 </xsl:call-template>
886 </xsl:when>
887 <xsl:when test="$G_kind='VBoxEventHeader'">
888 <xsl:call-template name="genCommonEventHeader">
889 </xsl:call-template>
890 </xsl:when>
891 <xsl:otherwise>
892 <xsl:call-template name="fatalError">
893 <xsl:with-param name="msg" select="concat('Request unsupported: ', $G_kind)" />
894 </xsl:call-template>
895 </xsl:otherwise>
896 </xsl:choose>
897</xsl:template>
898
899</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