4
* A template to generate a MS IDL compatible interface definition file
5
* from the generic interface definition expressed in XML.
7
Copyright (C) 2006-2007 innotek GmbH
9
This file is part of VirtualBox Open Source Edition (OSE), as
10
available from http://www.virtualbox.org. This file is free software;
11
you can redistribute it and/or modify it under the terms of the GNU
12
General Public License as published by the Free Software Foundation,
13
in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14
distribution. VirtualBox OSE is distributed in the hope that it will
15
be useful, but WITHOUT ANY WARRANTY of any kind.
18
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
19
<xsl:output method="text"/>
21
<xsl:strip-space elements="*"/>
26
/////////////////////////////////////////////////////////////////////////////
30
* capitalizes the first letter
32
<xsl:template name="capitalize">
33
<xsl:param name="str" select="."/>
34
<xsl:value-of select="
36
translate(substring($str,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
43
* uncapitalizes the first letter only if the second one is not capital
44
* otherwise leaves the string unchanged
46
<xsl:template name="uncapitalize">
47
<xsl:param name="str" select="."/>
49
<xsl:when test="not(contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ', substring($str,2,1)))">
50
<xsl:value-of select="
52
translate(substring($str,1,1),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),
58
<xsl:value-of select="string($str)"/>
66
/////////////////////////////////////////////////////////////////////////////
73
<xsl:template match="/idl">
76
* DO NOT EDIT! This is a generated file.
78
* MS IDL (MIDL) definition for VirualBox Main API (COM interfaces)
79
* generated from XIDL (XML interface definition).
81
* Source : src/VBox/Main/idl/VirtualBox.xidl
82
* Generator : src/VBox/Main/idl/midl.xsl
85
<xsl:text>
</xsl:text>
86
<xsl:text>import "unknwn.idl";

</xsl:text>
87
<xsl:apply-templates/>
92
* ignore all |if|s except those for MIDL target
94
<xsl:template match="if">
95
<xsl:if test="@target='midl'">
96
<xsl:apply-templates/>
99
<xsl:template match="if" mode="forward">
100
<xsl:if test="@target='midl'">
101
<xsl:apply-templates mode="forward"/>
109
<xsl:template match="cpp">
110
<xsl:text>cpp_quote("</xsl:text>
111
<xsl:value-of select="@line"/>
112
<xsl:text>")

</xsl:text>
117
* #if statement (@if attribute)
119
<xsl:template match="@if" mode="begin">
120
<xsl:text>#if </xsl:text>
121
<xsl:value-of select="."/>
122
<xsl:text>
</xsl:text>
124
<xsl:template match="@if" mode="end">
125
<xsl:text>#endif
</xsl:text>
132
<xsl:template match="library">[
133
uuid(<xsl:value-of select="@uuid"/>),
134
version(<xsl:value-of select="@version"/>),
135
helpstring("<xsl:value-of select="@desc"/>")
137
<xsl:text>library </xsl:text>
138
<xsl:value-of select="@name"/>
139
<xsl:text>
{
</xsl:text>
140
<xsl:text>
importlib("stdole2.tlb");

</xsl:text>
141
<!-- forward declarations -->
142
<xsl:apply-templates select="if | interface | collection | enumerator" mode="forward"/>
143
<xsl:text>
</xsl:text>
144
<!-- all enums go first -->
145
<xsl:apply-templates select="enum | if/enum"/>
146
<!-- everything else but enums -->
147
<xsl:apply-templates select="*[not(self::enum) and not(self::if[enum])]"/>
149
<xsl:text>}; /* library </xsl:text>
150
<xsl:value-of select="@name"/>
151
<xsl:text> */

</xsl:text>
156
* forward declarations
158
<xsl:template match="interface | collection | enumerator" mode="forward">
159
<xsl:text>interface </xsl:text>
160
<xsl:value-of select="@name"/>
161
<xsl:text>;
</xsl:text>
168
<xsl:template match="interface">[
169
uuid(<xsl:value-of select="@uuid"/>),
173
<xsl:text>interface </xsl:text>
174
<xsl:value-of select="@name"/>
175
<xsl:text> : </xsl:text>
177
<xsl:when test="@extends='$unknown'">IUnknown</xsl:when>
178
<xsl:when test="@extends='$dispatched'">IDispatch</xsl:when>
179
<xsl:when test="@extends='$errorinfo'">IErrorInfo</xsl:when>
180
<xsl:otherwise><xsl:value-of select="@extends"/></xsl:otherwise>
182
<xsl:text>
{
</xsl:text>
183
<!-- attributes (properties) -->
184
<xsl:apply-templates select="attribute"/>
186
<xsl:apply-templates select="method"/>
187
<!-- 'if' enclosed elements, unsorted -->
188
<xsl:apply-templates select="if"/>
190
<xsl:text>}; /* interface </xsl:text>
191
<xsl:value-of select="@name"/>
192
<xsl:text> */

</xsl:text>
199
<xsl:template match="interface//attribute | collection//attribute">
200
<xsl:apply-templates select="@if" mode="begin"/>
201
<xsl:text> [propget] HRESULT </xsl:text>
202
<xsl:call-template name="capitalize">
203
<xsl:with-param name="str" select="@name"/>
205
<xsl:text> ([out, retval] </xsl:text>
206
<xsl:apply-templates select="@type"/>
207
<xsl:text> * a</xsl:text>
208
<xsl:call-template name="capitalize">
209
<xsl:with-param name="str" select="@name"/>
211
<xsl:text>);
</xsl:text>
212
<xsl:if test="not(@readonly='yes')">
213
<xsl:text> [propput] HRESULT </xsl:text>
214
<xsl:call-template name="capitalize">
215
<xsl:with-param name="str" select="@name"/>
217
<xsl:text> ([in] </xsl:text>
218
<xsl:apply-templates select="@type"/>
219
<xsl:text> a</xsl:text>
220
<xsl:call-template name="capitalize">
221
<xsl:with-param name="str" select="@name"/>
223
<xsl:text>);
</xsl:text>
225
<xsl:apply-templates select="@if" mode="end"/>
226
<xsl:text>
</xsl:text>
233
<xsl:template match="interface//method | collection//method">
234
<xsl:apply-templates select="@if" mode="begin"/>
235
<xsl:text> HRESULT </xsl:text>
236
<xsl:call-template name="capitalize">
237
<xsl:with-param name="str" select="@name"/>
239
<xsl:if test="param">
240
<xsl:text> (
</xsl:text>
241
<xsl:for-each select="param [position() != last()]">
242
<xsl:text> </xsl:text>
243
<xsl:apply-templates select="."/>
244
<xsl:text>,
</xsl:text>
246
<xsl:text> </xsl:text>
247
<xsl:apply-templates select="param [last()]"/>
248
<xsl:text>
 );
</xsl:text>
250
<xsl:if test="not(param)">
251
<xsl:text>();
</xsl:text>
253
<xsl:apply-templates select="@if" mode="end"/>
254
<xsl:text>
</xsl:text>
261
<xsl:template match="module/class">[
262
uuid(<xsl:value-of select="@uuid"/>)
264
<xsl:text>coclass </xsl:text>
265
<xsl:value-of select="@name"/>
266
<xsl:text>
{
</xsl:text>
267
<xsl:for-each select="interface">
268
<xsl:text> </xsl:text>
269
<xsl:if test="@default='yes'">
270
<xsl:text>[default] </xsl:text>
272
<xsl:text>interface </xsl:text>
273
<xsl:value-of select="@name"/>
274
<xsl:text>;
</xsl:text>
276
<xsl:text>
}; /* coclass </xsl:text>
277
<xsl:value-of select="@name"/>
278
<xsl:text> */

</xsl:text>
285
<xsl:template match="enumerator">[
286
uuid(<xsl:value-of select="@uuid"/>),
290
<xsl:text>interface </xsl:text>
291
<xsl:value-of select="@name"/>
292
<xsl:text> : IUnknown
{
</xsl:text>
294
<xsl:text> HRESULT HasMore ([out, retval] BOOL * more);

</xsl:text>
296
<xsl:text> HRESULT GetNext ([out, retval] </xsl:text>
297
<xsl:apply-templates select="@type"/>
298
<xsl:text> * next);

</xsl:text>
300
<xsl:text>
}; /* interface </xsl:text>
301
<xsl:value-of select="@name"/>
302
<xsl:text> */

</xsl:text>
309
<xsl:template match="collection">
310
<xsl:if test="not(@readonly='yes')">
311
<xsl:message terminate="yes">
312
<xsl:value-of select="concat(@name,': ')"/>
313
<xsl:text>non-readonly collections are not currently supported</xsl:text>
316
uuid(<xsl:value-of select="@uuid"/>),
320
<xsl:text>interface </xsl:text>
321
<xsl:value-of select="@name"/>
322
<xsl:text> : IUnknown
{
</xsl:text>
324
<xsl:text> [propget] HRESULT Count ([out, retval] ULONG * count);

</xsl:text>
326
<xsl:text> HRESULT GetItemAt ([in] ULONG index, [out, retval] </xsl:text>
327
<xsl:apply-templates select="@type"/>
328
<xsl:text> * item);

</xsl:text>
330
<xsl:text> HRESULT Enumerate ([out, retval] </xsl:text>
331
<xsl:apply-templates select="@enumerator"/>
332
<xsl:text> * enumerator);

</xsl:text>
333
<!-- other extra attributes (properties) -->
334
<xsl:apply-templates select="attribute"/>
335
<!-- other extra methods -->
336
<xsl:apply-templates select="method"/>
337
<!-- 'if' enclosed elements, unsorted -->
338
<xsl:apply-templates select="if"/>
340
<xsl:text>
}; /* interface </xsl:text>
341
<xsl:value-of select="@name"/>
342
<xsl:text> */

</xsl:text>
349
<xsl:template match="enum">[
350
uuid(<xsl:value-of select="@uuid"/>),
353
<xsl:text>typedef enum 
{
</xsl:text>
354
<xsl:for-each select="const">
355
<xsl:text> </xsl:text>
356
<xsl:value-of select="@name"/> = <xsl:value-of select="@value"/>
358
<xsl:when test="position()!=last()"><xsl:text>,
</xsl:text></xsl:when>
359
<xsl:otherwise><xsl:text>
</xsl:text></xsl:otherwise>
362
<xsl:text>} </xsl:text>
363
<xsl:value-of select="@name"/>
364
<xsl:text>;

</xsl:text>
366
<xsl:value-of select="concat('/* cross-platform type name for ', @name, ' */
')"/>
367
<xsl:value-of select="concat('cpp_quote("#define ', @name, '_T', ' ',
368
@name, '")

')"/>
369
<xsl:text>cpp_quote("")
</xsl:text>
371
<xsl:value-of select="concat('/* cross-platform constants for ', @name, ' */
')"/>
372
<xsl:for-each select="const">
373
<xsl:value-of select="concat('cpp_quote("#define ', ../@name, '_', @name, ' ',
374
@name, '")
')"/>
376
<xsl:when test="position()=last()"><xsl:text>cpp_quote("")
</xsl:text></xsl:when>
379
<xsl:text>

</xsl:text>
386
<xsl:template match="method/param">
387
<xsl:text>[</xsl:text>
389
<xsl:when test="@dir='in'">in</xsl:when>
390
<xsl:when test="@dir='out'">out</xsl:when>
391
<xsl:when test="@dir='return'">out, retval</xsl:when>
392
<xsl:otherwise>in</xsl:otherwise>
394
<xsl:if test="@array">
395
<xsl:if test="@dir='return'">
396
<xsl:message terminate="yes">
397
<xsl:value-of select="concat(../../@name,'::',../@name,'::',@name,': ')"/>
398
<xsl:text>return array parameters are not currently supported</xsl:text>
402
<xsl:when test="../param[@name=current()/@array]">
403
<xsl:if test="../param[@name=current()/@array]/@dir != @dir">
404
<xsl:message terminate="yes">
405
<xsl:value-of select="concat(../../@name,'::',../@name,': ')"/>
406
<xsl:value-of select="concat(@name,' and ',../param[@name=current()/@array]/@name)"/>
407
<xsl:text> must have the same direction</xsl:text>
410
<xsl:text>, size_is(</xsl:text>
411
<xsl:if test="@dir='out'">
412
<xsl:text>, </xsl:text>
414
<xsl:if test="../param[@name=current()/@array]/@dir='out'">
415
<xsl:text>*</xsl:text>
417
<!--xsl:value-of select="@array"/-->
418
<xsl:text>a</xsl:text>
419
<xsl:call-template name="capitalize">
420
<xsl:with-param name="str" select="@array"/>
422
<xsl:text>)</xsl:text>
425
<xsl:message terminate="yes">
426
<xsl:value-of select="concat(../../@name,'::',../@name,'::',@name,': ')"/>
427
<xsl:text>array attribute refers to non-existent param: </xsl:text>
428
<xsl:value-of select="@array"/>
433
<xsl:text>] </xsl:text>
434
<xsl:apply-templates select="@type"/>
435
<xsl:text> </xsl:text>
436
<xsl:if test="@array">
437
<xsl:text>* </xsl:text>
439
<xsl:if test="@dir='out' or @dir='return'">
440
<xsl:text>* </xsl:text>
442
<!--xsl:value-of select="@name"/-->
443
<xsl:text>a</xsl:text>
444
<xsl:call-template name="capitalize">
445
<xsl:with-param name="str" select="@name"/>
451
* attribute/parameter type conversion
453
<xsl:template match="
454
attribute/@type | param/@type |
455
enumerator/@type | collection/@type | collection/@enumerator
457
<xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
460
<!-- modifiers (ignored for 'enumeration' attributes)-->
461
<xsl:when test="name(current())='type' and ../@mod">
462
<xsl:if test="../@array">
463
<xsl:message terminate="yes">
464
<xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
465
<xsl:text>either 'array' or 'mod' attribute is allowed, but not both!</xsl:text>
469
<xsl:when test="../@mod='ptr'">
471
<!-- standard types -->
472
<!--xsl:when test=".='result'">??</xsl:when-->
473
<xsl:when test=".='boolean'">BOOL *</xsl:when>
474
<xsl:when test=".='octet'">BYTE *</xsl:when>
475
<xsl:when test=".='short'">SHORT *</xsl:when>
476
<xsl:when test=".='unsigned short'">USHORT *</xsl:when>
477
<xsl:when test=".='long'">LONG *</xsl:when>
478
<xsl:when test=".='long long'">LONG64 *</xsl:when>
479
<xsl:when test=".='unsigned long'">ULONG *</xsl:when>
480
<xsl:when test=".='unsigned long long'">ULONG64 *</xsl:when>
481
<xsl:when test=".='char'">CHAR *</xsl:when>
482
<!--xsl:when test=".='string'">??</xsl:when-->
483
<xsl:when test=".='wchar'">OLECHAR *</xsl:when>
484
<!--xsl:when test=".='wstring'">??</xsl:when-->
486
<xsl:message terminate="yes">
487
<xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
488
<xsl:text>attribute 'mod=</xsl:text>
489
<xsl:value-of select="concat('"',../@mod,'"')"/>
490
<xsl:text>' cannot be used with type </xsl:text>
491
<xsl:value-of select="concat('"',current(),'"!')"/>
497
<xsl:message terminate="yes">
498
<xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
499
<xsl:value-of select="concat('value "',../@mod,'" ')"/>
500
<xsl:text>of attibute 'mod' is invalid!</xsl:text>
505
<!-- no modifiers -->
508
<!-- standard types -->
509
<xsl:when test=".='result'">HRESULT</xsl:when>
510
<xsl:when test=".='boolean'">BOOL</xsl:when>
511
<xsl:when test=".='octet'">BYTE</xsl:when>
512
<xsl:when test=".='short'">SHORT</xsl:when>
513
<xsl:when test=".='unsigned short'">USHORT</xsl:when>
514
<xsl:when test=".='long'">LONG</xsl:when>
515
<xsl:when test=".='long long'">LONG64</xsl:when>
516
<xsl:when test=".='unsigned long'">ULONG</xsl:when>
517
<xsl:when test=".='unsigned long long'">ULONG64</xsl:when>
518
<xsl:when test=".='char'">CHAR</xsl:when>
519
<xsl:when test=".='string'">CHAR *</xsl:when>
520
<xsl:when test=".='wchar'">OLECHAR</xsl:when>
521
<xsl:when test=".='wstring'">BSTR</xsl:when>
523
<xsl:when test=".='uuid'">GUID</xsl:when>
524
<!-- system interface types -->
525
<xsl:when test=".='$unknown'">IUnknown *</xsl:when>
530
(ancestor::library/enum[@name=current()]) or
531
(ancestor::library/if[@target=$self_target]/enum[@name=current()])
533
<xsl:value-of select="."/>
535
<!-- custom interface types -->
537
(name(current())='enumerator' and
538
((ancestor::library/enumerator[@name=current()]) or
539
(ancestor::library/if[@target=$self_target]/enumerator[@name=current()]))
541
((ancestor::library/interface[@name=current()]) or
542
(ancestor::library/if[@target=$self_target]/interface[@name=current()])
544
((ancestor::library/collection[@name=current()]) or
545
(ancestor::library/if[@target=$self_target]/collection[@name=current()])
548
<xsl:value-of select="."/><xsl:text> *</xsl:text>
552
<xsl:message terminate="yes">
553
<xsl:text>Unknown parameter type: </xsl:text>
554
<xsl:value-of select="."/>