GuestImpl.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
/* $Id$ */
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2008 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "GuestImpl.h"
#include "Global.h"
#include "ConsoleImpl.h"
#include "ProgressImpl.h"
#include "VMMDev.h"
#include "AutoCaller.h"
#include "Logging.h"
#ifdef VBOX_WITH_GUEST_CONTROL
#endif
// defines
/////////////////////////////////////////////////////////////////////////////
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
void Guest::FinalRelease()
{
uninit ();
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the guest object.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* mData.mAdditionsActive is FALSE */
/* Confirm a successful initialization when it's the case */
else
mMemoryBalloonSize = 0; /* Default is no ballooning */
mStatUpdateInterval = 0; /* Default is not to report guest statistics at all */
/* Clear statistics. */
for (unsigned i = 0 ; i < GUESTSTATTYPE_MAX; i++)
mCurrentGuestStat[i] = 0;
#ifdef VBOX_WITH_GUEST_CONTROL
/* Init the context ID counter at 1000. */
mNextContextID = 1000;
#endif
return S_OK;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
{
LogFlowThisFunc(("\n"));
#ifdef VBOX_WITH_GUEST_CONTROL
/* Clean up callback data. */
/* Clear process list. */
#endif
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
}
// IGuest properties
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller(this);
// redirect the call to IMachine if no additions are installed
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
/* We must be 100% sure that IMachine::COMSETTER(MemoryBalloonSize)
* does not call us back in any way! */
{
/* forward the information to the VMM device */
if (vmmDev)
}
return ret;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
/* forward the information to the VMM device */
if (vmmDev)
return S_OK;
}
{
AutoCaller autoCaller(this);
*aMemBalloon = mCurrentGuestStat[GUESTSTATTYPE_MEMBALLOON] * (_4K/_1K); /* page (4K) -> 1KB units */
{
*aMemFreeTotal = 0;
if (rc == VINF_SUCCESS)
{
}
}
else
*aMemFreeTotal = 0;
return S_OK;
}
{
AutoCaller autoCaller(this);
if (enmType >= GUESTSTATTYPE_MAX)
return E_INVALIDARG;
return S_OK;
}
{
AutoCaller autoCaller(this);
/* forward the information to the VMM device */
if (vmmDev)
{
if (!aAllowInteractiveLogon)
return S_OK;
}
return setError(VBOX_E_VM_ERROR,
tr("VMM device is not available (is the VM running?)"));
}
#ifdef VBOX_WITH_GUEST_CONTROL
/**
* Appends environment variables to the environment block. Each var=value pair is separated
* by NULL (\0) sequence. The whole block will be stored in one blob and disassembled on the
* guest side later to fit into the HGCM param structure.
*
* @returns VBox status code.
*
* @todo
*
*/
int Guest::prepareExecuteEnv(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnv)
{
int rc = VINF_SUCCESS;
if (*ppvList)
{
{
rc = VERR_NO_MEMORY;
}
else
{
}
}
else
{
char *pcTmp;
{
/* Reset counters. */
*pcEnv = 0;
*pcbList = 0;
}
}
if (RT_SUCCESS(rc))
{
}
return rc;
}
/**
* Static callback function for receiving updates on guest control commands
* from the guest. Acts as a dispatcher for the actual class instance.
*
* @returns VBox status code.
*
* @todo
*
*/
void *pvParms,
{
using namespace guestControl;
/*
* No locking, as this is purely a notification which does not make any
* changes to the object state.
*/
LogFlowFunc(("pvExtension = %p, u32Function = %d, pvParms = %p, cbParms = %d\n",
int rc = VINF_SUCCESS;
if (u32Function == GUEST_EXEC_SEND_STATUS)
{
LogFlowFunc(("GUEST_EXEC_SEND_STATUS\n"));
}
else if (u32Function == GUEST_EXEC_SEND_OUTPUT)
{
LogFlowFunc(("GUEST_EXEC_SEND_OUTPUT\n"));
}
else
return rc;
}
/* Function for handling the execution start/termination notification. */
{
int rc = VINF_SUCCESS;
/* Callback can be called several times. */
{
/** @todo Copy void* buffer contents! */
/* Do progress handling. */
{
case PROC_STS_STARTED:
break;
case PROC_STS_TEN: /* Terminated normally. */
break;
case PROC_STS_TEA: /* Terminated abnormally. */
break;
case PROC_STS_TES: /* Terminated through signal. */
break;
case PROC_STS_TOK:
break;
case PROC_STS_TOA:
break;
case PROC_STS_DWN:
break;
default:
break;
}
/* Handle process list. */
/** @todo How to deal with multiple updates at once? */
{
/* Not found, add to list. */
GuestProcess p;
p.mFlags = 0;
}
else /* Update list. */
{
}
{
{
LogFlowFunc(("Callback (context ID=%u, status=%u) progress marked as completed\n",
}
else
LogFlowFunc(("Callback (context ID=%u, status=%u) progress already marked as completed\n",
}
}
else
LogFlowFunc(("Unexpected callback (magic=%u, context ID=%u) arrived\n", pData->hdr.u32Magic, pData->hdr.u32ContextID));
return rc;
}
/* Function for handling the execution output notification. */
{
int rc = VINF_SUCCESS;
{
/* Allocate data buffer and copy it */
{
}
}
else
LogFlowFunc(("Unexpected callback (magic=%u, context ID=%u) arrived\n", pData->hdr.u32Magic, pData->hdr.u32ContextID));
return rc;
}
{
/** @todo Maybe use a map instead of list for fast context lookup. */
{
return (it);
}
return it;
}
{
/** @todo Maybe use a map instead of list for fast context lookup. */
{
return (it);
}
return it;
}
{
{
/* Notify outstanding waits for progress ... */
{
}
}
}
/* Adds a callback with a user provided data block and an optional progress object
* to the callback list. A callback is identified by a unique context ID which is used
* to identify a callback from the guest side. */
uint32_t Guest::addCtrlCallbackContext(eVBoxGuestCtrlCallbackType enmType, void *pvData, uint32_t cbData, Progress *pProgress)
{
if (uNewContext == UINT32_MAX)
{
}
return uNewContext;
}
#endif /* VBOX_WITH_GUEST_CONTROL */
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
using namespace guestControl;
if (aFlags != 0) /* Flags are not supported at the moment. */
return E_INVALIDARG;
try
{
AutoCaller autoCaller(this);
/*
* Create progress object.
*/
{
FALSE);
}
/*
* Prepare process execution.
*/
int vrc = VINF_SUCCESS;
/* Adjust timeout */
if (aTimeoutMS == 0)
/* Prepare arguments. */
if (aArguments > 0)
{
}
if (RT_SUCCESS(vrc))
{
uint32_t uContextID = 0;
if (uNumArgs > 0)
if (RT_SUCCESS(vrc))
{
/* Prepare environment. */
if (aEnvironment > 0)
{
{
if (RT_FAILURE(vrc))
break;
}
}
if (RT_SUCCESS(vrc))
{
Assert(uContextID > 0);
int i = 0;
/* Make sure mParent is valid, so set a read lock in this scope. */
/* Forward the information to the VMM device. */
if (vmmDev)
{
LogFlowFunc(("hgcmHostCall numParms=%d\n", i));
i, paParms);
}
else
}
}
if (RT_SUCCESS(vrc))
{
/*
* Wait for the HGCM low level callback until the process
* has been started (or something went wrong). This is necessary to
* get the PID.
*/
{
do
{
unsigned cMsWait;
if (aTimeoutMS == RT_INDEFINITE_WAIT)
cMsWait = 1000;
else
{
if (cMsElapsed >= aTimeoutMS)
break; /* Timed out. */
}
RTThreadSleep(100);
}
/* Did we get some status? */
{
{
case PROC_STS_STARTED:
/* Process is (still) running; get PID. */
break;
/* In any other case the process either already
* terminated or something else went wrong, so no PID ... */
case PROC_STS_TEN: /* Terminated normally. */
case PROC_STS_TEA: /* Terminated abnormally. */
case PROC_STS_TES: /* Terminated through signal. */
case PROC_STS_TOK:
case PROC_STS_TOA:
case PROC_STS_DWN:
/*
* Process (already) ended, but we want to get the
* PID anyway to retrieve the output in a later call.
*/
break;
case PROC_STS_ERROR:
break;
default:
break;
}
}
else /* If callback not called within time ... well, that's a timeout! */
vrc = VERR_TIMEOUT;
/*
* Do *not* remove the callback yet - we might wait with the IProgress object on something
* else (like end of process) ...
*/
if (RT_FAILURE(vrc))
{
{
}
else if (vrc == VERR_BAD_EXE_FORMAT)
{
}
else if (vrc == VERR_LOGON_FAILURE)
{
}
else if (vrc == VERR_TIMEOUT)
{
}
else if (vrc == VERR_INVALID_PARAMETER)
{
}
else
{
}
}
else
{
/* Return the progress to the caller. */
}
}
else
{
if (vrc == VERR_INVALID_VM_HANDLE)
{
tr("VMM device is not available (is the VM running?)"));
}
else if (vrc == VERR_TIMEOUT)
{
tr("The guest execution service is not ready"));
}
else /* HGCM call went wrong. */
{
}
}
for (unsigned i = 0; i < uNumArgs; i++)
}
}
{
rc = E_OUTOFMEMORY;
}
return rc;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP Guest::GetProcessOutput(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, ULONG64 aSize, ComSafeArrayOut(BYTE, aData))
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
using namespace guestControl;
/* Search for existing PID. */
PHOSTEXECOUTCALLBACKDATA pData = (HOSTEXECOUTCALLBACKDATA*)RTMemAlloc(sizeof(HOSTEXECOUTCALLBACKDATA));
Assert(uContextID > 0);
int i = 0;
int vrc = VINF_SUCCESS;
{
/* Make sure mParent is valid, so set the read lock while using. */
/* Forward the information to the VMM device. */
if (vmmDev)
{
LogFlowFunc(("hgcmHostCall numParms=%d\n", i));
i, paParms);
}
}
if (RT_SUCCESS(vrc))
{
/*
* Wait for the HGCM low level callback until the process
* has been started (or something went wrong). This is necessary to
* get the PID.
*/
{
do
{
unsigned cMsWait;
if (aTimeoutMS == RT_INDEFINITE_WAIT)
cMsWait = 1000;
else
{
if (cMsElapsed >= aTimeoutMS)
break; /* timed out */
}
RTThreadSleep(100);
/* Did we get some output? */
{
/* Do we need to resize the array? */
/* Fill output in supplied out buffer. */
}
else
}
/* If something failed (or there simply was no data, indicated by VERR_NO_DATA,
* we return an empty array so that the frontend knows when to give up. */
outputData.resize(0);
}
return rc;
#endif
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
using namespace guestControl;
{
break;
}
{
}
else
return rc;
#endif
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller(this);
/* Older Additions didn't have this finer grained capability bit,
* so enable it by default. Newer Additions will disable it immediately
* if relevant. */
}
{
AutoCaller autoCaller(this);
}
{
AutoCaller autoCaller(this);
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */