VirtualBox

Changeset 43546 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 4, 2012 4:28:57 PM (12 years ago)
Author:
vboxsync
Message:

webservice/websrv-php.xsl: fix for safearray setters contributed by James Lucas plus lots of output cleanup and coding style cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/webservice/websrv-php.xsl

    r43103 r43546  
    1212     Contributed by James Lucas (mjlucas at eng.uts.edu.au).
    1313
    14     Copyright (C) 2008-2010 Oracle Corporation
     14    Copyright (C) 2008-2012 Oracle Corporation
    1515
    1616    This file is part of VirtualBox Open Source Edition (OSE), as
     
    120120  <xsl:param name="attrsafearray" />
    121121  <xsl:variable name="fname"><xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="$attrname"/></xsl:call-template> </xsl:variable>
    122    public function <xsl:value-of select="$fname"/>() {
    123        $request = new stdClass();
    124        $request->_this = $this->handle;
    125        $response = $this->connection->__soapCall('<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>', array((array)$request));
    126        <xsl:text>return </xsl:text>
    127        <xsl:call-template name="emitOutParam">
    128            <xsl:with-param name="type" select="$attrtype" />
    129            <xsl:with-param name="value" select="concat('$response->','returnval')" />
    130            <xsl:with-param name="safearray" select="@safearray"/>
    131          </xsl:call-template><xsl:text>;</xsl:text>
    132    }
     122    public function <xsl:value-of select="$fname"/>()
     123    {
     124        $request = new stdClass();
     125        $request->_this = $this->handle;
     126        $response = $this->connection->__soapCall('<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>', array((array)$request));
     127        <xsl:text>return </xsl:text>
     128        <xsl:call-template name="emitOutParam">
     129            <xsl:with-param name="type" select="$attrtype" />
     130            <xsl:with-param name="value" select="concat('$response->','returnval')" />
     131            <xsl:with-param name="safearray" select="@safearray"/>
     132          </xsl:call-template><xsl:text>;</xsl:text>
     133    }
    133134</xsl:template>
    134135
     
    139140  <xsl:param name="attrsafearray" />
    140141  <xsl:variable name="fname"><xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="$attrname"/></xsl:call-template></xsl:variable>
    141    public function <xsl:value-of select="$fname"/>($value) {
    142        $request = new stdClass();
    143        $request->_this = $this->handle;
    144        if (is_null($value) || is_scalar($value)) {
     142    public function <xsl:value-of select="$fname"/>($value)
     143    {
     144        $request = new stdClass();
     145        $request->_this = $this->handle;
     146<xsl:choose>
     147<xsl:when test="$attrsafearray='yes'">        if (is_array($value) || is_null($value) || is_scalar($value))</xsl:when>
     148<xsl:otherwise>        if (is_null($value) || is_scalar($value))</xsl:otherwise>
     149</xsl:choose>
     150        {
    145151            $request-><xsl:value-of select="$attrname"/> = $value;
    146        }
    147        else
    148        {
     152        }
     153        else
     154        {
    149155            $request-><xsl:value-of select="$attrname"/> = $value->handle;
    150        }
    151        $this->connection->__soapCall('<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>', array((array)$request));
    152    }
     156        }
     157        $this->connection->__soapCall('<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>', array((array)$request));
     158    }
    153159</xsl:template>
    154160
     
    159165   <xsl:text>
    160166/**
    161 * Generated VBoxWebService Interface Wrapper
    162 */
     167 * Generated VBoxWebService Interface Wrapper
     168 */
    163169</xsl:text>
    164170   <xsl:choose>
    165171      <xsl:when test="($extends = '$unknown') or ($extends = '$dispatched') or ($extends = '$errorinfo')">
    166          <xsl:value-of select="concat('class ', $ifname, ' extends VBox_ManagedObject {&#10;')" />
     172         <xsl:value-of select="concat('class ', $ifname, ' extends VBox_ManagedObject&#10;{&#10;')" />
    167173      </xsl:when>
    168174      <xsl:when test="//interface[@name=$extends]">
    169          <xsl:value-of select="concat('class ', $ifname, ' extends ', $extends, ' {&#10;')" />
     175         <xsl:value-of select="concat('class ', $ifname, ' extends ', $extends, '&#10;{&#10;')" />
    170176      </xsl:when>
    171177   </xsl:choose>
     
    182188      <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
    183189      <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
     190      <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
    184191      <!-- skip this attribute if it has parameters of a type that has wsmap="suppress" -->
    185192      <xsl:choose>
     
    201208            <xsl:with-param name="attrname" select="$attrname" />
    202209            <xsl:with-param name="attrtype" select="$attrtype" />
     210            <xsl:with-param name="attrsafearray" select="$attrsafearray" />
    203211          </xsl:call-template>
    204212          <!-- bb) emit a set method if the attribute is read/write -->
     
    208216              <xsl:with-param name="attrname" select="$attrname" />
    209217              <xsl:with-param name="attrtype" select="$attrtype" />
     218              <xsl:with-param name="attrsafearray" select="$attrsafearray" />
    210219            </xsl:call-template>
    211220          </xsl:if>
     
    214223  </xsl:for-each>
    215224  <xsl:text>}
    216   </xsl:text>
     225</xsl:text>
    217226</xsl:template>
    218227
     
    221230   <xsl:text>
    222231/**
    223 * Generated VBoxWebService Managed Object Collection
    224 */</xsl:text>
    225 class <xsl:value-of select="$ifname"/>Collection extends VBox_ManagedObjectCollection {
    226    protected $_interfaceName = "<xsl:value-of select="$ifname"/>";
     232 * Generated VBoxWebService Managed Object Collection
     233 */</xsl:text>
     234class <xsl:value-of select="$ifname"/>Collection extends VBox_ManagedObjectCollection
     235{
     236    protected $_interfaceName = "<xsl:value-of select="$ifname"/>";
    227237}
    228238</xsl:template>
     
    232242   <xsl:text>
    233243/**
    234 * Generated VBoxWebService Struct
    235 */</xsl:text>
    236 class <xsl:value-of select="$ifname"/> extends VBox_Struct {
    237     <xsl:for-each select="attribute">
    238        protected $<xsl:value-of select="@name"/>;
    239     </xsl:for-each>
    240     public function __construct($connection, $values) {
    241        $this->connection = $connection;
    242     <xsl:for-each select="attribute">
    243        $this-><xsl:value-of select="@name"/> = $values-><xsl:value-of select="@name"/><xsl:text>;</xsl:text>
    244     </xsl:for-each>
    245     }
    246 
    247     <xsl:for-each select="attribute">
    248     public function <xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="@name"/></xsl:call-template>() {
     244 * Generated VBoxWebService Struct
     245 */</xsl:text>
     246class <xsl:value-of select="$ifname"/> extends VBox_Struct
     247{
     248<xsl:for-each select="attribute">    protected $<xsl:value-of select="@name"/>;
     249</xsl:for-each>
     250    public function __construct($connection, $values)
     251    {
     252        $this->connection = $connection;
     253<xsl:for-each select="attribute">        $this-><xsl:value-of select="@name"/> = $values-><xsl:value-of select="@name"/>;
     254</xsl:for-each>    }
     255
     256<xsl:for-each select="attribute">    public function <xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="@name"/></xsl:call-template>()
     257    {
    249258        <xsl:text>return </xsl:text>
    250259        <xsl:call-template name="emitOutParam">
     
    254263         </xsl:call-template>;
    255264    }
    256     </xsl:for-each>
    257 
    258 }
     265</xsl:for-each>}
    259266</xsl:template>
    260267
     
    263270   <xsl:text>
    264271/**
    265 * Generated VBoxWebService Struct Collection
    266 */</xsl:text>
    267 class <xsl:value-of select="$ifname"/>Collection extends VBox_StructCollection {
    268    protected $_interfaceName = "<xsl:value-of select="$ifname"/>";
     272 * Generated VBoxWebService Struct Collection
     273 */</xsl:text>
     274class <xsl:value-of select="$ifname"/>Collection extends VBox_StructCollection
     275{
     276    protected $_interfaceName = "<xsl:value-of select="$ifname"/>";
    269277}
    270278</xsl:template>
    271279
    272280<xsl:template name="genreq">
    273        <xsl:param name="wsmap" />
    274        <xsl:text>$request = new stdClass()</xsl:text>;
    275        <xsl:if test="$wsmap='managed'">
    276        $request->_this = $this->handle;
    277        </xsl:if>
    278        <xsl:for-each select="param[@dir='in']">
    279        $request-><xsl:value-of select="@name" /> = $arg_<xsl:value-of select="@name" /><xsl:text>;</xsl:text>
    280        </xsl:for-each>
    281        $response = $this->connection->__soapCall('<xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>', array((array)$request));
    282        <!-- return needs to be the first one -->
    283        return <xsl:if test="param[@dir='out']">
    284                 <xsl:text>array(</xsl:text>
    285               </xsl:if>
     281    <xsl:param name="wsmap" />
     282    <xsl:text>        $request = new stdClass();
     283</xsl:text>
     284    <xsl:if test="$wsmap='managed'">        $request->_this = $this->handle;</xsl:if>
     285    <xsl:for-each select="param[@dir='in']">
     286        $request-><xsl:value-of select="@name" /> = $arg_<xsl:value-of select="@name" /><xsl:text>;</xsl:text>
     287    </xsl:for-each>
     288        $response = $this->connection->__soapCall('<xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>', array((array)$request));
     289        return <xsl:if test="param[@dir='out']">
     290                 <xsl:text>array(</xsl:text>
     291               </xsl:if>
    286292         <xsl:for-each select="param[@dir='return']">
    287293         <xsl:call-template name="emitOutParam">
     
    311317
    312318<xsl:template name="method" >
    313    <xsl:param name="wsmap" />
    314    public function <xsl:value-of select="@name"/><xsl:text>(</xsl:text>
    315    <xsl:for-each select="param[@dir='in']">
    316      <xsl:if test="not(position()=1)">
    317        <xsl:text>, </xsl:text>
    318      </xsl:if>
    319      <xsl:value-of select="concat('$arg_',@name)"/>
    320    </xsl:for-each><xsl:text>) { &#10;       </xsl:text>
    321    <xsl:call-template name="genreq"><xsl:with-param name="wsmap" select="$wsmap" /></xsl:call-template>
    322    <xsl:text>  }&#10;</xsl:text>
     319    <xsl:param name="wsmap" />
     320    public function <xsl:value-of select="@name"/><xsl:text>(</xsl:text>
     321    <xsl:for-each select="param[@dir='in']">
     322      <xsl:if test="not(position()=1)">
     323        <xsl:text>, </xsl:text>
     324      </xsl:if>
     325      <xsl:value-of select="concat('$arg_',@name)"/>
     326    </xsl:for-each> <xsl:text>)&#10;    {&#10;</xsl:text>
     327    <xsl:call-template name="genreq"><xsl:with-param name="wsmap" select="$wsmap" /></xsl:call-template>
     328    <xsl:text>    }&#10;</xsl:text>
    323329</xsl:template>
    324330
     
    326332  <xsl:text>
    327333/**
    328 * Generated VBoxWebService ENUM
    329 */</xsl:text>
    330 class <xsl:value-of select="@name"/> extends VBox_Enum {
    331    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>);
    332    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>);
     334 * Generated VBoxWebService ENUM
     335 */</xsl:text>
     336class <xsl:value-of select="@name"/> extends VBox_Enum
     337{
     338    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>);
     339    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>);
    333340}
    334341</xsl:template>
     
    338345   <xsl:text>
    339346/**
    340 * Generated VBoxWebService Enum Collection
    341 */</xsl:text>
    342 class <xsl:value-of select="$ifname"/>Collection extends VBox_EnumCollection {
    343    protected $_interfaceName = "<xsl:value-of select="$ifname"/>";
     347 * Generated VBoxWebService Enum Collection
     348 */</xsl:text>
     349class <xsl:value-of select="$ifname"/>Collection extends VBox_EnumCollection
     350{
     351    protected $_interfaceName = "<xsl:value-of select="$ifname"/>";
    344352}
    345353</xsl:template>
    346354
    347355<xsl:template name="comResultCodes">
    348    const <xsl:value-of select="@name"/> = <xsl:value-of select="@value"/>;
     356    const <xsl:value-of select="@name"/> = <xsl:value-of select="@value"/>;
    349357</xsl:template>
    350358
     
    353361
    354362/*
    355  * Copyright (C) 2008-2010 Oracle Corporation
     363 * Copyright (C) 2008-2012 Oracle Corporation
    356364 *
    357365 * This file is part of a free software library; you can redistribute
     
    408416    }
    409417
    410    public function getHandle()
    411    {
    412        return $this->handle;
    413    }
    414 
    415    public function cast($class)
    416    {
    417        if (is_subclass_of($class, 'VBox_ManagedObject'))
    418        {
    419            return new $class($this->connection, $this->handle);
    420        }
    421        throw new Exception('Cannot cast VBox_ManagedObject to non-child class VBox_ManagedObject');
    422    }
    423 
    424    public function releaseRemote()
    425    {
    426        try
    427        {
    428            $request = new stdClass();
    429            $request->_this = $this->handle;
    430            $this->connection->__soapCall('IManagedObjectRef_release', array((array)$request));
    431        } catch (Exception $ex) {}
    432    }
    433 }
    434 
    435 abstract class VBox_Collection implements ArrayAccess, Iterator, Countable {
     418    public function getHandle()
     419    {
     420        return $this->handle;
     421    }
     422
     423    public function cast($class)
     424    {
     425        if (is_subclass_of($class, 'VBox_ManagedObject'))
     426        {
     427            return new $class($this->connection, $this->handle);
     428        }
     429        throw new Exception('Cannot cast VBox_ManagedObject to non-child class VBox_ManagedObject');
     430    }
     431
     432    public function releaseRemote()
     433    {
     434        try
     435        {
     436            $request = new stdClass();
     437            $request->_this = $this->handle;
     438            $this->connection->__soapCall('IManagedObjectRef_release', array((array)$request));
     439        }
     440        catch (Exception $ex)
     441        {
     442        }
     443    }
     444}
     445
     446abstract class VBox_Collection implements ArrayAccess, Iterator, Countable
     447{
    436448    protected $_connection;
    437449    protected $_values;
     
    439451    protected $_interfaceName;
    440452
    441     public function __construct($soap, array $values = array()) {
     453    public function __construct($soap, array $values = array())
     454    {
    442455        $this->_connection = $soap;
    443456        $this->_values = $values;
     
    445458    }
    446459
    447     protected function _soapToObject() {
     460    protected function _soapToObject()
     461    {
    448462        $this->_objects = array();
    449463        foreach($this->_values as $value)
     
    454468
    455469    /** ArrayAccess Functions **/
    456     public function offsetSet($offset, $value) {
     470    public function offsetSet($offset, $value)
     471    {
    457472        if ($value instanceof $this->_interfaceName)
    458473        {
     
    472487    }
    473488
    474     public function offsetExists($offset) {
     489    public function offsetExists($offset)
     490    {
    475491        return isset($this->_objects[$offset]);
    476492    }
    477493
    478     public function offsetUnset($offset) {
     494    public function offsetUnset($offset)
     495    {
    479496        unset($this->_objects[$offset]);
    480497    }
    481498
    482     public function offsetGet($offset) {
     499    public function offsetGet($offset)
     500    {
    483501        return isset($this->_objects[$offset]) ? $this->_objects[$offset] : null;
    484502    }
    485503
    486504    /** Iterator Functions **/
    487     public function rewind() {
     505    public function rewind()
     506    {
    488507        reset($this->_objects);
    489508    }
    490509
    491     public function current() {
     510    public function current()
     511    {
    492512        return current($this->_objects);
    493513    }
    494514
    495     public function key() {
     515    public function key()
     516    {
    496517        return key($this->_objects);
    497518    }
    498519
    499     public function next() {
     520    public function next()
     521    {
    500522        return next($this->_objects);
    501523    }
    502524
    503     public function valid() {
     525    public function valid()
     526    {
    504527        return ($this->current() !== false);
    505528    }
    506529
    507530    /** Countable Functions **/
    508     public function count() {
     531    public function count()
     532    {
    509533        return count($this->_objects);
    510534    }
    511535}
    512536
    513 class VBox_ManagedObjectCollection extends VBox_Collection {
     537class VBox_ManagedObjectCollection extends VBox_Collection
     538{
    514539    protected $_interfaceName = 'VBox_ManagedObject';
    515540
    516541    // Result is undefined if this is called AFTER any call to VBox_Collection::offsetSet or VBox_Collection::offsetUnset
    517     public function setInterfaceName($interface) {
    518        if (!is_subclass_of($interface, 'VBox_ManagedObject'))
    519        {
    520            throw new Exception('Cannot set collection interface to non-child class of VBox_ManagedObject');
    521        }
    522        $this->_interfaceName = $interface;
    523        $this->_soapToObject();
    524     }
    525 }
    526 
    527 abstract class VBox_Struct {
     542    public function setInterfaceName($interface)
     543    {
     544        if (!is_subclass_of($interface, 'VBox_ManagedObject'))
     545        {
     546            throw new Exception('Cannot set collection interface to non-child class of VBox_ManagedObject');
     547        }
     548        $this->_interfaceName = $interface;
     549        $this->_soapToObject();
     550    }
     551}
     552
     553abstract class VBox_Struct
     554{
    528555    protected $connection;
    529556
     
    538565}
    539566
    540 abstract class VBox_StructCollection extends VBox_Collection {
     567abstract class VBox_StructCollection extends VBox_Collection
     568{
    541569
    542570    public function __construct($soap, array $values = array())
     
    550578}
    551579
    552 abstract class VBox_Enum {
    553    protected $_handle;
    554 
    555    public function __construct($connection, $handle)
    556    {
    557        if (is_string($handle))
    558            $this->_handle = $this->ValueMap[$handle];
    559        else
    560            $this->_handle = $handle;
    561    }
    562 
    563    public function __toString()
    564    {
    565        return (string)$this->NameMap[$this->_handle];
    566    }
    567 }
    568 
    569 abstract class VBox_EnumCollection extends VBox_Collection {
     580abstract class VBox_Enum
     581{
     582    protected $_handle;
     583
     584    public function __construct($connection, $handle)
     585    {
     586        if (is_string($handle))
     587            $this->_handle = $this->ValueMap[$handle];
     588        else
     589            $this->_handle = $handle;
     590    }
     591
     592    public function __toString()
     593    {
     594        return (string)$this->NameMap[$this->_handle];
     595    }
     596}
     597
     598abstract class VBox_EnumCollection extends VBox_Collection
     599{
    570600}
    571601
     
    574604<xsl:text>
    575605/**
    576 * VirtualBox COM result codes
    577 */
    578 class VirtualBox_COM_result_codes {
     606 * VirtualBox COM result codes
     607 */
     608class VirtualBox_COM_result_codes
     609{
    579610</xsl:text>
    580611  <xsl:for-each select="/idl/library/result">
     
    588619       <xsl:call-template name="collection"/>
    589620  </xsl:for-each>
    590    <xsl:for-each select="//interface[@wsmap='struct']">
     621  <xsl:for-each select="//interface[@wsmap='struct']">
    591622       <xsl:call-template name="interfacestruct"/>
    592623       <xsl:call-template name="structcollection"/>
Note: See TracChangeset for help on using the changeset viewer.

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