VBoxManage.cpp revision 54d012edb10277db6ae96a7ddaefde72dbb37745
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/* $Id$ */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** @file
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * VBoxManage - VirtualBox's command-line interface.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Copyright (C) 2006-2009 Sun Microsystems, Inc.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * available from http://www.virtualbox.org. This file is free software;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * General Public License (GPL) as published by the Free Software
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * additional information or have any questions.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/*******************************************************************************
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync* Header Files *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync*******************************************************************************/
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifndef VBOX_ONLY_DOCS
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/com/com.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/com/string.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/com/Guid.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/com/array.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/com/ErrorInfo.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/com/errorprint2.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/com/EventQueue.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/com/VirtualBox.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <vector>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <list>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif /* !VBOX_ONLY_DOCS */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/asm.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/cidr.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/ctype.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/dir.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/env.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/err.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/file.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/initterm.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/param.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/path.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/stream.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/string.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/stdarg.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/thread.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/uuid.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/version.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/log.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include "VBoxManage.h"
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifndef VBOX_ONLY_DOCS
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncusing namespace com;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** command handler type */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsynctypedef int (*PFNHANDLER)(HandlerArg *a);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif /* !VBOX_ONLY_DOCS */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync////////////////////////////////////////////////////////////////////////////////
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync//
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync// global variables
6a795f9e75e30c7f1d75cd45e5de233c71662f58vboxsync//
6a795f9e75e30c7f1d75cd45e5de233c71662f58vboxsync////////////////////////////////////////////////////////////////////////////////
6a795f9e75e30c7f1d75cd45e5de233c71662f58vboxsync
6a795f9e75e30c7f1d75cd45e5de233c71662f58vboxsync/*extern*/ bool g_fDetailedProgress = false;
6a795f9e75e30c7f1d75cd45e5de233c71662f58vboxsync
6a795f9e75e30c7f1d75cd45e5de233c71662f58vboxsync////////////////////////////////////////////////////////////////////////////////
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync//
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync// functions
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync//
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync////////////////////////////////////////////////////////////////////////////////
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifndef VBOX_ONLY_DOCS
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Print out progress on the console
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncvoid showProgress(ComPtr<IProgress> progress)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync BOOL fCompleted;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ULONG ulCurrentPercent;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ULONG ulLastPercent = 0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ULONG ulCurrentOperationPercent;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ULONG ulLastOperationPercent;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ULONG ulLastOperation = (ULONG)-1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr bstrOperationDescription;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ULONG cOperations;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync progress->COMGETTER(OperationCount)(&cOperations);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!g_fDetailedProgress)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("0%%...");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTStrmFlush(g_pStdOut);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync while (SUCCEEDED(progress->COMGETTER(Completed(&fCompleted))))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ULONG ulOperation;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync progress->COMGETTER(Operation)(&ulOperation);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync progress->COMGETTER(Percent(&ulCurrentPercent));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync progress->COMGETTER(OperationPercent(&ulCurrentOperationPercent));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (g_fDetailedProgress)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (ulLastOperation != ulOperation)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync progress->COMGETTER(OperationDescription(bstrOperationDescription.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ulLastPercent = (ULONG)-1; // force print
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ulLastOperation = ulOperation;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if ( (ulCurrentPercent != ulLastPercent)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync || (ulCurrentOperationPercent != ulLastOperationPercent)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync )
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync LONG lSecsRem;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync progress->COMGETTER(TimeRemaining)(&lSecsRem);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("(%ld/%ld) %ls %ld%% => %ld%% (%d s remaining)\n", ulOperation + 1, cOperations, bstrOperationDescription.raw(), ulCurrentOperationPercent, ulCurrentPercent, lSecsRem);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ulLastPercent = ulCurrentPercent;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ulLastOperationPercent = ulCurrentOperationPercent;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* did we cross a 10% mark? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (((ulCurrentPercent / 10) > (ulLastPercent / 10)))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* make sure to also print out missed steps */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (ULONG curVal = (ulLastPercent / 10) * 10 + 10; curVal <= (ulCurrentPercent / 10) * 10; curVal += 10)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (curVal < 100)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("%ld%%...", curVal);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTStrmFlush(g_pStdOut);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ulLastPercent = (ulCurrentPercent / 10) * 10;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (fCompleted)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* make sure the loop is not too tight */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync progress->WaitForCompletion(100);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* complete the line. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (SUCCEEDED(progress->COMGETTER(ResultCode)(&rc)))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (SUCCEEDED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("100%%\n");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("FAILED\n");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("\n");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTStrmFlush(g_pStdOut);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif /* !VBOX_ONLY_DOCS */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncvoid showLogo(void)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync static bool fShown; /* show only once */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!fShown)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("VirtualBox Command Line Management Interface Version "
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync VBOX_VERSION_STRING "\n"
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync "(C) 2005-2009 Sun Microsystems, Inc.\n"
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync "All rights reserved.\n"
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync "\n");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync fShown = true;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifndef VBOX_ONLY_DOCS
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int handleRegisterVM(HandlerArg *a)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc != 1)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_REGISTERVM, "Incorrect number of parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IMachine> machine;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, OpenMachine(Bstr(a->argv[0]), machine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (SUCCEEDED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ASSERT(machine);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, RegisterMachine(machine));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return SUCCEEDED(rc) ? 0 : 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int handleUnregisterVM(HandlerArg *a)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync if ((a->argc != 1) && (a->argc != 2))
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync return errorSyntax(USAGE_UNREGISTERVM, "Incorrect number of parameters");
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync ComPtr<IMachine> machine;
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync /* assume it's a UUID */
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync rc = a->virtualBox->GetMachine(Guid(a->argv[0]), machine.asOutParam());
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync if (FAILED(rc) || !machine)
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync {
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync /* must be a name */
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]), machine.asOutParam()));
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync }
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync if (machine)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Guid uuid;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync machine->COMGETTER(Id)(uuid.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync machine = NULL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, UnregisterMachine(uuid, machine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (SUCCEEDED(rc) && machine)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* are we supposed to delete the config file? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if ((a->argc == 2) && (strcmp(a->argv[1], "-delete") == 0))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(machine, DeleteSettings());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return SUCCEEDED(rc) ? 0 : 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int handleCreateVM(HandlerArg *a)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr baseFolder;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr settingsFile;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr name;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr osTypeId;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTUUID id;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync bool fRegister = false;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTUuidClear(&id);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (int i = 0; i < a->argc; i++)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync if (strcmp(a->argv[i], "-basefolder") == 0)
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc <= i + 1)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorArgument("Missing argument to '%s'", a->argv[i]);
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync i++;
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync baseFolder = a->argv[i];
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync }
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync else if (strcmp(a->argv[i], "-settingsfile") == 0)
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc <= i + 1)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorArgument("Missing argument to '%s'", a->argv[i]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync i++;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync settingsFile = a->argv[i];
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[i], "-name") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc <= i + 1)
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync return errorArgument("Missing argument to '%s'", a->argv[i]);
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync i++;
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync name = a->argv[i];
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync }
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync else if (strcmp(a->argv[i], "-ostype") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc <= i + 1)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorArgument("Missing argument to '%s'", a->argv[i]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync i++;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync osTypeId = a->argv[i];
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[i], "-uuid") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc <= i + 1)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorArgument("Missing argument to '%s'", a->argv[i]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync i++;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (RT_FAILURE(RTUuidFromStr(&id, a->argv[i])))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorArgument("Invalid UUID format %s\n", a->argv[i]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[i], "-register") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync fRegister = true;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_CREATEVM, "Invalid parameter '%s'", Utf8Str(a->argv[i]).raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!name)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_CREATEVM, "Parameter -name is required");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!!baseFolder && !!settingsFile)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_CREATEVM, "Either -basefolder or -settingsfile must be specified");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync do
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IMachine> machine;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!settingsFile)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(a->virtualBox,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CreateMachine(name, osTypeId, baseFolder, Guid(id), machine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(a->virtualBox,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CreateLegacyMachine(name, osTypeId, settingsFile, Guid(id), machine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(machine, SaveSettings());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (fRegister)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(a->virtualBox, RegisterMachine(machine));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Guid uuid;
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync CHECK_ERROR_BREAK(machine, COMGETTER(Id)(uuid.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(machine, COMGETTER(SettingsFilePath)(settingsFile.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("Virtual machine '%ls' is created%s.\n"
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync "UUID: %s\n"
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync "Settings file: '%ls'\n",
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync name.raw(), fRegister ? " and registered" : "",
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uuid.toString().raw(), settingsFile.raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync while (0);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return SUCCEEDED(rc) ? 0 : 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Parses a number.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @returns Valid number on success.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @returns 0 if invalid number. All necesary bitching has been done.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param psz Pointer to the nic number.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncunsigned parseNum(const char *psz, unsigned cMaxNum, const char *name)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint32_t u32;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync char *pszNext;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int rc = RTStrToUInt32Ex(psz, &pszNext, 10, &u32);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if ( RT_SUCCESS(rc)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync && *pszNext == '\0'
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync && u32 >= 1
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync && u32 <= cMaxNum)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return (unsigned)u32;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorArgument("Invalid %s number '%s'", name, psz);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return 0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** @todo refine this after HDD changes; MSC 8.0/64 has trouble with handleModifyVM. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#if defined(_MSC_VER)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync# pragma optimize("", on)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int handleStartVM(HandlerArg *a)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc < 1)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_STARTVM, "Not enough parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IMachine> machine;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* assume it's a UUID */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = a->virtualBox->GetMachine(Guid(a->argv[0]), machine.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc) || !machine)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* must be a name */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]), machine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (machine)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Guid uuid;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync machine->COMGETTER(Id)(uuid.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* default to GUI session type */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr sessionType = "gui";
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* has a session type been specified? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if ((a->argc > 2) && (strcmp(a->argv[1], "-type") == 0))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[2], "gui") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync sessionType = "gui";
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifdef VBOX_WITH_VRDP
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[2], "vrdp") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync sessionType = "vrdp";
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[2], "capture") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync sessionType = "capture";
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorArgument("Invalid session type argument '%s'", a->argv[2]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr env;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifdef RT_OS_LINUX
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* make sure the VM process will start on the same display as VBoxManage */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync const char *display = RTEnvGet ("DISPLAY");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (display)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync env = Utf8StrFmt ("DISPLAY=%s", display);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IProgress> progress;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_RET(a->virtualBox, OpenRemoteSession(a->session, uuid, sessionType,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync env, progress.asOutParam()), rc);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("Waiting for the remote session to open...\n");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_RET(progress, WaitForCompletion (-1), 1);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync BOOL completed;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_RET(progress, COMGETTER(Completed)(&completed), rc);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ASSERT(completed);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT resultCode;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_RET(progress, COMGETTER(ResultCode)(&resultCode), rc);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(resultCode))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IVirtualBoxErrorInfo> errorInfo;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_RET(progress, COMGETTER(ErrorInfo)(errorInfo.asOutParam()), 1);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ErrorInfo info (errorInfo);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync GluePrintErrorInfo(info);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("Remote session has been successfully opened.\n");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* it's important to always close sessions */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync a->session->Close();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return SUCCEEDED(rc) ? 0 : 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int handleControlVM(HandlerArg *a)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc < 2)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_CONTROLVM, "Not enough parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* try to find the given machine */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IMachine> machine;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Guid uuid (a->argv[0]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!uuid.isEmpty())
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR (a->virtualBox, GetMachine (uuid, machine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR (a->virtualBox, FindMachine (Bstr(a->argv[0]), machine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (SUCCEEDED (rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync machine->COMGETTER(Id) (uuid.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED (rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* open a session for the VM */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_RET (a->virtualBox, OpenExistingSession (a->session, uuid), 1);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync do
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* get the associated console */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IConsole> console;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (a->session, COMGETTER(Console)(console.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* ... and session machine */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IMachine> sessionMachine;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (a->session, COMGETTER(Machine)(sessionMachine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* which command? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[1], "pause") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (console, Pause());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[1], "resume") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (console, Resume());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[1], "reset") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (console, Reset());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[1], "poweroff") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (console, PowerDown());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[1], "savestate") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IProgress> progress;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (console, SaveState(progress.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync showProgress(progress);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync progress->COMGETTER(ResultCode)(&rc);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync com::ProgressErrorInfo info(progress);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (info.isBasicAvailable())
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("Error: failed to save machine state. Error message: %lS\n", info.getText().raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("Error: failed to save machine state. No error message available!\n");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[1], "acpipowerbutton") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (console, PowerButton());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[1], "acpisleepbutton") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (console, SleepButton());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[1], "injectnmi") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* get the machine debugger. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IMachineDebugger> debugger;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(console, COMGETTER(Debugger)(debugger.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(debugger, InjectNMI());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[1], "keyboardputscancode") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IKeyboard> keyboard;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(console, COMGETTER(Keyboard)(keyboard.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc <= 1 + 1)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorArgument("Missing argument to '%s'. Expected IBM PC AT set 2 keyboard scancode(s) as hex byte(s).", a->argv[1]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Arbitrary restrict the length of a sequence of scancodes to 1024. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync LONG alScancodes[1024];
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int cScancodes = 0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Process the command line. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int i;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (i = 1 + 1; i < a->argc && cScancodes < (int)RT_ELEMENTS(alScancodes); i++, cScancodes++)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if ( RT_C_IS_XDIGIT (a->argv[i][0])
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync && RT_C_IS_XDIGIT (a->argv[i][1])
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync && a->argv[i][2] == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint8_t u8Scancode;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int rc = RTStrToUInt8Ex(a->argv[i], NULL, 16, &u8Scancode);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (RT_FAILURE (rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("Error: converting '%s' returned %Rrc!\n", a->argv[i], rc);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync alScancodes[cScancodes] = u8Scancode;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("Error: '%s' is not a hex byte!\n", a->argv[i]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
8b82f5ce032cb07de31804c998483b0988530aebvboxsync if (FAILED(rc))
8b82f5ce032cb07de31804c998483b0988530aebvboxsync break;
8b82f5ce032cb07de31804c998483b0988530aebvboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if ( cScancodes == RT_ELEMENTS(alScancodes)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync && i < a->argc)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("Error: too many scancodes, maximum %d allowed!\n", RT_ELEMENTS(alScancodes));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Send scancodes to the VM.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Note: 'PutScancodes' did not work here. Only the first scancode was transmitted.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (i = 0; i < cScancodes; i++)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(keyboard, PutScancode(alScancodes[i]));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("Scancode[%d]: 0x%02X\n", i, alScancodes[i]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strncmp(a->argv[1], "setlinkstate", 12) == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Get the number of network adapters */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ULONG NetworkAdapterCount = 0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <ISystemProperties> info;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (a->virtualBox, COMGETTER(SystemProperties) (info.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (info, COMGETTER(NetworkAdapterCount) (&NetworkAdapterCount));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync unsigned n = parseNum(&a->argv[1][12], NetworkAdapterCount, "NIC");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!n)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc <= 1 + 1)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* get the corresponding network adapter */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<INetworkAdapter> adapter;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (adapter)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[2], "on") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (adapter, COMSETTER(CableConnected)(TRUE));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[2], "off") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (adapter, COMSETTER(CableConnected)(FALSE));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorArgument("Invalid link state '%s'", Utf8Str(a->argv[2]).raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifdef VBOX_WITH_VRDP
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[1], "vrdp") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc <= 1 + 1)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorArgument("Missing argument to '%s'", a->argv[1]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* get the corresponding VRDP server */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IVRDPServer> vrdpServer;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync sessionMachine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ASSERT(vrdpServer);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (vrdpServer)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[2], "on") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (vrdpServer, COMSETTER(Enabled)(TRUE));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[2], "off") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (vrdpServer, COMSETTER(Enabled)(FALSE));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorArgument("Invalid vrdp server state '%s'", Utf8Str(a->argv[2]).raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif /* VBOX_WITH_VRDP */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp (a->argv[1], "usbattach") == 0 ||
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync strcmp (a->argv[1], "usbdetach") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc < 3)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorSyntax(USAGE_CONTROLVM, "Not enough parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync bool attach = strcmp (a->argv[1], "usbattach") == 0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Guid usbId = a->argv [2];
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (usbId.isEmpty())
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync // assume address
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (attach)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IHost> host;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (a->virtualBox, COMGETTER(Host) (host.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync SafeIfaceArray <IHostUSBDevice> coll;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (host, COMGETTER(USBDevices) (ComSafeArrayAsOutParam(coll)));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IHostUSBDevice> dev;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (host, FindUSBDeviceByAddress (Bstr (a->argv [2]), dev.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (dev, COMGETTER(Id) (usbId.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync SafeIfaceArray <IUSBDevice> coll;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (console, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(coll)));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IUSBDevice> dev;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (console, FindUSBDeviceByAddress (Bstr (a->argv [2]),
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync dev.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (dev, COMGETTER(Id) (usbId.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (attach)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (console, AttachUSBDevice (usbId));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IUSBDevice> dev;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (console, DetachUSBDevice (usbId, dev.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[1], "setvideomodehint") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc != 5 && a->argc != 6)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint32_t xres = RTStrToUInt32(a->argv[2]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint32_t yres = RTStrToUInt32(a->argv[3]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint32_t bpp = RTStrToUInt32(a->argv[4]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint32_t displayIdx = 0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc == 6)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync displayIdx = RTStrToUInt32(a->argv[5]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IDisplay> display;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(console, COMGETTER(Display)(display.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(display, SetVideoModeHint(xres, yres, bpp, displayIdx));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[1], "setcredentials") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync bool fAllowLocalLogon = true;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc == 7)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[5], "-allowlocallogon") != 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorArgument("Invalid parameter '%s'", a->argv[5]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[6], "no") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync fAllowLocalLogon = false;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (a->argc != 5)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IGuest> guest;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(console, COMGETTER(Guest)(guest.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(guest, SetCredentials(Bstr(a->argv[2]), Bstr(a->argv[3]), Bstr(a->argv[4]), fAllowLocalLogon));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[1], "dvdattach") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc != 3)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IDVDDrive> dvdDrive;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync sessionMachine->COMGETTER(DVDDrive)(dvdDrive.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ASSERT(dvdDrive);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* unmount? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[2], "none") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(dvdDrive, Unmount());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* host drive? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strncmp(a->argv[2], "host:", 5) == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IHost> host;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync com::SafeIfaceArray <IHostDVDDrive> hostDVDs;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = host->COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(hostDVDs));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IHostDVDDrive> hostDVDDrive;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = host->FindHostDVDDrive(Bstr(a->argv[2] + 5), hostDVDDrive.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!hostDVDDrive)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorArgument("Invalid host DVD drive name");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(dvdDrive, CaptureHostDrive(hostDVDDrive));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* first assume it's a UUID */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Guid uuid(a->argv[2]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IDVDImage> dvdImage;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = a->virtualBox->GetDVDImage(uuid, dvdImage.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc) || !dvdImage)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* must be a filename, check if it's in the collection */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = a->virtualBox->FindDVDImage(Bstr(a->argv[2]), dvdImage.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* not registered, do that on the fly */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!dvdImage)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Guid emptyUUID;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, OpenDVDImage(Bstr(a->argv[2]), emptyUUID, dvdImage.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!dvdImage)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync dvdImage->COMGETTER(Id)(uuid.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(dvdDrive, MountImage(uuid));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[1], "floppyattach") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc != 3)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IFloppyDrive> floppyDrive;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync sessionMachine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ASSERT(floppyDrive);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* unmount? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[2], "none") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(floppyDrive, Unmount());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* host drive? */
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync else if (strncmp(a->argv[2], "host:", 5) == 0)
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync {
4946f90c5c7016131555f0c925091d4ede6bdde0vboxsync ComPtr<IHost> host;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync com::SafeIfaceArray <IHostFloppyDrive> hostFloppies;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = host->COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(hostFloppies));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CheckComRCReturnRC (rc);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IHostFloppyDrive> hostFloppyDrive;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync host->FindHostFloppyDrive(Bstr(a->argv[2] + 5), hostFloppyDrive.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!hostFloppyDrive)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorArgument("Invalid host floppy drive name");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(floppyDrive, CaptureHostDrive(hostFloppyDrive));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* first assume it's a UUID */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Guid uuid(a->argv[2]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IFloppyImage> floppyImage;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = a->virtualBox->GetFloppyImage(uuid, floppyImage.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc) || !floppyImage)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* must be a filename, check if it's in the collection */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = a->virtualBox->FindFloppyImage(Bstr(a->argv[2]), floppyImage.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* not registered, do that on the fly */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!floppyImage)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Guid emptyUUID;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, OpenFloppyImage(Bstr(a->argv[2]), emptyUUID, floppyImage.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!floppyImage)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync floppyImage->COMGETTER(Id)(uuid.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(floppyDrive, MountImage(uuid));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifdef VBOX_WITH_MEM_BALLOONING
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strncmp(a->argv[1], "-guestmemoryballoon", 19) == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc != 3)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint32_t uVal;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int vrc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync vrc = RTStrToUInt32Ex(a->argv[2], NULL, 0, &uVal);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (vrc != VINF_SUCCESS)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorArgument("Error parsing guest memory balloon size '%s'", a->argv[2]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* guest is running; update IGuest */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IGuest> guest;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = console->COMGETTER(Guest)(guest.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (SUCCEEDED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(guest, COMSETTER(MemoryBalloonSize)(uVal));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strncmp(a->argv[1], "-gueststatisticsinterval", 24) == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc != 3)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint32_t uVal;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int vrc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync vrc = RTStrToUInt32Ex(a->argv[2], NULL, 0, &uVal);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (vrc != VINF_SUCCESS)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorArgument("Error parsing guest statistics interval '%s'", a->argv[2]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* guest is running; update IGuest */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IGuest> guest;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = console->COMGETTER(Guest)(guest.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (SUCCEEDED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(guest, COMSETTER(StatisticsUpdateInterval)(uVal));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync errorSyntax(USAGE_CONTROLVM, "Invalid parameter '%s'", Utf8Str(a->argv[1]).raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = E_FAIL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync while (0);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync a->session->Close();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return SUCCEEDED (rc) ? 0 : 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int handleDiscardState(HandlerArg *a)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc != 1)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_DISCARDSTATE, "Incorrect number of parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IMachine> machine;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* assume it's a UUID */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = a->virtualBox->GetMachine(Guid(a->argv[0]), machine.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc) || !machine)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* must be a name */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]), machine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (machine)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync do
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* we have to open a session for this task */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Guid guid;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync machine->COMGETTER(Id)(guid.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(a->virtualBox, OpenSession(a->session, guid));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync do
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IConsole> console;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(a->session, COMGETTER(Console)(console.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(console, DiscardSavedState());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync while (0);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(a->session, Close());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync while (0);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return SUCCEEDED(rc) ? 0 : 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int handleAdoptdState(HandlerArg *a)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc != 2)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_ADOPTSTATE, "Incorrect number of parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IMachine> machine;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* assume it's a UUID */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = a->virtualBox->GetMachine(Guid(a->argv[0]), machine.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc) || !machine)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* must be a name */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]), machine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (machine)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync do
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* we have to open a session for this task */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Guid guid;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync machine->COMGETTER(Id)(guid.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(a->virtualBox, OpenSession(a->session, guid));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync do
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IConsole> console;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(a->session, COMGETTER(Console)(console.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(console, AdoptSavedState (Bstr (a->argv[1])));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync while (0);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(a->session, Close());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync while (0);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return SUCCEEDED(rc) ? 0 : 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int handleGetExtraData(HandlerArg *a)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc = S_OK;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc != 2)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_GETEXTRADATA, "Incorrect number of parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* global data? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[0], "global") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* enumeration? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[1], "enumerate") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr extraDataKey;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync do
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr nextExtraDataKey;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr nextExtraDataValue;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rcEnum = a->virtualBox->GetNextExtraDataKey(extraDataKey, nextExtraDataKey.asOutParam(),
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync nextExtraDataValue.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync extraDataKey = nextExtraDataKey;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (SUCCEEDED(rcEnum) && extraDataKey)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("Key: %lS, Value: %lS\n", nextExtraDataKey.raw(), nextExtraDataValue.raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync } while (extraDataKey);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr value;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, GetExtraData(Bstr(a->argv[1]), value.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (value)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("Value: %lS\n", value.raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("No value set!\n");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync ComPtr<IMachine> machine;
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync /* assume it's a UUID */
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync rc = a->virtualBox->GetMachine(Guid(a->argv[0]), machine.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc) || !machine)
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* must be a name */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]), machine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync if (machine)
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync {
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync /* enumeration? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[1], "enumerate") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr extraDataKey;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync do
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr nextExtraDataKey;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr nextExtraDataValue;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rcEnum = machine->GetNextExtraDataKey(extraDataKey, nextExtraDataKey.asOutParam(),
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync nextExtraDataValue.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync extraDataKey = nextExtraDataKey;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (SUCCEEDED(rcEnum) && extraDataKey)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("Key: %lS, Value: %lS\n", nextExtraDataKey.raw(), nextExtraDataValue.raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync } while (extraDataKey);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr value;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(machine, GetExtraData(Bstr(a->argv[1]), value.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (value)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("Value: %lS\n", value.raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("No value set!\n");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return SUCCEEDED(rc) ? 0 : 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int handleSetExtraData(HandlerArg *a)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc = S_OK;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc < 2)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_SETEXTRADATA, "Not enough parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* global data? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[0], "global") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc < 3)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, SetExtraData(Bstr(a->argv[1]), NULL));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (a->argc == 3)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, SetExtraData(Bstr(a->argv[1]), Bstr(a->argv[2])));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_SETEXTRADATA, "Too many parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IMachine> machine;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* assume it's a UUID */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = a->virtualBox->GetMachine(Guid(a->argv[0]), machine.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc) || !machine)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* must be a name */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]), machine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (machine)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc < 3)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(machine, SetExtraData(Bstr(a->argv[1]), NULL));
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync else if (a->argc == 3)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(machine, SetExtraData(Bstr(a->argv[1]), Bstr(a->argv[2])));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_SETEXTRADATA, "Too many parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return SUCCEEDED(rc) ? 0 : 1;
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int handleSetProperty(HandlerArg *a)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* there must be two arguments: property name and value */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc != 2)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_SETPROPERTY, "Incorrect number of parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<ISystemProperties> systemProperties;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync a->virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[0], "hdfolder") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* reset to default? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[1], "default") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(systemProperties, COMSETTER(DefaultHardDiskFolder)(NULL));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(systemProperties, COMSETTER(DefaultHardDiskFolder)(Bstr(a->argv[1])));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[0], "machinefolder") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* reset to default? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[1], "default") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(systemProperties, COMSETTER(DefaultMachineFolder)(NULL));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(systemProperties, COMSETTER(DefaultMachineFolder)(Bstr(a->argv[1])));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[0], "vrdpauthlibrary") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* reset to default? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[1], "default") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(systemProperties, COMSETTER(RemoteDisplayAuthLibrary)(NULL));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(systemProperties, COMSETTER(RemoteDisplayAuthLibrary)(Bstr(a->argv[1])));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[0], "websrvauthlibrary") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* reset to default? */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[1], "default") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(systemProperties, COMSETTER(WebServiceAuthLibrary)(NULL));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(systemProperties, COMSETTER(WebServiceAuthLibrary)(Bstr(a->argv[1])));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[0], "hwvirtexenabled") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[1], "yes") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(systemProperties, COMSETTER(HWVirtExEnabled)(TRUE));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[1], "no") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(systemProperties, COMSETTER(HWVirtExEnabled)(FALSE));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorArgument("Invalid value '%s' for hardware virtualization extension flag", a->argv[1]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[0], "loghistorycount") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint32_t uVal;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int vrc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync vrc = RTStrToUInt32Ex(a->argv[1], NULL, 0, &uVal);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (vrc != VINF_SUCCESS)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorArgument("Error parsing Log history count '%s'", a->argv[1]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(systemProperties, COMSETTER(LogHistoryCount)(uVal));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_SETPROPERTY, "Invalid parameter '%s'", a->argv[0]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return SUCCEEDED(rc) ? 0 : 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int handleSharedFolder (HandlerArg *a)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* we need at least a command and target */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc < 2)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_SHAREDFOLDER, "Not enough parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IMachine> machine;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* assume it's a UUID */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = a->virtualBox->GetMachine(Guid(a->argv[1]), machine.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc) || !machine)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* must be a name */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[1]), machine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!machine)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Guid uuid;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync machine->COMGETTER(Id)(uuid.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[0], "add") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* we need at least four more parameters */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc < 5)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_SHAREDFOLDER_ADD, "Not enough parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync char *name = NULL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync char *hostpath = NULL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync bool fTransient = false;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync bool fWritable = true;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (int i = 2; i < a->argc; i++)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[i], "-name") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc <= i + 1 || !*a->argv[i+1])
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorArgument("Missing argument to '%s'", a->argv[i]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync i++;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync name = a->argv[i];
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[i], "-hostpath") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc <= i + 1 || !*a->argv[i+1])
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorArgument("Missing argument to '%s'", a->argv[i]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync i++;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync hostpath = a->argv[i];
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[i], "-readonly") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync fWritable = false;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[i], "-transient") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync fTransient = true;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_SHAREDFOLDER_ADD, "Invalid parameter '%s'", Utf8Str(a->argv[i]).raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (NULL != strstr(name, " "))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_SHAREDFOLDER_ADD, "No spaces allowed in parameter '-name'!");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* required arguments */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!name || !hostpath)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_SHAREDFOLDER_ADD, "Parameters -name and -hostpath are required");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (fTransient)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IConsole> console;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync /* open an existing session for the VM */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_RET(a->virtualBox, OpenExistingSession (a->session, uuid), 1);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* get the session machine */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_RET(a->session, COMGETTER(Machine)(machine.asOutParam()), 1);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* get the session console */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_RET(a->session, COMGETTER(Console)(console.asOutParam()), 1);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(console, CreateSharedFolder(Bstr(name), Bstr(hostpath), fWritable));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (console)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync a->session->Close();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* open a session for the VM */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_RET (a->virtualBox, OpenSession(a->session, uuid), 1);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* get the mutable session machine */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync a->session->COMGETTER(Machine)(machine.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(machine, CreateSharedFolder(Bstr(name), Bstr(hostpath), fWritable));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (SUCCEEDED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(machine, SaveSettings());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync a->session->Close();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[0], "remove") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* we need at least two more parameters */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc < 3)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_SHAREDFOLDER_REMOVE, "Not enough parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync char *name = NULL;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync bool fTransient = false;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (int i = 2; i < a->argc; i++)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(a->argv[i], "-name") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc <= i + 1 || !*a->argv[i+1])
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorArgument("Missing argument to '%s'", a->argv[i]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync i++;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync name = a->argv[i];
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(a->argv[i], "-transient") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync fTransient = true;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_SHAREDFOLDER_REMOVE, "Invalid parameter '%s'", Utf8Str(a->argv[i]).raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* required arguments */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!name)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_SHAREDFOLDER_REMOVE, "Parameter -name is required");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (fTransient)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IConsole> console;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* open an existing session for the VM */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_RET(a->virtualBox, OpenExistingSession (a->session, uuid), 1);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* get the session machine */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_RET(a->session, COMGETTER(Machine)(machine.asOutParam()), 1);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* get the session console */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_RET(a->session, COMGETTER(Console)(console.asOutParam()), 1);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(console, RemoveSharedFolder(Bstr(name)));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (console)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync a->session->Close();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* open a session for the VM */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_RET (a->virtualBox, OpenSession(a->session, uuid), 1);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* get the mutable session machine */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync a->session->COMGETTER(Machine)(machine.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(machine, RemoveSharedFolder(Bstr(name)));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* commit and close the session */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(machine, SaveSettings());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync a->session->Close();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_SETPROPERTY, "Invalid parameter '%s'", Utf8Str(a->argv[0]).raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return 0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int handleVMStatistics(HandlerArg *a)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* at least one option: the UUID or name of the VM */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (a->argc < 1)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_VM_STATISTICS, "Incorrect number of parameters");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* try to find the given machine */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IMachine> machine;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Guid uuid (a->argv[0]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!uuid.isEmpty())
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, GetMachine(uuid, machine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, FindMachine(Bstr(a->argv[0]), machine.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (SUCCEEDED (rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync machine->COMGETTER(Id)(uuid.asOutParam());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync /* parse arguments. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync bool fReset = false;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync bool fWithDescriptions = false;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync const char *pszPattern = NULL; /* all */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (int i = 1; i < a->argc; i++)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!strcmp(a->argv[i], "-pattern"))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (pszPattern)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_VM_STATISTICS, "Multiple -patterns options is not permitted");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (i + 1 >= a->argc)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorArgument("Missing argument to '%s'", a->argv[i]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pszPattern = a->argv[++i];
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (!strcmp(a->argv[i], "-descriptions"))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync fWithDescriptions = true;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* add: -file <filename> and -formatted */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (!strcmp(a->argv[i], "-reset"))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync fReset = true;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return errorSyntax(USAGE_VM_STATISTICS, "Unknown option '%s'", a->argv[i]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (fReset && fWithDescriptions)
9b9a21c4dedad15ac8b2059a858a94c5a33db1bdvboxsync return errorSyntax(USAGE_VM_STATISTICS, "The -reset and -descriptions options does not mix");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* open an existing session for the VM. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->virtualBox, OpenExistingSession(a->session, uuid));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (SUCCEEDED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* get the session console. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IConsole> console;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(a->session, COMGETTER(Console)(console.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (SUCCEEDED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* get the machine debugger. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IMachineDebugger> debugger;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(console, COMGETTER(Debugger)(debugger.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (SUCCEEDED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (fReset)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(debugger, ResetStats(Bstr(pszPattern)));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr stats;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR(debugger, GetStats(Bstr(pszPattern), fWithDescriptions, stats.asOutParam()));
9b9a21c4dedad15ac8b2059a858a94c5a33db1bdvboxsync if (SUCCEEDED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* if (fFormatted)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { big mess }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("%ls\n", stats.raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync a->session->Close();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9b9a21c4dedad15ac8b2059a858a94c5a33db1bdvboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return SUCCEEDED(rc) ? 0 : 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif /* !VBOX_ONLY_DOCS */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncenum ConvertSettings
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ConvertSettings_No = 0,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ConvertSettings_Yes = 1,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ConvertSettings_Backup = 2,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ConvertSettings_Ignore = 3,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync};
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifndef VBOX_ONLY_DOCS
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Checks if any of the settings files were auto-converted and informs the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * user if so.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @return @false if the program should terminate and @true otherwise.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic bool checkForAutoConvertedSettings (ComPtr<IVirtualBox> virtualBox,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<ISession> session,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ConvertSettings fConvertSettings)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* return early if nothing to do */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (fConvertSettings == ConvertSettings_Ignore)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return true;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync do
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr formatVersion;
9b9a21c4dedad15ac8b2059a858a94c5a33db1bdvboxsync CHECK_ERROR_BREAK(virtualBox, COMGETTER(SettingsFormatVersion) (formatVersion.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync bool isGlobalConverted = false;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync std::list <ComPtr <IMachine> > cvtMachines;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync std::list <Utf8Str> fileList;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr version;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr filePath;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync com::SafeIfaceArray <IMachine> machines;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(virtualBox, COMGETTER(Machines)(ComSafeArrayAsOutParam (machines)));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (size_t i = 0; i < machines.size(); ++ i)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync BOOL accessible;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(machines[i], COMGETTER(Accessible) (&accessible));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!accessible)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync continue;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(machines[i], COMGETTER(SettingsFileVersion) (version.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (version != formatVersion)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync cvtMachines.push_back (machines [i]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr filePath;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(machines[i], COMGETTER(SettingsFilePath) (filePath.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync fileList.push_back (Utf8StrFmt ("%ls (%ls)", filePath.raw(),
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync version.raw()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(virtualBox, COMGETTER(SettingsFileVersion) (version.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (version != formatVersion)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync isGlobalConverted = true;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(virtualBox, COMGETTER(SettingsFilePath) (filePath.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync fileList.push_back (Utf8StrFmt ("%ls (%ls)", filePath.raw(),
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync version.raw()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (fileList.size() > 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync switch (fConvertSettings)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync case ConvertSettings_No:
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync RTPrintf (
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync"WARNING! The following VirtualBox settings files have been automatically\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync"converted to the new settings file format version '%ls':\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync"\n",
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync formatVersion.raw());
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync
2d8894b1c178c9f1199cac84059ca66aa5dee6b3vboxsync for (std::list <Utf8Str>::const_iterator f = fileList.begin();
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync f != fileList.end(); ++ f)
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync RTPrintf (" %S\n", (*f).raw());
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync RTPrintf (
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync"\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync"The current command was aborted to prevent overwriting the above settings\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync"files with the results of the auto-conversion without your permission.\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync"Please put one of the following command line switches to the beginning of\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync"the VBoxManage command line and repeat the command:\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync"\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync" -convertSettings - to save all auto-converted files (it will not\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync" be possible to use these settings files with an\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync" older version of VirtualBox in the future);\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync" -convertSettingsBackup - to create backup copies of the settings files in\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync" the old format before saving them in the new format;\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync" -convertSettingsIgnore - to not save the auto-converted settings files.\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync"\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync"Note that if you use -convertSettingsIgnore, the auto-converted settings files\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync"will be implicitly saved in the new format anyway once you change a setting or\n"
23631945c9cb3df68ca51c69ed0b77e90164b402vboxsync"start a virtual machine, but NO backup copies will be created in this case.\n");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return false;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync case ConvertSettings_Yes:
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync case ConvertSettings_Backup:
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync default:
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertFailedReturn (false);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (std::list <ComPtr <IMachine> >::const_iterator m = cvtMachines.begin();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync m != cvtMachines.end(); ++ m)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Guid id;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK((*m), COMGETTER(Id) (id.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* open a session for the VM */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK (virtualBox, OpenSession (session, id));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr <IMachine> sm;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR_BREAK(session, COMGETTER(Machine) (sm.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr bakFileName;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (fConvertSettings == ConvertSettings_Backup)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR (sm, SaveSettingsWithBackup (bakFileName.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR (sm, SaveSettings());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync session->Close();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (isGlobalConverted)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Bstr bakFileName;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (fConvertSettings == ConvertSettings_Backup)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR (virtualBox, SaveSettingsWithBackup (bakFileName.asOutParam()));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync CHECK_ERROR (virtualBox, SaveSettings());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync while (0);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return SUCCEEDED (rc);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif /* !VBOX_ONLY_DOCS */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync// main
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync///////////////////////////////////////////////////////////////////////////////
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncint main(int argc, char *argv[])
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Before we do anything, init the runtime without loading
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * the support driver.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTR3Init();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync bool fShowLogo = true;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int iCmd = 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int iCmdArg;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ConvertSettings fConvertSettings = ConvertSettings_No;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* global options */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (int i = 1; i < argc || argc <= iCmd; i++)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if ( argc <= iCmd
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync || (strcmp(argv[i], "help") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync || (strcmp(argv[i], "-?") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync || (strcmp(argv[i], "-h") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync || (strcmp(argv[i], "-help") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync || (strcmp(argv[i], "--help") == 0))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync showLogo();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync printUsage(USAGE_ALL);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return 0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if ( strcmp(argv[i], "-v") == 0
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync || strcmp(argv[i], "-version") == 0
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync || strcmp(argv[i], "-Version") == 0
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync || strcmp(argv[i], "--version") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Print version number, and do nothing else. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("%sr%d\n", VBOX_VERSION_STRING, VBoxSVNRev ());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return 0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(argv[i], "-dumpopts") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Special option to dump really all commands,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * even the ones not understood on this platform. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync printUsage(USAGE_DUMPOPTS);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return 0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(argv[i], "-nologo") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* suppress the logo */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync fShowLogo = false;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync iCmd++;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(argv[i], "-convertSettings") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync fConvertSettings = ConvertSettings_Yes;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync iCmd++;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(argv[i], "-convertSettingsBackup") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync fConvertSettings = ConvertSettings_Backup;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync iCmd++;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (strcmp(argv[i], "-convertSettingsIgnore") == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync fConvertSettings = ConvertSettings_Ignore;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync iCmd++;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync iCmdArg = iCmd + 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (fShowLogo)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync showLogo();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifdef VBOX_ONLY_DOCS
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int rc = 0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#else /* !VBOX_ONLY_DOCS */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HRESULT rc = 0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = com::Initialize();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("ERROR: failed to initialize COM!\n");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * The input is in the host OS'es codepage (NT guarantees ACP).
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * For VBox we use UTF-8 and convert to UCS-2 when calling (XP)COM APIs.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * For simplicity, just convert the argv[] array here.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (int i = iCmdArg; i < argc; i++)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync char *converted;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTStrCurrentCPToUtf8(&converted, argv[i]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync argv[i] = converted;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync do
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync // scopes all the stuff till shutdown
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ////////////////////////////////////////////////////////////////////////////
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* convertfromraw: does not need a VirtualBox instantiation. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (argc >= iCmdArg && ( !strcmp(argv[iCmd], "convertfromraw")
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync || !strcmp(argv[iCmd], "convertdd")))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = handleConvertFromRaw(argc - iCmdArg, argv + iCmdArg);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<IVirtualBox> virtualBox;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ComPtr<ISession> session;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = virtualBox.createLocalObject(CLSID_VirtualBox);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("ERROR: failed to create the VirtualBox object!\n");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = session.createInprocObject(CLSID_Session);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("ERROR: failed to create a session object!\n");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (FAILED(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync com::ErrorInfo info;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!info.isFullAvailable() && !info.isBasicAvailable())
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync com::GluePrintRCMessage(rc);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTPrintf("Most likely, the VirtualBox COM server is not running or failed to start.\n");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync GluePrintErrorInfo(info);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* create the event queue
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * (here it is necessary only to process remaining XPCOM/IPC events
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * after the session is closed) */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifdef USE_XPCOM_QUEUE
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync nsCOMPtr<nsIEventQueue> eventQ;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync NS_GetMainEventQ(getter_AddRefs(eventQ));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!checkForAutoConvertedSettings (virtualBox, session, fConvertSettings))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifdef USE_XPCOM_QUEUE
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HandlerArg handlerArg = { 0, NULL, eventQ, virtualBox, session };
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync HandlerArg handlerArg = { 0, NULL, virtualBox, session };
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * All registered command handlers
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync struct
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync const char *command;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PFNHANDLER handler;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync } commandHandlers[] =
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "internalcommands", handleInternalCommands },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "list", handleList },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "showvminfo", handleShowVMInfo },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "registervm", handleRegisterVM },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "unregistervm", handleUnregisterVM },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "createhd", handleCreateHardDisk },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "createvdi", handleCreateHardDisk }, /* backward compatiblity */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "modifyhd", handleModifyHardDisk },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "modifyvdi", handleModifyHardDisk }, /* backward compatiblity */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "clonehd", handleCloneHardDisk },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "clonevdi", handleCloneHardDisk }, /* backward compatiblity */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "addiscsidisk", handleAddiSCSIDisk },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "createvm", handleCreateVM },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "modifyvm", handleModifyVM },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "startvm", handleStartVM },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "controlvm", handleControlVM },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "discardstate", handleDiscardState },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "adoptstate", handleAdoptdState },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "snapshot", handleSnapshot },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "openmedium", handleOpenMedium },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "registerimage", handleOpenMedium }, /* backward compatiblity */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "closemedium", handleCloseMedium },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "unregisterimage", handleCloseMedium }, /* backward compatiblity */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "showhdinfo", handleShowHardDiskInfo },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "showvdiinfo", handleShowHardDiskInfo }, /* backward compatiblity */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "getextradata", handleGetExtraData },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "setextradata", handleSetExtraData },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "setproperty", handleSetProperty },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "usbfilter", handleUSBFilter },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "sharedfolder", handleSharedFolder },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "vmstatistics", handleVMStatistics },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifdef VBOX_WITH_GUEST_PROPS
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "guestproperty", handleGuestProperty },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif /* VBOX_WITH_GUEST_PROPS defined */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "metrics", handleMetrics },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "import", handleImportAppliance },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "export", handleExportAppliance },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#if defined(VBOX_WITH_NETFLT)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "hostonlyif", handleHostonlyIf },
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { "dhcpserver", handleDHCPServer},
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync { NULL, NULL }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync };
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int commandIndex;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (commandIndex = 0; commandHandlers[commandIndex].command != NULL; commandIndex++)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (strcmp(commandHandlers[commandIndex].command, argv[iCmd]) == 0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync handlerArg.argc = argc - iCmdArg;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync handlerArg.argv = &argv[iCmdArg];
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = commandHandlers[commandIndex].handler(&handlerArg);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!commandHandlers[commandIndex].command)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = errorSyntax(USAGE_ALL, "Invalid command '%s'", Utf8Str(argv[iCmd]).raw());
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Although all handlers should always close the session if they open it,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * we do it here just in case if some of the handlers contains a bug --
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * leaving the direct session not closed will turn the machine state to
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Aborted which may have unwanted side effects like killing the saved
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * state file (if the machine was in the Saved state before). */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync session->Close();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifdef USE_XPCOM_QUEUE
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync eventQ->ProcessPendingEvents();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync // end "all-stuff" scope
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ////////////////////////////////////////////////////////////////////////////
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync while (0);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync com::Shutdown();
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif /* !VBOX_ONLY_DOCS */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Free converted argument vector
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (int i = iCmdArg; i < argc; i++)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTStrFree(argv[i]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return rc != 0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync