ConsoleImpl.h revision 30a15c7ce03b2f8a95fcec78ec3d201e563019c2
/* $Id$ */
/** @file
* VBox Console COM Class definition
*/
/*
* 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.
*/
#ifndef ____H_CONSOLEIMPL
#define ____H_CONSOLEIMPL
#include "VirtualBoxBase.h"
#include "SchemaDefs.h"
#include "EventImpl.h"
#ifdef VBOX_WITH_USB_VIDEO
#endif
#ifdef VBOX_WITH_EXTPACK
#endif
#ifdef VBOX_WITH_GUEST_PROPS
#endif
#ifdef RT_OS_WINDOWS
# include "../src-server/win/VBoxComEvents.h"
#endif
struct VUSBIRHCONFIG;
typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
#include <list>
// defines
///////////////////////////////////////////////////////////////////////////////
/**
* Checks the availability of the underlying VM device driver corresponding
* to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
* not available (NULL), sets error info and returns returns E_ACCESSDENIED.
* The translatable error message is defined in null context.
*
* Intended to used only within Console children (i.e. Keyboard, Mouse,
* Display, etc.).
*
* @param drv driver pointer to check (compare it with NULL)
*/
#define CHECK_CONSOLE_DRV(drv) \
do { \
if (!(drv)) \
} while (0)
// Console
///////////////////////////////////////////////////////////////////////////////
/** IConsole implementation class */
{
Console();
~Console();
void FinalRelease();
// public initializers/uninitializers for internal purposes only
void uninit();
// IConsole properties
// IConsole methods
STDMETHOD(PowerButton)();
STDMETHOD(SleepButton)();
STDMETHOD(Teleport)(IN_BSTR aHostname, ULONG aPort, IN_BSTR aPassword, ULONG aMaxDowntime, IProgress **aProgress);
// public methods for internal purposes only
/*
* Note: the following methods do not increase refcount. intended to be
* called only by the VM execution thread.
*/
bool useHostClipboard() { return mfUseHostClipboard; }
/** Method is called only from ConsoleVRDPServer */
// events from IInternalSessionControl
#ifdef VBOX_WITH_EXTPACK
#endif
int VRDPClientLogon(uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
void processRemoteUSBDevices(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevList, uint32_t cbDevList);
// callback callers (partly; for some events console callbacks are notified
// directly from IInternalSessionControl event handlers declared above)
void onAdditionsStateChange();
void onAdditionsOutdated();
void onVRDEServerInfoChange();
static const PDMDRVREG DrvStatusReg;
static HRESULT convertBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
// Called from event listener
/**
* Base template for AutoVMCaller and SaveVMPtr. Template arguments
* have the same meaning as arguments of Console::addVMCaller().
*/
{
{
}
{
mThat->releaseVMCaller();
}
/** Decreases the number of callers before the instance is destroyed. */
void releaseCaller()
{
mThat->releaseVMCaller();
}
/** Restores the number of callers after by #release(). #rc() must be
* rechecked to ensure the operation succeeded. */
void addYY()
{
}
/** Returns the result of Console::addVMCaller() */
/** Shortcut to SUCCEEDED(rc()) */
};
#if 0
/**
* Helper class that protects sections of code using the mpVM pointer by
* automatically calling addVMCaller() on construction and
* releaseVMCaller() on destruction. Intended for Console methods dealing
* with mpVM. The usage pattern is:
* <code>
* AutoVMCaller autoVMCaller(this);
* if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();
* ...
* VMR3ReqCall (mpVM, ...
* </code>
*
* @note Temporarily locks the argument for writing.
*
* @sa SafeVMPtr, SafeVMPtrQuiet
* @obsolete Use SafeVMPtr
*/
typedef AutoVMCallerBase<false, false> AutoVMCaller;
#endif
/**
* Same as AutoVMCaller but doesn't set extended error info on failure.
*
* @note Temporarily locks the argument for writing.
* @obsolete Use SafeVMPtrQuiet
*/
typedef AutoVMCallerBase<true, false> AutoVMCallerQuiet;
/**
* Same as AutoVMCaller but allows a null VM pointer (to trigger an error
* instead of assertion).
*
* @note Temporarily locks the argument for writing.
* @obsolete Use SafeVMPtr
*/
typedef AutoVMCallerBase<false, true> AutoVMCallerWeak;
/**
* Same as AutoVMCaller but doesn't set extended error info on failure
* and allows a null VM pointer (to trigger an error instead of
* assertion).
*
* @note Temporarily locks the argument for writing.
* @obsolete Use SafeVMPtrQuiet
*/
typedef AutoVMCallerBase<true, true> AutoVMCallerQuietWeak;
/**
* Base template for SaveVMPtr and SaveVMPtrQuiet.
*/
{
{
}
{
release();
}
/** Smart SaveVMPtr to PVM cast operator */
/** Direct PVM access for printf()-like functions */
/** Direct PUVM access for printf()-like functions */
/** Release the handles. */
void release()
{
Base::releaseCaller();
}
};
/**
* Helper class that safely manages the Console::mpVM pointer
* by calling addVMCaller() on construction and releaseVMCaller() on
* destruction. Intended for Console children. The usage pattern is:
* <code>
* Console::SaveVMPtr pVM(mParent);
* if (FAILED(pVM.rc())) return pVM.rc();
* ...
* VMR3ReqCall(pVM, ...
* ...
* printf("%p\n", pVM.raw());
* </code>
*
* @note Temporarily locks the argument for writing.
*
* @sa SafeVMPtrQuiet, AutoVMCaller
*/
/**
* A deviation of SaveVMPtr that doesn't set the error info on failure.
* Intended for pieces of code that don't need to return the VM access
* failure to the caller. The usage pattern is:
* <code>
* Console::SaveVMPtrQuiet pVM(mParent);
* if (pVM.rc())
* VMR3ReqCall(pVM, ...
* return S_OK;
* </code>
*
* @note Temporarily locks the argument for writing.
*
* @sa SafeVMPtr, AutoVMCaller
*/
{
{ }
bool aWritable,
bool aAutoMount)
{ }
// copy constructor
{ }
bool m_fWritable;
bool m_fAutoMount;
};
void releaseVMCaller();
/* Note: FreeBSD needs this whether netflt is used or not. */
#endif
{
}
bool aSetError = false);
const char *pcszDevice,
unsigned uInstance,
bool fUseHostIOCache,
bool fBuiltinIoCache,
bool fSetupMerge,
unsigned uMergeSource,
unsigned uMergeTarget,
bool fAttachDetach,
bool fForceUnmount,
bool fHotplug,
bool fPassthrough,
bool fUseHostIOCache,
bool fBuiltinIoCache,
bool fSetupMerge,
unsigned uMergeSource,
unsigned uMergeTarget,
const char *pcszBwGroup,
const char *pcszDevice,
unsigned uInstance,
bool fUseHostIOCache,
bool fBuiltinIoCache,
bool fSetupMerge,
unsigned uMergeSource,
unsigned uMergeTarget,
const char *pcszDevice,
unsigned uInstance,
bool fUseHostIOCache,
bool fForce);
bool fAttachDetach, bool fIgnoreConnectFailure);
#ifdef VBOX_WITH_USB
static DECLCALLBACK(int) usbAttachCallback(Console *that, PVM pVM, IUSBDevice *aHostDevice, PCRTUUID aUuid,
static DECLCALLBACK(int) usbDetachCallback(Console *that, PVM pVM, USBDeviceList::iterator *aIt, PCRTUUID aUuid);
#endif
const char *pcszDevice,
unsigned uInstance,
bool fUseHostIOCache,
const char *pcszDevice,
unsigned uInstance,
const char *pszErrorId, const char *pszFormat, ...);
void detachAllUSBDevices(bool aDone);
static DECLCALLBACK(void) vmm2User_NotifyEmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
static DECLCALLBACK(void) vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
int mcAudioRefs;
volatile uint32_t mcVRDPClients;
volatile bool mcGuestCredentialsProvided;
static const char *sSSMConsoleUnit;
static uint32_t sSSMConsoleVer;
static DECLCALLBACK(int) loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
#ifdef VBOX_WITH_GUEST_PROPS
static DECLCALLBACK(int) doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
void guestPropertiesHandleVMReset(void);
bool guestPropertiesVRDPEnabled(void);
void guestPropertiesVRDPUpdateLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
#endif
/** @name Teleporter support
* @{ */
HRESULT teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
HRESULT teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
/** @} */
bool mSavedStateDataLoaded : 1;
ConsoleVRDPServer * const mConsoleVRDPServer;
#ifdef VBOX_WITH_EXTPACK
#endif
/** The user mode VM handle. */
/** Holds the number of "readonly" mpVM callers (users) */
/** Semaphore posted when the number of mpVM callers drops to zero */
/** true when Console has entered the mpVM destruction phase */
bool mVMDestroying : 1;
/** true when power down is initiated by vmstateChangeCallback (EMT) */
bool mVMPoweredOff : 1;
/** true when vmstateChangeCallback shouldn't initiate a power down. */
bool mVMIsAlreadyPoweringOff : 1;
/** true if we already showed the snapshot folder size warning. */
bool mfSnapshotFolderSizeWarningShown : 1;
bool mfSnapshotFolderExt4WarningShown : 1;
/** true if we already listed the disk type of the snapshot folder. */
bool mfSnapshotFolderDiskTypeShown : 1;
/** Pointer to the VMM -> User (that's us) callbacks. */
{
/** The current network attachment type in the VM.
* This doesn't have to match the network attachment type maintained in the
* NetworkAdapter. This is needed to change the network attachment
* dynamically.
*/
AudioSniffer * const mAudioSniffer;
#ifdef VBOX_WITH_USB_VIDEO
UsbWebcamInterface * const mUsbWebcamInterface;
#endif
enum
{
iLedFloppy = 0,
cLedFloppy = 1,
cLedIde = 4,
cLedSata = 30,
cLedScsi = 16,
cLedSas = 8,
};
/* Note: FreeBSD needs this whether netflt is used or not. */
#endif
bool mfUseHostClipboard;
/** Local machine state value. */
/** Pointer to the progress object of a live cancelable task.
*
* This is currently only used by Console::Teleport(), but is intended to later
* be used by the live snapshot code path as well. Actions like
* Console::PowerDown, which automatically cancels out the running snapshot /
* teleportation operation, will cancel the teleportation / live snapshot
* operation before starting. */
struct
{
/** OnMousePointerShapeChange() cache */
struct
{
bool valid;
bool visible;
bool alpha;
}
mpsc;
/** OnMouseCapabilityChange() cache */
struct
{
bool valid;
}
mcc;
/** OnKeyboardLedsChange() cache */
struct
{
bool valid;
bool numLock;
bool capsLock;
bool scrollLock;
}
klc;
void clear()
{
/* We cannot do memset() on mpsc to avoid cleaning shape's vtable */
}
}
};
#endif // !____H_CONSOLEIMPL
/* vi: set tabstop=4 shiftwidth=4 expandtab: */