VirtualBox

source: vbox/trunk/src/VBox/Main/webservice/websrv-php.xsl

Last change on this file was 98108, checked in by vboxsync, 16 months ago

Manual (C) year updates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 21.8 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
5<!--
6 websrv-php.xsl:
7 XSLT stylesheet that generates vboxServiceWrappers.php from
8 VirtualBox.xidl. This PHP file represents our
9 web service API. Depends on WSDL file for actual SOAP bindings.
10
11 Contributed by James Lucas (mjlucas at eng.uts.edu.au).
12-->
13<!--
14 Copyright (C) 2008-2023 Oracle and/or its affiliates.
15
16 This file is part of VirtualBox base platform packages, as
17 available from https://www.virtualbox.org.
18
19 This program is free software; you can redistribute it and/or
20 modify it under the terms of the GNU General Public License
21 as published by the Free Software Foundation, in version 3 of the
22 License.
23
24 This program is distributed in the hope that it will be useful, but
25 WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 General Public License for more details.
28
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, see <https://www.gnu.org/licenses>.
31
32 SPDX-License-Identifier: GPL-3.0-only
33-->
34
35
36<xsl:output
37 method="text"
38 version="1.0"
39 encoding="utf-8"
40 indent="no"/>
41
42<xsl:include href="../idl/typemap-shared.inc.xsl" />
43
44<xsl:variable name="G_setSuppressedInterfaces"
45 select="//interface[@wsmap='suppress']" />
46
47<xsl:key name="G_keyInterfacesByName" match="//interface[@name]" use="@name"/>
48
49<xsl:template name="emitOutParam">
50 <xsl:param name="type" />
51 <xsl:param name="value" />
52 <xsl:param name="safearray" />
53
54 <xsl:choose>
55 <xsl:when test="$type='wstring' or $type='uuid'">
56 <xsl:call-template name="emitPrimitive">
57 <xsl:with-param name="type">string</xsl:with-param>
58 <xsl:with-param name="value" select="$value" />
59 <xsl:with-param name="safearray" select="$safearray"/>
60 </xsl:call-template>
61 </xsl:when>
62 <xsl:when test="$type='boolean'">
63 <xsl:call-template name="emitPrimitive">
64 <xsl:with-param name="type">bool</xsl:with-param>
65 <xsl:with-param name="value" select="$value" />
66 <xsl:with-param name="safearray" select="$safearray"/>
67 </xsl:call-template>
68 </xsl:when>
69 <xsl:when test="$type='short' or $type='unsigned short' or $type='long' or $type='octet'">
70 <xsl:call-template name="emitPrimitive">
71 <xsl:with-param name="type">int</xsl:with-param>
72 <xsl:with-param name="value" select="$value" />
73 <xsl:with-param name="safearray" select="$safearray"/>
74 </xsl:call-template>
75 </xsl:when>
76 <xsl:when test="$type='double' or $type='float' or $type='unsigned long' or $type='long long' or $type='unsigned long long'">
77 <xsl:call-template name="emitPrimitive">
78 <xsl:with-param name="type">float</xsl:with-param>
79 <xsl:with-param name="value" select="$value" />
80 <xsl:with-param name="safearray" select="$safearray"/>
81 </xsl:call-template>
82 </xsl:when>
83 <xsl:when test="$type='$unknown'">
84 <xsl:call-template name="emitObject">
85 <xsl:with-param name="type">VBox_ManagedObject</xsl:with-param>
86 <xsl:with-param name="value" select="$value" />
87 <xsl:with-param name="safearray" select="$safearray"/>
88 </xsl:call-template>
89 </xsl:when>
90 <xsl:otherwise>
91 <xsl:call-template name="emitObject">
92 <xsl:with-param name="type" select="$type" />
93 <xsl:with-param name="value" select="$value" />
94 <xsl:with-param name="safearray" select="$safearray"/>
95 </xsl:call-template>
96 </xsl:otherwise>
97 </xsl:choose>
98</xsl:template>
99
100<xsl:template name="emitObject">
101 <xsl:param name="type" />
102 <xsl:param name="value" />
103 <xsl:param name="safearray" />
104 <xsl:choose>
105 <xsl:when test="$safearray='yes'">
106 <xsl:text>new </xsl:text><xsl:value-of select="$type" />Collection ($this->connection, (array)<xsl:value-of select="$value"/><xsl:text>)</xsl:text>
107 </xsl:when>
108 <xsl:otherwise>
109 <xsl:text>new </xsl:text><xsl:value-of select="$type" /> ($this->connection, <xsl:value-of select="$value"/><xsl:text>)</xsl:text>
110 </xsl:otherwise>
111 </xsl:choose>
112</xsl:template>
113
114<xsl:template name="emitPrimitive">
115 <xsl:param name="type" />
116 <xsl:param name="value" />
117 <xsl:param name="safearray" />
118 <xsl:choose>
119 <xsl:when test="$safearray='yes'">
120 <xsl:text>(array)</xsl:text><xsl:value-of select="$value"/>
121 </xsl:when>
122 <xsl:otherwise>
123 <xsl:text>(</xsl:text><xsl:value-of select="$type" /><xsl:text>)</xsl:text><xsl:value-of select="$value"/>
124 </xsl:otherwise>
125 </xsl:choose>
126</xsl:template>
127
128<xsl:template name="emitGetAttribute">
129 <xsl:param name="ifname" />
130 <xsl:param name="attrname" />
131 <xsl:param name="attrtype" />
132 <xsl:param name="attrsafearray" />
133 <xsl:variable name="fname"><xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="$attrname"/></xsl:call-template> </xsl:variable>
134 public function <xsl:value-of select="$fname"/>()
135 {
136 $request = new stdClass();
137 $request->_this = $this->handle;
138 $response = $this->connection->__soapCall('<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>', array((array)$request));
139 <xsl:text>return </xsl:text>
140 <xsl:call-template name="emitOutParam">
141 <xsl:with-param name="type" select="$attrtype" />
142 <xsl:with-param name="value" select="concat('$response->','returnval')" />
143 <xsl:with-param name="safearray" select="@safearray"/>
144 </xsl:call-template><xsl:text>;</xsl:text>
145 }
146</xsl:template>
147
148<xsl:template name="emitSetAttribute">
149 <xsl:param name="ifname" />
150 <xsl:param name="attrname" />
151 <xsl:param name="attrtype" />
152 <xsl:param name="attrsafearray" />
153 <xsl:variable name="fname"><xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="$attrname"/></xsl:call-template></xsl:variable>
154 public function <xsl:value-of select="$fname"/>($value)
155 {
156 $request = new stdClass();
157 $request->_this = $this->handle;
158<xsl:choose>
159<xsl:when test="$attrsafearray='yes'"> if (is_array($value) || is_null($value) || is_scalar($value))</xsl:when>
160<xsl:otherwise> if (is_null($value) || is_scalar($value))</xsl:otherwise>
161</xsl:choose>
162 {
163 $request-><xsl:value-of select="$attrname"/> = $value;
164 }
165 else
166 {
167 $request-><xsl:value-of select="$attrname"/> = $value->handle;
168 }
169 $this->connection->__soapCall('<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>', array((array)$request));
170 }
171</xsl:template>
172
173<xsl:template name="interface">
174 <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
175 <xsl:variable name="wsmap"><xsl:value-of select="@wsmap" /></xsl:variable>
176 <xsl:variable name="extends"><xsl:value-of select="@extends" /></xsl:variable>
177 <xsl:text>
178/**
179 * Generated VBoxWebService Interface Wrapper
180 */
181</xsl:text>
182 <xsl:choose>
183 <xsl:when test="($extends = '$unknown') or ($extends = '$errorinfo')">
184 <xsl:value-of select="concat('class ', $ifname, ' extends VBox_ManagedObject&#10;{&#10;')" />
185 </xsl:when>
186 <xsl:when test="count(key('G_keyInterfacesByName', $extends)) > 0">
187 <xsl:value-of select="concat('class ', $ifname, ' extends ', $extends, '&#10;{&#10;')" />
188 </xsl:when>
189 </xsl:choose>
190 <xsl:for-each select="method">
191 <xsl:if test="not((param[@type=($G_setSuppressedInterfaces/@name)])
192 or (param[@mod='ptr']))" >
193 <xsl:call-template name="method">
194 <xsl:with-param name="wsmap" select="$wsmap" />
195 </xsl:call-template>
196 </xsl:if>
197 </xsl:for-each>
198 <xsl:for-each select="attribute">
199 <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
200 <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
201 <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
202 <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
203 <!-- skip this attribute if it has parameters of a type that has wsmap="suppress" -->
204 <xsl:choose>
205 <xsl:when test="( $attrtype=($G_setSuppressedInterfaces/@name) )">
206 <xsl:comment><xsl:value-of select="concat('skipping attribute ', $attrtype, ' for it is of a suppressed type')" /></xsl:comment>
207 </xsl:when>
208 <xsl:otherwise>
209 <xsl:choose>
210 <xsl:when test="@readonly='yes'">
211 <xsl:comment> readonly attribute <xsl:copy-of select="$ifname" />::<xsl:copy-of select="$attrname" /> </xsl:comment>
212 </xsl:when>
213 <xsl:otherwise>
214 <xsl:comment> read/write attribute <xsl:copy-of select="$ifname" />::<xsl:copy-of select="$attrname" /> </xsl:comment>
215 </xsl:otherwise>
216 </xsl:choose>
217 <!-- aa) get method: emit request and result -->
218 <xsl:call-template name="emitGetAttribute">
219 <xsl:with-param name="ifname" select="$ifname" />
220 <xsl:with-param name="attrname" select="$attrname" />
221 <xsl:with-param name="attrtype" select="$attrtype" />
222 <xsl:with-param name="attrsafearray" select="$attrsafearray" />
223 </xsl:call-template>
224 <!-- bb) emit a set method if the attribute is read/write -->
225 <xsl:if test="not($attrreadonly='yes')">
226 <xsl:call-template name="emitSetAttribute">
227 <xsl:with-param name="ifname" select="$ifname" />
228 <xsl:with-param name="attrname" select="$attrname" />
229 <xsl:with-param name="attrtype" select="$attrtype" />
230 <xsl:with-param name="attrsafearray" select="$attrsafearray" />
231 </xsl:call-template>
232 </xsl:if>
233 </xsl:otherwise>
234 </xsl:choose>
235 </xsl:for-each>
236 <xsl:text>}
237</xsl:text>
238</xsl:template>
239
240<xsl:template name="collection">
241 <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
242 <xsl:text>
243/**
244 * Generated VBoxWebService Managed Object Collection
245 */</xsl:text>
246class <xsl:value-of select="$ifname"/>Collection extends VBox_ManagedObjectCollection
247{
248 protected $_interfaceName = "<xsl:value-of select="$ifname"/>";
249}
250</xsl:template>
251
252<xsl:template name="interfacestruct">
253 <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
254 <xsl:text>
255/**
256 * Generated VBoxWebService Struct
257 */</xsl:text>
258class <xsl:value-of select="$ifname"/> extends VBox_Struct
259{
260<xsl:for-each select="attribute"> protected $<xsl:value-of select="@name"/>;
261</xsl:for-each>
262 public function __construct($connection, $values)
263 {
264 $this->connection = $connection;
265<xsl:for-each select="attribute"> $this-><xsl:value-of select="@name"/> = $values-><xsl:value-of select="@name"/>;
266</xsl:for-each> }
267
268<xsl:for-each select="attribute"> public function <xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="@name"/></xsl:call-template>()
269 {
270 <xsl:text>return </xsl:text>
271 <xsl:call-template name="emitOutParam">
272 <xsl:with-param name="type" select="@type" />
273 <xsl:with-param name="value" select="concat('$this->',@name)" />
274 <xsl:with-param name="safearray" select="@safearray"/>
275 </xsl:call-template>;
276 }
277</xsl:for-each>}
278</xsl:template>
279
280<xsl:template name="structcollection">
281 <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
282 <xsl:text>
283/**
284 * Generated VBoxWebService Struct Collection
285 */</xsl:text>
286class <xsl:value-of select="$ifname"/>Collection extends VBox_StructCollection
287{
288 protected $_interfaceName = "<xsl:value-of select="$ifname"/>";
289}
290</xsl:template>
291
292<xsl:template name="genreq">
293 <xsl:param name="wsmap" />
294 <xsl:text> $request = new stdClass();
295</xsl:text>
296 <xsl:if test="$wsmap='managed'"> $request->_this = $this->handle;</xsl:if>
297 <xsl:for-each select="param[@dir='in']">
298 $request-><xsl:value-of select="@name" /> = $arg_<xsl:value-of select="@name" /><xsl:text>;</xsl:text>
299 </xsl:for-each>
300 $response = $this->connection->__soapCall('<xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>', array((array)$request));
301 return <xsl:if test="param[@dir='out']">
302 <xsl:text>array(</xsl:text>
303 </xsl:if>
304 <xsl:for-each select="param[@dir='return']">
305 <xsl:call-template name="emitOutParam">
306 <xsl:with-param name="type" select="@type" />
307 <xsl:with-param name="value" select="concat('$response->','returnval')" />
308 <xsl:with-param name="safearray" select="@safearray"/>
309 </xsl:call-template>
310 <xsl:if test="../param[@dir='out']">
311 <xsl:text>, </xsl:text>
312 </xsl:if>
313 </xsl:for-each>
314 <xsl:for-each select="param[@dir='out']">
315 <xsl:if test="not(position()=1)">
316 <xsl:text>, </xsl:text>
317 </xsl:if>
318 <xsl:call-template name="emitOutParam">
319 <xsl:with-param name="type" select="@type" />
320 <xsl:with-param name="value" select="concat('$response->',@name)" />
321 <xsl:with-param name="safearray" select="@safearray"/>
322 </xsl:call-template>
323 </xsl:for-each>
324 <xsl:if test="param[@dir='out']">
325 <xsl:text>)</xsl:text>
326 </xsl:if>
327 <xsl:text>;&#10;</xsl:text>
328</xsl:template>
329
330<xsl:template name="method" >
331 <xsl:param name="wsmap" />
332 public function <xsl:value-of select="@name"/><xsl:text>(</xsl:text>
333 <xsl:for-each select="param[@dir='in']">
334 <xsl:if test="not(position()=1)">
335 <xsl:text>, </xsl:text>
336 </xsl:if>
337 <xsl:value-of select="concat('$arg_',@name)"/>
338 </xsl:for-each> <xsl:text>)&#10; {&#10;</xsl:text>
339 <xsl:call-template name="genreq"><xsl:with-param name="wsmap" select="$wsmap" /></xsl:call-template>
340 <xsl:text> }&#10;</xsl:text>
341</xsl:template>
342
343<xsl:template name="enum">
344 <xsl:text>
345/**
346 * Generated VBoxWebService ENUM
347 */</xsl:text>
348class <xsl:value-of select="@name"/> extends VBox_Enum
349{
350 public $NameMap = array(<xsl:for-each select="const"><xsl:if test="not(@wsmap='suppress')"><xsl:value-of select="@value"/> => '<xsl:value-of select="@name"/>'<xsl:if test="not(position()=last())">, </xsl:if></xsl:if></xsl:for-each>);
351 public $ValueMap = array(<xsl:for-each select="const"><xsl:if test="not(@wsmap='suppress')">'<xsl:value-of select="@name"/>' => <xsl:value-of select="@value"/><xsl:if test="not(position()=last())">, </xsl:if></xsl:if></xsl:for-each>);
352}
353</xsl:template>
354
355<xsl:template name="enumcollection">
356 <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
357 <xsl:text>
358/**
359 * Generated VBoxWebService Enum Collection
360 */</xsl:text>
361class <xsl:value-of select="$ifname"/>Collection extends VBox_EnumCollection
362{
363 protected $_interfaceName = "<xsl:value-of select="$ifname"/>";
364}
365</xsl:template>
366
367<xsl:template name="comResultCodes">
368 const <xsl:value-of select="@name"/> = <xsl:value-of select="@value"/>;
369</xsl:template>
370
371<xsl:template match="/">
372<xsl:text>&lt;?php
373
374/*
375 * Copyright (C) 2008-2023 Oracle and/or its affiliates.
376 *
377 * This file is part of a free software library; you can redistribute
378 * it and/or modify it under the terms of the GNU Lesser General
379 * Public License version 2.1 as published by the Free Software
380 * Foundation and shipped in the "COPYING.LIB" file with this library.
381 * The library is distributed in the hope that it will be useful,
382 * but WITHOUT ANY WARRANTY of any kind.
383 *
384 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if
385 * any license choice other than GPL or LGPL is available it will
386 * apply instead, Oracle elects to use only the Lesser General Public
387 * License version 2.1 (LGPLv2) at this time for any software where
388 * a choice of LGPL license versions is made available with the
389 * language indicating that LGPLv2 or any later version may be used,
390 * or where a choice of which version of the LGPL is applied is
391 * otherwise unspecified.
392 *
393 * SPDX-License-Identifier: LGPL-2.1-only
394 */
395/*
396 * This file is autogenerated from VirtualBox.xidl, DO NOT EDIT!
397 */
398
399class VBox_ManagedObject
400{
401 protected $connection;
402 protected $handle;
403
404 public function __construct($soap, $handle = null)
405 {
406 $this->connection = $soap;
407 $this->handle = $handle;
408 }
409
410 public function __toString()
411 {
412 return (string)$this->handle;
413 }
414
415 public function __set($attr, $value)
416 {
417 $methodName = "set" . $attr;
418 if (method_exists($this, $methodName))
419 $this->$methodName($value);
420 else
421 throw new Exception("Attribute does not exist");
422 }
423
424 public function __get($attr)
425 {
426 $methodName = "get" . $attr;
427 if (method_exists($this, $methodName))
428 return $this->$methodName();
429 else
430 throw new Exception("Attribute does not exist");
431 }
432
433 public function getHandle()
434 {
435 return $this->handle;
436 }
437
438 public function cast($class)
439 {
440 if (is_subclass_of($class, 'VBox_ManagedObject'))
441 {
442 return new $class($this->connection, $this->handle);
443 }
444 throw new Exception('Cannot cast VBox_ManagedObject to non-child class VBox_ManagedObject');
445 }
446
447 public function releaseRemote()
448 {
449 try
450 {
451 $request = new stdClass();
452 $request->_this = $this->handle;
453 $this->connection->__soapCall('IManagedObjectRef_release', array((array)$request));
454 }
455 catch (Exception $ex)
456 {
457 }
458 }
459}
460
461abstract class VBox_Collection implements ArrayAccess, Iterator, Countable
462{
463 protected $_connection;
464 protected $_values;
465 protected $_objects;
466 protected $_interfaceName;
467
468 public function __construct($soap, array $values = array())
469 {
470 $this->_connection = $soap;
471 $this->_values = $values;
472 $this->_soapToObject();
473 }
474
475 protected function _soapToObject()
476 {
477 $this->_objects = array();
478 foreach($this->_values as $value)
479 {
480 $this->_objects[] = new $this->_interfaceName($this->_connection, $value);
481 }
482 }
483
484 /** ArrayAccess Functions **/
485 public function offsetSet($offset, $value)
486 {
487 if ($value instanceof $this->_interfaceName)
488 {
489 if ($offset)
490 {
491 $this->_objects[$offset] = $value;
492 }
493 else
494 {
495 $this->_objects[] = $value;
496 }
497 }
498 else
499 {
500 throw new Exception("Value must be a instance of " . $this->_interfaceName);
501 }
502 }
503
504 public function offsetExists($offset)
505 {
506 return isset($this->_objects[$offset]);
507 }
508
509 public function offsetUnset($offset)
510 {
511 unset($this->_objects[$offset]);
512 }
513
514 public function offsetGet($offset)
515 {
516 return isset($this->_objects[$offset]) ? $this->_objects[$offset] : null;
517 }
518
519 /** Iterator Functions **/
520 public function rewind()
521 {
522 reset($this->_objects);
523 }
524
525 public function current()
526 {
527 return current($this->_objects);
528 }
529
530 public function key()
531 {
532 return key($this->_objects);
533 }
534
535 public function next()
536 {
537 return next($this->_objects);
538 }
539
540 public function valid()
541 {
542 return ($this->current() !== false);
543 }
544
545 /** Countable Functions **/
546 public function count()
547 {
548 return count($this->_objects);
549 }
550}
551
552class VBox_ManagedObjectCollection extends VBox_Collection
553{
554 protected $_interfaceName = 'VBox_ManagedObject';
555
556 // Result is undefined if this is called AFTER any call to VBox_Collection::offsetSet or VBox_Collection::offsetUnset
557 public function setInterfaceName($interface)
558 {
559 if (!is_subclass_of($interface, 'VBox_ManagedObject'))
560 {
561 throw new Exception('Cannot set collection interface to non-child class of VBox_ManagedObject');
562 }
563 $this->_interfaceName = $interface;
564 $this->_soapToObject();
565 }
566}
567
568abstract class VBox_Struct
569{
570 protected $connection;
571
572 public function __get($attr)
573 {
574 $methodName = "get" . $attr;
575 if (method_exists($this, $methodName))
576 return $this->$methodName();
577 else
578 throw new Exception("Attribute does not exist");
579 }
580}
581
582abstract class VBox_StructCollection extends VBox_Collection
583{
584
585 public function __construct($soap, array $values = array())
586 {
587 if (!(array_values($values) === $values))
588 {
589 $values = array((object)$values); //Fix for when struct return value only contains one list item (e.g. one medium attachment)
590 }
591 parent::__construct($soap, $values);
592 }
593}
594
595abstract class VBox_Enum
596{
597 protected $_handle;
598
599 public function __construct($connection, $handle)
600 {
601 if (is_string($handle))
602 $this->_handle = $this->ValueMap[$handle];
603 else
604 $this->_handle = $handle;
605 }
606
607 public function __toString()
608 {
609 return (string)$this->NameMap[$this->_handle];
610 }
611}
612
613abstract class VBox_EnumCollection extends VBox_Collection
614{
615}
616
617</xsl:text>
618
619<xsl:text>
620/**
621 * VirtualBox COM result codes
622 */
623class VirtualBox_COM_result_codes
624{
625</xsl:text>
626 <xsl:for-each select="/idl/library/result">
627 <xsl:call-template name="comResultCodes"/>
628 </xsl:for-each>
629<xsl:text>
630}
631</xsl:text>
632 <xsl:for-each select="//interface[@wsmap='managed' or @wsmap='global']">
633 <xsl:call-template name="interface"/>
634 <xsl:call-template name="collection"/>
635 </xsl:for-each>
636 <xsl:for-each select="//interface[@wsmap='struct']">
637 <xsl:call-template name="interfacestruct"/>
638 <xsl:call-template name="structcollection"/>
639 </xsl:for-each>
640 <xsl:for-each select="//enum">
641 <xsl:call-template name="enum"/>
642 <xsl:call-template name="enumcollection"/>
643 </xsl:for-each>
644
645</xsl:template>
646
647</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use