/*
* Copyright (C) 2010-2011 Oracle Corporation
*
* This file is part of the VirtualBox SDK, as available from
* http://www.virtualbox.org. This library is free software; you can
* redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation, in version 2.1
* as it comes in the "COPYING.LIB" file of the VirtualBox SDK distribution.
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
*
* DO NOT EDIT! This is a generated file.
* Generated from: src/VBox/Main/idl/VirtualBox.xidl (VirtualBox's interface definitions in XML)
* Generator: src/VBox/Main/glue/glue-java.xsl
*/
(
,
Holder
)
()
{@link
}
#
NOTE:
@see
/**
Expected result codes:
<table>
<tr>
<td>
</td><tr>
</table>
Interface ID: <tt>{
}</tt>
*/
@return
*/
@param value
*/
*/
@return
@param
Interface ID: <tt>{
}</tt>
*/
*/
,
;
private final int value;
value = v;
}
public int value() {
return value;
}
if (c.value == (int)v) {
return c;
}
}
throw new IllegalArgumentException(Long.toString(v));
}
}
IUnknown
void
void
,
void
,
import java.util.List;
import java.util.List;
import java.util.List;
{
public T value;
public Holder()
{
}
public Holder(T value)
{
this.value = value;
}
}
]]>
wrap(byte[] vals) {
if (vals==null)
return null;
List ret = new ArrayList(vals.length);
for (short v : vals) {
ret.add(v);
}
return ret;
}
public static List wrap(int[] vals) {
if (vals==null)
return null;
List ret = new ArrayList(vals.length);
for (int v : vals) {
ret.add(v);
}
return ret;
}
public static List wrap(long[] vals) {
if (vals==null)
return null;
List ret = new ArrayList(vals.length);
for (long v : vals) {
ret.add(v);
}
return ret;
}
public static List wrap(String[] vals) {
if (vals==null)
return null;
List ret = new ArrayList(vals.length);
for (String v : vals) {
ret.add(v);
}
return ret;
}
public static List wrap(Class wrapperClass, T[] thisPtrs) {
if (thisPtrs==null)
return null;
List ret = new ArrayList(thisPtrs.length);
for (T thisPtr : thisPtrs) {
ret.add(thisPtr);
}
return ret;
}
public static List wrapEnum(Class wrapperClass, long values[]) {
try {
if (values==null)
return null;
Constructor c = wrapperClass.getConstructor(int.class);
List ret = new ArrayList(values.length);
for (long v : values) {
ret.add(c.newInstance(v));
}
return ret;
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
}
}
public static short[] unwrapUShort(List vals) {
if (vals==null)
return null;
short[] ret = new short[vals.size()];
int i = 0;
for (short l : vals) {
ret[i++] = l;
}
return ret;
}
public static int[] unwrapInteger(List vals) {
if (vals == null)
return null;
int[] ret = new int[vals.size()];
int i = 0;
for (int l : vals) {
ret[i++] = l;
}
return ret;
}
public static long[] unwrapULong(List vals) {
if (vals == null)
return null;
long[] ret = new long[vals.size()];
int i = 0;
for (long l : vals) {
ret[i++] = l;
}
return ret;
}
public static boolean[] unwrapBoolean(List vals) {
if (vals==null)
return null;
boolean[] ret = new boolean[vals.size()];
int i = 0;
for (boolean l : vals) {
ret[i++] = l;
}
return ret;
}
public static String[] unwrapStr(List vals) {
if (vals==null)
return null;
String[] ret = new String[vals.size()];
int i = 0;
for (String l : vals) {
ret[i++] = l;
}
return ret;
}
public static > long[] unwrapEnum(Class enumClass, List values) {
if (values == null) return null;
long result[] = new long[values.size()];
try {
java.lang.reflect.Method valueM = enumClass.getMethod("value");
int i = 0;
for (T v : values) {
result[i++] = (Integer)valueM.invoke(v);
}
return result;
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch(SecurityException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (IllegalArgumentException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
}
}
public static List wrap2(Class wrapperClass1, Class wrapperClass2, T2[] thisPtrs) {
try {
if (thisPtrs==null)
return null;
Constructor c = wrapperClass1.getConstructor(wrapperClass2);
List ret = new ArrayList(thisPtrs.length);
for (T2 thisPtr : thisPtrs) {
ret.add(c.newInstance(thisPtr));
}
return ret;
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
}
}
@SuppressWarnings( "unchecked")
public static T[] unwrap(Class wrapperClass, List thisPtrs) {
if (thisPtrs==null)
return null;
if (thisPtrs.size() == 0)
return null;
return (T[])thisPtrs.toArray((T[])Array.newInstance(wrapperClass, thisPtrs.size()));
}
@SuppressWarnings( "unchecked" )
public static T queryInterface(Object obj, String uuid, Class iface)
{
return (T)queryInterface(obj, uuid);
}
public static Object queryInterface(Object obj, String uuid)
{
try {
/* Kind of ugly, but does the job of casting */
org.mozilla.xpcom.Mozilla moz = org.mozilla.xpcom.Mozilla.getInstance();
long xpobj = moz.wrapJavaObject(obj, uuid);
return moz.wrapXPCOMObject(xpobj, uuid);
} catch (Exception e) {
return null;
}
}
@SuppressWarnings("unchecked")
public static T2[] unwrap2(Class wrapperClass1, Class wrapperClass2, List thisPtrs) {
if (thisPtrs==null) return null;
T2 ret[] = (T2[])Array.newInstance(wrapperClass2, thisPtrs.size());
int i = 0;
for (T1 obj : thisPtrs) {
ret[i++] = (T2)obj.getWrapped();
}
return ret;
}
}
]]>
= end)
return false;
}
return true;
}
public boolean startVm(String name, String type, int timeout)
{
IMachine m = vbox.findMachine(name);
if (m == null)
return false;
ISession session = getSessionObject();
if (type == null)
type = "gui";
IProgress p = m.launchVMProcess(session, type, "");
progressBar(p, timeout);
session.unlockMachine();
return true;
}
public void waitForEvents(long tmo)
{
mozilla.waitForEvents(tmo);
}
}
]]>
wrap(short[] vals) {
if (vals==null) return null;
if (vals.length == 0) return Collections.emptyList();
List ret = new ArrayList(vals.length);
for (short v : vals) {
ret.add(v);
}
return ret;
}
public static List wrap(int[] vals) {
if (vals == null) return null;
if (vals.length == 0) return Collections.emptyList();
List ret = new ArrayList(vals.length);
for (int v : vals) {
ret.add(v);
}
return ret;
}
public static List wrap(long[] vals) {
if (vals==null) return null;
if (vals.length == 0) return Collections.emptyList();
List ret = new ArrayList(vals.length);
for (long v : vals) {
ret.add(v);
}
return ret;
}
public static List wrap(String[] vals) {
if (vals==null) return null;
if (vals.length == 0) return Collections.emptyList();
List ret = new ArrayList(vals.length);
for (String v : vals) {
ret.add(v);
}
return ret;
}
public static T wrapDispatch(Class wrapperClass, Dispatch d)
{
try {
if (d == null || d.m_pDispatch == 0)
return null;
Constructor c = wrapperClass.getConstructor(Dispatch.class);
return (T)c.newInstance(d);
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
}
}
@SuppressWarnings("unchecked")
public static Object wrapVariant(Class wrapperClass, Variant v)
{
if (v == null)
return null;
short vt = v.getvt();
switch (vt)
{
case Variant.VariantNull:
return null;
case Variant.VariantBoolean:
return v.getBoolean();
case Variant.VariantByte:
return v.getByte();
case Variant.VariantShort:
return v.getShort();
case Variant.VariantInt:
return v.getInt();
case Variant.VariantLongInt:
return v.getLong();
case Variant.VariantString:
return v.getString();
case Variant.VariantDispatch:
return wrapDispatch(wrapperClass, v.getDispatch());
default:
throw new RuntimeException("unhandled variant type "+vt);
}
}
public static byte[] wrapBytes(SafeArray sa) {
if (sa==null) return null;
int saLen = sa.getUBound() - sa.getLBound() + 1;
byte[] ret = new byte[saLen];
int j = 0;
for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
{
Variant v = sa.getVariant(i);
// come upo with more effective approach!!!
ret[j++] = v.getByte();
}
return ret;
}
@SuppressWarnings("unchecked")
public static List wrap(Class wrapperClass, SafeArray sa) {
if (sa==null) return null;
int saLen = sa.getUBound() - sa.getLBound() + 1;
if (saLen == 0) return Collections.emptyList();
List ret = new ArrayList(saLen);
for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
{
Variant v = sa.getVariant(i);
ret.add((T)wrapVariant(wrapperClass, v));
}
return ret;
}
public static List wrapEnum(Class wrapperClass, SafeArray sa) {
try {
if (sa==null) return null;
int saLen = sa.getUBound() - sa.getLBound() + 1;
if (saLen == 0) return Collections.emptyList();
List ret = new ArrayList(saLen);
Constructor c = wrapperClass.getConstructor(int.class);
for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
{
Variant v = sa.getVariant(i);
ret.add(c.newInstance(v.getInt()));
}
return ret;
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
}
}
public static SafeArray unwrapInt(List vals) {
if (vals==null) return null;
SafeArray ret = new SafeArray(Variant.VariantInt, vals.size());
int i = 0;
for (int l : vals) {
ret.setInt(i++, l);
}
return ret;
}
public static SafeArray unwrapLong(List vals) {
if (vals==null) return null;
SafeArray ret = new SafeArray(Variant.VariantLongInt, vals.size());
int i = 0;
for (long l : vals) {
ret.setLong(i++, l);
}
return ret;
}
public static SafeArray unwrapBool(List vals) {
if (vals==null) return null;
SafeArray result = new SafeArray(Variant.VariantBoolean, vals.size());
int i = 0;
for (boolean l : vals) {
result.setBoolean(i++, l);
}
return result;
}
public static SafeArray unwrapBytes(byte[] vals) {
if (vals==null) return null;
SafeArray result = new SafeArray(Variant.VariantByte, vals.length);
int i = 0;
for (byte l : vals) {
result.setByte(i++, l);
}
return result;
}
public static > SafeArray unwrapEnum(Class enumClass, List values) {
if (values == null) return null;
SafeArray result = new SafeArray(Variant.VariantInt, values.size());
try {
java.lang.reflect.Method valueM = enumClass.getMethod("value");
int i = 0;
for (T v : values) {
result.setInt(i++, (Integer)valueM.invoke(v));
}
return result;
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch(SecurityException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (IllegalArgumentException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
}
}
public static SafeArray unwrapString(List vals) {
if (vals==null)
return null;
SafeArray result = new SafeArray(Variant.VariantString, vals.size());
int i = 0;
for (String l : vals) {
result.setString(i++, l);
}
return result;
}
public static List wrap2(Class wrapperClass1, Class wrapperClass2, T2[] thisPtrs) {
try {
if (thisPtrs==null) return null;
if (thisPtrs.length == 0) return Collections.emptyList();
Constructor c = wrapperClass1.getConstructor(wrapperClass2);
List ret = new ArrayList(thisPtrs.length);
for (T2 thisPtr : thisPtrs) {
ret.add(c.newInstance(thisPtr));
}
return ret;
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
}
}
@SuppressWarnings("unchecked")
public static T[] unwrap(Class wrapperClass, List thisPtrs) {
if (thisPtrs==null) return null;
return (T[])thisPtrs.toArray((T[])Array.newInstance(wrapperClass, thisPtrs.size()));
}
@SuppressWarnings("unchecked")
public static T2[] unwrap2(Class wrapperClass1, Class wrapperClass2, List thisPtrs) {
if (thisPtrs==null) return null;
T2 ret[] = (T2[])Array.newInstance(wrapperClass2, thisPtrs.size());
int i = 0;
for (T1 obj : thisPtrs) {
ret[i++] = (T2)obj.getWrapped();
}
return ret;
}
/* We have very long invoke lists sometimes */
public static Variant invoke(Dispatch d, String method, Object ... args)
{
return Dispatch.callN(d, method, args);
}
}
]]>
= end)
return false;
}
return true;
}
public boolean startVm(String name, String type, int timeout)
{
IMachine m = vbox.findMachine(name);
if (m == null)
return false;
ISession session = getSessionObject();
if (type == null)
type = "gui";
IProgress p = m.launchVMProcess(session, type, "");
progressBar(p, timeout);
session.unlockMachine();
return true;
}
public void waitForEvents(long tmo)
{
// what to do here?
try {
Thread.sleep(tmo);
} catch (InterruptedException ie) {
}
}
}
]]>
List wrap(Class wrapperClass, VboxPortType pt, List thisPtrs) {
try {
if(thisPtrs==null) return null;
Constructor c = wrapperClass.getConstructor(String.class, VboxPortType.class);
List ret = new ArrayList(thisPtrs.size());
for (String thisPtr : thisPtrs) {
ret.add(c.newInstance(thisPtr,pt));
}
return ret;
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
}
}
public static List wrap2(Class wrapperClass1, Class wrapperClass2, VboxPortType pt, List thisPtrs) {
try {
if(thisPtrs==null) return null;
Constructor c = wrapperClass1.getConstructor(wrapperClass2, VboxPortType.class);
List ret = new ArrayList(thisPtrs.size());
for (T2 thisPtr : thisPtrs) {
ret.add(c.newInstance(thisPtr,pt));
}
return ret;
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
}
}
public static List unwrap(List thisPtrs) {
if (thisPtrs==null) return null;
List ret = new ArrayList(thisPtrs.size());
for (T obj : thisPtrs) {
ret.add(obj.getWrapped());
}
return ret;
}
@SuppressWarnings("unchecked" )
public static , T2 extends Enum > List convertEnums(Class fromClass,
Class toClass,
List values) {
try {
if (values==null)
return null;
java.lang.reflect.Method fromValue = toClass.getMethod("fromValue", String.class);
List ret = new ArrayList(values.size());
for (T1 v : values) {
// static method is called with null this
ret.add((T2)fromValue.invoke(null, v.name()));
}
return ret;
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
}
}
/* Pretty naive Base64 encoder/decoder. */
private static final char[] valToChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
private static final int[] charToVal = new int[256];
/* Initialize recoding alphabet. */
static
{
for (int i = 0; i < charToVal.length; i++)
charToVal[i] = -1;
for (int i = 0; i < valToChar.length; i++)
charToVal[valToChar[i]] = i;
charToVal['='] = 0;
}
public static String encodeBase64(byte[] data)
{
if (data == null)
return null;
if (data.length == 0)
return "";
int fullTriplets = data.length / 3;
int resultLen = ((data.length - 1) / 3 + 1) * 4;
char[] result = new char[resultLen];
int dataIndex = 0, stringIndex = 0;
for (int i = 0; i < fullTriplets; i++)
{
int ch1 = data[dataIndex++] & 0xff;
result[stringIndex++] = valToChar[ch1 >> 2];
int ch2 = data[dataIndex++] & 0xff;
result[stringIndex++] = valToChar[((ch1 << 4) & 0x3f) | (ch2 >> 4)];
int ch3 = data[dataIndex++] & 0xff;
result[stringIndex++] = valToChar[((ch2 << 2) & 0x3f) | (ch3 >> 6)];
result[stringIndex++] = valToChar[ch3 & 0x3f];
}
switch (data.length - dataIndex)
{
case 0:
// do nothing
break;
case 1:
{
int ch1 = data[dataIndex++] & 0xff;
result[stringIndex++] = valToChar[ch1 >> 2];
result[stringIndex++] = valToChar[(ch1 << 4) & 0x3f];
result[stringIndex++] = '=';
result[stringIndex++] = '=';
break;
}
case 2:
{
int ch1 = data[dataIndex++] & 0xff;
result[stringIndex++] = valToChar[ch1 >> 2];
int ch2 = data[dataIndex++] & 0xff;
result[stringIndex++] = valToChar[((ch1 << 4) & 0x3f) | (ch2 >> 4)];
result[stringIndex++] = valToChar[(ch2 << 2) & 0x3f];
result[stringIndex++] = '=';
break;
}
default:
throw new RuntimeException("bug!");
}
return new String(result);
}
private static int skipInvalid(String str, int stringIndex)
{
while (charToVal[str.charAt(stringIndex)] < 0)
stringIndex++;
return stringIndex;
}
public static byte[] decodeBase64(String str)
{
if (str == null)
return null;
int stringLength = str.length();
if (stringLength == 0)
return new byte[0];
int validChars = 0, padChars = 0;
for (int i = 0; i < str.length(); i++)
{
char ch = str.charAt(i);
if (charToVal[ch] >= 0)
validChars++;
if (ch == '=')
padChars++;
}
if ((validChars * 3 % 4) != 0)
throw new RuntimeException("invalid encoded string "+str);
int resultLength = validChars * 3 / 4 - padChars;
byte[] result = new byte[resultLength];
int dataIndex = 0, stringIndex = 0;
int quadraplets = validChars / 4;
for (int i=0; i> 4) & 0xff);
/* we check this to ensure that we don't override data with '=' padding. */
if (dataIndex < result.length)
result[dataIndex++] = (byte)(((charToVal[ch2] << 4) | charToVal[ch3] >> 2) & 0xff);
if (dataIndex < result.length)
result[dataIndex++] = (byte)(((charToVal[ch3] << 6) | charToVal[ch4]) & 0xff);
}
return result;
}
}
]]>
import java.net.URL;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Holder;
import javax.xml.ws.WebServiceException;
class PortPool
{
private final static String wsdlFile = ;
known;
private boolean initStarted;
private VboxService svc;
PortPool(boolean usePreinit)
{
known = new HashMap();
if (usePreinit)
{
new Thread(new Runnable()
{
public void run()
{
// need to sync on something else but 'this'
synchronized (known)
{
initStarted = true;
known.notify();
}
preinit();
}
}).start();
synchronized (known)
{
while (!initStarted)
{
try {
known.wait();
} catch (InterruptedException e) {
break;
}
}
}
}
}
private synchronized void preinit()
{
VboxPortType port = getPort();
releasePort(port);
}
synchronized VboxPortType getPort()
{
VboxPortType port = null;
int ttl = 0;
for (VboxPortType cur: known.keySet())
{
int value = known.get(cur);
if ((value & 0x10000) == 0)
{
port = cur;
ttl = value & 0xffff;
break;
}
}
if (port == null)
{
if (svc == null) {
URL wsdl = PortPool.class.getClassLoader().getResource(wsdlFile);
if (wsdl == null)
throw new LinkageError(wsdlFile+" not found, but it should have been in the jar");
svc = new VboxService(wsdl,
new QName("http://www.virtualbox.org/Service",
"vboxService"));
}
port = svc.getVboxServicePort();
// reuse this object 0x10 times
ttl = 0x10;
}
// mark as used
known.put(port, new Integer(0x10000 | ttl));
return port;
}
synchronized void releasePort(VboxPortType port)
{
Integer val = known.get(port);
if (val == null || val == 0)
{
// know you not
return;
}
int v = val;
int ttl = v & 0xffff;
// decrement TTL, and throw away port if used too much times
if (--ttl <= 0)
{
known.remove(port);
}
else
{
v = ttl; // set new TTL and clear busy bit
known.put(port, v);
}
}
}
public class VirtualBoxManager
{
private static PortPool pool = new PortPool(true);
protected VboxPortType port;
private IVirtualBox vbox;
private VirtualBoxManager()
{
}
public static void initPerThread()
{
}
public static void deinitPerThread()
{
}
public void connect(String url, String username, String passwd)
{
this.port = pool.getPort();
try {
((BindingProvider)port).getRequestContext().
put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
String handle = port.iWebsessionManagerLogon(username, passwd);
this.vbox = new IVirtualBox(handle, port);
} catch (Throwable t) {
if (this.port != null && pool != null) {
pool.releasePort(this.port);
this.port = null;
}
// we have to throw smth derived from RuntimeException
throw new VBoxException(t, t.getMessage());
}
}
public void connect(String url, String username, String passwd,
Map requestContext, Map responseContext)
{
this.port = pool.getPort();
try {
((BindingProvider)port).getRequestContext();
if (requestContext != null)
((BindingProvider)port).getRequestContext().putAll(requestContext);
if (responseContext != null)
((BindingProvider)port).getResponseContext().putAll(responseContext);
((BindingProvider)port).getRequestContext().
put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
String handle = port.iWebsessionManagerLogon(username, passwd);
this.vbox = new IVirtualBox(handle, port);
} catch (Throwable t) {
if (this.port != null && pool != null) {
pool.releasePort(this.port);
this.port = null;
}
// we have to throw smth derived from RuntimeException
throw new VBoxException(t, t.getMessage());
}
}
public void disconnect()
{
try {
if (this.vbox != null)
port.iWebsessionManagerLogoff(this.vbox.getWrapped());
} catch (InvalidObjectFaultMsg e) {
throw new VBoxException(e, e.getMessage());
} catch (RuntimeFaultMsg e) {
throw new VBoxException(e, e.getMessage());
} finally {
if (this.port != null) {
pool.releasePort(this.port);
this.port = null;
}
}
}
public IVirtualBox getVBox()
{
return this.vbox;
}
public ISession getSessionObject()
{
if (this.vbox == null)
throw new RuntimeException("connect first");
try {
String handle = port.iWebsessionManagerGetSessionObject(this.vbox.getWrapped());
return new ISession(handle, port);
} catch (InvalidObjectFaultMsg e) {
throw new VBoxException(e, e.getMessage());
} catch (RuntimeFaultMsg e) {
throw new VBoxException(e, e.getMessage());
}
}
public ISession openMachineSession(IMachine m) throws Exception
{
ISession s = getSessionObject();
m.lockMachine(s, LockType.Shared);
return s;
}
public void closeMachineSession(ISession s)
{
if (s != null)
s.unlockMachine();
}
public static synchronized VirtualBoxManager createInstance(String home)
{
return new VirtualBoxManager();
}
public IEventListener createListener(Object sink)
{
throw new RuntimeException("no active listeners here");
}
public void cleanup()
{
disconnect();
deinitPerThread();
}
public boolean progressBar(IProgress p, int wait)
{
long end = System.currentTimeMillis() + wait;
while (!p.getCompleted())
{
p.waitForCompletion(wait);
if (System.currentTimeMillis() >= end)
return false;
}
return true;
}
public boolean startVm(String name, String type, int timeout)
{
IMachine m = vbox.findMachine(name);
if (m == null)
return false;
ISession session = getSessionObject();
if (type == null)
type = "gui";
IProgress p = m.launchVMProcess(session, type, "");
progressBar(p, timeout);
session.unlockMachine();
return true;
}
public void waitForEvents(long tmo)
{
}
protected void finalize() throws Throwable
{
try {
cleanup();
} catch(Exception e) {
}
finally {
super.finalize();
}
}
}
]]>