VirtualBox

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

Last change on this file since 53390 was 52719, checked in by vboxsync, 10 years ago

Main/Event: wrapper conversion, not covering the automatically generated event implementations

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