ConsoleImpl.h revision d31dae02d859afafb9342ce6fe64020160204de0
/* $Id$ */
/** @file
* VBox Console COM Class definition
*/
/*
* Copyright (C) 2005-2014 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 "EventImpl.h"
#include "ConsoleWrap.h"
#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
#else
#endif
#ifdef VBOX_WITH_USB_CARDREADER
#endif
#ifdef VBOX_WITH_EXTPACK
#endif
#include <iprt/memsafer.h>
#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>
#include <vector>
// 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
///////////////////////////////////////////////////////////////////////////////
{
BOOL needsHostCursor){NOREF(supportsAbsolute); NOREF(supportsRelative); NOREF(supportsMT); NOREF(needsHostCursor);}
};
/** IConsole implementation class */
{
void FinalRelease();
// public initializers/uninitializers for internal purposes only
void uninit();
// public methods for internal purposes only
/*
* Note: the following methods do not increase refcount. intended to be
* called only by the VM execution thread.
*/
#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
#else
#endif
bool i_useHostClipboard() { return mfUseHostClipboard; }
/** Method is called only from ConsoleVRDPServer */
// events from IInternalSessionControl
HRESULT i_getGuestProperty(const Utf8Str &aName, Utf8Str *aValue, LONG64 *aTimestamp, Utf8Str *aFlags);
#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
#else
#endif
#ifdef VBOX_WITH_EXTPACK
#endif
#ifdef VBOX_WITH_USB_CARDREADER
#endif
int i_VRDPClientLogon(uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
void i_processRemoteUSBDevices(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevList, uint32_t cbDevList, bool fDescExt);
{
}
// callback callers (partly; for some events console callbacks are notified
// directly from IInternalSessionControl event handlers declared above)
void i_onAdditionsStateChange();
void i_onAdditionsOutdated();
void i_onVRDEServerInfoChange();
static const PDMDRVREG DrvStatusReg;
static HRESULT i_convertBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
// Called from event listener
// Mouse interface
/**
* Sets the disk encryption keys.
*
* @returns COM status code.
* @þaram strCfg The config for the disks.
*
* @note: One line in the config string contains all required data for one disk.
* The format for one disk is some sort of comma separated value using
* key=value pairs.
* There are two keys defined at the moment:
* - uuid: The uuid of the base image the key is for (with or without)
* the curly braces.
* - dek: The data encryption key in base64 encoding
*/
// wraped IConsole properties
// wraped IConsole methods
/**
* Base template for AutoVMCaller and SafeVMPtr. Template arguments
* have the same meaning as arguments of Console::addVMCaller().
*/
{
{
}
{
doRelease();
}
/** Decreases the number of callers before the instance is destroyed. */
void releaseCaller()
{
doRelease();
}
/** 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()) */
void doRelease()
{
{
}
}
};
#if 0
/**
* Helper class that protects sections of code using the mpUVM pointer by
* automatically calling addVMCaller() on construction and
* releaseVMCaller() on destruction. Intended for Console methods dealing
* with mpUVM. The usage pattern is:
* <code>
* AutoVMCaller autoVMCaller(this);
* if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();
* ...
* VMR3ReqCall (mpUVM, ...
* </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 SafeVMPtr and SafeVMPtrQuiet.
*/
{
{
}
{
doRelease();
}
/** Direct PUVM access. */
/** Release the handles. */
void release()
{
doRelease();
}
/** The combined result of Console::addVMCaller() and Console::safeVMPtrRetainer */
/** Shortcut to SUCCEEDED(rc()) */
void doRelease()
{
{
}
}
};
/*
* Helper class that safely manages the Console::mpUVM pointer
* by calling addVMCaller() on construction and releaseVMCaller() on
* destruction. Intended for Console children. The usage pattern is:
* <code>
* Console::SafeVMPtr ptrVM(mParent);
* if (!ptrVM.isOk())
* return ptrVM.rc();
* ...
* VMR3ReqCall(ptrVM.rawUVM(), ...
* ...
* printf("%p\n", ptrVM.rawUVM());
* </code>
*
* @note Temporarily locks the argument for writing.
*
* @sa SafeVMPtrQuiet, AutoVMCaller
*/
/**
* A deviation of SafeVMPtr 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::SafeVMPtrQuiet 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;
};
/**
* Class for managing emulated USB MSDs.
*/
{
{ }
/** The UUID associated with the USB device. */
/** Port of the storage device. */
};
/**
* Class for managing cryptographic keys.
* @todo: Replace with a keystore implementation once it is ready.
*/
{
SecretKey() { }
: m_cRefs(0),
{ }
~SecretKey()
{
m_cRefs = 0;
m_cbKey = 0;
}
/** Reference counter of the key. */
/** Key material. */
/** Size of the key in bytes. */
};
void i_releaseVMCaller();
/* Note: FreeBSD needs this whether netflt is used or not. */
#endif
{
}
bool aSetError = false);
bool fHMEnabled);
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,
bool fDiscard,
const char *pcszDevice,
unsigned uInstance,
bool fUseHostIOCache,
bool fBuiltinIoCache,
bool fSetupMerge,
unsigned uMergeSource,
unsigned uMergeTarget,
const char *pcszDevice,
unsigned uInstance,
bool fUseHostIOCache,
bool fForce);
const char *pcszDevice, unsigned uInstance);
bool fAttachDetach, bool fIgnoreConnectFailure);
static DECLCALLBACK(void) i_vmstateChangeCallback(PUVM pUVM, VMSTATE enmState, VMSTATE enmOldState, void *pvUser);
static DECLCALLBACK(int) i_changeNetworkAttachment(Console *pThis, PUVM pUVM, const char *pszDevice,
#ifdef VBOX_WITH_USB
static DECLCALLBACK(int) i_usbAttachCallback(Console *that, PUVM pUVM, IUSBDevice *aHostDevice, PCRTUUID aUuid,
#endif
const char *pcszDevice,
unsigned uInstance,
bool fUseHostIOCache,
bool fSilent);
const char *pcszDevice,
unsigned uInstance,
bool fSilent);
static DECLCALLBACK(void) i_genericVMSetErrorCallback(PUVM pUVM, void *pvUser, int rc, RT_SRC_POS_DECL,
void i_setVMRuntimeErrorCallbackF(uint32_t fFatal, const char *pszErrorId, const char *pszFormat, ...);
void i_detachAllUSBDevices(bool aDone);
static DECLCALLBACK(void) i_vmm2User_NotifyEmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
static DECLCALLBACK(void) i_vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
static DECLCALLBACK(void) i_vmm2User_NotifyResetTurnedIntoPowerOff(PCVMM2USERMETHODS pThis, PUVM pUVM);
static DECLCALLBACK(int) i_drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
static DECLCALLBACK(int) i_pdmIfSecKey_KeyRetain(PPDMISECKEY pInterface, const char *pszId, const uint8_t **ppbKey,
int mcAudioRefs;
volatile uint32_t mcVRDPClients;
volatile bool mcGuestCredentialsProvided;
static const char *sSSMConsoleUnit;
static uint32_t sSSMConsoleVer;
static DECLCALLBACK(int) i_loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
#ifdef VBOX_WITH_GUEST_PROPS
static DECLCALLBACK(int) i_doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
void i_guestPropertiesHandleVMReset(void);
bool i_guestPropertiesVRDPEnabled(void);
void i_guestPropertiesVRDPUpdateLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
#endif
bool i_isResetTurnedIntoPowerOff(void);
/** @name Disk encryption support
* @{ */
/** @} */
/** @name Teleporter support
* @{ */
HRESULT i_teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
HRESULT i_teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
/** @} */
bool mSavedStateDataLoaded : 1;
ConsoleVRDPServer * const mConsoleVRDPServer;
bool mfVRDEChangeInProcess;
bool mfVRDEChangePending;
/** This can safely be used without holding any locks.
* An AutoCaller suffices to prevent it being destroy while in use and
* internally there is a lock providing the necessary serialization. */
#ifdef VBOX_WITH_EXTPACK
#endif
/** The user mode VM handle. */
/** Holds the number of "readonly" mpUVM callers (users). */
/** Semaphore posted when the number of mpUVM callers drops to zero. */
/** true when Console has entered the mpUVM 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;
/** true if a USB controller is available (i.e. USB devices can be attached). */
bool mfVMHasUsbController : 1;
/** true if the VM power off was caused by reset. */
bool mfPowerOffCausedByReset : 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.
*/
#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
AudioVRDE * const mAudioVRDE;
#else
AudioSniffer * const mAudioSniffer;
#endif
#ifdef VBOX_WITH_USB_CARDREADER
UsbCardReader * const mUsbCardReader;
#endif
enum
{
iLedFloppy = 0,
cLedFloppy = 2,
cLedIde = 4,
cLedSata = 30,
cLedScsi = 16,
cLedSas = 8,
cLedUsb = 8,
};
/** List of attached USB storage devices. */
/** Map of secret keys used for disk encryption. */
/** Pointer to the key consumer -> provider (that's us) callbacks. */
{
} *mpIfSecKey;
/* 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. */
/* The purpose of caching of some events is probably in order to
automatically fire them at new event listeners. However, there is no
(longer?) any code making use of this... */
#ifdef CONSOLE_WITH_EVENT_CACHE
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 RT_ZERO mpsc because of shape's vtable. */
}
#endif
};
#endif // !____H_CONSOLEIMPL
/* vi: set tabstop=4 shiftwidth=4 expandtab: */