1 | <xsl:stylesheet version = '1.0'
|
---|
2 | xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
|
---|
3 | xmlns:vbox="http://www.virtualbox.org/">
|
---|
4 |
|
---|
5 | <!--
|
---|
6 |
|
---|
7 | websrv-python.xsl:
|
---|
8 | XSLT stylesheet that generates VirtualBox_services.py from
|
---|
9 | VirtualBox.xidl. This Python file represents our
|
---|
10 | web service API. Depends on WSDL file for actual SOAP bindings.
|
---|
11 |
|
---|
12 | Copyright (C) 2008-2020 Oracle Corporation
|
---|
13 |
|
---|
14 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
15 | available from http://www.virtualbox.org. This file is free software;
|
---|
16 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
17 | General Public License (GPL) as published by the Free Software
|
---|
18 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
19 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
20 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
21 | -->
|
---|
22 |
|
---|
23 |
|
---|
24 | <xsl:output
|
---|
25 | method="text"
|
---|
26 | version="1.0"
|
---|
27 | encoding="utf-8"
|
---|
28 | indent="no"/>
|
---|
29 |
|
---|
30 | <xsl:include href="../idl/typemap-shared.inc.xsl" />
|
---|
31 |
|
---|
32 | <xsl:variable name="G_setSuppressedInterfaces"
|
---|
33 | select="//interface[@wsmap='suppress']" />
|
---|
34 |
|
---|
35 | <xsl:template name="emitConvertedType">
|
---|
36 | <xsl:param name="ifname" />
|
---|
37 | <xsl:param name="methodname" />
|
---|
38 | <xsl:param name="type" />
|
---|
39 | <xsl:choose>
|
---|
40 | <xsl:when test="$type='wstring'">String</xsl:when>
|
---|
41 | <xsl:when test="$type='uuid'">String</xsl:when>
|
---|
42 | <xsl:when test="$type='boolean'">Boolean</xsl:when>
|
---|
43 | <xsl:when test="$type='unsigned long'">UnsignedInt</xsl:when>
|
---|
44 | <xsl:when test="$type='double'">Double</xsl:when>
|
---|
45 | <xsl:when test="$type='float'">Float</xsl:when>
|
---|
46 | <xsl:when test="$type='long'">Int</xsl:when>
|
---|
47 | <xsl:when test="$type='long long'">Long</xsl:when>
|
---|
48 | <xsl:when test="$type='short'">Short</xsl:when>
|
---|
49 | <xsl:when test="$type='unsigned short'">UnsignedShort</xsl:when>
|
---|
50 | <xsl:when test="$type='unsigned long long'">UnsignedLong</xsl:when>
|
---|
51 | <xsl:when test="$type='result'">UnsignedInt</xsl:when>
|
---|
52 | <xsl:when test="$type='octet'">Octet</xsl:when>
|
---|
53 | <xsl:when test="$type='$unknown'">IUnknown</xsl:when>
|
---|
54 | <xsl:otherwise><xsl:value-of select="$type" /></xsl:otherwise>
|
---|
55 | </xsl:choose>
|
---|
56 | </xsl:template>
|
---|
57 |
|
---|
58 | <xsl:template name="emitOutParam">
|
---|
59 | <xsl:param name="ifname" />
|
---|
60 | <xsl:param name="methodname" />
|
---|
61 | <xsl:param name="type" />
|
---|
62 | <xsl:param name="value" />
|
---|
63 | <xsl:param name="safearray" />
|
---|
64 |
|
---|
65 | <xsl:choose>
|
---|
66 | <xsl:when test="$type='octet' and $safearray">
|
---|
67 | <xsl:value-of select="concat('self.mgr.decodebase64(',$value,')')" />
|
---|
68 | </xsl:when>
|
---|
69 | <xsl:otherwise>
|
---|
70 | <xsl:call-template name="emitConvertedType">
|
---|
71 | <xsl:with-param name="ifname" select="$ifname" />
|
---|
72 | <xsl:with-param name="methodname" select="$methodname" />
|
---|
73 | <xsl:with-param name="type" select="$type" />
|
---|
74 | </xsl:call-template>
|
---|
75 | <xsl:text>(</xsl:text>
|
---|
76 | <xsl:text>self.mgr,</xsl:text>
|
---|
77 | <xsl:value-of select="$value"/>
|
---|
78 | <xsl:if test="$safearray='yes'">
|
---|
79 | <xsl:value-of select="', True'"/>
|
---|
80 | </xsl:if>
|
---|
81 | <xsl:text>)</xsl:text>
|
---|
82 | </xsl:otherwise>
|
---|
83 | </xsl:choose>
|
---|
84 | </xsl:template>
|
---|
85 |
|
---|
86 |
|
---|
87 | <xsl:template name="emitGetAttribute">
|
---|
88 | <xsl:param name="ifname" />
|
---|
89 | <xsl:param name="attrname" />
|
---|
90 | <xsl:param name="attrtype" />
|
---|
91 | <xsl:param name="attrsafearray" />
|
---|
92 | <xsl:variable name="fname"><xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="$attrname"/></xsl:call-template> </xsl:variable>
|
---|
93 | def <xsl:value-of select="$fname"/>(self):
|
---|
94 | req=<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>RequestMsg()
|
---|
95 | req._this=self.handle
|
---|
96 | val=self.mgr.getPort().<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>(req)
|
---|
97 | <xsl:text>return </xsl:text>
|
---|
98 | <xsl:call-template name="emitOutParam">
|
---|
99 | <xsl:with-param name="ifname" select="$ifname" />
|
---|
100 | <xsl:with-param name="methodname" select="@name" />
|
---|
101 | <xsl:with-param name="type" select="$attrtype" />
|
---|
102 | <xsl:with-param name="value" select="concat('val.','_returnval')" />
|
---|
103 | <xsl:with-param name="safearray" select="$attrsafearray"/>
|
---|
104 | </xsl:call-template>
|
---|
105 | </xsl:template>
|
---|
106 |
|
---|
107 | <xsl:template name="emitSetAttribute">
|
---|
108 | <xsl:param name="ifname" />
|
---|
109 | <xsl:param name="attrname" />
|
---|
110 | <xsl:param name="attrtype" />
|
---|
111 | <xsl:param name="attrsafearray" />
|
---|
112 | <xsl:variable name="fname"><xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="$attrname"/></xsl:call-template> </xsl:variable>
|
---|
113 | def <xsl:value-of select="$fname"/>(self, value):
|
---|
114 | req=<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>RequestMsg()
|
---|
115 | req._this=self.handle
|
---|
116 | if type(value) in [int, bool, basestring, str<xsl:if test="$attrsafearray='yes'">, tuple, list</xsl:if>]:
|
---|
117 | req._<xsl:value-of select="$attrname"/> = value
|
---|
118 | else:
|
---|
119 | req._<xsl:value-of select="$attrname"/> = value.handle
|
---|
120 | self.mgr.getPort().<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>(req)
|
---|
121 | </xsl:template>
|
---|
122 |
|
---|
123 | <xsl:template name="collection">
|
---|
124 | <xsl:variable name="cname"><xsl:value-of select="@name" /></xsl:variable>
|
---|
125 | <xsl:variable name="ename"><xsl:value-of select="@type" /></xsl:variable>
|
---|
126 | class <xsl:value-of select="$cname"/>:
|
---|
127 | def __init__(self, mgr, array):
|
---|
128 | self.array = array
|
---|
129 | self.mgr = mgr
|
---|
130 |
|
---|
131 | def __next(self):
|
---|
132 | return self.array.__next()
|
---|
133 |
|
---|
134 | def __size(self):
|
---|
135 | return self.array._array.__size()
|
---|
136 |
|
---|
137 | def __len__(self):
|
---|
138 | return self.array._array.__len__()
|
---|
139 |
|
---|
140 | def __getitem__(self, index):
|
---|
141 | return <xsl:value-of select="$ename"/>(self.mgr, self.array._array[index])
|
---|
142 |
|
---|
143 | </xsl:template>
|
---|
144 |
|
---|
145 |
|
---|
146 | <xsl:template name="computeExtends">
|
---|
147 | <xsl:param name="base" />
|
---|
148 |
|
---|
149 | <xsl:choose>
|
---|
150 | <xsl:when test="($base = '$unknown')">
|
---|
151 | <xsl:value-of select="'IUnknown'"/>
|
---|
152 | </xsl:when>
|
---|
153 | <xsl:when test="($base = '$errorinfo') ">
|
---|
154 | <xsl:value-of select="'IUnknown'"/>
|
---|
155 | </xsl:when>
|
---|
156 | <xsl:otherwise>
|
---|
157 | <xsl:value-of select="$base"/>
|
---|
158 | </xsl:otherwise>
|
---|
159 | </xsl:choose>
|
---|
160 | </xsl:template>
|
---|
161 |
|
---|
162 | <xsl:template name="interface">
|
---|
163 | <xsl:variable name="base">
|
---|
164 | <xsl:call-template name="computeExtends">
|
---|
165 | <xsl:with-param name="base" select="@extends" />
|
---|
166 | </xsl:call-template>
|
---|
167 | </xsl:variable>
|
---|
168 | <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
|
---|
169 |
|
---|
170 | class <xsl:value-of select="$ifname"/>(<xsl:value-of select="$base" />):
|
---|
171 | def __init__(self, mgr, handle, isarray = False):
|
---|
172 | self.mgr = mgr
|
---|
173 | if handle is None:
|
---|
174 | raise Exception("bad handle: "+str(handle))
|
---|
175 | self.handle = handle
|
---|
176 | self.isarray = isarray
|
---|
177 | if self.isarray:
|
---|
178 | for strHnd in handle:
|
---|
179 | mgr.register(strHnd)
|
---|
180 | else:
|
---|
181 | mgr.register(self.handle)
|
---|
182 |
|
---|
183 | def __del__(self):
|
---|
184 | self.releaseRemote()
|
---|
185 |
|
---|
186 | def releaseRemote(self):
|
---|
187 | try:
|
---|
188 | if self.handle is not None:
|
---|
189 | if self.isarray:
|
---|
190 | for strHnd in self.handle:
|
---|
191 | self.mgr.unregister(strHnd)
|
---|
192 | else:
|
---|
193 | self.mgr.unregister(self.handle)
|
---|
194 | self.handle = None;
|
---|
195 | except:
|
---|
196 | pass
|
---|
197 |
|
---|
198 | def __next(self):
|
---|
199 | if self.isarray:
|
---|
200 | return self.handle.__next()
|
---|
201 | raise TypeError("iteration over non-sequence")
|
---|
202 |
|
---|
203 | def __size(self):
|
---|
204 | if self.isarray:
|
---|
205 | return self.handle.__size()
|
---|
206 | raise TypeError("iteration over non-sequence")
|
---|
207 |
|
---|
208 | def __len__(self):
|
---|
209 | if self.isarray:
|
---|
210 | return self.handle.__len__()
|
---|
211 | raise TypeError("iteration over non-sequence")
|
---|
212 |
|
---|
213 | def __getitem__(self, index):
|
---|
214 | if self.isarray:
|
---|
215 | return <xsl:value-of select="$ifname" />(self.mgr, self.handle[index])
|
---|
216 | raise TypeError("iteration over non-sequence")
|
---|
217 |
|
---|
218 | def __str__(self):
|
---|
219 | if self.isarray:
|
---|
220 | return str(self.handle)
|
---|
221 | else:
|
---|
222 | return self.handle
|
---|
223 |
|
---|
224 | def isValid(self):
|
---|
225 | return self.handle != None and self.handle != ''
|
---|
226 |
|
---|
227 | def __getattr__(self,name):
|
---|
228 | hndl = <xsl:value-of select="$ifname" />._Attrs_.get(name, None)
|
---|
229 | if hndl != None:
|
---|
230 | if hndl[0] != None:
|
---|
231 | return hndl[0](self)
|
---|
232 | else:
|
---|
233 | raise AttributeError
|
---|
234 | else:
|
---|
235 | return <xsl:value-of select="$base" />.__getattr__(self, name)
|
---|
236 |
|
---|
237 | def __setattr__(self, name, val):
|
---|
238 | hndl = <xsl:value-of select="$ifname" />._Attrs_.get(name, None)
|
---|
239 | if (hndl != None and hndl[1] != None):
|
---|
240 | hndl[1](self,val)
|
---|
241 | else:
|
---|
242 | self.__dict__[name] = val
|
---|
243 |
|
---|
244 | <xsl:for-each select="method">
|
---|
245 | <xsl:call-template name="method"/>
|
---|
246 | </xsl:for-each>
|
---|
247 |
|
---|
248 | <xsl:for-each select="attribute">
|
---|
249 | <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
|
---|
250 | <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
|
---|
251 | <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
|
---|
252 | <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
|
---|
253 | <!-- skip this attribute if it has parameters of a type that has wsmap="suppress" -->
|
---|
254 | <xsl:choose>
|
---|
255 | <xsl:when test="( $attrtype=($G_setSuppressedInterfaces/@name) )">
|
---|
256 | <xsl:comment><xsl:value-of select="concat('skipping attribute ', $attrtype, ' for it is of a suppressed type')" /></xsl:comment>
|
---|
257 | </xsl:when>
|
---|
258 | <xsl:otherwise>
|
---|
259 | <xsl:choose>
|
---|
260 | <xsl:when test="@readonly='yes'">
|
---|
261 | <xsl:comment> readonly attribute <xsl:copy-of select="$ifname" />::<xsl:copy-of select="$attrname" /> </xsl:comment>
|
---|
262 | </xsl:when>
|
---|
263 | <xsl:otherwise>
|
---|
264 | <xsl:comment> read/write attribute <xsl:copy-of select="$ifname" />::<xsl:copy-of select="$attrname" /> </xsl:comment>
|
---|
265 | </xsl:otherwise>
|
---|
266 | </xsl:choose>
|
---|
267 | <!-- aa) get method: emit request and result -->
|
---|
268 | <xsl:call-template name="emitGetAttribute">
|
---|
269 | <xsl:with-param name="ifname" select="$ifname" />
|
---|
270 | <xsl:with-param name="attrname" select="$attrname" />
|
---|
271 | <xsl:with-param name="attrtype" select="$attrtype" />
|
---|
272 | <xsl:with-param name="attrsafearray" select="$attrsafearray" />
|
---|
273 | </xsl:call-template>
|
---|
274 | <!-- bb) emit a set method if the attribute is read/write -->
|
---|
275 | <xsl:if test="not($attrreadonly='yes')">
|
---|
276 | <xsl:call-template name="emitSetAttribute">
|
---|
277 | <xsl:with-param name="ifname" select="$ifname" />
|
---|
278 | <xsl:with-param name="attrname" select="$attrname" />
|
---|
279 | <xsl:with-param name="attrtype" select="$attrtype" />
|
---|
280 | <xsl:with-param name="attrsafearray" select="$attrsafearray" />
|
---|
281 | </xsl:call-template>
|
---|
282 | </xsl:if>
|
---|
283 | </xsl:otherwise>
|
---|
284 | </xsl:choose>
|
---|
285 | </xsl:for-each>
|
---|
286 |
|
---|
287 |
|
---|
288 | _Attrs_=<xsl:text>{</xsl:text>
|
---|
289 | <xsl:for-each select="attribute">
|
---|
290 | <xsl:if test="not( @type=($G_setSuppressedInterfaces/@name) )">
|
---|
291 | <xsl:text> </xsl:text>'<xsl:value-of select="@name"/>'<xsl:text>:[</xsl:text>
|
---|
292 | <xsl:call-template name="makeGetterName">
|
---|
293 | <xsl:with-param name="attrname" select="@name"/>
|
---|
294 | </xsl:call-template>
|
---|
295 | <xsl:text>,</xsl:text>
|
---|
296 | <xsl:choose>
|
---|
297 | <xsl:when test="@readonly='yes'">
|
---|
298 | <xsl:text>None</xsl:text>
|
---|
299 | </xsl:when>
|
---|
300 | <xsl:otherwise>
|
---|
301 | <xsl:call-template name="makeSetterName">
|
---|
302 | <xsl:with-param name="attrname" select="@name"/>
|
---|
303 | </xsl:call-template>,
|
---|
304 | </xsl:otherwise>
|
---|
305 | </xsl:choose>
|
---|
306 | <xsl:text>]</xsl:text>
|
---|
307 | <xsl:if test="not(position()=last())"><xsl:text>, </xsl:text></xsl:if>
|
---|
308 | </xsl:if>
|
---|
309 | </xsl:for-each>
|
---|
310 | <xsl:text>}</xsl:text>
|
---|
311 | </xsl:template>
|
---|
312 |
|
---|
313 | <xsl:template name="interfacestruct">
|
---|
314 | <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
|
---|
315 | class <xsl:value-of select="$ifname"/>:
|
---|
316 | def __init__(self, mgr, handle, isarray = False):
|
---|
317 | self.mgr = mgr
|
---|
318 | self.isarray = isarray
|
---|
319 | if isarray:
|
---|
320 | self.handle = handle
|
---|
321 | else:
|
---|
322 | <xsl:for-each select="attribute">
|
---|
323 | self.<xsl:value-of select="@name"/> = <xsl:call-template name="emitConvertedType">
|
---|
324 | <xsl:with-param name="ifname" select="$ifname" />
|
---|
325 | <xsl:with-param name="methodname" select="''" />
|
---|
326 | <xsl:with-param name="type" select="@type" />
|
---|
327 | </xsl:call-template>(self.mgr, handle._<xsl:value-of select="@name"/>)
|
---|
328 | </xsl:for-each>
|
---|
329 | pass
|
---|
330 |
|
---|
331 | <!-- also do getters/setters -->
|
---|
332 | <xsl:for-each select="attribute">
|
---|
333 | def <xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="@name"/></xsl:call-template>(self):
|
---|
334 | return self.<xsl:value-of select="@name"/>
|
---|
335 |
|
---|
336 | def <xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="@name"/></xsl:call-template>(self):
|
---|
337 | raise Error('setters not supported')
|
---|
338 | </xsl:for-each>
|
---|
339 |
|
---|
340 | def __next(self):
|
---|
341 | if self.isarray:
|
---|
342 | return self.handle.__next()
|
---|
343 | raise TypeError("iteration over non-sequence")
|
---|
344 |
|
---|
345 | def __size(self):
|
---|
346 | if self.isarray:
|
---|
347 | return self.handle.__size()
|
---|
348 | raise TypeError("iteration over non-sequence")
|
---|
349 |
|
---|
350 | def __len__(self):
|
---|
351 | if self.isarray:
|
---|
352 | return self.handle.__len__()
|
---|
353 | raise TypeError("iteration over non-sequence")
|
---|
354 |
|
---|
355 | def __getitem__(self, index):
|
---|
356 | if self.isarray:
|
---|
357 | return <xsl:value-of select="$ifname" />(self.mgr, self.handle[index])
|
---|
358 | raise TypeError("iteration over non-sequence")
|
---|
359 | <xsl:call-template name="xsltprocNewlineOutputHack"/>
|
---|
360 | </xsl:template>
|
---|
361 |
|
---|
362 | <xsl:template name="convertInParam">
|
---|
363 | <xsl:param name="type" />
|
---|
364 | <xsl:param name="safearray" />
|
---|
365 | <xsl:param name="arg" />
|
---|
366 |
|
---|
367 | <xsl:choose>
|
---|
368 | <xsl:when test="$type='octet' and $safearray">
|
---|
369 | <xsl:value-of select="concat('self.mgr.encodebase64(',$arg,')')" />
|
---|
370 | </xsl:when>
|
---|
371 | <xsl:otherwise>
|
---|
372 | <xsl:value-of select="$arg" />
|
---|
373 | </xsl:otherwise>
|
---|
374 | </xsl:choose>
|
---|
375 | </xsl:template>
|
---|
376 |
|
---|
377 | <xsl:template name="genreq">
|
---|
378 | <xsl:text>req=</xsl:text><xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>RequestMsg()
|
---|
379 | req._this=self.handle
|
---|
380 | <xsl:for-each select="param[@dir='in']">
|
---|
381 | req._<xsl:value-of select="@name" />=<xsl:call-template name="convertInParam">
|
---|
382 | <xsl:with-param name="type" select="@type" />
|
---|
383 | <xsl:with-param name="safearray" select="@safearray" />
|
---|
384 | <xsl:with-param name="arg" select="concat('_arg_', @name)" />
|
---|
385 | </xsl:call-template>
|
---|
386 | </xsl:for-each>
|
---|
387 | val=self.mgr.getPort().<xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>(req)
|
---|
388 | <!-- return needs to be the first one -->
|
---|
389 | return <xsl:for-each select="param[@dir='return']">
|
---|
390 | <xsl:call-template name="emitOutParam">
|
---|
391 | <xsl:with-param name="ifname" select="../@name" />
|
---|
392 | <xsl:with-param name="methodname" select="@name" />
|
---|
393 | <xsl:with-param name="type" select="@type" />
|
---|
394 | <xsl:with-param name="value" select="concat('val.','_returnval')" />
|
---|
395 | <xsl:with-param name="safearray" select="@safearray"/>
|
---|
396 | </xsl:call-template>
|
---|
397 | <xsl:if test="../param[@dir='out']">
|
---|
398 | <xsl:text>, </xsl:text>
|
---|
399 | </xsl:if>
|
---|
400 | </xsl:for-each>
|
---|
401 | <xsl:for-each select="param[@dir='out']">
|
---|
402 | <xsl:if test="not(position()=1)">
|
---|
403 | <xsl:text>, </xsl:text>
|
---|
404 | </xsl:if>
|
---|
405 | <xsl:call-template name="emitOutParam">
|
---|
406 | <xsl:with-param name="ifname" select="../@name" />
|
---|
407 | <xsl:with-param name="methodname" select="@name" />
|
---|
408 | <xsl:with-param name="type" select="@type" />
|
---|
409 | <xsl:with-param name="value" select="concat('val._',@name)" />
|
---|
410 | <xsl:with-param name="safearray" select="@safearray"/>
|
---|
411 | </xsl:call-template>
|
---|
412 | </xsl:for-each>
|
---|
413 | <xsl:text> </xsl:text>
|
---|
414 | </xsl:template>
|
---|
415 |
|
---|
416 | <xsl:template name="method" >
|
---|
417 | def <xsl:value-of select="@name"/><xsl:text>(self</xsl:text>
|
---|
418 | <xsl:for-each select="param[@dir='in']">
|
---|
419 | <xsl:text>, </xsl:text>
|
---|
420 | <xsl:value-of select="concat('_arg_',@name)"/>
|
---|
421 | </xsl:for-each><xsl:text>): </xsl:text>
|
---|
422 | <xsl:call-template name="genreq"/>
|
---|
423 | </xsl:template>
|
---|
424 |
|
---|
425 | <xsl:template name="makeConstantName" >
|
---|
426 | <xsl:choose>
|
---|
427 | <!-- special case for reserved word, maybe will need more in the future -->
|
---|
428 | <xsl:when test="@name='None'">
|
---|
429 | <xsl:text>_None</xsl:text>
|
---|
430 | </xsl:when>
|
---|
431 | <xsl:otherwise>
|
---|
432 | <xsl:value-of select="@name"/>
|
---|
433 | </xsl:otherwise>
|
---|
434 | </xsl:choose>
|
---|
435 | </xsl:template>
|
---|
436 |
|
---|
437 | <xsl:template name="enum">
|
---|
438 | class <xsl:value-of select="@name"/>:
|
---|
439 | def __init__(self,mgr,handle):
|
---|
440 | self.mgr=mgr
|
---|
441 | if isinstance(handle,basestring):
|
---|
442 | self.handle=<xsl:value-of select="@name"/>._ValueMap[handle]
|
---|
443 | else:
|
---|
444 | self.handle=handle
|
---|
445 |
|
---|
446 | def __eq__(self,other):
|
---|
447 | if isinstance(other,<xsl:value-of select="@name"/>):
|
---|
448 | return self.handle == other.handle
|
---|
449 | if isinstance(other,int):
|
---|
450 | return self.handle == other
|
---|
451 | if isinstance(other,basestring):
|
---|
452 | return str(self) == other
|
---|
453 | return False
|
---|
454 |
|
---|
455 | def __ne__(self,other):
|
---|
456 | if isinstance(other,<xsl:value-of select="@name"/>):
|
---|
457 | return self.handle != other.handle
|
---|
458 | if isinstance(other,int):
|
---|
459 | return self.handle != other
|
---|
460 | if isinstance(other,basestring):
|
---|
461 | return str(self) != other
|
---|
462 | return True
|
---|
463 |
|
---|
464 | def __str__(self):
|
---|
465 | return <xsl:value-of select="@name"/>._NameMap[self.handle]
|
---|
466 |
|
---|
467 | def __int__(self):
|
---|
468 | return self.handle
|
---|
469 |
|
---|
470 | _NameMap={<xsl:for-each select="const">
|
---|
471 | <xsl:value-of select="@value"/>:'<xsl:value-of select="@name"/>'<xsl:if test="not(position()=last())">,</xsl:if>
|
---|
472 | </xsl:for-each>}
|
---|
473 | _ValueMap={<xsl:for-each select="const">
|
---|
474 | '<xsl:value-of select="@name"/>':<xsl:value-of select="@value"/><xsl:if test="not(position()=last())">,</xsl:if>
|
---|
475 | </xsl:for-each>}
|
---|
476 |
|
---|
477 | <xsl:for-each select="const"><xsl:text> </xsl:text><xsl:call-template name="makeConstantName"><xsl:with-param name="name" select="@name"/></xsl:call-template>=<xsl:value-of select="@value"/><xsl:text>
</xsl:text>
|
---|
478 | </xsl:for-each>
|
---|
479 | </xsl:template>
|
---|
480 |
|
---|
481 | <xsl:template match="/">
|
---|
482 | <xsl:text># Copyright (C) 2008-2020 Oracle Corporation
|
---|
483 | #
|
---|
484 | # This file is part of a free software library; you can redistribute
|
---|
485 | # it and/or modify it under the terms of the GNU Lesser General
|
---|
486 | # Public License version 2.1 as published by the Free Software
|
---|
487 | # Foundation and shipped in the "COPYING.LIB" file with this library.
|
---|
488 | # The library is distributed in the hope that it will be useful,
|
---|
489 | # but WITHOUT ANY WARRANTY of any kind.
|
---|
490 | #
|
---|
491 | # Oracle LGPL Disclaimer: For the avoidance of doubt, except that if
|
---|
492 | # any license choice other than GPL or LGPL is available it will
|
---|
493 | # apply instead, Oracle elects to use only the Lesser General Public
|
---|
494 | # License version 2.1 (LGPLv2) at this time for any software where
|
---|
495 | # a choice of LGPL license versions is made available with the
|
---|
496 | # language indicating that LGPLv2 or any later version may be used,
|
---|
497 | # or where a choice of which version of the LGPL is applied is
|
---|
498 | # otherwise unspecified.
|
---|
499 | #
|
---|
500 | # This file is autogenerated from VirtualBox.xidl, DO NOT EDIT!
|
---|
501 | #
|
---|
502 |
|
---|
503 | # Works only with ZSI 2.0 generated stubs (part of the VirtualBox SDK).
|
---|
504 | from VirtualBox_client import *
|
---|
505 |
|
---|
506 | class ObjectRefManager:
|
---|
507 | def __init__(self, sessionmgr):
|
---|
508 | self.map = {}
|
---|
509 | self.sessionmgr = sessionmgr
|
---|
510 |
|
---|
511 | def register(self, handle):
|
---|
512 | if handle == None:
|
---|
513 | return
|
---|
514 | c = self.map.get(handle,0)
|
---|
515 | c = c + 1
|
---|
516 | self.map[handle]=c
|
---|
517 |
|
---|
518 | def unregister(self, handle):
|
---|
519 | if handle == None:
|
---|
520 | return
|
---|
521 | c = self.map.get(handle,-1)
|
---|
522 | if c == -1:
|
---|
523 | raise Error('wrong refcount')
|
---|
524 | c = c - 1
|
---|
525 | if c == 0:
|
---|
526 | try:
|
---|
527 | req=IManagedObjectRef_releaseRequestMsg()
|
---|
528 | req._this=handle
|
---|
529 | self.sessionmgr.getPort().IManagedObjectRef_release(req)
|
---|
530 | except:
|
---|
531 | pass
|
---|
532 | del self.map[handle]
|
---|
533 | else:
|
---|
534 | self.map[handle] = c
|
---|
535 |
|
---|
536 | class String:
|
---|
537 | def __init__(self, mgr, handle, isarray = False):
|
---|
538 | self.handle = handle
|
---|
539 | self.mgr = mgr
|
---|
540 | self.isarray = isarray
|
---|
541 |
|
---|
542 | def __next(self):
|
---|
543 | if self.isarray:
|
---|
544 | return self.handle.__next()
|
---|
545 | raise TypeError("iteration over non-sequence")
|
---|
546 |
|
---|
547 | def __size(self):
|
---|
548 | if self.isarray:
|
---|
549 | return self.handle.__size()
|
---|
550 | raise TypeError("iteration over non-sequence")
|
---|
551 |
|
---|
552 | def __len__(self):
|
---|
553 | if self.isarray:
|
---|
554 | return self.handle.__len__()
|
---|
555 | raise TypeError("iteration over non-sequence")
|
---|
556 |
|
---|
557 | def __getitem__(self, index):
|
---|
558 | if self.isarray:
|
---|
559 | return String(self.mgr, self.handle[index])
|
---|
560 | raise TypeError("iteration over non-sequence")
|
---|
561 |
|
---|
562 | def __str__(self):
|
---|
563 | return str(self.handle)
|
---|
564 |
|
---|
565 | def __eq__(self,other):
|
---|
566 | if self.isarray:
|
---|
567 | return isinstance(other,String) and self.handle == other.handle
|
---|
568 | if isinstance(other,String):
|
---|
569 | return self.handle == other.handle
|
---|
570 | if isinstance(other,basestring):
|
---|
571 | return self.handle == other
|
---|
572 | return False
|
---|
573 |
|
---|
574 | def __ne__(self,other):
|
---|
575 | if self.isarray:
|
---|
576 | return not isinstance(other,String) or self.handle != other.handle
|
---|
577 | if isinstance(other,String):
|
---|
578 | return self.handle != other.handle
|
---|
579 | if isinstance(other,basestring):
|
---|
580 | return self.handle != other
|
---|
581 | return True
|
---|
582 |
|
---|
583 | def __add__(self,other):
|
---|
584 | return str(self.handle)+str(other)
|
---|
585 |
|
---|
586 |
|
---|
587 | class Boolean:
|
---|
588 | def __init__(self, mgr, handle, isarray = False):
|
---|
589 | self.handle = handle
|
---|
590 | if self.handle == "false":
|
---|
591 | self.handle = None
|
---|
592 | self.mgr = mgr
|
---|
593 | self.isarray = isarray
|
---|
594 |
|
---|
595 | def __str__(self):
|
---|
596 | if self.handle:
|
---|
597 | return "true"
|
---|
598 | else:
|
---|
599 | return "false"
|
---|
600 |
|
---|
601 | def __eq__(self,other):
|
---|
602 | if isinstance(other,Bool):
|
---|
603 | return self.handle == other.value
|
---|
604 | if isinstance(other,bool):
|
---|
605 | return self.handle == other
|
---|
606 | return False
|
---|
607 |
|
---|
608 | def __ne__(self,other):
|
---|
609 | if isinstance(other,Bool):
|
---|
610 | return self.handle != other.handle
|
---|
611 | if isinstance(other,bool):
|
---|
612 | return self.handle != other
|
---|
613 | return True
|
---|
614 |
|
---|
615 | def __int__(self):
|
---|
616 | if self.handle:
|
---|
617 | return 1
|
---|
618 | else:
|
---|
619 | return 0
|
---|
620 |
|
---|
621 | def __long__(self):
|
---|
622 | if self.handle:
|
---|
623 | return 1
|
---|
624 | else:
|
---|
625 | return 0
|
---|
626 |
|
---|
627 | def __nonzero__(self):
|
---|
628 | if self.handle:
|
---|
629 | return True
|
---|
630 | else:
|
---|
631 | return False
|
---|
632 |
|
---|
633 | def __next(self):
|
---|
634 | if self.isarray:
|
---|
635 | return self.handle.__next()
|
---|
636 | raise TypeError("iteration over non-sequence")
|
---|
637 |
|
---|
638 | def __size(self):
|
---|
639 | if self.isarray:
|
---|
640 | return self.handle.__size()
|
---|
641 | raise TypeError("iteration over non-sequence")
|
---|
642 |
|
---|
643 | def __len__(self):
|
---|
644 | if self.isarray:
|
---|
645 | return self.handle.__len__()
|
---|
646 | raise TypeError("iteration over non-sequence")
|
---|
647 |
|
---|
648 | def __getitem__(self, index):
|
---|
649 | if self.isarray:
|
---|
650 | return Boolean(self.mgr, self.handle[index])
|
---|
651 | raise TypeError("iteration over non-sequence")
|
---|
652 |
|
---|
653 | class Number:
|
---|
654 | def __init__(self, mgr, handle, isarray = False):
|
---|
655 | self.handle = handle
|
---|
656 | self.mgr = mgr
|
---|
657 | self.isarray = isarray
|
---|
658 |
|
---|
659 | def __next(self):
|
---|
660 | if self.isarray:
|
---|
661 | return self.handle.__next()
|
---|
662 | raise TypeError("iteration over non-sequence")
|
---|
663 |
|
---|
664 | def __size(self):
|
---|
665 | if self.isarray:
|
---|
666 | return self.handle.__size()
|
---|
667 | raise TypeError("iteration over non-sequence")
|
---|
668 |
|
---|
669 | def __len__(self):
|
---|
670 | if self.isarray:
|
---|
671 | return self.handle.__len__()
|
---|
672 | raise TypeError("iteration over non-sequence")
|
---|
673 |
|
---|
674 | def __str__(self):
|
---|
675 | return str(self.handle)
|
---|
676 |
|
---|
677 | def __int__(self):
|
---|
678 | return int(self.handle)
|
---|
679 |
|
---|
680 | def __long__(self):
|
---|
681 | return long(self.handle)
|
---|
682 |
|
---|
683 | def __float__(self):
|
---|
684 | return float(self.handle)
|
---|
685 |
|
---|
686 | def __lt__(self, other):
|
---|
687 | if self.isarray:
|
---|
688 | return NotImplemented
|
---|
689 | else:
|
---|
690 | return self.handle < other
|
---|
691 |
|
---|
692 | def __le__(self, other):
|
---|
693 | if self.isarray:
|
---|
694 | return NotImplemented
|
---|
695 | else:
|
---|
696 | return self.handle <= other
|
---|
697 |
|
---|
698 | def __eq__(self, other):
|
---|
699 | return self.handle == other
|
---|
700 |
|
---|
701 | def __ne__(self, other):
|
---|
702 | return self.handle != other
|
---|
703 |
|
---|
704 | def __gt__(self, other):
|
---|
705 | if self.isarray:
|
---|
706 | return NotImplemented
|
---|
707 | else:
|
---|
708 | return self.handle > other
|
---|
709 |
|
---|
710 | def __ge__(self, other):
|
---|
711 | if self.isarray:
|
---|
712 | return NotImplemented
|
---|
713 | else:
|
---|
714 | return self.handle >= other
|
---|
715 |
|
---|
716 | class Octet:
|
---|
717 | def __init__(self, mgr, handle, isarray = False):
|
---|
718 | self.mgr = mgr
|
---|
719 | self.isarray = isarray
|
---|
720 | if isarray:
|
---|
721 | self.handle = mgr.decodebase64(handle)
|
---|
722 | else:
|
---|
723 | raise TypeError("only octet arrays")
|
---|
724 |
|
---|
725 | def __getitem__(self, index):
|
---|
726 | return self.handle[index]
|
---|
727 |
|
---|
728 | def __str__(self):
|
---|
729 | return str(self.handle)
|
---|
730 |
|
---|
731 | def __len__(self):
|
---|
732 | return self.handle.__len__()
|
---|
733 |
|
---|
734 | class UnsignedInt(Number):
|
---|
735 | def __init__(self, mgr, handle, isarray = False):
|
---|
736 | self.handle = handle
|
---|
737 | self.mgr = mgr
|
---|
738 | self.isarray = isarray
|
---|
739 |
|
---|
740 | def __getitem__(self, index):
|
---|
741 | if self.isarray:
|
---|
742 | return UnsignedInt(self.mgr, self.handle[index])
|
---|
743 | raise TypeError("iteration over non-sequence")
|
---|
744 |
|
---|
745 |
|
---|
746 | class Int(Number):
|
---|
747 | def __init__(self, mgr, handle, isarray = False):
|
---|
748 | self.handle = handle
|
---|
749 | self.mgr = mgr
|
---|
750 | self.isarray = isarray
|
---|
751 |
|
---|
752 | def __getitem__(self, index):
|
---|
753 | if self.isarray:
|
---|
754 | return Int(self.mgr, self.handle[index])
|
---|
755 | raise TypeError("iteration over non-sequence")
|
---|
756 |
|
---|
757 | class UnsignedShort(Number):
|
---|
758 | def __init__(self, mgr, handle, isarray = False):
|
---|
759 | self.handle = handle
|
---|
760 | self.mgr = mgr
|
---|
761 | self.isarray = isarray
|
---|
762 |
|
---|
763 | def __getitem__(self, index):
|
---|
764 | if self.isarray:
|
---|
765 | return UnsignedShort(self.mgr, self.handle[index])
|
---|
766 | raise TypeError("iteration over non-sequence")
|
---|
767 |
|
---|
768 | class Short(Number):
|
---|
769 | def __init__(self, mgr, handle, isarray = False):
|
---|
770 | self.handle = handle
|
---|
771 | self.mgr = mgr
|
---|
772 | self.isarray = isarray
|
---|
773 |
|
---|
774 | def __getitem__(self, index):
|
---|
775 | if self.isarray:
|
---|
776 | return Short(self.mgr, self.handle[index])
|
---|
777 | raise TypeError("iteration over non-sequence")
|
---|
778 |
|
---|
779 | class UnsignedLong(Number):
|
---|
780 | def __init__(self, mgr, handle, isarray = False):
|
---|
781 | self.handle = handle
|
---|
782 | self.mgr = mgr
|
---|
783 | self.isarray = isarray
|
---|
784 |
|
---|
785 | def __getitem__(self, index):
|
---|
786 | if self.isarray:
|
---|
787 | return UnsignedLong(self.mgr, self.handle[index])
|
---|
788 | raise TypeError("iteration over non-sequence")
|
---|
789 |
|
---|
790 | class Long(Number):
|
---|
791 | def __init__(self, mgr, handle, isarray = False):
|
---|
792 | self.handle = handle
|
---|
793 | self.mgr = mgr
|
---|
794 | self.isarray = isarray
|
---|
795 |
|
---|
796 | def __getitem__(self, index):
|
---|
797 | if self.isarray:
|
---|
798 | return Long(self.mgr, self.handle[index])
|
---|
799 | raise TypeError("iteration over non-sequence")
|
---|
800 |
|
---|
801 | class Double(Number):
|
---|
802 | def __init__(self, mgr, handle, isarray = False):
|
---|
803 | self.handle = handle
|
---|
804 | self.mgr = mgr
|
---|
805 | self.isarray = isarray
|
---|
806 |
|
---|
807 | def __getitem__(self, index):
|
---|
808 | if self.isarray:
|
---|
809 | return Double(self.mgr, self.handle[index])
|
---|
810 | raise TypeError("iteration over non-sequence")
|
---|
811 |
|
---|
812 | class Float(Number):
|
---|
813 | def __init__(self, mgr, handle, isarray = False):
|
---|
814 | self.handle = handle
|
---|
815 | self.mgr = mgr
|
---|
816 | self.isarray = isarray
|
---|
817 |
|
---|
818 | def __getitem__(self, index):
|
---|
819 | if self.isarray:
|
---|
820 | return Float(self.mgr, self.handle[index])
|
---|
821 | raise TypeError("iteration over non-sequence")
|
---|
822 |
|
---|
823 | class IUnknown:
|
---|
824 | def __init__(self, mgr, handle, isarray = False):
|
---|
825 | self.handle = handle
|
---|
826 | self.mgr = mgr
|
---|
827 | self.isarray = isarray
|
---|
828 |
|
---|
829 | def __nonzero__(self):
|
---|
830 | if self.handle != "":
|
---|
831 | return True
|
---|
832 | else:
|
---|
833 | return False
|
---|
834 |
|
---|
835 | def __next(self):
|
---|
836 | if self.isarray:
|
---|
837 | return self.handle.__next()
|
---|
838 | raise TypeError("iteration over non-sequence")
|
---|
839 |
|
---|
840 | def __size(self):
|
---|
841 | if self.isarray:
|
---|
842 | return self.handle.__size()
|
---|
843 | raise TypeError("iteration over non-sequence")
|
---|
844 |
|
---|
845 | def __len__(self):
|
---|
846 | if self.isarray:
|
---|
847 | return self.handle.__len__()
|
---|
848 | raise TypeError("iteration over non-sequence")
|
---|
849 |
|
---|
850 | def __getitem__(self, index):
|
---|
851 | if self.isarray:
|
---|
852 | return IUnknown(self.mgr, self.handle[index])
|
---|
853 | raise TypeError("iteration over non-sequence")
|
---|
854 |
|
---|
855 | def __str__(self):
|
---|
856 | return str(self.handle)
|
---|
857 |
|
---|
858 | def __eq__(self, other):
|
---|
859 | return self.handle == other
|
---|
860 |
|
---|
861 | def __ne__(self, other):
|
---|
862 | return self.handle != other
|
---|
863 |
|
---|
864 | def __getattr__(self,attr):
|
---|
865 | if self.__class__.__dict__.get(attr) != None:
|
---|
866 | return self.__class__.__dict__.get(attr)
|
---|
867 | if self.__dict__.get(attr) != None:
|
---|
868 | return self.__dict__.get(attr)
|
---|
869 | raise AttributeError
|
---|
870 |
|
---|
871 | </xsl:text>
|
---|
872 | <xsl:for-each select="//interface[@wsmap='managed' or @wsmap='global']">
|
---|
873 | <xsl:call-template name="interface"/>
|
---|
874 | </xsl:for-each>
|
---|
875 | <xsl:for-each select="//interface[@wsmap='struct']">
|
---|
876 | <xsl:call-template name="interfacestruct"/>
|
---|
877 | </xsl:for-each>
|
---|
878 | <xsl:for-each select="//enum">
|
---|
879 | <xsl:call-template name="enum"/>
|
---|
880 | </xsl:for-each>
|
---|
881 | <xsl:text>
|
---|
882 |
|
---|
883 | import base64
|
---|
884 |
|
---|
885 | class IWebsessionManager2(IWebsessionManager, ObjectRefManager):
|
---|
886 | def __init__(self, url):
|
---|
887 | self.url = url
|
---|
888 | self.port = None
|
---|
889 | self.handle = None
|
---|
890 | self.mgr = self
|
---|
891 | ObjectRefManager.__init__(self, self.mgr)
|
---|
892 |
|
---|
893 | def getPort(self):
|
---|
894 | if self.port is None:
|
---|
895 | try:
|
---|
896 | self.port = vboxServiceLocator().getvboxPortType(self.url)
|
---|
897 | except:
|
---|
898 | self.port = vboxServiceLocator().getvboxServicePort(self.url)
|
---|
899 | return self.port
|
---|
900 |
|
---|
901 | def decodebase64(self, str):
|
---|
902 | return base64.decodestring(str)
|
---|
903 |
|
---|
904 | def encodebase64(self, str):
|
---|
905 | return base64.encodestring(str)
|
---|
906 | </xsl:text>
|
---|
907 | </xsl:template>
|
---|
908 |
|
---|
909 | </xsl:stylesheet>
|
---|