VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/java/tests/TestVBox.java@ 29186

Last change on this file since 29186 was 29186, checked in by vboxsync, 15 years ago

typo

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1/* $Id:$ */
2/*
3 * Copyright (C) 2010 Oracle Corporation
4 *
5 * This file is part of VirtualBox Open Source Edition (OSE), as
6 * available from http://www.215389.xyz. This file is free software;
7 * you can redistribute it and/or modify it under the terms of the GNU
8 * General Public License (GPL) as published by the Free Software
9 * Foundation, in version 2 as it comes in the "COPYING" file of the
10 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
11 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
12 */
13
14import org.mozilla.interfaces.*;
15import org.virtualbox.*;
16
17public class TestVBox
18{
19
20 public static class VBoxCallbacks implements IVirtualBoxCallback
21 {
22 public void onGuestPropertyChange(String machineId, String name, String value, String flags) {}
23 public void onSnapshotChange(String machineId, String snapshotId) {}
24 public void onSnapshotDeleted(String machineId, String snapshotId) {}
25 public void onSnapshotTaken(String machineId, String snapshotId) {}
26 /** @todo is there a type SessionState instead of long? */
27 public void onSessionStateChange(String machineId, long state) {}
28 public void onMachineRegistered(String machineId, boolean registered) {}
29 /** @todo long -> MediumType */
30 public void onMediumRegistered(String mediumId, long mediumType, boolean registered) {}
31 public void onExtraDataChange(String machineId, String key, String value) {}
32 public boolean onExtraDataCanChange(String machineId, String key, String value, String[] error) { return true; }
33 public void onMachineDataChange(String machineId) {}
34 /** @todo long -> MachineState */
35 public void onMachineStateChange(String machineId, long state) { System.out.println("onMachineStateChange -- VM: " + machineId + ", state: " + state); };
36
37 /** @todo ugly reimplementation of queryInterface, should have base class to derive from */
38 public nsISupports queryInterface(String iid) { return org.mozilla.xpcom.Mozilla.queryInterface(this, iid); }
39 };
40
41
42 public static void main(String[] args)
43 {
44 VirtualBoxManager mgr = VirtualBoxManager.getInstance(null);
45
46 System.out.println("\n--> initialized\n");
47
48 try
49 {
50 IVirtualBox vbox = mgr.getVBox();
51 System.out.println("VirtualBox version: " + vbox.getVersion() + "\n");
52
53 /* list all VMs and print some info for each */
54 IMachine[] machs = vbox.getMachines(null);
55 for (IMachine m : machs)
56 {
57 try
58 {
59 System.out.println("VM name: " + m.getName() + ", RAM size: " + m.getMemorySize() + "MB");
60 System.out.println(" HWVirt: " + m.getHWVirtExProperty(HWVirtExPropertyType.Enabled)
61 + ", Nested Paging: " + m.getHWVirtExProperty(HWVirtExPropertyType.NestedPaging)
62 + ", PAE: " + m.getCPUProperty(CPUPropertyType.PAE) );
63 }
64 catch (Throwable e)
65 {
66 e.printStackTrace();
67 }
68 }
69
70 VBoxCallbacks vboxCallbacks = new VBoxCallbacks();
71 vbox.registerCallback(mgr.makeVirtualBoxCallback(vboxCallbacks));
72
73 /* do something silly, start the first VM in the list */
74 String m = machs[0].getName();
75 System.out.println("\nAttempting to start VM '" + m + "'");
76 if (mgr.startVm(m, 7000))
77 {
78 if (false)
79 {
80 System.out.println("started, presss any key...");
81 int ch = System.in.read();
82 } else {
83 while (true)
84 {
85 mgr.waitForEvents(500);
86 }
87 }
88 }
89 else
90 {
91 System.out.println("cannot start machine "+m);
92 }
93
94 vbox.unregisterCallback(vboxCallbacks);
95 }
96 catch (Throwable e)
97 {
98 e.printStackTrace();
99 }
100
101 mgr.cleanup();
102
103 System.out.println("\n--< done\n");
104 }
105
106}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette