VirtualBox

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

Last change on this file since 34393 was 34393, checked in by vboxsync, 14 years ago

Main: better type checks when firing events

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