VirtualBox

Changeset 20036 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
May 26, 2009 1:21:41 PM (16 years ago)
Author:
vboxsync
Message:

Python: docs update, webserice bindings support custom URLs, cleanup

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/vboxapi.py

    r19902 r20036  
    106106            #win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBox')
    107107
    108     def getSessionObject(self):
     108    def getSessionObject(self, vbox):
    109109        import win32com
    110110        from win32com.client import Dispatch
     
    145145        import xpcom.components
    146146
    147     def getSessionObject(self):
     147    def getSessionObject(self, vbox):
    148148        import xpcom.components
    149149        return xpcom.components.classes["@virtualbox.org/Session;1"].createInstance()
     
    177177        import VirtualBox_services
    178178        import VirtualBox_wrappers
    179         from VirtualBox_wrappers import IWebsessionManager
    180         from VirtualBox_wrappers import g_port
    181         from VirtualBox_wrappers import g_reflectionInfo
    182         self.wsmgr = IWebsessionManager()
    183         self.port = g_port
    184         self.constants = g_reflectionInfo
    185         self.user = ""
    186         self.password = ""
    187 
    188     def getSessionObject(self):
    189         return self.wsmgr.getSessionObject()
     179        from VirtualBox_wrappers import IWebsessionManager2
     180        if params is not None:
     181            self.user = params.get("user", "")
     182            self.password = params.get("password", "")
     183            self.url = params.get("url", "")
     184        else:
     185            self.user = ""
     186            self.password = ""
     187            self.url = None
     188        self.wsmgr = IWebsessionManager2(self.url)
     189
     190    def getSessionObject(self, vbox):
     191        return self.wsmgr.getSessionObject(vbox)
    190192
    191193    def getVirtualBox(self):
     
    193195
    194196    def getConstants(self):
    195         from VirtualBox_wrappers import g_reflectionInfo
    196         return g_reflectionInfo
     197        return None
    197198   
    198199    def getType(self):
     
    216217
    217218    def getSessionObject(self, vbox):
    218         return self.mgr.platform.getSessionObject()
     219        return self.mgr.platform.getSessionObject(vbox)
    219220
    220221class VirtualBoxManager:
  • trunk/src/VBox/Main/webservice/Makefile.kmk

    r19853 r20036  
    326326 #
    327327 VBOXWEB_GLUE_PYTHON           = $(VBOX_PATH_SDK)/bindings/webservice/python/lib/VirtualBox_wrappers.py
    328  VBOXWEB_WS_PYTHON             = $(VBOX_PATH_SDK)/bindings/webservice/python/lib/VirtualBox_service.py
     328 VBOXWEB_WS_PYTHON             = $(VBOX_PATH_SDK)/bindings/webservice/python/lib/VirtualBox_services.py
    329329 VBOXWEB_WS_PERL               = $(VBOX_PATH_SDK)/bindings/webservice/perl/lib/vboxService.pm
    330330 VBOXWEB_SAMPLES_AXIS_DIR      = $(VBOX_PATH_SDK)/bindings/webservice/java/axis/samples
  • trunk/src/VBox/Main/webservice/websrv-python.xsl

    r19320 r20036  
    7272  </xsl:call-template>
    7373  <xsl:text>(</xsl:text>
     74   <xsl:text>self.mgr,</xsl:text>
    7475  <xsl:value-of select="$value"/>
    7576  <xsl:if test="$safearray='yes'">
     
    8990       req=<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>RequestMsg()
    9091       req._this=self.handle
    91        val=g_port.<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>(req)
     92       val=self.mgr.getPort().<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>(req)
    9293       <xsl:text>return  </xsl:text>
    9394       <xsl:call-template name="emitOutParam">
     
    113114       else:
    114115            req._<xsl:value-of select="$attrname"/> = value.handle
    115        g_port.<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>(req)     
     116       self.mgr.getPort().<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>(req)     
    116117</xsl:template>
    117118
     
    120121   <xsl:variable name="ename"><xsl:value-of select="@type" /></xsl:variable>
    121122class <xsl:value-of select="$cname"/>:
    122    def __init__(self, array):
     123   def __init__(self, mgr, array):
    123124       self.array = array
     125       self.mgr = mgr
    124126
    125127   def __next(self):
     
    133135
    134136   def __getitem__(self, index):
    135        return <xsl:value-of select="$ename"/>(self.array._array[index])
     137       return <xsl:value-of select="$ename"/>(self.mgr, self.array._array[index])
    136138       
    137139</xsl:template>
     
    140142   <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
    141143class <xsl:value-of select="$ifname"/>:
    142    def __init__(self, handle = None,isarray = False):
     144   def __init__(self, mgr, handle, isarray = False):
     145       self.mgr = mgr
     146       if handle is None or handle == "":
     147           raise Exception("bad handle: "+str(handle))
    143148       self.handle = handle
    144149       self.isarray = isarray
    145150<!--
    146151    This doesn't work now
    147        g_manMgr.register(handle)
     152       mgr.register(handle)
    148153
    149154   def __del__(self):
    150        g_manMgr.unregister(self.handle)
     155       mgr.unregister(self.handle)
    151156-->
    152157   def releaseRemote(self):
     
    154159            req=IManagedObjectRef_releaseRequestMsg()
    155160            req._this=handle
    156             g_port.IManagedObjectRef_release(req)
     161            self.mgr.getPort().IManagedObjectRef_release(req)
    157162        except:
    158163            pass
     
    175180   def __getitem__(self, index):
    176181      if self.isarray:
    177           return <xsl:value-of select="$ifname" />(self.handle[index])
     182          return <xsl:value-of select="$ifname" />(self.mgr, self.handle[index])
    178183      raise TypeError, "iteration over non-sequence"       
    179184
     
    267272   <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
    268273class <xsl:value-of select="$ifname"/>:
    269     def __init__(self, handle):<xsl:for-each select="attribute">
     274    def __init__(self, mgr, handle):<xsl:for-each select="attribute">
     275       self.mgr = mgr
    270276       self.<xsl:value-of select="@name"/> = handle._<xsl:value-of select="@name"/>
    271277       </xsl:for-each>
     
    287293       req._<xsl:value-of select="@name" />=_arg_<xsl:value-of select="@name" />
    288294       </xsl:for-each>
    289        val=g_port.<xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>(req)
     295       val=self.mgr.getPort().<xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>(req)
    290296       <!-- return needs to be the first one -->     
    291297       return <xsl:for-each select="param[@dir='return']">
     
    339345<xsl:template name="enum">
    340346class <xsl:value-of select="@name"/>:
    341    def __init__(self,handle):
     347   def __init__(self,mgr,handle):
     348       self.mgr=mgr
    342349       if isinstance(handle,basestring):
    343350           self.handle=<xsl:value-of select="@name"/>._ValueMap[handle]
     
    395402from VirtualBox_services import *
    396403
    397 g_port = vboxServiceLocator().getvboxPortType()
    398 
    399404class ManagedManager:
    400405  def __init__(self):
     
    419424            req=IManagedObjectRef_releaseRequestMsg()
    420425            req._this=handle
    421             g_port.IManagedObjectRef_release(req)
     426            self.mgr.getPort().IManagedObjectRef_release(req)
    422427        except:
    423428            pass
     
    426431     else:
    427432        self.map[handle] = c
    428 
    429 g_manMgr = ManagedManager()
    430 
     433 
    431434class String:
    432   def __init__(self, handle = None, isarray = False):
     435  def __init__(self, mgr, handle, isarray = False):
    433436      self.handle = handle
    434437      self.isarray = isarray
     
    477480
    478481class UUID:
    479   def __init__(self, handle = None, isarray = False):
     482  def __init__(self, mgr, handle, isarray = False):
    480483      self.handle = handle
    481484      self.isarray = isarray
     
    523526
    524527class Boolean:
    525   def __init__(self, handle = None, isarray = False):
     528  def __init__(self, mgr, handle, isarray = False):
    526529       self.handle = handle
    527530       self.isarray = isarray
     
    545548
    546549class UnsignedInt:
    547   def __init__(self, handle = None, isarray = False):
     550  def __init__(self, mgr, handle, isarray = False):
    548551       self.handle = handle
    549552       self.isarray = isarray
     
    577580   
    578581class Int:
    579   def __init__(self, handle = None, isarray = False):
     582  def __init__(self, mgr, handle, isarray = False):
    580583       self.handle = handle
    581584       self.isarray = isarray
     
    608611
    609612class UnsignedShort:
    610   def __init__(self, handle = None, isarray = False):
     613  def __init__(self, mgr, handle, isarray = False):
    611614       self.handle = handle
    612615       self.isarray = isarray
     
    619622
    620623class Short:
    621   def __init__(self, handle = None, isarray = False):
     624  def __init__(self, mgr, handle, isarray = False):
    622625       self.handle = handle
    623626 
     
    629632
    630633class UnsignedLong:
    631   def __init__(self, handle = None, isarray = False):
     634  def __init__(self, mgr, handle, isarray = False):
    632635       self.handle = handle
    633636 
     
    639642
    640643class Long:
    641   def __init__(self, handle = None, isarray = False):
     644  def __init__(self, mgr, handle, isarray = False):
    642645       self.handle = handle
    643646 
     
    649652
    650653class Double:
    651   def __init__(self, handle = None, isarray = False):
     654  def __init__(self, mgr, handle, isarray = False):
    652655       self.handle = handle
    653656 
     
    659662
    660663class Float:
    661   def __init__(self, handle = None, isarray = False):
    662        self.handle = handle
    663  
     664  def __init__(self, mgr, handle, isarray = False):
     665       self.handle = handle
     666      
    664667  def __str__(self):
    665668       return str(self.handle)
     
    670673
    671674class IUnknown:
    672   def __init__(self, handle = None, isarray = False):
    673        self.handle = handle
     675  def __init__(self,  mgr, handle, isarray = False):
     676       self.handle = handle
     677       self.mgr = mgr
    674678       self.isarray = isarray
    675679
     
    691695  def __getitem__(self, index):
    692696      if self.isarray:
    693           return IUnknown(self.handle[index])
     697          return IUnknown(self.mgr, self.handle[index])
    694698      raise TypeError, "iteration over non-sequence"       
    695699 
     
    711715  </xsl:for-each>
    712716
    713 class VirtualBoxReflectionInfo:
    714    def __init__(self):
    715       self.map = {}
    716  
    717    def add(self,name,ref):
    718       self.map[name] = ref
    719 
    720    def __getattr__(self,name):
    721       ref = self.map.get(name,None)
    722       if ref == None:
    723           return self.__dict__[name]
    724       return ref
    725 
    726 g_reflectionInfo = VirtualBoxReflectionInfo()
    727 <xsl:for-each select="//enum">
    728   <xsl:variable name="ename">
    729     <xsl:value-of select="@name"/>
    730   </xsl:variable>
    731   <xsl:value-of select="concat('g_reflectionInfo.add(&#34;',$ename,'&#34;,',$ename,')&#10;')"/>
    732 </xsl:for-each>
     717class IWebsessionManager2(IWebsessionManager):
     718  def __init__(self, url):
     719       self.url = url
     720       self.port = None
     721       self.handle = None
     722       self.mgr = self
     723
     724  def getPort(self):
     725      if self.port is None:
     726          self.port = vboxServiceLocator().getvboxPortType(self.url)
     727      return self.port
    733728
    734729</xsl:template>
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