tstAPI.cpp revision 579e60b48b08878f555d02809aa2c88c67af1ef7
/** @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
// 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(false);
{
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(virualBox)=%p IVirtualBox(virualBox2)=%p\n",
unk2 = virtualBox2;
printf ("IUnknown(virualBox)=%p IUnknown(virualBox2)=%p\n",
printf ("IVirtualBox(IUnknown(virualBox))=%p IVirtualBox(IUnknown(virualBox2))=%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 1
// Array test
////////////////////////////////////////////////////////////////////////////
{
printf ("Calling IVirtualBox::Machines...\n");
printf ("%u machines registered (machines.isNull()=%d).\n",
{
}
}
#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
///////////////////////////////////////////////////////////////////////////
do
{
static const wchar_t *Names[] =
{
#ifndef RT_OS_LINUX
L"E:/Develop/innotek/images/thinker/freedos.vdi",
L"E:/Develop/innotek/images/thinker/fReeDoS.vDI",
L"E:/Develop/innotek/images/vmdk/haiku.vmdk",
#else
#endif
};
{
{
printf ("Found, UUID={%Vuuid}, location='%ls'.\n",
}
else
{
}
}
}
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
// enumerate hard disks & dvd images
///////////////////////////////////////////////////////////////////////////
do
{
{
{
printf ("Hard Disk: id={%s}, path={%ls}\n",
mid.asOutParam())
);
printf (" not used\n");
else
}
CHECK_RC_BREAK (rc);
}
{
{
mIDs.asOutParam())
);
printf (" not used\n");
else
}
CHECK_RC_BREAK (rc);
}
}
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 1
do {
// Get collector
// Fill base metrics array
// Get host
// Get machine
// Setup base metrics
// 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");
// Get console
printf ("Getting console object...\n");
printf("Metrics collected with DSL machine running: --------------------\n");
// Pause
printf ("Press enter to pause the VM execution in the remote session...");
getchar();
printf("Metrics collected with DSL machine paused: ---------------------\n");
// Power off
printf ("Press enter to power off VM...");
getchar();
printf ("Press enter to close this session...");
getchar();
} while (false);
#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;
}
#if 1
{
Bstr metricNames[] = { L"CPU/Load/User:avg,CPU/Load/System:avg,CPU/Load/Idle:avg,RAM/Usage/Total,RAM/Usage/Used:avg" };
{
// Get info for the metric
for (unsigned j = 0; j < retLengths[i]; j++)
{
printf(", %d %ls", retData[retIndices[i] + j] / (strcmp((const char *)metricUnit.raw(), "%")?1:1000), metricUnit.raw());
}
printf("\n");
}
}
#endif