vboxapi.py revision 29179bad4ddd202d265455fed7c5eae723859a8e
5f40efb5cd27c6ff21ca70bf3271564e7e79e3a4vboxsync#
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync# Copyright (C) 2009 Oracle Corporation
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#
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncimport sys,os
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncimport traceback
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
b5b8f3d0d95893edd81062c1b5d0bc455cc79bc1vboxsync# To set Python bitness on OSX use 'export VERSIONER_PYTHON_PREFER_32_BIT=yes'
b5b8f3d0d95893edd81062c1b5d0bc455cc79bc1vboxsync
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:
b5b8f3d0d95893edd81062c1b5d0bc455cc79bc1vboxsync # Will be set by the installer
b5b8f3d0d95893edd81062c1b5d0bc455cc79bc1vboxsync VboxSdkDir = "%VBOX_SDK_PATH%"
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
aaa80e9df329609078dea844a11f2611443b677avboxsync def __init__(self, mgr, vbox):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """ Initializes the instance.
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync """
aaa80e9df329609078dea844a11f2611443b677avboxsync self.mgr = mgr
08e715a5fb97536a462b199124a0c6e925cfa76cvboxsync self.isMscom = (mgr.type == 'MSCOM')
aaa80e9df329609078dea844a11f2611443b677avboxsync self.collector = vbox.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 """
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync # Get around the problem with input arrays returned in output
aaa80e9df329609078dea844a11f2611443b677avboxsync # parameters (see #3953) for MSCOM.
aaa80e9df329609078dea844a11f2611443b677avboxsync if self.isMscom:
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):
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync return name[0].capitalize()+name[1:]
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync_COMForward = { 'getattr' : None,
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync 'setattr' : None}
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync
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
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync
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 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__']
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync DispatchBaseClass.__dict__['__getattr__'] = CustomGetAttr
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync _COMForward['setattr'] = DispatchBaseClass.__dict__['__setattr__']
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync DispatchBaseClass.__dict__['__setattr__'] = CustomSetAttr
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync win32com.client.gencache.EnsureDispatch('VirtualBox.Session')
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBox')
5c57f3ae389a4fd2d1614c2a02a52bc7d56ee7b5vboxsync win32com.client.gencache.EnsureDispatch('VirtualBox.CallbackWrapper')
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync def getSessionObject(self, vbox):
da570ef57fe454ae2d9d5d88a7bfea214723dbb1vboxsync import win32com
08122b11035de1e54ce1e665dff7260fc548db72vboxsync from win32com.client import Dispatch
1d96c25e994a2160c1697208bb398d79ca117c4avboxsync return win32com.client.Dispatch("VirtualBox.Session")
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getVirtualBox(self):
1d96c25e994a2160c1697208bb398d79ca117c4avboxsync import win32com
08122b11035de1e54ce1e665dff7260fc548db72vboxsync from win32com.client import Dispatch
2ea0ec406117609d51bd5ac51cbb3d4f0de9a16dvboxsync return win32com.client.Dispatch("VirtualBox.VirtualBox")
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
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 pythoncom\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"
17c83edfe874290c12f93dd01ee0302045b5a659vboxsync str += " _reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER\n"
17c83edfe874290c12f93dd01ee0302045b5a659vboxsync # Maybe we'd better implement Dynamic invoke policy, to be more flexible here
17c83edfe874290c12f93dd01ee0302045b5a659vboxsync str += " _reg_policy_spec_ = 'win32com.server.policy.EventHandlerPolicy'\n"
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync
70fc3227c8df64856d2282ee60fee11fe35cd5devboxsync # generate capitalized version of callback methods -
5c57f3ae389a4fd2d1614c2a02a52bc7d56ee7b5vboxsync # that's how Python COM looks them up
0637d4d8793a5ce81c481f2cac4a8daf0fb91683vboxsync for m in dir(impl):
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync if m.startswith("on"):
bf3b45b409e14f2fde6b2bdde95332c45fd72d46vboxsync str += " "+ComifyName(m)+"=BaseClass."+m+"\n"
0637d4d8793a5ce81c481f2cac4a8daf0fb91683vboxsync
3acd338a7a2154c8d73de9a2629bc7057b051334vboxsync str += " def __init__(self): BaseClass.__init__(self, arg)\n"
5c57f3ae389a4fd2d1614c2a02a52bc7d56ee7b5vboxsync str += "result = win32com.client.Dispatch('VirtualBox.CallbackWrapper')\n"
17c83edfe874290c12f93dd01ee0302045b5a659vboxsync str += "result.SetLocalObject(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
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync def interruptWaitEvents(self):
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync from win32api import PostThreadMessage
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync from win32con import WM_USER
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync PostThreadMessage(self.tid, WM_USER, None, None)
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync
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
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 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):
5c57f3ae389a4fd2d1614c2a02a52bc7d56ee7b5vboxsync import xpcom
5c57f3ae389a4fd2d1614c2a02a52bc7d56ee7b5vboxsync xpcom._xpcom.AttachThread()
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync def deinitPerThread(self):
5c57f3ae389a4fd2d1614c2a02a52bc7d56ee7b5vboxsync import xpcom
5c57f3ae389a4fd2d1614c2a02a52bc7d56ee7b5vboxsync xpcom._xpcom.DetachThread()
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"
d879e0dbc8f0a06aea09adc18f3be9711918bd19vboxsync str += "result = xpcom.components.classes['@virtualbox.org/CallbackWrapper;1'].createInstance()\n"
70fc3227c8df64856d2282ee60fee11fe35cd5devboxsync str += "result.setLocalObject("+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
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync def interruptWaitEvents(self):
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync import xpcom
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync xpcom._xpcom.InterruptWait()
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def deinit(self):
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync import xpcom
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync xpcom._xpcom.DeinitCOM()
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncclass PlatformWEBSERVICE:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def __init__(self, params):
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync sys.path.append(os.path.join(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
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync
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
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync self.vbox = None
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync def getSessionObject(self, vbox):
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync return self.wsmgr.getSessionObject(vbox)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getVirtualBox(self):
355edde34018a687b4a4d17054c378b780e3d8abvboxsync return self.connect(self.url, self.user, self.password)
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync def connect(self, url, user, passwd):
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync if self.vbox is not None:
355edde34018a687b4a4d17054c378b780e3d8abvboxsync self.disconnect()
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync from VirtualBox_wrappers import IWebsessionManager2
355edde34018a687b4a4d17054c378b780e3d8abvboxsync if url is None:
355edde34018a687b4a4d17054c378b780e3d8abvboxsync url = ""
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)
355edde34018a687b4a4d17054c378b780e3d8abvboxsync if not self.vbox.handle:
355edde34018a687b4a4d17054c378b780e3d8abvboxsync raise Exception("cannot connect to '"+self.url+"' as '"+self.user+"'")
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 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
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync def interruptWaitEvents(self, timeout):
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync # Webservices cannot do that yet
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync pass
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def deinit(self):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync try:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync disconnect()
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync except:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync pass
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
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"
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync
760ec8be64fa28d2bc7f493d707385c757a12e8evboxsync exec "self.platform = Platform"+style+"(platparams)"
760ec8be64fa28d2bc7f493d707385c757a12e8evboxsync # for webservices, enums are symbolic
760ec8be64fa28d2bc7f493d707385c757a12e8evboxsync self.constants = VirtualBoxReflectionInfo(style == "WEBSERVICE")
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync self.type = self.platform.getType()
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync self.remote = self.platform.getRemote()
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync self.style = style
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync self.mgr = SessionManager(self)
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync try:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync self.vbox = self.platform.getVirtualBox()
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync except NameError,ne:
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync print "Installation problem: check that appropriate libs in place"
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync traceback.print_exc()
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync raise ne
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)
29179bad4ddd202d265455fed7c5eae723859a8evboxsync try:
29179bad4ddd202d265455fed7c5eae723859a8evboxsync self.vbox.openExistingSession(session, machineId)
29179bad4ddd202d265455fed7c5eae723859a8evboxsync except:
29179bad4ddd202d265455fed7c5eae723859a8evboxsync self.vbox.openSession(session, machineId)
1a9a9af4ac32622963b734736acbe9c79411f138vboxsync return session
1a9a9af4ac32622963b734736acbe9c79411f138vboxsync
1a9a9af4ac32622963b734736acbe9c79411f138vboxsync def closeMachineSession(self, session):
29179bad4ddd202d265455fed7c5eae723859a8evboxsync if session is not None:
29179bad4ddd202d265455fed7c5eae723859a8evboxsync 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
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync def interruptWaitEvents(self):
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync return self.platform.interruptWaitEvents()
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync def getPerfCollector(self, vbox):
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync return PerfCollector(self, vbox)
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync def getBinDir(self):
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync global VboxBinDir
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync return VboxBinDir
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync def getSdkDir(self):
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync global VboxSdkDir
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync return VboxSdkDir