GuestImpl.cpp revision 6247ed385ebae63ace78866255c47a956abffe49
/* $Id$ */
/** @file
* VirtualBox COM class implementation: Guest
*/
/*
* Copyright (C) 2006-2011 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 BaseFinalConstruct();
}
void Guest::FinalRelease()
{
uninit ();
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the guest object.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Confirm a successful initialization when it's the case */
else
mMemoryBalloonSize = 0; /* Default is no ballooning */
else
mfPageFusionEnabled = false; /* Default is no page fusion*/
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
/* Scope write lock as much as possible. */
{
/*
* Cleanup must be done *before* AutoUninitSpan to cancel all
* all outstanding waits in API functions (which hold AutoCaller
* ref counts).
*/
/* Clean up callback data. */
/* Clear process map. */
}
#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);
/* Only try alternative way if GA are active! */
{
/*
* If we got back an empty string from GetAdditionsVersion() we either
* really don't have the Guest Additions version yet or the guest is running
* older Guest Additions (< 3.2.0) which don't provide VMMDevReq_ReportGuestInfo2,
* so get the version + revision from the (hopefully) provided guest properties
* instead.
*/
{
&& !addVersion.isEmpty()
&& !addRevision.isEmpty())
{
/* Some Guest Additions versions had interchanged version + revision values,
* so check if the version value at least has a dot to identify it and change
* both values to reflect the right content. */
{
}
}
/** @todo r=bird: else: Should not return failure! */
}
else
{
/* If getting the version + revision above fails or they simply aren't there
* because of *really* old Guest Additions we only can report the interface
* version to at least have something. */
/** @todo r=bird: hr is still indicating failure! */
}
}
else
return hr;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
return mfPageFusionEnabled;
}
{
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 */
/* MUST release all locks before calling VMM device as its critsect
* has higher lock order than anything in Main. */
if (pVMMDev)
{
if (pVMMDevPort)
}
}
return ret;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
/* forward the information to the VMM device */
/* MUST release all locks before calling VMM device as its critsect
* has higher lock order than anything in Main. */
if (pVMMDev)
{
if (pVMMDevPort)
}
return S_OK;
}
{
AutoCaller autoCaller(this);
*aMemBalloon = mCurrentGuestStat[GUESTSTATTYPE_MEMBALLOON] * (_4K/_1K); /* page (4K) -> 1KB units */
/* MUST release all locks before calling any PGM statistics queries,
* as they are executed by EMT and that might deadlock us by VMM device
* activity which waits for the Guest object lock. */
{
*aMemFreeTotal = 0;
int rc = PGMR3QueryVMMMemoryStats(pVM.raw(), &uAllocTotal, &uFreeTotal, &uBalloonedTotal, &uSharedTotal);
if (rc == VINF_SUCCESS)
{
}
/* Query the missing per-VM memory statistics. */
*aMemShared = 0;
if (rc == VINF_SUCCESS)
{
}
}
else
{
*aMemFreeTotal = 0;
*aMemShared = 0;
}
return S_OK;
}
{
AutoCaller autoCaller(this);
if (enmType >= GUESTSTATTYPE_MAX)
return E_INVALIDARG;
return S_OK;
}
/**
* Returns the status of a specified Guest Additions facility.
*
* @return aStatus Current status of specified facility.
* @param aType Facility to get the status from.
* @param aTimestamp Timestamp of last facility status update in ms (optional).
*/
STDMETHODIMP Guest::GetFacilityStatus(AdditionsFacilityType_T aType, LONG64 *aTimestamp, AdditionsFacilityStatus_T *aStatus)
{
AutoCaller autoCaller(this);
/* Not checking for aTimestamp is intentional; it's optional. */
{
if (aTimestamp)
}
else
{
/*
* Do not fail here -- could be that the facility never has been brought up (yet) but
* the host wants to have its status anyway. So just tell we don't know at this point.
*/
if (aTimestamp)
*aTimestamp = RTTimeMilliTS();
}
return S_OK;
}
{
AutoCaller autoCaller(this);
switch (aLevel)
{
break;
break;
break;
default:
break;
}
return rc;
}
{
AutoCaller autoCaller(this);
/* forward the information to the VMM device */
if (pVMMDev)
{
if (pVMMDevPort)
{
if (!aAllowInteractiveLogon)
u32Flags);
return S_OK;
}
}
return setError(VBOX_E_VM_ERROR,
tr("VMM device is not available (is the VM running?)"));
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
/**
* Sets the general Guest Additions information like
* API (interface) version and OS type. Gets called by
* vmmdevUpdateGuestInfo.
*
* @param aInterfaceVersion
* @param aOsType
*/
{
AutoCaller autoCaller(this);
/*
* Note: The Guest Additions API (interface) version is deprecated
* and will not be used anymore! We might need it to at least report
* something as version number if *really* ancient Guest Additions are
* installed (without the guest version + revision properties having set).
*/
/*
* Older Additions rely on the Additions API version whether they
* are assumed to be active or not. Since newer Additions do report
* the Additions version *before* calling this function (by calling
* VMMDevReportGuestInfo2, VMMDevReportGuestStatus, VMMDevReportGuestInfo,
* in that order) we can tell apart old and new Additions here. Old
* Additions never would set VMMDevReportGuestInfo2 (which set mData.mAdditionsVersion)
* so they just rely on the aInterfaceVersion string (which gets set by
* VMMDevReportGuestInfo).
*
* So only mark the Additions as being active (run level = system) when we
* don't have the Additions version set.
*/
{
if (aInterfaceVersion.isEmpty())
else
}
/*
* Older Additions didn't have this finer grained capability bit,
* so enable it by default. Newer Additions will not enable this here
* and use the setSupportedFeatures function instead.
*/
facilityUpdate(VBoxGuestFacilityType_Graphics, facilityIsActive(VBoxGuestFacilityType_VBoxGuestDriver) ?
/*
* Note! There is a race going on between setting mAdditionsRunLevel and
* its real status when using new(er) Guest Additions.
*/
}
/**
* Sets the Guest Additions version information details.
* Gets called by vmmdevUpdateGuestInfo2.
*
* @param aAdditionsVersion
* @param aVersionName
*/
{
AutoCaller autoCaller(this);
if (!aVersionName.isEmpty())
/*
* aVersionName could be "x.y.z_BETA1_FOOBAR", so append revision manually to
* become "x.y.z_BETA1_FOOBAR r12345".
*/
else /* aAdditionsVersion is in x.y.zr12345 format. */
}
{
{
}
return false;
}
{
{
}
else
{
}
LogFlowFunc(("Returned with rc=%Rrc\n"));
return rc;
}
/**
* Sets the status of a certain Guest Additions facility.
* Gets called by vmmdevUpdateGuestStatus.
*
* @param enmFacility Facility to set the status for.
* @param enmStatus Actual status to set.
* @param aFlags
*/
void Guest::setAdditionsStatus(VBoxGuestFacilityType enmFacility, VBoxGuestFacilityStatus enmStatus, ULONG aFlags)
{
AutoCaller autoCaller(this);
/*
* Set overall additions run level.
*/
/* First check for disabled status. */
|| ( enmFacility == VBoxGuestFacilityType_All
)
{
}
else if (uCurFacility >= VBoxGuestFacilityType_VBoxTrayClient)
{
}
else if (uCurFacility >= VBoxGuestFacilityType_VBoxService)
{
}
else if (uCurFacility >= VBoxGuestFacilityType_VBoxGuestDriver)
{
}
else /* Should never happen! */
/*
* Set a specific facility status.
*/
if (enmFacility)
{
if (enmFacility == VBoxGuestFacilityType_All)
{
{
it++;
}
}
else /* Update one facility only. */
}
}
/**
* Sets the supported features (and whether they are active or not).
*
* @param fCaps Guest capability bit mask (VMMDEV_GUEST_SUPPORTS_XXX).
*/
{
AutoCaller autoCaller(this);
/** @todo Add VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING */
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */