GuestImpl.cpp revision 038fb20139baee46969c6aa2521d6bd18c5d263d
/* $Id$ */
/** @file
* VirtualBox COM class implementation: Guest
*/
/*
* Copyright (C) 2006-2012 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"
#ifdef VBOX_WITH_DRAG_AND_DROP
# include "GuestDnDImpl.h"
#endif
#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
#ifdef VBOX_WITH_DRAG_AND_DROP
m_pGuestDnD = new GuestDnD(this);
#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"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
#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).
*/
/* Notify left over callbacks that we are about to shutdown ... */
{
}
/* Destroy left over callback data. */
/* Clear process map (remove all callbacks). */
}
#endif
#ifdef VBOX_WITH_DRAG_AND_DROP
delete m_pGuestDnD;
m_pGuestDnD = NULL;
#endif
}
// IGuest properties
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller(this);
{
else
{
/* Redirect the call to IMachine if no additions are installed. */
}
}
return hrc;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
{
/*
* Return the ReportGuestInfo2 version info if available.
*/
else
{
/*
* If we're running older guest additions (< 3.2.0) try get it from
* the guest properties. Detected switched around Version and
* Revision in early 3.1.x releases (see r57115).
*/
hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Version").raw(), bstr.asOutParam());
{
hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Revision").raw(), bstr.asOutParam());
}
else
{
/* Returning 1.4 is better than nothing. */
}
}
}
return hrc;
}
{
AutoCaller autoCaller(this);
{
/*
* Return the ReportGuestInfo2 version info if available.
*/
else
{
/*
* If we're running older guest additions (< 3.2.0) try get it from
* the guest properties. Detected switched around Version and
* Revision in early 3.1.x releases (see r57115).
*/
hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Revision").raw(), bstr.asOutParam());
{
{
hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Version").raw(), bstr.asOutParam());
{
}
}
if (vrc == VINF_SUCCESS)
else
}
{
/* Return 0 if we don't know. */
*a_puAdditionsRevision = 0;
}
}
}
return hrc;
}
{
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 = PGMR3QueryGlobalMemoryStats(pVM.raw(), &uAllocTotal, &uFreeTotal, &uBalloonedTotal, &uSharedTotal);
if (rc == VINF_SUCCESS)
{
}
else
return E_FAIL;
/* Query the missing per-VM memory statistics. */
*aMemShared = 0;
if (rc == VINF_SUCCESS)
{
}
else
return E_FAIL;
}
else
{
*aMemAllocTotal = 0;
*aMemFreeTotal = 0;
*aMemBalloonTotal = 0;
*aMemSharedTotal = 0;
*aMemShared = 0;
return E_FAIL;
}
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?)"));
}
STDMETHODIMP Guest::DragHGEnter(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), DragAndDropAction_T *pResultAction)
{
/* Input validation */
AutoCaller autoCaller(this);
#ifdef VBOX_WITH_DRAG_AND_DROP
return m_pGuestDnD->dragHGEnter(uScreenId, uX, uY, defaultAction, ComSafeArrayInArg(allowedActions), ComSafeArrayInArg(formats), pResultAction);
#else /* VBOX_WITH_DRAG_AND_DROP */
#endif /* !VBOX_WITH_DRAG_AND_DROP */
}
STDMETHODIMP Guest::DragHGMove(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), DragAndDropAction_T *pResultAction)
{
/* Input validation */
AutoCaller autoCaller(this);
#ifdef VBOX_WITH_DRAG_AND_DROP
return m_pGuestDnD->dragHGMove(uScreenId, uX, uY, defaultAction, ComSafeArrayInArg(allowedActions), ComSafeArrayInArg(formats), pResultAction);
#else /* VBOX_WITH_DRAG_AND_DROP */
#endif /* !VBOX_WITH_DRAG_AND_DROP */
}
{
AutoCaller autoCaller(this);
#ifdef VBOX_WITH_DRAG_AND_DROP
#else /* VBOX_WITH_DRAG_AND_DROP */
#endif /* !VBOX_WITH_DRAG_AND_DROP */
}
STDMETHODIMP Guest::DragHGDrop(ULONG uScreenId, ULONG uX, ULONG uY, DragAndDropAction_T defaultAction, ComSafeArrayIn(DragAndDropAction_T, allowedActions), ComSafeArrayIn(IN_BSTR, formats), BSTR *pstrFormat, DragAndDropAction_T *pResultAction)
{
/* Input validation */
AutoCaller autoCaller(this);
#ifdef VBOX_WITH_DRAG_AND_DROP
return m_pGuestDnD->dragHGDrop(uScreenId, uX, uY, defaultAction, ComSafeArrayInArg(allowedActions), ComSafeArrayInArg(formats), pstrFormat, pResultAction);
#else /* VBOX_WITH_DRAG_AND_DROP */
#endif /* !VBOX_WITH_DRAG_AND_DROP */
}
STDMETHODIMP Guest::DragHGPutData(ULONG uScreenId, IN_BSTR bstrFormat, ComSafeArrayIn(BYTE, data), IProgress **ppProgress)
{
/* Input validation */
AutoCaller autoCaller(this);
#ifdef VBOX_WITH_DRAG_AND_DROP
#else /* VBOX_WITH_DRAG_AND_DROP */
#endif /* !VBOX_WITH_DRAG_AND_DROP */
}
STDMETHODIMP Guest::DragGHPending(ULONG uScreenId, ComSafeArrayOut(BSTR, formats), ComSafeArrayOut(DragAndDropAction_T, allowedActions), DragAndDropAction_T *pDefaultAction)
{
/* Input validation */
AutoCaller autoCaller(this);
#ifdef VBOX_WITH_DRAG_AND_DROP
return m_pGuestDnD->dragGHPending(uScreenId, ComSafeArrayOutArg(formats), ComSafeArrayOutArg(allowedActions), pDefaultAction);
#else /* VBOX_WITH_DRAG_AND_DROP */
#endif /* !VBOX_WITH_DRAG_AND_DROP */
}
STDMETHODIMP Guest::DragGHDropped(IN_BSTR bstrFormat, DragAndDropAction_T action, IProgress **ppProgress)
{
/* Input validation */
AutoCaller autoCaller(this);
#ifdef VBOX_WITH_DRAG_AND_DROP
#else /* VBOX_WITH_DRAG_AND_DROP */
#endif /* !VBOX_WITH_DRAG_AND_DROP */
}
{
/* Input validation */
AutoCaller autoCaller(this);
#ifdef VBOX_WITH_DRAG_AND_DROP
#else /* VBOX_WITH_DRAG_AND_DROP */
#endif /* !VBOX_WITH_DRAG_AND_DROP */
}
// 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
{
/*
* To keep it compatible with the old Guest Additions behavior we need to set the
* "graphics" (feature) facility to active as soon as we got the Guest Additions
* interface version.
*/
facilityUpdate(VBoxGuestFacilityType_Graphics, VBoxGuestFacilityStatus_Active, 0 /*fFlags*/, &TimeSpecTS);
}
}
/*
* 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.
*/
/** @todo r=bird: I don't get the above comment nor the code below...
* One talks about capability bits, the one always does something to a facility.
* Then there is the comment below it all, which is placed like it addresses the
* mOSTypeId, but talks about something which doesn't remotely like mOSTypeId...
*
* Andy, could you please try clarify and make the comments shorter and more
* coherent! Also, explain why this is important and what depends on it.
*
* PS. There is the VMMDEV_GUEST_SUPPORTS_GRAPHICS capability* report... It
* should come in pretty quickly after this update, normally.
*/
0 /*fFlags*/, &TimeSpecTS); /** @todo the timestamp isn't gonna be right here on saved state restore. */
/*
* 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 and vmmdevUpdateGuestInfo (to clear the
* state).
*
* @param a_uFullVersion VBoxGuestInfo2::additionsMajor,
* VBoxGuestInfo2::additionsMinor and
* VBoxGuestInfo2::additionsBuild combined into
* one value by VBOX_FULL_VERSION_MAKE.
*
* When this is 0, it's vmmdevUpdateGuestInfo
* calling to reset the state.
*
* string if neiter of those are present.
* @param a_uRevision See VBoxGuestInfo2::additionsRevision.
* @param a_fFeatures See VBoxGuestInfo2::additionsFeatures.
*/
void Guest::setAdditionsInfo2(uint32_t a_uFullVersion, const char *a_pszName, uint32_t a_uRevision, uint32_t a_fFeatures)
{
AutoCaller autoCaller(this);
if (a_uFullVersion)
{
}
else
{
mData.mAdditionsRevision = 0;
mData.mAdditionsFeatures = 0;
}
}
{
{
}
return false;
}
void Guest::facilityUpdate(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus,
{
{
}
else
{
{
/* The easy way out for now. We could automatically destroy
inactive facilities like VMMDev does if we like... */
}
HRESULT hrc = ptrFac->init(this, (AdditionsFacilityType_T)a_enmFacility, (AdditionsFacilityStatus_T)a_enmStatus,
}
}
/**
* Sets the status of a certain Guest Additions facility.
*
* Gets called by vmmdevUpdateGuestStatus, which just passes the report along.
*
* @param a_pInterface Pointer to this interface.
* @param a_enmFacility The facility.
* @param a_enmStatus The status.
* @param a_fFlags Flags assoicated with the update. Currently
* reserved and should be ignored.
* @param a_pTimeSpecTS Pointer to the timestamp of this report.
* @sa PDMIVMMDEVCONNECTOR::pfnUpdateGuestStatus, vmmdevUpdateGuestStatus
* @thread The emulation thread.
*/
void Guest::setAdditionsStatus(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus,
{
AutoCaller autoCaller(this);
/*
* Set a specific facility status.
*/
else /* Update one facility only. */
/*
* Recalc the runlevel.
*/
else
}
/**
* 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 A nit: The timestamp is wrong on saved state restore. Would be better
* to move the graphics and seamless capability -> facility translation to
* VMMDev so this could be saved. */
aCaps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive,
0 /*fFlags*/, &TimeSpecTS);
/** @todo Add VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING */
aCaps & VMMDEV_GUEST_SUPPORTS_GRAPHICS ? VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive,
0 /*fFlags*/, &TimeSpecTS);
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */