tstAPI.cpp revision 5dc096519aecf7c7c7cec2296565dc199633e873
/** @file
*
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* 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.
*/
#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
///////////////////////////////////////////////////////////////////////////////
{
RTPrintf("Getting machine name...\n");
RTPrintf("Getting machine GUID...\n");
} else {
RTPrintf("WARNING: there's no GUID!");
}
RTPrintf("Getting memory size...\n");
RTPrintf("Getting machine state...\n");
RTPrintf("Are any settings modified?...\n");
{
RTPrintf("Are any settings modified now?...\n");
ASSERT_RET(modified, 0);
RTPrintf("Getting memory size again...\n");
if (readonlyMachine)
{
RTPrintf("Getting memory size of the counterpart readonly machine...\n");
}
RTPrintf("Discarding recent changes...\n");
RTPrintf("Are any settings modified after discarding?...\n");
ASSERT_RET(!modified, 0);
RTPrintf("Getting memory size once more...\n");
}
RTPrintf("Getting description...\n");
desc = L"This is an exemplary description (changed).";
RTPrintf("Saving machine settings...\n");
{
RTPrintf("Are any settings modified after saving?...\n");
ASSERT_RET(!modified, 0);
if (readonlyMachine) {
RTPrintf("Getting memory size of the counterpart readonly machine...\n");
}
}
} else {
RTPrintf("No extra data exists\n");
}
extraData = L"Das ist die Berliner Luft, Luft, Luft...";
else
RTPrintf("Setting extra data key {%ls} to {%ls}...\n",
} else {
RTPrintf("No extra data exists\n");
}
}
return rc;
}
// main
///////////////////////////////////////////////////////////////////////////////
{
/*
* Initialize the VBox runtime without loading
* the support driver.
*/
{
char homeDir[RTPATH_MAX];
}
RTPrintf("Initializing COM...\n");
{
RTPrintf("ERROR: failed to initialize COM!\n");
return rc;
}
do
{
// scopes all the stuff till shutdown
////////////////////////////////////////////////////////////////////////////
#if 0
// Utf8Str test
////////////////////////////////////////////////////////////////////////////
#endif
RTPrintf("Creating VirtualBox object...\n");
RTPrintf("ERROR: failed to create the VirtualBox object!\n");
else
{
RTPrintf("ERROR: failed to create a session object!\n");
}
{
{
RTPrintf("Most likely, the VirtualBox COM server is not running or failed to start.\n");
}
else
break;
}
#if 0
// Testing VirtualBox::COMGETTER(ProgressOperations).
// This is designed to be tested while running
// "./VBoxManage clonehd src.vdi clone.vdi" in parallel.
// It will then display the progress every 2 seconds.
////////////////////////////////////////////////////////////////////////////
{
RTPrintf("Testing VirtualBox::COMGETTER(ProgressOperations)...\n");
for (;;) {
if (operations.size() == 0)
break; // No more operations left.
}
}
}
#endif
#if 0
// IUnknown identity test
////////////////////////////////////////////////////////////////////////////
{
{
RTPrintf("Creating one more VirtualBox object...\n");
{
break;
}
RTPrintf("IVirtualBox(virtualBox)=%p IVirtualBox(virtualBox2)=%p\n",
unk2 = virtualBox2;
RTPrintf("IUnknown(virtualBox)=%p IUnknown(virtualBox2)=%p\n",
RTPrintf("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) */
}
// RTPrintf("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
////////////////////////////////////////////////////////////////////////////
{
RTPrintf("Calling IVirtualBox::Machines...\n");
RTPrintf("%u machines registered (machines.isNull()=%d).\n",
{
}
#if 0
{
RTPrintf("Testing [out] arrays...\n");
}
{
RTPrintf("Testing [in] arrays...\n");
{
}
}
#endif
}
#endif
#if 0
// some outdated stuff
////////////////////////////////////////////////////////////////////////////
RTPrintf("Getting IHost interface...\n");
{
{
while (dvdDrive)
{
char *driveNameUtf8;
dvdDriveTemp->Release();
}
} else
{
RTPrintf("Could not get host DVD drive collection\n");
}
{
while (floppyDrive)
{
char *driveNameUtf8;
}
floppyColl->Release();
} else
{
RTPrintf("Could not get host floppy drive collection\n");
}
} else
{
RTPrintf("Call failed\n");
}
RTPrintf("\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
{
RTPrintf("Enter to continue...\n");
getchar();
RTPrintf("Enter to continue...\n");
getchar();
}
while (FALSE);
RTPrintf("\n");
#endif
#if 0
// find and unregister the existing hard disk image
///////////////////////////////////////////////////////////////////////////
do
{
}
while (FALSE);
RTPrintf("\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);
RTPrintf("\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
};
RTPrintf("\n");
{
{
RTPrintf("Found, UUID={%RTuuid}, location='%ls'.\n",
RTPrintf("Properties:\n");
RTPrintf(" <none>\n");
#if 0
#endif
}
else
{
}
RTPrintf("\n");
}
}
while (FALSE);
RTPrintf("\n");
#endif
#if 0
// access the machine in read-only mode
///////////////////////////////////////////////////////////////////////////
do
{
RTPrintf("Accessing the machine in read-only mode:\n");
#if 0
if (argc != 2)
{
RTPrintf("Error: a string has to be supplied!\n");
}
else
{
}
#endif
}
while (0);
RTPrintf("\n");
#endif
#if 0
// create a new machine (w/o registering it)
///////////////////////////////////////////////////////////////////////////
do
{
#if defined(RT_OS_LINUX)
#else
#endif
RTPrintf("Creating a new machine object(base dir '%ls', name '%ls')...\n",
false,
machine.asOutParam()));
RTPrintf("Getting name...\n");
RTPrintf("Are any settings modified?...\n");
name = L"Kakaya prekrasnaya virtual'naya mashina!";
RTPrintf("Setting memory size to 111...\n");
RTPrintf("Saving new machine settings...\n");
RTPrintf("Accessing the newly created machine:\n");
}
while (FALSE);
RTPrintf("\n");
#endif
#if 0
// enumerate host DVD drives
///////////////////////////////////////////////////////////////////////////
do
{
{
{
}
{
}
}
}
while (FALSE);
RTPrintf("\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
{
{
RTPrintf("%u base hard disks registered (disks.isNull()=%d).\n",
{
RTPrintf(" disks[%u]: '%ls'\n"
" UUID: {%RTuuid}\n"
" State: %s\n"
" Format: %ls\n",
"???",
if (state == MediaState_Inaccessible)
{
}
/* get usage */
RTPrintf(" Used by VMs:\n");
{
RTPrintf(" <not used>\n");
}
else
{
{
}
}
}
}
{
RTPrintf("%u DVD images registered (images.isNull()=%d).\n",
{
RTPrintf(" images[%u]: '%ls'\n"
" UUID: {%RTuuid}\n"
" State: %s\n",
"???");
if (state == MediaState_Inaccessible)
{
}
/* get usage */
RTPrintf(" Used by VMs:\n");
{
RTPrintf(" <not used>\n");
}
else
{
{
}
}
}
}
}
while (FALSE);
RTPrintf("\n");
#endif
#if 0
// open a (direct) session
///////////////////////////////////////////////////////////////////////////
do
{
RTPrintf("Opening a session for this machine...\n");
#if 1
RTPrintf("Getting machine session object...\n");
RTPrintf("Accessing the machine within the session:\n");
#if 0
RTPrintf("\n");
RTPrintf("Enabling the VRDE server (must succeed even if the VM is saved):\n");
{
}
else
{
}
#endif
#endif
#if 0
RTPrintf("Getting the console object...\n");
RTPrintf("Discarding the current machine state...\n");
RTPrintf("Waiting for completion...\n");
{
}
#endif
RTPrintf("Press enter to close session...");
getchar();
}
while (FALSE);
RTPrintf("\n");
#endif
#if 0
// open a remote session
///////////////////////////////////////////////////////////////////////////
do
{
RTPrintf("Opening a remote session for this machine...\n");
RTPrintf("Waiting for the session to open...\n");
RTPrintf("Getting machine session object...\n");
RTPrintf("Getting console object...\n");
RTPrintf("Press enter to pause the VM execution in the remote session...");
getchar();
RTPrintf("Press enter to close this session...");
getchar();
}
while (FALSE);
RTPrintf("\n");
#endif
#if 0
// open an existing remote session
///////////////////////////////////////////////////////////////////////////
do
{
RTPrintf("Opening an existing remote session for this machine...\n");
RTPrintf("Getting machine session object...\n");
#if 0
#endif
#if 0
RTPrintf("Getting console object...\n");
RTPrintf("Press enter to pause the VM execution in the remote session...");
getchar();
RTPrintf("Press enter to close this session...");
getchar();
#endif
}
while (FALSE);
RTPrintf("\n");
#endif
#if 0
do {
// Get host
} while (0);
#endif
#if 0
do {
// Get host
if (hostNetworkInterfaces.size() > 0)
{
RTPrintf("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
{
RTPrintf("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
RTPrintf("Launching VM process...\n");
RTPrintf("Waiting for the VM to power on...\n");
// ComPtr<IMachine> sessionMachine;
// RTPrintf("Getting machine session object...\n");
// CHECK_ERROR_BREAK(session, COMGETTER(Machine)(sessionMachine.asOutParam()));
// Setup base metrics
// Note that one needs to set up metrics after a session is open for a machine.
//machine.queryInterfaceTo(&objects[1]);
// Get console
RTPrintf("Getting console object...\n");
RTPrintf("\nMetrics collected with VM running: --------------------\n");
// Pause
//RTPrintf("Press enter to pause the VM execution in the remote session...");
//getchar();
RTPrintf("\nMetrics collected with VM paused: ---------------------\n");
RTPrintf("\nDrop collected metrics: ----------------------------------------\n");
RTPrintf("\nDisable collection of VM metrics: ------------------------------\n");
RTPrintf("\nRe-enable collection of all metrics: ---------------------------\n");
// Power off
RTPrintf("Press enter to power off VM...");
getchar();
RTPrintf("Waiting for the VM to power down...\n");
RTPrintf("Press enter to close this session...");
getchar();
session->UnlockMachine();
} while (false);
#endif /* VBOX_WITH_RESOURCE_USAGE_API */
#if 0
// check of OVF appliance handling
///////////////////////////////////////////////////////////////////////////
do
{
RTPrintf("Appliance:\n");
// Fetch all disks
{
RTPrintf("Disks:");
RTPrintf("\n");
}
/* Fetch all virtual system descriptions */
{
{
RTPrintf("VirtualSystemDescription:\n");
{
RTPrintf(" %d %ls %ls %ls\n",
retTypes[a],
}
/* Show warnings from interpret */
if (retWarnings.size() > 0)
{
RTPrintf("The following warnings occurs on interpret:\n");
for (unsigned r = 0; r < retWarnings.size(); ++r)
RTPrintf("\n");
}
}
RTPrintf("\n");
}
RTPrintf("Try to import the appliance ...\n");
{
/* Check if the import was successfully */
{
if (info.isBasicAvailable())
else
RTPrintf("Error: failed to import appliance. No error message available!\n");
}else
RTPrintf("Successfully imported the appliance.\n");
}
}
while (FALSE);
RTPrintf("\n");
#endif
RTPrintf("Press enter to release Session and VirtualBox instances...");
getchar();
// end "all-stuff" scope
////////////////////////////////////////////////////////////////////////////
}
while (0);
RTPrintf("Press enter to shutdown COM...");
getchar();
RTPrintf("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 */
/* vim: set shiftwidth=4 tabstop=4 expandtab: */