vboxapi.py revision 0ad756e595c9bb21b406d2b8f608ca778f2c1df3
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# -*- coding: utf-8 -*-
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# $Id$
e35e9d6317da2985728e7510bea9337b9893b66evboxsync"""
e35e9d6317da2985728e7510bea9337b9893b66evboxsyncVirtualBox Python API Glue.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync"""
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync__copyright__ = \
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsync"""
b844a5645b69a09c4d6dacb9cfe96bb138cb21d4vboxsyncCopyright (C) 2009-2013 Oracle Corporation
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsync
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsyncThis file is part of VirtualBox Open Source Edition (OSE), as
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsyncavailable from http://www.virtualbox.org. This file is free software;
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsyncyou can redistribute it and/or modify it under the terms of the GNU
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsyncGeneral Public License (GPL) as published by the Free Software
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsyncFoundation, in version 2 as it comes in the "COPYING" file of the
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsyncVirtualBox OSE distribution. VirtualBox OSE is distributed in the
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsynchope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsync"""
e35e9d6317da2985728e7510bea9337b9893b66evboxsync__version__ = "$Revision$"
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# Note! To set Python bitness on OSX use 'export VERSIONER_PYTHON_PREFER_32_BIT=yes'
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# Standard Python imports.
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsyncimport sys, os
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncimport traceback
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
b5b8f3d0d95893edd81062c1b5d0bc455cc79bc1vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# Globals, environment and sys.path changes.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsyncVBoxBinDir = os.environ.get("VBOX_PROGRAM_PATH", None)
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsyncVBoxSdkDir = os.environ.get("VBOX_SDK_PATH", None)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsyncif VBoxBinDir is None:
2561352ae77d8f2f825526a6cbafa34b45f16972vboxsync # Will be set by the installer
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync VBoxBinDir = "%VBOX_INSTALL_PATH%"
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsyncif VBoxSdkDir is None:
b5b8f3d0d95893edd81062c1b5d0bc455cc79bc1vboxsync # Will be set by the installer
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync VBoxSdkDir = "%VBOX_SDK_PATH%"
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsyncos.environ["VBOX_PROGRAM_PATH"] = VBoxBinDir
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsyncos.environ["VBOX_SDK_PATH"] = VBoxSdkDir
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsyncsys.path.append(VBoxBinDir)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# Import the generated VirtualBox constants.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#
c65e2fedaf400b449a85ae6db7b84858f2613708vboxsyncfrom VirtualBox_constants import VirtualBoxReflectionInfo
c65e2fedaf400b449a85ae6db7b84858f2613708vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsyncclass PerfCollector(object):
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
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# Attribute hacks.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsyncdef ComifyName(name):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return name[0].capitalize() + name[1:]
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync## This is for saving the original DispatchBaseClass __getattr__ and __setattr__
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# method references.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync_g_dCOMForward = {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync 'getattr': None,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync 'setattr': None,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync}
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsyncdef _CustomGetAttr(self, sAttr):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """ Our getattr replacement for DispatchBaseClass. """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Fastpath.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oRet = self.__class__.__dict__.get(sAttr);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if oRet != None:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return oRet;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Try case-insensitivity workaround for class attributes (COM methods).
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync sAttrLower = sAttr.lower();
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync for sKey in self.__class__.__dict__.keys():
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if sKey.lower() == sAttrLower:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync self.__class__.__dict__[sAttr] = self.__class__.__dict__[sKey]
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return getattr(self, sKey)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Slow path.
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync try:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return _g_dCOMForward['getattr'](self, ComifyName(sAttr))
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync except AttributeError:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return _g_dCOMForward['getattr'](self, sAttr)
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsyncdef _CustomSetAttr(self, sAttr, oValue):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """ Our setattr replacement for DispatchBaseClass. """
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync try:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return _g_dCOMForward['setattr'](self, ComifyName(sAttr), oValue)
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync except AttributeError:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return _g_dCOMForward['setattr'](self, sAttr, oValue)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsyncclass PlatformBase(object):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Base class for the platform specific code.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def __init__(self, aoParams):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _ = aoParams;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def getVirtualBox(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Gets a the IVirtualBox singleton.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return None;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def getSessionObject(self, oIVBox):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Get a session object that can be used for opening machine sessions.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync The oIVBox parameter is an getVirtualBox() return value, i.e. an
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IVirtualBox reference.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync See also openMachineSession.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _ = oIVBox;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return None;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def getType(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ Returns the platform type (class name sans 'Platform'). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return None;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def isRemote(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Returns True if remote (web services) and False if local (COM/XPCOM).
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return False
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def getArray(self, oInterface, sAttrib):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Retrives the value of the array attribute 'sAttrib' from
e35e9d6317da2985728e7510bea9337b9893b66evboxsync interface 'oInterface'.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync This is for hiding platform specific differences in attributes
e35e9d6317da2985728e7510bea9337b9893b66evboxsync returning arrays.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _ = oInterface;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _ = sAttrib;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return None;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def initPerThread(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Does backend specific initialization for the calling thread.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return True;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def deinitPerThread(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Does backend specific uninitialization for the calling thread.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return True;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def createListener(self, oImplClass, dArgs):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Instantiates and wraps an active event listener class so it can be
e35e9d6317da2985728e7510bea9337b9893b66evboxsync passed to an event source for registration.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync oImplClass is a class (type, not instance) which implements
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IEventListener.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync dArgs is a dictionary with string indexed variables. This may be
e35e9d6317da2985728e7510bea9337b9893b66evboxsync modified by the method to pass platform specific parameters. Can
e35e9d6317da2985728e7510bea9337b9893b66evboxsync be None.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync This currently only works on XPCOM. COM support is not possible due to
e35e9d6317da2985728e7510bea9337b9893b66evboxsync shortcuts taken in the COM bridge code, which is not under our control.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Use passive listeners for COM and web services.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _ = oImplClass;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _ = dArgs;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync raise Exception("No active listeners for this platform");
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return None;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def waitForEvents(self, cMsTimeout):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Wait for events to arrive and process them.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync The timeout (cMsTimeout) is in milliseconds for how long to wait for
e35e9d6317da2985728e7510bea9337b9893b66evboxsync events to arrive. A negative value means waiting for ever, while 0
e35e9d6317da2985728e7510bea9337b9893b66evboxsync does not wait at all.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Returns 0 if events was processed.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Returns 1 if timed out or interrupted in some way.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Returns 2 on error (like not supported for web services).
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Raises an exception if the calling thread is not the main thread (the one
e35e9d6317da2985728e7510bea9337b9893b66evboxsync that initialized VirtualBoxManager) or if the time isn't an integer.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _ = cMsTimeout;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return 2;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def interruptWaitEvents(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Interrupt a waitForEvents call.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync This is normally called from a worker thread to wake up the main thread.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Returns True on success, False on failure.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return False;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def deinit(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Unitializes the platform specific backend.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return None;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def queryInterface(self, oIUnknown, sClassName):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IUnknown::QueryInterface wrapper.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync oIUnknown is who to ask.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync sClassName is the name of the interface we're asking for.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return None;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync #
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Error (exception) access methods.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync #
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errGetStatus(self, oXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns the COM status code from the VBox API given exception.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return None;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errIsDeadInterface(self, oXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns True if the exception indicates that the interface is dead, False if not.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return False;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errIsEqual(oXcpt, hrStatus):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Checks if the exception oXcpt is equal to the COM/XPCOM status code
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync hrStatus.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync The oXcpt parameter can be any kind of object, we'll just return True
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if it doesn't behave like a our exception class.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Will not raise any exception as long as hrStatus and self are not bad.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync try:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync hrXcpt = self.errGetStatus(oXcpt);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync except AttributeError:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return False;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return hrXcpt == hrStatus;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errGetMessage(self, oXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns the best error message found in the COM-like exception.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns None to fall back on errToString.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Raises exception if oXcpt isn't our kind of exception object.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return None;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errGetBaseXcpt(self):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns the base exception class.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return None;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errSetupConstants(self, oDst):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Copy/whatever all error constants onto oDst.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return oDst;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync @staticmethod
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errCopyErrorConstants(oDst, oSrc):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Copy everything that looks like error constants from oDst to oSrc.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync for sAttr in dir(oSrc):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if sAttr[0].isupper() and (sAttr[1].isupper() or sAttr[1] == '_'):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oAttr = getattr(oSrc, sAttr);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if type(oAttr) is int:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync setattr(oDst, sAttr, oAttr);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return oDst;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsyncclass PlatformMSCOM(PlatformBase):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Platform specific code for MS COM.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync ## @name VirtualBox COM Typelib definitions (should be generate)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync #
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # @remarks Must be updated when the corresponding VirtualBox.xidl bits
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # are changed. Fortunately this isn't very often.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # @{
e35e9d6317da2985728e7510bea9337b9893b66evboxsync VBOX_TLB_GUID = '{D7569351-1750-46F0-936E-BD127D5BC264}'
e35e9d6317da2985728e7510bea9337b9893b66evboxsync VBOX_TLB_LCID = 0
e35e9d6317da2985728e7510bea9337b9893b66evboxsync VBOX_TLB_MAJOR = 1
e35e9d6317da2985728e7510bea9337b9893b66evboxsync VBOX_TLB_MINOR = 3
e35e9d6317da2985728e7510bea9337b9893b66evboxsync ## @}
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync class ConstantFake(object):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ Class to fake access to constants in style of foo.bar.boo """
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync
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)
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync 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)
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync except AttributeError, e:
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return self.__dict__['_rootFake'].__getattr__(a)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def __init__(self, dParams):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync PlatformBase.__init__(self, dParams);
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync #
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Since the code runs on all platforms, we have to do a lot of
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # importing here instead of at the top of the file where it's normally located.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync #
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync from win32com import universal
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync from win32com.client import gencache, DispatchBaseClass
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync from win32com.client import constants, getevents
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync import win32com
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync import pythoncom
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync import win32api
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync import winerror
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync from win32con import DUPLICATE_SAME_ACCESS
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync from win32api import GetCurrentThread, GetCurrentThreadId, DuplicateHandle, GetCurrentProcess
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync import threading
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync self.winerror = winerror;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync pid = GetCurrentProcess()
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync self.tid = GetCurrentThreadId()
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync handle = DuplicateHandle(pid, GetCurrentThread(), pid, 0, 0, DUPLICATE_SAME_ACCESS)
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync self.handles = []
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync self.handles.append(handle)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Hack the COM dispatcher base class so we can modify method and
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # attribute names to match those in xpcom.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if _g_dCOMForward['setattr'] is None:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _g_dCOMForward['getattr'] = DispatchBaseClass.__dict__['__getattr__']
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync DispatchBaseClass.__dict__['__getattr__'] = _CustomGetAttr
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _g_dCOMForward['setattr'] = DispatchBaseClass.__dict__['__setattr__']
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync DispatchBaseClass.__dict__['__setattr__'] = _CustomSetAttr
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Hack the exception base class so the users doesn't need to check for
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # XPCOM or COM and do different things.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync ## @todo
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync win32com.client.gencache.EnsureDispatch('VirtualBox.Session')
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBox')
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync self.oIntCv = threading.Condition()
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync self.fInterrupted = False;
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _ = dParams;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def getSessionObject(self, oIVBox):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _ = oIVBox
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
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def getArray(self, oInterface, sAttrib):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return oInterface.__getattr__(sAttrib)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync def initPerThread(self):
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync import pythoncom
1d27f9d208503988168cd9a8a902a0f48cf52a12vboxsync pythoncom.CoInitializeEx(0)
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync def deinitPerThread(self):
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync import pythoncom
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync pythoncom.CoUninitialize()
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def createListener(self, oImplClass, dArgs):
989c8375a95357db2bd39e0897fdcb218e749b30vboxsync if True:
989c8375a95357db2bd39e0897fdcb218e749b30vboxsync raise Exception('no active listeners on Windows as PyGatewayBase::QueryInterface() '
989c8375a95357db2bd39e0897fdcb218e749b30vboxsync 'returns new gateway objects all the time, thus breaking EventQueue '
989c8375a95357db2bd39e0897fdcb218e749b30vboxsync 'assumptions about the listener interface pointer being constants between calls ');
989c8375a95357db2bd39e0897fdcb218e749b30vboxsync # Did this code ever really work?
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync d = {}
e35e9d6317da2985728e7510bea9337b9893b66evboxsync d['BaseClass'] = oImplClass
e35e9d6317da2985728e7510bea9337b9893b66evboxsync d['dArgs'] = dArgs
e35e9d6317da2985728e7510bea9337b9893b66evboxsync d['tlb_guid'] = PlatformMSCOM.VBOX_TLB_GUID
b844a5645b69a09c4d6dacb9cfe96bb138cb21d4vboxsync d['tlb_major'] = PlatformMSCOM.VBOX_TLB_MAJOR
b844a5645b69a09c4d6dacb9cfe96bb138cb21d4vboxsync d['tlb_minor'] = PlatformMSCOM.VBOX_TLB_MINOR
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str = ""
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += "import win32com.server.util\n"
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += "import pythoncom\n"
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += "class ListenerImpl(BaseClass):\n"
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += " _com_interfaces_ = ['IEventListener']\n"
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += " _typelib_guid_ = tlb_guid\n"
b844a5645b69a09c4d6dacb9cfe96bb138cb21d4vboxsync str += " _typelib_version_ = tlb_major, tlb_minor\n"
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += " _reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER\n"
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync # Maybe we'd better implement Dynamic invoke policy, to be more flexible here
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += " _reg_policy_spec_ = 'win32com.server.policy.EventHandlerPolicy'\n"
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync
dafcc1aee6fa9a280e6c6d7630132e5a778f3a6fvboxsync # capitalized version of listener method
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += " HandleEvent=BaseClass.handleEvent\n"
e35e9d6317da2985728e7510bea9337b9893b66evboxsync str += " def __init__(self): BaseClass.__init__(self, dArgs)\n"
4bb0fd45b2679a58b304ba2d7bff3e19b74a447fvboxsync str += "result = win32com.server.util.wrap(ListenerImpl())\n"
e35e9d6317da2985728e7510bea9337b9893b66evboxsync exec(str, d, d)
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync return d['result']
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def waitForEvents(self, timeout):
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync from win32api import GetCurrentThreadId
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync from win32event import INFINITE
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync from win32event import MsgWaitForMultipleObjects, \
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync QS_ALLINPUT, WAIT_TIMEOUT, WAIT_OBJECT_0
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync from pythoncom import PumpWaitingMessages
e9802cd9ee289e494f01f2c37e714911d120cd30vboxsync import types
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync
e9802cd9ee289e494f01f2c37e714911d120cd30vboxsync if not isinstance(timeout, types.IntType):
e9802cd9ee289e494f01f2c37e714911d120cd30vboxsync raise TypeError("The timeout argument is not an integer")
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync if (self.tid != GetCurrentThreadId()):
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync raise Exception("wait for events from the same thread you inited!")
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync if timeout < 0:
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync cMsTimeout = INFINITE
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync else:
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync cMsTimeout = timeout
e9802cd9ee289e494f01f2c37e714911d120cd30vboxsync rc = MsgWaitForMultipleObjects(self.handles, 0, cMsTimeout, QS_ALLINPUT)
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync if rc >= WAIT_OBJECT_0 and rc < WAIT_OBJECT_0+len(self.handles):
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync # is it possible?
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync rc = 2;
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync elif rc==WAIT_OBJECT_0 + len(self.handles):
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync # Waiting messages
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync PumpWaitingMessages()
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync rc = 0;
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync else:
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync # Timeout
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync rc = 1;
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync # check for interruption
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync self.oIntCv.acquire()
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync if self.fInterrupted:
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync self.fInterrupted = False
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync rc = 1;
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync self.oIntCv.release()
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync return rc;
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync def interruptWaitEvents(self):
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Basically a python implementation of NativeEventQueue::postEvent().
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync The magic value must be in sync with the C++ implementation or this
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync won't work.
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync Note that because of this method we cannot easily make use of a
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync non-visible Window to handle the message like we would like to do.
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync """
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync from win32api import PostThreadMessage
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync from win32con import WM_USER
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync self.oIntCv.acquire()
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync self.fInterrupted = True
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync self.oIntCv.release()
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync try:
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync PostThreadMessage(self.tid, WM_USER, None, 0xf241b819)
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync except:
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync return False;
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync return True;
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
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def queryInterface(self, oIUnknown, sClassName):
ced49ddf2480e97120d7bb28cd774ab609047875vboxsync from win32com.client import CastTo
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return CastTo(oIUnknown, sClassName)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errGetStatus(self, oXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # The DISP_E_EXCEPTION + excptinfo fun needs checking up, only
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # empirical info on it so far.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync hrXcpt = oXcpt.hresult
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if hrXcpt == self.winerror.DISP_E_EXCEPTION:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync try: hrXcpt = oXcpt.excepinfo[5];
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync except: pass;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return hrXcpt;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errIsDeadInterface(self, oXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return self.errGetStatus(oXcpt) in [
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync 0x800706ba, -2147023174, # RPC_S_SERVER_UNAVAILABLE.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync 0x800706be, -2147023170, # RPC_S_CALL_FAILED.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync 0x800706bf, -2147023169, # RPC_S_CALL_FAILED_DNE.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync 0x80010108, -2147417848, # RPC_E_DISCONNECTED.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ];
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errGetMessage(self, oXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if hasattr(oXcpt, 'excepinfo'):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync try:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if len(oXcpt.excepinfo) >= 3:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync sRet = oXcpt.excepinfo[2];
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if len(sRet) > 0:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return sRet[0:];
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync except:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync pass;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if hasattr(oXcpt, 'strerror'):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync try:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync sRet = oXcpt.strerror;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if len(sRet) > 0:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return sRet;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync except:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync pass;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return None;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errGetBaseXcpt(self):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync import pythoncom;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return pythoncom.com_error;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errSetupConstants(self, oDst):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync import winerror;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst = self.errCopyErrorConstants(oDst, winerror);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # XPCOM compatability constants.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.NS_OK = oDst.S_OK;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.NS_ERROR_FAILURE = oDst.E_FAIL;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.NS_ERROR_ABORT = oDst.E_ABORT;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.NS_ERROR_NULL_POINTER = oDst.E_POINTER;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.NS_ERROR_NO_INTERFACE = oDst.E_NOINTERFACE;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.NS_ERROR_INVALID_ARG = oDst.E_INVALIDARG;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.NS_ERROR_OUT_OF_MEMORY = oDst.E_OUTOFMEMORY;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.NS_ERROR_NOT_IMPLEMENTED = oDst.E_NOTIMPL;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.NS_ERROR_UNEXPECTED = oDst.E_UNEXPECTED;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return oDst;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsyncclass PlatformXPCOM(PlatformBase):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Platform specific code for XPCOM.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def __init__(self, dParams):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync PlatformBase.__init__(self, dParams);
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync sys.path.append(VBoxSdkDir+'/bindings/xpcom/python/')
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import xpcom.vboxxpcom
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import xpcom
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import xpcom.components
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _ = dParams;
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def getSessionObject(self, oIVBox):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync _ = oIVBox;
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
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def getArray(self, oInterface, sAttrib):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return oInterface.__getattr__('get'+ComifyName(sAttrib))()
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
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def createListener(self, oImplClass, dArgs):
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync d = {}
e35e9d6317da2985728e7510bea9337b9893b66evboxsync d['BaseClass'] = oImplClass
e35e9d6317da2985728e7510bea9337b9893b66evboxsync d['dArgs'] = dArgs
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str = ""
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += "import xpcom.components\n"
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += "class ListenerImpl(BaseClass):\n"
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += " _com_interfaces_ = xpcom.components.interfaces.IEventListener\n"
e35e9d6317da2985728e7510bea9337b9893b66evboxsync str += " def __init__(self): BaseClass.__init__(self, dArgs)\n"
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync str += "result = ListenerImpl()\n"
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync exec (str, d, d)
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync return d['result']
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def waitForEvents(self, timeout):
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync import xpcom
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync return xpcom._xpcom.WaitForEvents(timeout)
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync def interruptWaitEvents(self):
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync import xpcom
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync return xpcom._xpcom.InterruptWait()
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def deinit(self):
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync import xpcom
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync xpcom._xpcom.DeinitCOM()
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def queryInterface(self, oIUnknown, sClassName):
8532fcd8b260a1648f09ab3df65e5353aa148825vboxsync import xpcom.components
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return oIUnknown.queryInterface(getattr(xpcom.components.interfaces, sClassName))
8532fcd8b260a1648f09ab3df65e5353aa148825vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errGetStatus(self, oXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return oXcpt.errno;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errIsDeadInterface(self, oXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return self.errGetStatus(oXcpt) in [
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync 0x80004004, -2147467260, # NS_ERROR_ABORT
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync 0x800706be, -2147023170, # NS_ERROR_CALL_FAILED (RPC_S_CALL_FAILED)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ];
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errGetMessage(self, oXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if hasattr(oXcpt, 'msg'):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync try:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync sRet = oXcpt.msg;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if len(sRet) > 0:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return sRet;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync except:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync pass;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return None;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errGetBaseXcpt(self):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync import xpcom;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return xpcom.Exception;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errSetupConstants(self, oDst):
0ad756e595c9bb21b406d2b8f608ca778f2c1df3vboxsync import xpcom;
0ad756e595c9bb21b406d2b8f608ca778f2c1df3vboxsync oDst = self.errCopyErrorConstants(oDst, xpcom.nsError);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # COM compatability constants.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.E_ACCESSDENIED = -2147024891; # see VBox/com/defs.h
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.S_OK = oDst.NS_OK;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.E_FAIL = oDst.NS_ERROR_FAILURE;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.E_ABORT = oDst.NS_ERROR_ABORT;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.E_POINTER = oDst.NS_ERROR_NULL_POINTER;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.E_NOINTERFACE = oDst.NS_ERROR_NO_INTERFACE;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.E_INVALIDARG = oDst.NS_ERROR_INVALID_ARG;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.E_OUTOFMEMORY = oDst.NS_ERROR_OUT_OF_MEMORY;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.E_NOTIMPL = oDst.NS_ERROR_NOT_IMPLEMENTED;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.E_UNEXPECTED = oDst.NS_ERROR_UNEXPECTED;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oDst.DISP_E_EXCEPTION = -2147352567; # For COM compatability only.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return oDst;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsyncclass PlatformWEBSERVICE(PlatformBase):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync VirtualBox Web Services API specific code.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def __init__(self, dParams):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync PlatformBase.__init__(self, dParams);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Import web services stuff. Fix the sys.path the first time.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync sWebServLib = os.path.join(VBoxSdkDir, 'bindings', 'webservice', 'python', 'lib');
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if sWebServLib not in sys.path:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync sys.path.append(sWebServLib);
08122b11035de1e54ce1e665dff7260fc548db72vboxsync import VirtualBox_wrappers
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync from VirtualBox_wrappers import IWebsessionManager2
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Initialize instance variables from parameters.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if dParams is not None:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.user = dParams.get("user", "")
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.password = dParams.get("password", "")
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.url = dParams.get("url", "")
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync else:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.user = ""
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync self.password = ""
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.url = None
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.vbox = None
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.wsmgr = None;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync #
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Base class overrides.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync #
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def getSessionObject(self, oIVBox):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return self.wsmgr.getSessionObject(oIVBox)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getVirtualBox(self):
355edde34018a687b4a4d17054c378b780e3d8abvboxsync return self.connect(self.url, self.user, self.password)
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getType(self):
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return 'WEBSERVICE'
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def isRemote(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ Returns True if remote VBox host, False if local. """
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return True
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def getArray(self, oInterface, sAttrib):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return oInterface.__getattr__(sAttrib)
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def waitForEvents(self, timeout):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync # Webservices cannot do that yet
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync return 2;
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync def interruptWaitEvents(self, timeout):
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync # Webservices cannot do that yet
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync return False;
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def deinit(self):
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync try:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync disconnect()
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync except:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync pass
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def queryInterface(self, oIUnknown, sClassName):
ced49ddf2480e97120d7bb28cd774ab609047875vboxsync d = {}
e35e9d6317da2985728e7510bea9337b9893b66evboxsync d['oIUnknown'] = oIUnknown
ced49ddf2480e97120d7bb28cd774ab609047875vboxsync str = ""
e35e9d6317da2985728e7510bea9337b9893b66evboxsync str += "from VirtualBox_wrappers import "+sClassName+"\n"
e35e9d6317da2985728e7510bea9337b9893b66evboxsync str += "result = "+sClassName+"(oIUnknown.mgr, oIUnknown.handle)\n"
8532fcd8b260a1648f09ab3df65e5353aa148825vboxsync # wrong, need to test if class indeed implements this interface
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync exec (str, d, d)
ced49ddf2480e97120d7bb28cd774ab609047875vboxsync return d['result']
8532fcd8b260a1648f09ab3df65e5353aa148825vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync #
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Web service specific methods.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync #
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def connect(self, url, user, passwd):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if self.vbox is not None:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.disconnect()
e35e9d6317da2985728e7510bea9337b9893b66evboxsync from VirtualBox_wrappers import IWebsessionManager2
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if url is None:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync url = ""
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.url = url
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if user is None:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync user = ""
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.user = user
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if passwd is None:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync passwd = ""
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.password = passwd
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.wsmgr = IWebsessionManager2(self.url)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.vbox = self.wsmgr.logon(self.user, self.password)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if not self.vbox.handle:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync raise Exception("cannot connect to '"+self.url+"' as '"+self.user+"'")
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return self.vbox
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def disconnect(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if self.vbox is not None and self.wsmgr is not None:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.wsmgr.logoff(self.vbox)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.vbox = None
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.wsmgr = None
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync## The current (last) exception class.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync# This is reinitalized whenever VirtualBoxManager is called, so it will hold
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync# the reference to the error exception class for the last platform/style that
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync# was used. Most clients does talk to multiple VBox instance on different
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync# platforms at the same time, so this should be sufficent for most uses and
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync# be way simpler to use than VirtualBoxManager::oXcptClass.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsyncCurXctpClass = None;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsyncclass VirtualBoxManager(object):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync VirtualBox API manager class.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync The API users will have to instantiate this. If no parameters are given,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync it will default to interface with the VirtualBox running on the local
e35e9d6317da2985728e7510bea9337b9893b66evboxsync machine. sStyle can be None (default), MSCOM, XPCOM or WEBSERVICES. Most
e35e9d6317da2985728e7510bea9337b9893b66evboxsync users will either be specifying None or WEBSERVICES.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync The dPlatformParams is an optional dictionary for passing parameters to the
e35e9d6317da2985728e7510bea9337b9893b66evboxsync WEBSERVICE backend.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync class Statuses(object):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def __init__(self):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync pass;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def __init__(self, sStyle = None, dPlatformParams = None):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if sStyle is None:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if sys.platform == 'win32':
e35e9d6317da2985728e7510bea9337b9893b66evboxsync sStyle = "MSCOM"
e35e9d6317da2985728e7510bea9337b9893b66evboxsync else:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync sStyle = "XPCOM"
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if sStyle == 'XPCOM':
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.platform = PlatformXPCOM(dPlatformParams);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync elif sStyle == 'MSCOM':
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.platform = PlatformMSCOM(dPlatformParams);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync elif sStyle == 'WEBSERVICE':
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.platform = PlatformWEBSERVICE(dPlatformParams);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync else:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync raise Exception('Unknown sStyle=%s' % (sStyle,));
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.style = sStyle
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.type = self.platform.getType()
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.remote = self.platform.isRemote()
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ## VirtualBox API constants (for webservices, enums are symbolic).
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.constants = VirtualBoxReflectionInfo(sStyle == "WEBSERVICE")
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ## Status constants.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync self.statuses = self.platform.errSetupConstants(VirtualBoxManager.Statuses());
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ## @todo Add VBOX_E_XXX to statuses? They're already in constants...
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ## Dictionary for errToString, built on demand.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync self._dErrorValToName = None;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ## The exception class for the selected platform.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync self.oXcptClass = self.platform.errGetBaseXcpt();
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync global CurXcptClass;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync CurXcptClass = self.oXcptClass;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Get the virtualbox singleton.
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync try:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync self.vbox = self.platform.getVirtualBox()
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync except NameError, ne:
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync print "Installation problem: check that appropriate libs in place"
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync traceback.print_exc()
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync raise ne
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync except Exception, e:
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync print "init exception: ", e
08122b11035de1e54ce1e665dff7260fc548db72vboxsync traceback.print_exc()
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync if self.remote:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync self.vbox = None
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync else:
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync raise e
e35e9d6317da2985728e7510bea9337b9893b66evboxsync ## @deprecated
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # This used to refer to a session manager class with only one method
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # called getSessionObject. The method has moved into this call.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.mgr = self;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def __del__(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.deinit()
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def getPythonApiRevision(self):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns a Python API revision number.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync This will be incremented when features are added to this file.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return 2;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync #
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Wrappers for self.platform methods.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync #
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync def getVirtualBox(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::getVirtualBox(). """
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync return self.platform.getVirtualBox()
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def getSessionObject(self, oIVBox):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::getSessionObject(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return self.platform.getSessionObject(oIVBox);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def getArray(self, oInterface, sAttrib):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::getArray(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return self.platform.getArray(oInterface, sAttrib)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def createListener(self, oImplClass, dArgs = None):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::createListener(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return self.platform.createListener(oImplClass, dArgs)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def waitForEvents(self, cMsTimeout):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::waitForEvents(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return self.platform.waitForEvents(cMsTimeout)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def interruptWaitEvents(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::interruptWaitEvents(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return self.platform.interruptWaitEvents()
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def queryInterface(self, oIUnknown, sClassName):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::queryInterface(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return self.platform.queryInterface(oIUnknown, sClassName)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync #
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Init and uninit.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync #
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def initPerThread(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::deinitPerThread(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync self.platform.initPerThread()
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def deinitPerThread(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """ See PlatformBase::deinitPerThread(). """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return self.platform.deinitPerThread()
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync def deinit(self):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync For unitializing the manager.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Do not access it after calling this method.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
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
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return True;
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync #
e35e9d6317da2985728e7510bea9337b9893b66evboxsync # Utility methods.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync #
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def openMachineSession(self, oIMachine, fPermitSharing = True):
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Attemts to open the a session to the machine.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Returns a session object on success.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Raises exception on failure.
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync oSession = self.mgr.getSessionObject(self.vbox);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if fPermitSharing:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync type = self.constants.LockType_Shared;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync else:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync type = self.constants.LockType_Write;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync oIMachine.lockMachine(oSession, type);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return oSession;
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def closeMachineSession(self, oSession):
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Closes a session opened by openMachineSession.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Ignores None parameters.
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if oSession is not None:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync oSession.unlockMachine()
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return True;
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync def getPerfCollector(self, oIVBox):
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Returns a helper class (PerfCollector) for accessing performance
e35e9d6317da2985728e7510bea9337b9893b66evboxsync collector goodies. See PerfCollector for details.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync """
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return PerfCollector(self, oIVBox)
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync def getBinDir(self):
20606357beeba9ef9025b662f5e3d178dd37d559vboxsync """
20606357beeba9ef9025b662f5e3d178dd37d559vboxsync Returns the VirtualBox binary directory.
20606357beeba9ef9025b662f5e3d178dd37d559vboxsync """
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync global VBoxBinDir
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync return VBoxBinDir
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync def getSdkDir(self):
20606357beeba9ef9025b662f5e3d178dd37d559vboxsync """
20606357beeba9ef9025b662f5e3d178dd37d559vboxsync Returns the VirtualBox SDK directory.
20606357beeba9ef9025b662f5e3d178dd37d559vboxsync """
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync global VBoxSdkDir
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync return VBoxSdkDir
8532fcd8b260a1648f09ab3df65e5353aa148825vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync #
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Error code utilities.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync #
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ## @todo port to webservices!
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errGetStatus(self, oXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Gets the status code from an exception.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return self.platform.errGetStatus(oXcpt);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errIsDeadInterface(self, oXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns True if the exception indicates that the interface is dead, False if not.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return self.platform.errIsDeadInterface(oXcpt);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errIsOurXcptKind(self, oXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Checks if the exception is one that could come from the VBox API.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if self.oXcptClass is None: ## @todo find the exception class for web services!
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return False;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return isinstance(oXcpt, self.oXcptClass);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errIsEqual(self, oXcpt, hrStatus):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """ See PlatformBase::errIsEqual(). """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return self.platform.errIsEqual(oXcpt, hrStatus);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errIsNotEqual(self, oXcpt, hrStatus):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Negated errIsEqual.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return self.errIsEqual(oXcpt, hrStatus);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errToString(self, hrStatusOrXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Converts the specified COM status code, or the status code of the
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync specified exception, to a C constant string.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Deal with exceptions.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if self.errIsOurXcptKind(hrStatusOrXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync hrStatus = self.errGetStatus(hrStatusOrXcpt);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync else:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync hrStatus = hrStatusOrXcpt;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Build the dictionary on demand.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if self._dErrorValToName is None:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync dErrorValToName = dict();
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync for sKey in dir(self.statuses):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if sKey[0].isupper():
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync oValue = getattr(self.statuses, sKey);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if type(oValue) is int:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync dErrorValToName[oValue] = sKey;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync self._dErrorValToName = dErrorValToName;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync # Do the lookup, falling back on formatting the status number.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync try:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync sStr = self._dErrorValToName[int(hrStatus)];
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync except KeyError:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync hrLong = long(hrStatus);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync sStr = '%#x (%d)' % (hrLong, hrLong);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return sStr;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync def errGetMessage(self, oXcpt):
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync Returns the best error message found in the COM-like exception.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync """
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync sRet = self.platform.errGetMessage(oXcpt);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if sRet is None:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync sRet = self.errToString(oXcpt);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync return sRet;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync