tstAPI.cpp revision c9d3e78cd287b97e4fd981a2268b6d8bf2437d71
/** @file
*
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include <stdio.h>
#include <stdlib.h>
using namespace com;
#define LOG_ENABLED
#define LOG_GROUP LOG_GROUP_MAIN
#define LOG_INSTANCE NULL
#include <iprt/initterm.h>
// forward declarations
///////////////////////////////////////////////////////////////////////////////
// funcs
///////////////////////////////////////////////////////////////////////////////
{
printf ("Getting machine name...\n");
printf("Getting machine GUID...\n");
} else {
printf ("WARNING: there's no GUID!");
}
printf ("Getting memory size...\n");
printf ("Getting machine state...\n");
printf ("Are any settings modified?...\n");
{
printf ("Are any settings modified now?...\n");
ASSERT_RET (modified, 0);
printf ("Getting memory size again...\n");
if (readonlyMachine)
{
printf ("Getting memory size of the counterpart readonly machine...\n");
}
printf ("Discarding recent changes...\n");
printf ("Are any settings modified after discarding?...\n");
ASSERT_RET (!modified, 0);
printf ("Getting memory size once more...\n");
}
printf ("Getting description...\n");
desc = L"This is an exemplary description (changed).";
printf ("Saving machine settings...\n");
{
printf ("Are any settings modified after saving?...\n");
ASSERT_RET (!modified, 0);
if (readonlyMachine) {
printf ("Getting memory size of the counterpart readonly machine...\n");
}
}
} else {
printf ("No extra data exists\n");
else
printf ("Extra data is empty\n");
}
extraData = L"Das ist die Berliner Luft, Luft, Luft...";
else
printf (
"Setting extra data key {%ls} to {%ls}...\n",
);
} else {
printf ("No extra data exists\n");
else
printf ("Extra data is empty\n");
}
}
return rc;
}
// main
///////////////////////////////////////////////////////////////////////////////
{
/*
* Initialize the VBox runtime without loading
* the support driver.
*/
RTR3Init();
{
char homeDir [RTPATH_MAX];
}
printf ("Initializing COM...\n");
do
{
// scopes all the stuff till shutdown
////////////////////////////////////////////////////////////////////////////
#if 0
// Utf8Str test
////////////////////////////////////////////////////////////////////////////
0, "utf8StrFmt", 1);
#endif
printf ("Creating VirtualBox object...\n");
{
break;
}
printf ("Creating Session object...\n");
{
break;
}
#if 0
// IUnknown identity test
////////////////////////////////////////////////////////////////////////////
{
{
printf ("Creating one more VirtualBox object...\n");
{
break;
}
printf ("IVirtualBox(virtualBox)=%p IVirtualBox(virtualBox2)=%p\n",
unk2 = virtualBox2;
printf ("IUnknown(virtualBox)=%p IUnknown(virtualBox2)=%p\n",
printf ("IVirtualBox(IUnknown(virtualBox))=%p IVirtualBox(IUnknown(virtualBox2))=%p\n",
}
{
/* query IUnknown on IUnknown */
/* query IUnknown on IUnknown in the opposite direction */
/* query IUnknown again after releasing all previous IUnknown instances
* but keeping IHost -- it should remain the same (Identity Rule) */
}
// printf ("Will be now released (press Enter)...");
// getchar();
}
#endif
// create the event queue
// after the session is closed)
#if 0
// the simplest COM API test
////////////////////////////////////////////////////////////////////////////
{
}
#endif
#if 0
// Array test
////////////////////////////////////////////////////////////////////////////
{
printf ("Calling IVirtualBox::Machines...\n");
printf ("%u machines registered (machines.isNull()=%d).\n",
{
}
#if 0
{
printf ("Testing [out] arrays...\n");
}
{
printf ("Testing [in] arrays...\n");
{
}
}
#endif
}
#endif
#if 0
// some outdated stuff
////////////////////////////////////////////////////////////////////////////
printf("Getting IHost interface...\n");
{
{
while (dvdDrive)
{
char *driveNameUtf8;
dvdDriveTemp->Release();
}
} else
{
printf("Could not get host DVD drive collection\n");
}
{
while (floppyDrive)
{
char *driveNameUtf8;
}
floppyColl->Release();
} else
{
printf("Could not get host floppy drive collection\n");
}
} else
{
printf("Call failed\n");
}
printf ("\n");
#endif
#if 0
// IVirtualBoxErrorInfo test
////////////////////////////////////////////////////////////////////////////
{
// RPC calls
// call a method that will definitely fail
// {
// com::ErrorInfo info (virtualBox);
// PRINT_ERROR_INFO (info);
// }
// call a method that will definitely succeed
{
}
// Local calls
// call a method that will definitely fail
// {
// com::ErrorInfo info (virtualBox);
// PRINT_ERROR_INFO (info);
// }
// call a method that will definitely succeed
{
}
}
#endif
#if 0
// register the existing hard disk image
///////////////////////////////////////////////////////////////////////////
do
{
printf ("Enter to continue...\n");
getchar();
printf ("Enter to continue...\n");
getchar();
}
while (FALSE);
printf ("\n");
#endif
#if 0
// find and unregister the existing hard disk image
///////////////////////////////////////////////////////////////////////////
do
{
}
while (FALSE);
printf ("\n");
#endif
#if 0
// clone the registered hard disk
///////////////////////////////////////////////////////////////////////////
do
{
#if defined RT_OS_LINUX
#else
#endif
RTPrintf ("Waiting for completion...\n");
{
}
else
{
}
}
while (FALSE);
printf ("\n");
#endif
#if 0
// find a registered hard disk by location and get properties
///////////////////////////////////////////////////////////////////////////
do
{
static const wchar_t *Names[] =
{
#ifndef RT_OS_LINUX
L"freedos.vdi",
L"MS-DOS.vmdk",
L"iscsi",
#else
L"xp.vdi",
L"Xp.vDI",
#endif
};
printf ("\n");
{
{
printf ("Found, UUID={%Vuuid}, location='%ls'.\n",
printf ("Properties:\n");
printf (" <none>\n");
#if 0
#endif
}
else
{
}
printf ("\n");
}
}
while (FALSE);
printf ("\n");
#endif
#if 0
// access the machine in read-only mode
///////////////////////////////////////////////////////////////////////////
do
{
printf ("Accessing the machine in read-only mode:\n");
#if 0
if (argc != 2)
{
printf ("Error: a string has to be supplied!\n");
}
else
{
}
#endif
}
while (0);
printf ("\n");
#endif
#if 0
// create a new machine (w/o registering it)
///////////////////////////////////////////////////////////////////////////
do
{
#if defined (RT_OS_LINUX)
#else
#endif
printf ("Creating a new machine object (base dir '%ls', name '%ls')...\n",
machine.asOutParam()));
printf ("Getting name...\n");
printf ("Are any settings modified?...\n");
name = L"Kakaya prekrasnaya virtual'naya mashina!";
printf ("Setting memory size to 111...\n");
printf ("Saving new machine settings...\n");
printf ("Accessing the newly created machine:\n");
}
while (FALSE);
printf ("\n");
#endif
#if 0
// enumerate host DVD drives
///////////////////////////////////////////////////////////////////////////
do
{
{
{
}
CHECK_RC_BREAK (rc);
{
}
}
}
while (FALSE);
printf ("\n");
#endif
#if 0
// check for available hd backends
///////////////////////////////////////////////////////////////////////////
{
RTPrintf("Supported hard disk backends: --------------------------\n");
{
/* General information */
RTPrintf("Backend %u: id='%ls' description='%ls' capabilities=%#06x extensions='",
/* File extensions */
{
RTPrintf (",");
}
RTPrintf ("'");
/* Configuration keys */
RTPrintf (" config=(");
if (propertyNames.size() > 0)
{
{
RTPrintf ("key='%ls' desc='%ls' type=", Bstr (propertyNames [a]).raw(), Bstr (propertyDescriptions [a]).raw());
switch (propertyTypes [a])
{
}
RTPrintf (",");
}
}
RTPrintf (")\n");
}
RTPrintf("-------------------------------------------------------\n");
}
#endif
#if 0
// enumerate hard disks & dvd images
///////////////////////////////////////////////////////////////////////////
do
{
{
printf ("%u base hard disks registered (disks.isNull()=%d).\n",
{
printf (" disks[%u]: '%ls'\n"
" UUID: {%Vuuid}\n"
" State: %s\n"
" Format: %ls\n",
"???",
if (state == MediaState_Inaccessible)
{
CHECK_ERROR_BREAK (disks [i],
}
/* get usage */
printf (" Used by VMs:\n");
CHECK_ERROR_BREAK (disks [i],
{
printf (" <not used>\n");
}
else
{
{
}
}
}
}
{
printf ("%u DVD images registered (images.isNull()=%d).\n",
{
printf (" images[%u]: '%ls'\n"
" UUID: {%Vuuid}\n"
" State: %s\n",
"???");
if (state == MediaState_Inaccessible)
{
CHECK_ERROR_BREAK (images [i],
}
/* get usage */
printf (" Used by VMs:\n");
CHECK_ERROR_BREAK (images [i],
{
printf (" <not used>\n");
}
else
{
{
}
}
}
}
}
while (FALSE);
printf ("\n");
#endif
#if 0
// open a (direct) session
///////////////////////////////////////////////////////////////////////////
do
{
printf ("Opening a session for this machine...\n");
#if 1
printf ("Getting sessioned machine object...\n");
printf ("Accessing the machine within the session:\n");
#if 0
printf ("\n");
printf ("Enabling the VRDP server (must succeed even if the VM is saved):\n");
{
}
else
{
}
#endif
#endif
#if 0
printf ("Getting the console object...\n");
printf ("Discarding the current machine state...\n");
printf ("Waiting for completion...\n");
{
}
#endif
printf("Press enter to close session...");
getchar();
}
while (FALSE);
printf ("\n");
#endif
#if 0
// open a remote session
///////////////////////////////////////////////////////////////////////////
do
{
printf ("Opening a remote session for this machine...\n");
printf ("Waiting for the session to open...\n");
printf ("Getting sessioned machine object...\n");
printf ("Getting console object...\n");
printf ("Press enter to pause the VM execution in the remote session...");
getchar();
printf ("Press enter to close this session...");
getchar();
}
while (FALSE);
printf ("\n");
#endif
#if 0
// open an existing remote session
///////////////////////////////////////////////////////////////////////////
do
{
printf ("Opening an existing remote session for this machine...\n");
printf ("Getting sessioned machine object...\n");
#if 0
#endif
#if 0
printf ("Getting console object...\n");
printf ("Press enter to pause the VM execution in the remote session...");
getchar();
printf ("Press enter to close this session...");
getchar();
#endif
}
while (FALSE);
printf ("\n");
#endif
#if 0
do {
// Get host
} while (0);
#endif
#if 1
do {
// Get host
if (hostNetworkInterfaces.size() > 0)
{
printf("Found %d network interfaces, testing with %lS...\n", hostNetworkInterfaces.size(), interfaceName.raw());
// Find the interface by its name
if (interfaceGuid2 != interfaceGuid)
// Find the interface by its guid
if (interfaceName != interfaceName2)
}
else
{
printf("No network interfaces found!\n");
}
} while (0);
#endif
#if 0 && defined (VBOX_WITH_RESOURCE_USAGE_API)
do {
// Get collector
// Fill base metrics array
// Get host
// Get machine
// Open session
printf ("Opening a remote session for this machine...\n");
printf ("Waiting for the session to open...\n");
printf ("Getting sessioned machine object...\n");
// Setup base metrics
// Note that one needs to set up metrics after a session is open for a machine.
// Get console
printf ("Getting console object...\n");
printf("\nMetrics collected with VM running: --------------------\n");
// Pause
//printf ("Press enter to pause the VM execution in the remote session...");
//getchar();
printf("\nMetrics collected with VM paused: ---------------------\n");
printf("\nDrop collected metrics: ----------------------------------------\n");
printf("\nDisable collection of VM metrics: ------------------------------\n");
printf("\nRe-enable collection of all metrics: ---------------------------\n");
// Power off
printf ("Press enter to power off VM...");
getchar();
printf ("Press enter to close this session...");
getchar();
} while (false);
#endif /* VBOX_WITH_RESOURCE_USAGE_API */
#if 0
// check of OVF appliance handling
///////////////////////////////////////////////////////////////////////////
do
{
//Bstr ovf = L"/home/poetzsch/projects/someOVF.ovf";
// Bstr ovf = L"/Users/poetzsch/projects/someOVF.ovf";
// Bstr name = argc > 1 ? argv [1] : "dsl";
printf ("Appliance:\n");
// Fetch all disks
{
printf ("Disks:");
printf ("\n");
}
/* Fetch all virtual system descriptions */
{
{
CHECK_ERROR_BREAK (retVSD [i],
printf ("VirtualSystemDescription:\n");
{
printf (" %d %u %ls %ls %ls\n",
retTypes [a],
retRefs [a],
}
}
printf ("\n");
}
}
while (FALSE);
printf ("\n");
#endif
printf ("Press enter to release Session and VirtualBox instances...");
getchar();
// end "all-stuff" scope
////////////////////////////////////////////////////////////////////////////
}
while (0);
printf("Press enter to shutdown COM...");
getchar();
printf ("tstAPI FINISHED.\n");
return rc;
}
#ifdef VBOX_WITH_RESOURCE_USAGE_API
{
//Bstr metricNames[] = { L"CPU/Load/User:avg,CPU/Load/System:avg,CPU/Load/Idle:avg,RAM/Usage/Total,RAM/Usage/Used:avg" };
RTPrintf("Object Metric Values\n"
"---------- -------------------- --------------------------------------------\n");
{
const char *separator = "";
for (unsigned j = 0; j < retLengths[i]; j++)
{
if (retScales[i] == 1)
else
separator = ", ";
}
RTPrintf("\n");
}
}
{
return Bstr("host");
{
return name;
}
return Bstr("unknown");
}
{
{
RTPrintf("The following metrics were modified:\n\n"
"Object Metric\n"
"---------- --------------------\n");
{
RTPrintf("%-10ls %-20ls\n",
}
RTPrintf("\n");
}
else
{
RTPrintf("No metrics match the specified filter!\n");
}
}
#endif /* VBOX_WITH_RESOURCE_USAGE_API */