vboxapi.py revision b24a4c8472377f462bad08867b6203fe8bbe9663
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync#
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync# Copyright (C) 2009 Sun Microsystems, Inc.
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync#
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync# available from http://www.virtualbox.org. This file is free software;
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync# you can redistribute it and/or modify it under the terms of the GNU
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync# General Public License (GPL) as published by the Free Software
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync#
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync# Clara, CA 95054 USA or visit http://www.sun.com if you need
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync# additional information or have any questions.
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync#
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncimport sys,os
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncimport traceback
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncVboxBinDir = os.environ.get("VBOX_PROGRAM_PATH", None)
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncVboxSdkDir = os.environ.get("VBOX_SDK_PATH", None)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncif VboxBinDir is None:
2561352ae77d8f2f825526a6cbafa34b45f16972vboxsync # Will be set by the installer
2561352ae77d8f2f825526a6cbafa34b45f16972vboxsync VboxBinDir = "%VBOX_INSTALL_PATH%"
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncif VboxSdkDir is None:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync VboxSdkDir = VboxBinDir+"/sdk"
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncos.environ["VBOX_PROGRAM_PATH"] = VboxBinDir
a2c132bb887bbbff1490a680748413f8cfc9cd20vboxsyncos.environ["VBOX_SDK_PATH"] = VboxSdkDir
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncsys.path.append(VboxBinDir)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
c65e2fedaf400b449a85ae6db7b84858f2613708vboxsyncfrom VirtualBox_constants import VirtualBoxReflectionInfo
c65e2fedaf400b449a85ae6db7b84858f2613708vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsyncclass PerfCollector:
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """ This class provides a wrapper over IPerformanceCollector in order to
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync get more 'pythonic' interface.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync To begin collection of metrics use setup() method.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync To get collected data use query() method.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync It is possible to disable metric collection without changing collection
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync parameters with disable() method. The enable() method resumes metric
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync collection.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync def __init__(self, vb):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """ Initializes the instance.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync Pass an instance of IVirtualBox as parameter.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync self.collector = vb.performanceCollector
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync def setup(self, names, objects, period, nsamples):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """ Discards all previously collected values for the specified
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync metrics, sets the period of collection and the number of retained
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync samples, enables collection.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync self.collector.setupMetrics(names, objects, period, nsamples)
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync def enable(self, names, objects):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """ Resumes metric collection for the specified metrics.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync self.collector.enableMetrics(names, objects)
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync def disable(self, names, objects):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """ Suspends metric collection for the specified metrics.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync self.collector.disableMetrics(names, objects)
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync def query(self, names, objects):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """ Retrieves collected metric values as well as some auxiliary
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync information. Returns an array of dictionaries, one dictionary per
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync metric. Each dictionary contains the following entries:
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'name': metric name
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'object': managed object this metric associated with
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'unit': unit of measurement
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'scale': divide 'values' by this number to get float numbers
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'values': collected data
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'values_as_string': pre-processed values ready for 'print' statement
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """
a7f701e8c51193f7c21137cc173ea5f86e53cac2vboxsync # Get around the problem with input arrays returned in output parameters (see #3953).
a7f701e8c51193f7c21137cc173ea5f86e53cac2vboxsync if sys.platform == 'win32':
a7f701e8c51193f7c21137cc173ea5f86e53cac2vboxsync (values, names, objects, names_out, objects_out, units, scales, sequence_numbers,
a7f701e8c51193f7c21137cc173ea5f86e53cac2vboxsync indices, lengths) = self.collector.queryMetricsData(names, objects)
a7f701e8c51193f7c21137cc173ea5f86e53cac2vboxsync else:
a7f701e8c51193f7c21137cc173ea5f86e53cac2vboxsync (values, names_out, objects_out, units, scales, sequence_numbers,
a7f701e8c51193f7c21137cc173ea5f86e53cac2vboxsync indices, lengths) = self.collector.queryMetricsData(names, objects)
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync out = []
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync for i in xrange(0, len(names_out)):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync scale = int(scales[i])
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync if scale != 1:
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync fmt = '%.2f%s'
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync else:
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync fmt = '%d %s'
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync out.append({
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'name':str(names_out[i]),
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'object':str(objects_out[i]),
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'unit':str(units[i]),
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'scale':scale,
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'values':[int(values[j]) for j in xrange(int(indices[i]), int(indices[i])+int(lengths[i]))],
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync 'values_as_string':'['+', '.join([fmt % (int(values[j])/scale, units[i]) for j in xrange(int(indices[i]), int(indices[i])+int(lengths[i]))])+']'
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync })
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync return out
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsyncdef ComifyName(name):
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync return name[0].capitalize()+name[1:]
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync_COMForward = { 'getattr' : None,
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync 'setattr' : None}
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsyncdef CustomGetAttr(self, attr):
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync # fastpath
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync if self.__class__.__dict__.get(attr) != None:
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync return self.__class__.__dict__.get(attr)
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync # try case-insensitivity workaround for class attributes (COM methods)
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync for k in self.__class__.__dict__.keys():
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync if k.lower() == attr.lower():
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync self.__class__.__dict__[attr] = self.__class__.__dict__[k]
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync return getattr(self, k)
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync try:
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync return _COMForward['getattr'](self,ComifyName(attr))
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync except AttributeError:
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync return _COMForward['getattr'](self,attr)
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsyncdef CustomSetAttr(self, attr, value):
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync try:
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync return _COMForward['setattr'](self, ComifyName(attr), value)
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync except AttributeError:
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync return _COMForward['setattr'](self, attr, value)
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncclass PlatformMSCOM:
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync # Class to fake access to constants in style of foo.bar.boo
08122b11035de1e54ce1e665dff7260fc548db72vboxsync class ConstantFake:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def __init__(self, parent, name):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync self.__dict__['_parent'] = parent
08122b11035de1e54ce1e665dff7260fc548db72vboxsync self.__dict__['_name'] = name
08122b11035de1e54ce1e665dff7260fc548db72vboxsync self.__dict__['_consts'] = {}
08122b11035de1e54ce1e665dff7260fc548db72vboxsync try:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync self.__dict__['_depth']=parent.__dict__['_depth']+1
08122b11035de1e54ce1e665dff7260fc548db72vboxsync except:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync self.__dict__['_depth']=0
08122b11035de1e54ce1e665dff7260fc548db72vboxsync if self.__dict__['_depth'] > 4:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync raise AttributeError
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync def __getattr__(self, attr):
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync import win32com
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync from win32com.client import constants
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync if attr.startswith("__"):
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync raise AttributeError
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync consts = self.__dict__['_consts']
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync fake = consts.get(attr, None)
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync if fake != None:
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync return fake
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync try:
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync name = self.__dict__['_name']
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync parent = self.__dict__['_parent']
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync while parent != None:
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync if parent._name is not None:
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync name = parent._name+'_'+name
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync parent = parent._parent
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync if name is not None:
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync name += "_" + attr
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync else:
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync name = attr
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync return win32com.client.constants.__getattr__(name)
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync except AttributeError,e:
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync fake = PlatformMSCOM.ConstantFake(self, attr)
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync consts[attr] = fake
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync return fake
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync class InterfacesWrapper:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def __init__(self):
da570ef57fe454ae2d9d5d88a7bfea214723dbb1vboxsync self.__dict__['_rootFake'] = PlatformMSCOM.ConstantFake(None, None)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def __getattr__(self, a):
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync import win32com
7baa1c3bb51b48e79eee63a69e341442e342a18evboxsync from win32com.client import constants
08122b11035de1e54ce1e665dff7260fc548db72vboxsync if a.startswith("__"):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync raise AttributeError
08122b11035de1e54ce1e665dff7260fc548db72vboxsync try:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return win32com.client.constants.__getattr__(a)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync except AttributeError,e:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return self.__dict__['_rootFake'].__getattr__(a)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync VBOX_TLB_GUID = '{46137EEC-703B-4FE5-AFD4-7C9BBBBA0259}'
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync VBOX_TLB_LCID = 0
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync VBOX_TLB_MAJOR = 1
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync VBOX_TLB_MINOR = 0
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def __init__(self, params):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync from win32com import universal
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync from win32com.client import gencache, DispatchBaseClass
08122b11035de1e54ce1e665dff7260fc548db72vboxsync from win32com.client import constants, getevents
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import win32com
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import pythoncom
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import win32api
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync self.constants = PlatformMSCOM.InterfacesWrapper()
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync from win32con import DUPLICATE_SAME_ACCESS
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync from win32api import GetCurrentThread,GetCurrentThreadId,DuplicateHandle,GetCurrentProcess
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync pid = GetCurrentProcess()
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync self.tid = GetCurrentThreadId()
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync handle = DuplicateHandle(pid, GetCurrentThread(), pid, 0, 0, DUPLICATE_SAME_ACCESS)
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync self.handles = []
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync self.handles.append(handle)
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync _COMForward['getattr'] = DispatchBaseClass.__dict__['__getattr__']
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync DispatchBaseClass.__dict__['__getattr__'] = CustomGetAttr
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync _COMForward['setattr'] = DispatchBaseClass.__dict__['__setattr__']
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync DispatchBaseClass.__dict__['__setattr__'] = CustomSetAttr
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync win32com.client.gencache.EnsureDispatch('VirtualBox.Session')
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBox')
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync def getSessionObject(self, vbox):
da570ef57fe454ae2d9d5d88a7bfea214723dbb1vboxsync import win32com
08122b11035de1e54ce1e665dff7260fc548db72vboxsync from win32com.client import Dispatch
2ea0ec406117609d51bd5ac51cbb3d4f0de9a16dvboxsync return win32com.client.Dispatch("VirtualBox.Session")
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getVirtualBox(self):
da570ef57fe454ae2d9d5d88a7bfea214723dbb1vboxsync import win32com
08122b11035de1e54ce1e665dff7260fc548db72vboxsync from win32com.client import Dispatch
2ea0ec406117609d51bd5ac51cbb3d4f0de9a16dvboxsync return win32com.client.Dispatch("VirtualBox.VirtualBox")
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getConstants(self):
da570ef57fe454ae2d9d5d88a7bfea214723dbb1vboxsync return self.constants
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getType(self):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return 'MSCOM'
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getRemote(self):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return False
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getArray(self, obj, field):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return obj.__getattr__(field)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync def initPerThread(self):
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync import pythoncom
1d27f9d208503988168cd9a8a902a0f48cf52a12vboxsync pythoncom.CoInitializeEx(0)
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync def deinitPerThread(self):
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync import pythoncom
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync pythoncom.CoUninitialize()
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync def createCallback(self, iface, impl, arg):
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync d = {}
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync d['BaseClass'] = impl
3acd338a7a2154c8d73de9a2629bc7057b051334vboxsync d['arg'] = arg
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync d['tlb_guid'] = PlatformMSCOM.VBOX_TLB_GUID
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync str = ""
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync str += "import win32com.server.util\n"
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync #str += "import win32com.server.register\n"
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync #str += "from win32com import universal\n"
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync str += "import pythoncom\n"
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync #str += "universal.RegisterInterfaces(tlb_guid, 0, 1, 0, ['"+iface+"'])\n"
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync str += "class "+iface+"Impl(BaseClass):\n"
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync str += " _com_interfaces_ = ['"+iface+"']\n"
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync str += " _typelib_guid_ = tlb_guid\n"
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync str += " _typelib_version_ = 1, 0\n"
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync #str += " _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER\n"
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync #str += " _reg_clsid_ = '{F21202A2-959A-4149-B1C3-68B9013F3335}'\n"
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync #str += " _reg_progid_ = 'VirtualBox."+iface+"Impl'\n"
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync #str += " _reg_desc_ = 'Generated callback implementation class'\n"
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync #str += " _reg_policy_spec_ = 'win32com.server.policy.EventHandlerPolicy'\n"
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync
0637d4d8793a5ce81c481f2cac4a8daf0fb91683vboxsync # generate capitalized version of callbacks - that's how Python COM
0637d4d8793a5ce81c481f2cac4a8daf0fb91683vboxsync # looks them up on Windows
0637d4d8793a5ce81c481f2cac4a8daf0fb91683vboxsync for m in dir(impl):
0637d4d8793a5ce81c481f2cac4a8daf0fb91683vboxsync if m.startswith("on"):
bf3b45b409e14f2fde6b2bdde95332c45fd72d46vboxsync str += " "+ComifyName(m)+"=BaseClass."+m+"\n"
0637d4d8793a5ce81c481f2cac4a8daf0fb91683vboxsync
3acd338a7a2154c8d73de9a2629bc7057b051334vboxsync str += " def __init__(self): BaseClass.__init__(self, arg)\n"
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync #str += "win32com.server.register.UseCommandLine("+iface+"Impl)\n"
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync str += "result = win32com.server.util.wrap("+iface+"Impl())\n"
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync exec (str,d,d)
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync return d['result']
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def waitForEvents(self, timeout):
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync from win32api import GetCurrentThreadId
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync from win32event import MsgWaitForMultipleObjects, \
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync QS_ALLINPUT, WAIT_TIMEOUT, WAIT_OBJECT_0
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync from pythoncom import PumpWaitingMessages
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync if (self.tid != GetCurrentThreadId()):
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync raise Exception("wait for events from the same thread you inited!")
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync rc = MsgWaitForMultipleObjects(self.handles, 0, timeout, QS_ALLINPUT)
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync if rc >= WAIT_OBJECT_0 and rc < WAIT_OBJECT_0+len(self.handles):
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync # is it possible?
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync pass
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync elif rc==WAIT_OBJECT_0 + len(self.handles):
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync # Waiting messages
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync PumpWaitingMessages()
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync else:
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync # Timeout
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync pass
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def deinit(self):
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync import pythoncom
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync from win32file import CloseHandle
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync for h in self.handles:
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync if h is not None:
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync CloseHandle(h)
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync self.handles = None
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync pythoncom.CoUninitialize()
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync pass
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync def getPerfCollector(self, vbox):
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync return PerfCollector(vbox)
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncclass PlatformXPCOM:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def __init__(self, params):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync sys.path.append(VboxSdkDir+'/bindings/xpcom/python/')
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import xpcom.vboxxpcom
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import xpcom
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import xpcom.components
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync def getSessionObject(self, vbox):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import xpcom.components
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return xpcom.components.classes["@virtualbox.org/Session;1"].createInstance()
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getVirtualBox(self):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import xpcom.components
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return xpcom.components.classes["@virtualbox.org/VirtualBox;1"].createInstance()
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getConstants(self):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import xpcom.components
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return xpcom.components.interfaces
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getType(self):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return 'XPCOM'
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getRemote(self):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return False
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getArray(self, obj, field):
bf3b45b409e14f2fde6b2bdde95332c45fd72d46vboxsync return obj.__getattr__('get'+ComifyName(field))()
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync def initPerThread(self):
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync pass
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync def deinitPerThread(self):
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync pass
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync
3acd338a7a2154c8d73de9a2629bc7057b051334vboxsync def createCallback(self, iface, impl, arg):
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync d = {}
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync d['BaseClass'] = impl
3acd338a7a2154c8d73de9a2629bc7057b051334vboxsync d['arg'] = arg
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync str = ""
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync str += "import xpcom.components\n"
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync str += "class "+iface+"Impl(BaseClass):\n"
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync str += " _com_interfaces_ = xpcom.components.interfaces."+iface+"\n"
3acd338a7a2154c8d73de9a2629bc7057b051334vboxsync str += " def __init__(self): BaseClass.__init__(self, arg)\n"
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync str += "result = "+iface+"Impl()\n"
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync exec (str,d,d)
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync return d['result']
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def waitForEvents(self, timeout):
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync import xpcom
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync xpcom._xpcom.WaitForEvents(timeout)
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def deinit(self):
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync import xpcom
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync xpcom._xpcom.DeinitCOM()
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync def getPerfCollector(self, vbox):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync return PerfCollector(vbox)
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncclass PlatformWEBSERVICE:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def __init__(self, params):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync sys.path.append(VboxSdkDir+'/bindings/webservice/python/lib')
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync # not really needed, but just fail early if misconfigured
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import VirtualBox_services
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import VirtualBox_wrappers
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync from VirtualBox_wrappers import IWebsessionManager2
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync if params is not None:
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync self.user = params.get("user", "")
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync self.password = params.get("password", "")
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync self.url = params.get("url", "")
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync else:
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync self.user = ""
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync self.password = ""
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync self.url = None
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync self.vbox = None
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync def getSessionObject(self, vbox):
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync return self.wsmgr.getSessionObject(vbox)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getVirtualBox(self):
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync return connect(self.url, self.user, self.password)
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync def connect(self, url, user, passwd):
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync if self.vbox is not None:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync disconnect()
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync from VirtualBox_wrappers import IWebsessionManager2
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync self.url = url
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync if user is None:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync user = ""
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync self.user = user
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync if passwd is None:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync passwd = ""
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync self.password = passwd
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync self.wsmgr = IWebsessionManager2(self.url)
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync self.vbox = self.wsmgr.logon(self.user, self.password)
aca09683940c0bff7fc1f91c6e00beefaea2fe21vboxsync return self.vbox
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync def disconnect(self):
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync if self.vbox is not None and self.wsmgr is not None:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync self.wsmgr.logoff(self.vbox)
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync self.vbox = None
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync self.wsmgr = None
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getConstants(self):
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync return None
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getType(self):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return 'WEBSERVICE'
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getRemote(self):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return True
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getArray(self, obj, field):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return obj.__getattr__(field)
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync def initPerThread(self):
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync pass
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync def deinitPerThread(self):
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync pass
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
3acd338a7a2154c8d73de9a2629bc7057b051334vboxsync def createCallback(self, iface, impl, arg):
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync raise Exception("no callbacks for webservices")
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def waitForEvents(self, timeout):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync # Webservices cannot do that yet
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync pass
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def deinit(self):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync try:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync disconnect()
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync except:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync pass
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync def getPerfCollector(self, vbox):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync return PerfCollector(vbox)
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncclass SessionManager:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def __init__(self, mgr):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync self.mgr = mgr
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getSessionObject(self, vbox):
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync return self.mgr.platform.getSessionObject(vbox)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncclass VirtualBoxManager:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def __init__(self, style, platparams):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync if style is None:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync if sys.platform == 'win32':
08122b11035de1e54ce1e665dff7260fc548db72vboxsync style = "MSCOM"
08122b11035de1e54ce1e665dff7260fc548db72vboxsync else:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync style = "XPCOM"
08122b11035de1e54ce1e665dff7260fc548db72vboxsync try:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync exec "self.platform = Platform"+style+"(platparams)"
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync
c65e2fedaf400b449a85ae6db7b84858f2613708vboxsync self.constants = VirtualBoxReflectionInfo()
08122b11035de1e54ce1e665dff7260fc548db72vboxsync self.type = self.platform.getType()
08122b11035de1e54ce1e665dff7260fc548db72vboxsync self.remote = self.platform.getRemote()
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync self.style = style
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync self.mgr = SessionManager(self)
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync self.vbox = self.platform.getVirtualBox()
08122b11035de1e54ce1e665dff7260fc548db72vboxsync except Exception,e:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync print "init exception: ",e
08122b11035de1e54ce1e665dff7260fc548db72vboxsync traceback.print_exc()
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync if self.remote:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync self.vbox = None
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync else:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync raise e
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getArray(self, obj, field):
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync return self.platform.getArray(obj, field)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getVirtualBox(self):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return self.platform.getVirtualBox()
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def __del__(self):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync self.deinit()
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def deinit(self):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync if hasattr(self, "vbox"):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync del self.vbox
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync self.vbox = None
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync if hasattr(self, "platform"):
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync self.platform.deinit()
e8061cc98e3d41ea42f0f835db3501d58c26e7fbvboxsync self.platform = None
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync def initPerThread(self):
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync self.platform.initPerThread()
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync
1a9a9af4ac32622963b734736acbe9c79411f138vboxsync def openMachineSession(self, machineId):
1a9a9af4ac32622963b734736acbe9c79411f138vboxsync session = self.mgr.getSessionObject(self.vbox)
1a9a9af4ac32622963b734736acbe9c79411f138vboxsync self.vbox.openSession(session, machineId)
1a9a9af4ac32622963b734736acbe9c79411f138vboxsync return session
1a9a9af4ac32622963b734736acbe9c79411f138vboxsync
1a9a9af4ac32622963b734736acbe9c79411f138vboxsync def closeMachineSession(self, session):
1a9a9af4ac32622963b734736acbe9c79411f138vboxsync session.close()
1a9a9af4ac32622963b734736acbe9c79411f138vboxsync
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync def deinitPerThread(self):
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync self.platform.deinitPerThread()
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync
3acd338a7a2154c8d73de9a2629bc7057b051334vboxsync def createCallback(self, iface, impl, arg):
3acd338a7a2154c8d73de9a2629bc7057b051334vboxsync return self.platform.createCallback(iface, impl, arg)
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def waitForEvents(self, timeout):
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync return self.platform.waitForEvents(timeout)
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync def getPerfCollector(self, vbox):
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync return PerfCollector(vbox)