VirtualBox

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

Last change on this file since 30503 was 30479, checked in by vboxsync, 15 years ago

feedback

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.2 KB
Line 
1<xsl:stylesheet version = '1.0'
2 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
3 xmlns:vbox="http://www.215389.xyz/"
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.215389.xyz. 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.215389.xyz. 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
93 <xsl:choose>
94 <xsl:when test="(($type='wstring') or ($type='uuid')) and ($param='yes')">
95 <xsl:value-of select="'BSTR'" />
96 </xsl:when>
97 <xsl:when test="(($type='wstring') or ($type='uuid')) and not($param='yes')">
98 <xsl:value-of select="'Bstr'" />
99 </xsl:when>
100 <xsl:when test="//enum[@name=$type]">
101 <xsl:value-of select="concat($type,'_T')"/>
102 </xsl:when>
103 <xsl:when test="$type='boolean'">
104 <xsl:value-of select="'BOOL'" />
105 </xsl:when>
106 <xsl:otherwise>
107 <xsl:call-template name="fatalError">
108 <xsl:with-param name="msg" select="concat('Unhandled type: ', $type)" />
109 </xsl:call-template>
110 </xsl:otherwise>
111 </xsl:choose>
112
113 <xsl:if test="$dir='out'">
114 <xsl:value-of select="'*'"/>
115 </xsl:if>
116</xsl:template>
117
118
119<xsl:template name="genSetParam">
120 <xsl:param name="member"/>
121 <xsl:param name="param"/>
122 <xsl:param name="type"/>
123 <xsl:param name="safearray"/>
124
125 <xsl:value-of select="concat(' ', $member, ' = ', $param, ';&#10;')"/>
126</xsl:template>
127
128<xsl:template name="genRetParam">
129 <xsl:param name="member"/>
130 <xsl:param name="param"/>
131 <xsl:param name="type"/>
132 <xsl:param name="safearray"/>
133 <xsl:choose>
134 <xsl:when test="($type='wstring') or ($type = 'uuid')">
135 <xsl:value-of select="concat(' ', $member, '.cloneTo(', $param, ');&#10;')"/>
136 </xsl:when>
137 <xsl:otherwise>
138 <xsl:value-of select="concat(' *', $param, ' = ', $member, ';&#10;')"/>
139 </xsl:otherwise>
140 </xsl:choose>
141</xsl:template>
142
143<xsl:template name="genAttrInitCode">
144 <xsl:param name="name" />
145 <xsl:param name="obj" />
146 <xsl:variable name="extends">
147 <xsl:value-of select="//interface[@name=$name]/@extends" />
148 </xsl:variable>
149
150 <xsl:choose>
151 <xsl:when test="$extends='IEvent'">
152 </xsl:when>
153 <xsl:when test="//interface[@name=$extends]">
154 <xsl:call-template name="genAttrInitCode">
155 <xsl:with-param name="name" select="$extends" />
156 <xsl:with-param name="obj" select="$obj" />
157 </xsl:call-template>
158 </xsl:when>
159 <xsl:otherwise>
160 <xsl:call-template name="fatalError">
161 <xsl:with-param name="msg" select="concat('No idea how to process it: ', $name)" />
162 </xsl:call-template>
163 </xsl:otherwise>
164 </xsl:choose>
165
166
167 <xsl:for-each select="//interface[@name=$name]/attribute">
168 <xsl:variable name="aType">
169 <xsl:call-template name="typeIdl2Back">
170 <xsl:with-param name="type" select="@type" />
171 <xsl:with-param name="safearray" select="@safearray" />
172 <xsl:with-param name="param" select="'yes'" />
173 <xsl:with-param name="dir" select="'in'" />
174 </xsl:call-template>
175 </xsl:variable>
176
177 <xsl:value-of select="concat(' ',$aType, ' a_',@name,' = va_arg(args, ',$aType,');&#10;')"/>
178 <xsl:value-of select="concat(' ',$obj, '->set_', @name, '(a_', @name, ');&#10;')"/>
179 </xsl:for-each>
180</xsl:template>
181
182<xsl:template name="genImplList">
183 <xsl:param name="impl" />
184 <xsl:param name="name" />
185 <xsl:param name="depth" />
186 <xsl:param name="parents" />
187
188 <xsl:variable name="extends">
189 <xsl:value-of select="//interface[@name=$name]/@extends" />
190 </xsl:variable>
191
192 <xsl:choose>
193 <xsl:when test="$extends='IEvent'">
194 <xsl:value-of select=" '#ifdef VBOX_WITH_XPCOM&#10;'" />
195 <xsl:value-of select="concat('NS_DECL_CLASSINFO(', $impl, ')&#10;')" />
196 <xsl:value-of select="concat('NS_IMPL_THREADSAFE_ISUPPORTS',$depth,'_CI(', $impl, ', ', $name, $parents, ', IEvent)&#10;')" />
197 <xsl:value-of select=" '#endif&#10;&#10;'"/>
198 </xsl:when>
199 <xsl:when test="//interface[@name=$extends]">
200 <xsl:call-template name="genImplList">
201 <xsl:with-param name="impl" select="$impl" />
202 <xsl:with-param name="name" select="$extends" />
203 <xsl:with-param name="depth" select="$depth+1" />
204 <xsl:with-param name="parents" select="concat($parents, ', ', @name)" />
205 </xsl:call-template>
206 </xsl:when>
207 <xsl:otherwise>
208 <xsl:call-template name="fatalError">
209 <xsl:with-param name="msg" select="concat('No idea how to process it: ', $name)" />
210 </xsl:call-template>
211 </xsl:otherwise>
212 </xsl:choose>
213</xsl:template>
214
215<xsl:template name="genAttrCode">
216 <xsl:param name="name" />
217 <xsl:param name="depth" />
218 <xsl:param name="parents" />
219
220 <xsl:variable name="extends">
221 <xsl:value-of select="//interface[@name=$name]/@extends" />
222 </xsl:variable>
223
224 <xsl:for-each select="//interface[@name=$name]/attribute">
225 <xsl:variable name="mName">
226 <xsl:value-of select="concat('m_', @name)" />
227 </xsl:variable>
228 <xsl:variable name="mType">
229 <xsl:call-template name="typeIdl2Back">
230 <xsl:with-param name="type" select="@type" />
231 <xsl:with-param name="safearray" select="@safearray" />
232 <xsl:with-param name="param" select="'no'" />
233 <xsl:with-param name="dir" select="'in'" />
234 </xsl:call-template>
235 </xsl:variable>
236 <xsl:variable name="pName">
237 <xsl:value-of select="concat('a_', @name)" />
238 </xsl:variable>
239 <xsl:variable name="pTypeOut">
240 <xsl:call-template name="typeIdl2Back">
241 <xsl:with-param name="type" select="@type" />
242 <xsl:with-param name="safearray" select="@safearray" />
243 <xsl:with-param name="param" select="'yes'" />
244 <xsl:with-param name="dir" select="'out'" />
245 </xsl:call-template>
246 </xsl:variable>
247 <xsl:variable name="pTypeIn">
248 <xsl:call-template name="typeIdl2Back">
249 <xsl:with-param name="type" select="@type" />
250 <xsl:with-param name="safearray" select="@safearray" />
251 <xsl:with-param name="param" select="'yes'" />
252 <xsl:with-param name="dir" select="'in'" />
253 </xsl:call-template>
254 </xsl:variable>
255 <xsl:variable name="capsName">
256 <xsl:call-template name="capitalize">
257 <xsl:with-param name="str" select="@name" />
258 </xsl:call-template>
259 </xsl:variable>
260 <xsl:value-of select=" '&#10;'" />
261 <xsl:value-of select="concat(' // attribute ', @name,'&#10;')" />
262 <xsl:value-of select=" 'private:&#10;'" />
263 <xsl:value-of select="concat(' ', $mType, ' ', $mName,';&#10;')" />
264 <xsl:value-of select=" 'public:&#10;'" />
265 <xsl:value-of select="concat(' STDMETHOD(COMGETTER(', $capsName,'))(',$pTypeOut, ' ', $pName,') {&#10;')" />
266 <xsl:call-template name="genRetParam">
267 <xsl:with-param name="type" select="@type" />
268 <xsl:with-param name="member" select="$mName" />
269 <xsl:with-param name="param" select="$pName" />
270 <xsl:with-param name="safearray" select="@safearray" />
271 </xsl:call-template>
272 <xsl:value-of select=" ' return S_OK;&#10;'" />
273 <xsl:value-of select=" ' }&#10;'" />
274
275 <xsl:value-of select=" ' // purely internal setter&#10;'" />
276 <xsl:value-of select="concat(' int set_', @name,'(',$pTypeIn, ' ', $pName,') {&#10;')" />
277 <xsl:call-template name="genSetParam">
278 <xsl:with-param name="type" select="@type" />
279 <xsl:with-param name="member" select="$mName" />
280 <xsl:with-param name="param" select="$pName" />
281 <xsl:with-param name="safearray" select="@safearray" />
282 </xsl:call-template>
283 <xsl:value-of select=" ' return S_OK;&#10;'" />
284 <xsl:value-of select=" ' }&#10;'" />
285 </xsl:for-each>
286
287 <xsl:choose>
288 <xsl:when test="$extends='IEvent'">
289 <xsl:value-of select=" ' // skipping IEvent attributes &#10;'" />
290 </xsl:when>
291 <xsl:when test="//interface[@name=$extends]">
292 <xsl:call-template name="genAttrCode">
293 <xsl:with-param name="name" select="$extends" />
294 <xsl:with-param name="depth" select="$depth+1" />
295 <xsl:with-param name="parents" select="concat($parents, ', ', @name)" />
296 </xsl:call-template>
297 </xsl:when>
298 <xsl:otherwise>
299 <xsl:call-template name="fatalError">
300 <xsl:with-param name="msg" select="concat('No idea how to process it: ', $extends)" />
301 </xsl:call-template>
302 </xsl:otherwise>
303 </xsl:choose>
304</xsl:template>
305
306<xsl:template name="genEventImpl">
307 <xsl:param name="implName" />
308
309 <xsl:value-of select="concat('class ATL_NO_VTABLE ',$implName,
310 ' : public VirtualBoxBase, VBOX_SCRIPTABLE_IMPL(',
311 @name, ')&#10;{&#10;')" />
312 <xsl:value-of select="'public:&#10;'" />
313 <xsl:value-of select="concat(' DECLARE_NOT_AGGREGATABLE(', $implName, ')&#10;')" />
314 <xsl:value-of select=" ' DECLARE_PROTECT_FINAL_CONSTRUCT()&#10;'" />
315 <xsl:value-of select="concat(' BEGIN_COM_MAP(', $implName, ')&#10;')" />
316 <xsl:call-template name="genComEntry">
317 <xsl:with-param name="name" select="@name" />
318 </xsl:call-template>
319 <xsl:value-of select=" ' END_COM_MAP()&#10;'" />
320 <xsl:value-of select="concat(' ', $implName, '() {}&#10;')" />
321 <xsl:value-of select="concat(' virtual ~', $implName, '() {}&#10;')" />
322 <xsl:text><![CDATA[
323 HRESULT FinalConstruct()
324 {
325 return mEvent.createObject();
326 }
327 void FinalRelease() {
328 mEvent->FinalRelease();
329 }
330 STDMETHOD(COMGETTER(Type)) (VBoxEventType_T *aType)
331 {
332 return mEvent->COMGETTER(Type) (aType);
333 }
334 STDMETHOD(COMGETTER(Source)) (IEventSource * *aSource)
335 {
336 return mEvent->COMGETTER(Source) (aSource);
337 }
338 STDMETHOD(COMGETTER(Waitable)) (BOOL *aWaitable)
339 {
340 return mEvent->COMGETTER(Waitable) (aWaitable);
341 }
342 STDMETHOD(SetProcessed)()
343 {
344 return mEvent->SetProcessed();
345 }
346 STDMETHOD(WaitProcessed)(LONG aTimeout, BOOL *aResult)
347 {
348 return mEvent->WaitProcessed(aTimeout, aResult);
349 }
350 HRESULT init (IEventSource* aSource, VBoxEventType_T aType, BOOL aWaitable)
351 {
352 return mEvent->init(aSource, aType, aWaitable);
353 }
354 void uninit()
355 {
356 mEvent->uninit();
357 }
358]]></xsl:text>
359 <xsl:value-of select=" 'private:&#10;'" />
360 <xsl:value-of select=" ' ComObjPtr&lt;VBoxEvent&gt; mEvent;&#10;'" />
361
362 <xsl:call-template name="genAttrCode">
363 <xsl:with-param name="name" select="@name" />
364 </xsl:call-template>
365 <xsl:value-of select="'};&#10;'" />
366
367
368 <xsl:call-template name="genImplList">
369 <xsl:with-param name="impl" select="$implName" />
370 <xsl:with-param name="name" select="@name" />
371 <xsl:with-param name="depth" select="'2'" />
372 <xsl:with-param name="parents" select="''" />
373 </xsl:call-template>
374
375</xsl:template>
376
377
378<xsl:template name="genSwitchCase">
379 <xsl:param name="implName" />
380 <xsl:variable name="waitable">
381 <xsl:choose>
382 <xsl:when test="@waitable='yes'">
383 <xsl:value-of select="'TRUE'"/>
384 </xsl:when>
385 <xsl:otherwise>
386 <xsl:value-of select="'FALSE'"/>
387 </xsl:otherwise>
388 </xsl:choose>
389 </xsl:variable>
390 <xsl:value-of select="concat(' case VBoxEventType_', @id, ':&#10;')"/>
391 <xsl:value-of select=" ' {&#10;'"/>
392 <xsl:value-of select="concat(' ComObjPtr&lt;', $implName, '&gt; obj;&#10;')"/>
393 <xsl:value-of select=" ' obj.createObject();&#10;'"/>
394 <xsl:value-of select="concat(' obj->init(source, aType, ', $waitable, ');&#10;')"/>
395 <xsl:call-template name="genAttrInitCode">
396 <xsl:with-param name="name" select="@name" />
397 <xsl:with-param name="obj" select="'obj'" />
398 </xsl:call-template>
399 <xsl:value-of select=" ' obj.queryInterfaceTo(mEvent.asOutParam());&#10;'"/>
400 <xsl:value-of select=" ' break;&#10;'"/>
401 <xsl:value-of select=" ' }&#10;'"/>
402</xsl:template>
403
404<xsl:template name="genCommonEventCode">
405 <xsl:text><![CDATA[
406HRESULT VBoxEventDesc::init(IEventSource* source, VBoxEventType_T aType, ...)
407{
408 va_list args;
409 va_start(args, aType);
410 switch (aType)
411 {
412]]></xsl:text>
413
414 <xsl:for-each select="//interface[@autogen=$G_kind]">
415 <xsl:variable name="implName">
416 <xsl:value-of select="concat(@name,'Impl')" />
417 </xsl:variable>
418 <xsl:call-template name="genSwitchCase">
419 <xsl:with-param name="implName" select="$implName" />
420 </xsl:call-template>
421 </xsl:for-each>
422
423 <xsl:text><![CDATA[
424 default:
425 if (0) AssertFailed();
426 }
427 va_end(args);
428
429 return S_OK;
430}
431]]></xsl:text>
432
433</xsl:template>
434
435
436<xsl:template match="/">
437 <xsl:call-template name="fileheader">
438 <xsl:with-param name="name" select="'VBoxEvents.cpp'" />
439 </xsl:call-template>
440
441 <xsl:value-of select="'#include &quot;EventImpl.h&quot;&#10;&#10;'" />
442
443 <!-- Interfaces -->
444 <xsl:for-each select="//interface[@autogen=$G_kind]">
445 <xsl:value-of select="concat('// ', @name, ' implementation code &#10;')" />
446 <xsl:variable name="implName">
447 <xsl:value-of select="concat(@name,'Impl')" />
448 </xsl:variable>
449
450 <xsl:choose>
451 <xsl:when test="$G_kind='VBoxEvent'">
452 <xsl:call-template name="genEventImpl">
453 <xsl:with-param name="implName" select="$implName" />
454 </xsl:call-template>
455 </xsl:when>
456 </xsl:choose>
457 </xsl:for-each>
458
459 <!-- Global code -->
460 <xsl:choose>
461 <xsl:when test="$G_kind='VBoxEvent'">
462 <xsl:call-template name="genCommonEventCode">
463 </xsl:call-template>
464 </xsl:when>
465 </xsl:choose>
466</xsl:template>
467
468</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.

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