VBoxManage.cpp revision dbabc9de5bf52ce5eb77cf82b038e9a6166c5a04
/* $Id$ */
/** @file
* VBoxManage - VirtualBox's command-line interface.
*/
/*
* Copyright (C) 2006-2009 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#ifndef VBOX_ONLY_DOCS
# include <vector>
# include <list>
#endif /* !VBOX_ONLY_DOCS */
#include <iprt/buildconfig.h>
#include <iprt/initterm.h>
#include <signal.h>
#include "VBoxManage.h"
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/*extern*/ bool g_fDetailedProgress = false;
#ifndef VBOX_ONLY_DOCS
/** Set by the signal handler. */
static volatile bool g_fCanceled = false;
/**
* Signal handler that sets g_fCanceled.
*
* This can be executed on any thread in the process, on Windows it may even be
* a thread dedicated to delivering this signal. Do not doing anything
* unnecessary here.
*/
static void showProgressSignalHandler(int iSignal)
{
ASMAtomicWriteBool(&g_fCanceled, true);
}
/**
* Print out progress on the console
*/
{
using namespace com;
ULONG ulLastPercent = 0;
if (!g_fDetailedProgress)
{
RTPrintf("0%%...");
}
/* setup signal handling if cancelable */
bool fCanceledAlready = false;
fCancelable = FALSE;
if (fCancelable)
{
#ifdef SIGBREAK
#endif
}
{
if (g_fDetailedProgress)
{
if (ulLastOperation != ulOperation)
{
}
if ( ulCurrentPercent != ulLastPercent
)
{
RTPrintf("(%ld/%ld) %ls %ld%% => %ld%% (%d s remaining)\n", ulOperation + 1, cOperations, bstrOperationDescription.raw(), ulCurrentOperationPercent, ulCurrentPercent, lSecsRem);
}
}
else
{
/* did we cross a 10% mark? */
{
/* make sure to also print out missed steps */
for (ULONG curVal = (ulLastPercent / 10) * 10 + 10; curVal <= (ulCurrentPercent / 10) * 10; curVal += 10)
{
if (curVal < 100)
{
}
}
}
}
if (fCompleted)
break;
/* process async cancelation */
if (g_fCanceled && !fCanceledAlready)
{
fCanceledAlready = true;
else
g_fCanceled = false;
}
/* make sure the loop is not too tight */
}
/* undo signal handling */
if (fCancelable)
{
#ifdef SIGBREAK
#endif
}
/* complete the line. */
{
RTPrintf("100%%\n");
else if (g_fCanceled)
RTPrintf("CANCELED\n");
else
RTPrintf("FAILED\n");
}
else
RTPrintf("\n");
return iRc;
}
#endif /* !VBOX_ONLY_DOCS */
{
/*
* Before we do anything, init the runtime without loading
* the support driver.
*/
RTR3Init();
bool fShowLogo = true;
int iCmd = 1;
int iCmdArg;
/* global options */
{
{
showLogo();
return 0;
}
{
/* Print version number, and do nothing else. */
return 0;
}
{
/* Special option to dump really all commands,
* even the ones not understood on this platform. */
return 0;
}
{
/* suppress the logo */
fShowLogo = false;
iCmd++;
}
else
{
break;
}
}
if (fShowLogo)
showLogo();
#ifdef VBOX_ONLY_DOCS
int rc = 0;
#else /* !VBOX_ONLY_DOCS */
using namespace com;
{
RTPrintf("ERROR: failed to initialize COM!\n");
return rc;
}
/*
* The input is in the host OS'es codepage (NT guarantees ACP).
* For VBox we use UTF-8 and convert to UCS-2 when calling (XP)COM APIs.
* For simplicity, just convert the argv[] array here.
*/
{
char *converted;
}
do
{
// scopes all the stuff till shutdown
////////////////////////////////////////////////////////////////////////////
/* convertfromraw: does not need a VirtualBox instantiation. */
{
break;
}
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;
}
/*
* All registered command handlers
*/
static const struct
{
const char *command;
int (*handler)(HandlerArg *a);
} s_commandHandlers[] =
{
{ "internalcommands", handleInternalCommands },
{ "list", handleList },
{ "showvminfo", handleShowVMInfo },
{ "registervm", handleRegisterVM },
{ "unregistervm", handleUnregisterVM },
{ "createhd", handleCreateHardDisk },
{ "modifyhd", handleModifyHardDisk },
{ "clonehd", handleCloneHardDisk },
{ "addiscsidisk", handleAddiSCSIDisk },
{ "createvm", handleCreateVM },
{ "modifyvm", handleModifyVM },
{ "startvm", handleStartVM },
{ "controlvm", handleControlVM },
{ "discardstate", handleDiscardState },
{ "adoptstate", handleAdoptState },
{ "snapshot", handleSnapshot },
{ "openmedium", handleOpenMedium },
{ "closemedium", handleCloseMedium },
{ "storageattach", handleStorageAttach },
{ "storagectl", handleStorageController },
{ "showhdinfo", handleShowHardDiskInfo },
{ "getextradata", handleGetExtraData },
{ "setextradata", handleSetExtraData },
{ "setproperty", handleSetProperty },
{ "usbfilter", handleUSBFilter },
{ "sharedfolder", handleSharedFolder },
{ "vmstatistics", handleVMStatistics },
#ifdef VBOX_WITH_GUEST_PROPS
{ "guestproperty", handleGuestProperty },
#endif
{ "metrics", handleMetrics },
{ "import", handleImportAppliance },
{ "export", handleExportAppliance },
#ifdef VBOX_WITH_NETFLT
{ "hostonlyif", handleHostonlyIf },
#endif
{ "dhcpserver", handleDHCPServer},
};
int commandIndex;
{
{
break;
}
}
{
}
/* Although all handlers should always close the session if they open it,
* we do it here just in case if some of the handlers contains a bug --
* leaving the direct session not closed will turn the machine state to
* Aborted which may have unwanted side effects like killing the saved
* state file (if the machine was in the Saved state before). */
// end "all-stuff" scope
////////////////////////////////////////////////////////////////////////////
} while (0);
#endif /* !VBOX_ONLY_DOCS */
/*
* Free converted argument vector
*/
return rc != 0;
}