ConsoleImpl.h revision c56200b15a48fa25db8232c3ca3fb59cfa6c2f0d
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync/** @file
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync *
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * VBox Console COM Class definition
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync */
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync/*
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * Copyright (C) 2006 InnoTek Systemberatung GmbH
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync *
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * available from http://www.virtualbox.org. This file is free software;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * General Public License as published by the Free Software Foundation,
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync *
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * If you received this file as part of a commercial VirtualBox
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * distribution, then only the terms of your commercial VirtualBox
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * license agreement apply instead of the previous paragraph.
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync */
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync#ifndef ____H_CONSOLEIMPL
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync#define ____H_CONSOLEIMPL
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync#include "VirtualBoxBase.h"
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync#include "ProgressImpl.h"
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync
37c53e9b2c955f92dff6f11aff63809004945f17vboxsyncclass Guest;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsyncclass Keyboard;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsyncclass Mouse;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsyncclass Display;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsyncclass MachineDebugger;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsyncclass OUSBDevice;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsyncclass RemoteUSBDevice;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsyncclass SharedFolder;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsyncclass RemoteDisplayInfo;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsyncclass AudioSniffer;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsyncclass ConsoleVRDPServer;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsyncclass VMMDev;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync#include <VBox/vrdpapi.h>
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync#include <VBox/pdm.h>
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsyncstruct VUSBIRHCONFIG;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsynctypedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync#include <list>
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync// defines
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync///////////////////////////////////////////////////////////////////////////////
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync/**
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * Checks the availability of the underlying VM device driver corresponding
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * not available (NULL), sets error info and returns returns E_ACCESSDENIED.
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * The translatable error message is defined in null context.
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync *
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * Intended to used only within Console children (i,e. Keyboard, Mouse,
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * Display, etc.).
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync *
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * @param drv driver pointer to check (compare it with NULL)
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync */
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync#define CHECK_CONSOLE_DRV(drv) \
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync do { \
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync if (!(drv)) \
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync return setError (E_ACCESSDENIED, tr ("The console is not powered up")); \
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync } while (0)
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync/** @def VBOX_WITH_UNIXY_TAP_NETWORKING
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * Unixy style TAP networking. This is defined in the Makefile since it's also
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * used by NetworkAdapterImpl.h/cpp.
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync */
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync#ifdef __DOXYGEN__
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync# define VBOX_WITH_UNIXY_TAP_NETWORKING
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync#endif
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync// Console
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync///////////////////////////////////////////////////////////////////////////////
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync/** IConsole implementation class */
37c53e9b2c955f92dff6f11aff63809004945f17vboxsyncclass ATL_NO_VTABLE Console :
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync public VirtualBoxBaseWithChildrenNEXT,
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync public VirtualBoxSupportErrorInfoImpl <Console, IConsole>,
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync public VirtualBoxSupportTranslation <Console>,
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync public IConsole
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync{
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync Q_OBJECT
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsyncpublic:
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync DECLARE_NOT_AGGREGATABLE(Console)
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync DECLARE_PROTECT_FINAL_CONSTRUCT()
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync BEGIN_COM_MAP(Console)
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync COM_INTERFACE_ENTRY(ISupportErrorInfo)
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync COM_INTERFACE_ENTRY(IConsole)
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync END_COM_MAP()
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync NS_DECL_ISUPPORTS
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync Console();
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync ~Console();
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync HRESULT FinalConstruct();
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync void FinalRelease();
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync // public initializers/uninitializers for internal purposes only
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync HRESULT init (IMachine *aMachine, IInternalMachineControl *aControl);
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync void uninit();
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync // IConsole properties
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync STDMETHOD(COMGETTER(Machine)) (IMachine **aMachine);
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync STDMETHOD(COMGETTER(State)) (MachineState_T *aMachineState);
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync STDMETHOD(COMGETTER(Guest)) (IGuest **aGuest);
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync STDMETHOD(COMGETTER(Keyboard)) (IKeyboard **aKeyboard);
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync STDMETHOD(COMGETTER(Mouse)) (IMouse **aMouse);
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync STDMETHOD(COMGETTER(Display)) (IDisplay **aDisplay);
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync STDMETHOD(COMGETTER(Debugger)) (IMachineDebugger **aDebugger);
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync STDMETHOD(COMGETTER(USBDevices)) (IUSBDeviceCollection **aUSBDevices);
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync STDMETHOD(COMGETTER(RemoteUSBDevices)) (IHostUSBDeviceCollection **aRemoteUSBDevices);
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync STDMETHOD(COMGETTER(RemoteDisplayInfo)) (IRemoteDisplayInfo **aRemoteDisplayInfo);
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync STDMETHOD(COMGETTER(SharedFolders)) (ISharedFolderCollection **aSharedFolders);
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync // IConsole methods
ca5d48382e06537b69b713b1b772dc299e681d24vboxsync STDMETHOD(PowerUp) (IProgress **aProgress);
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync STDMETHOD(PowerDown)();
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync STDMETHOD(Reset)();
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync STDMETHOD(Pause)();
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync STDMETHOD(Resume)();
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync STDMETHOD(PowerButton)();
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync STDMETHOD(SaveState) (IProgress **aProgress);
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync STDMETHOD(DiscardSavedState)();
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync STDMETHOD(GetDeviceActivity) (DeviceType_T aDeviceType,
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync DeviceActivity_T *aDeviceActivity);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync STDMETHOD(AttachUSBDevice) (INPTR GUIDPARAM aId);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync STDMETHOD(DetachUSBDevice) (INPTR GUIDPARAM aId, IUSBDevice **aDevice);
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync STDMETHOD(CreateSharedFolder) (INPTR BSTR aName, INPTR BSTR aHostPath);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync STDMETHOD(RemoveSharedFolder) (INPTR BSTR aName);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync STDMETHOD(TakeSnapshot) (INPTR BSTR aName, INPTR BSTR aDescription,
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync IProgress **aProgress);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync STDMETHOD(DiscardSnapshot) (INPTR GUIDPARAM aId, IProgress **aProgress);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync STDMETHOD(DiscardCurrentState) (IProgress **aProgress);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync STDMETHOD(DiscardCurrentSnapshotAndState) (IProgress **aProgress);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync STDMETHOD(RegisterCallback) (IConsoleCallback *aCallback);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync STDMETHOD(UnregisterCallback)(IConsoleCallback *aCallback);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync // public methods for internal purposes only
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync /*
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync * Note: the following methods do not increase refcount. intended to be
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync * called only by the VM execution thread.
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync */
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync Guest *getGuest() { return mGuest; }
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync Keyboard *getKeyboard() { return mKeyboard; }
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync Mouse *getMouse() { return mMouse; }
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync Display *getDisplay() { return mDisplay; }
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync MachineDebugger *getMachineDebugger() { return mDebugger; }
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync const ComPtr <IMachine> &machine() { return mMachine; }
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync /** Method is called only from ConsoleVRDPServer */
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync IVRDPServer *getVRDPServer() { return mVRDPServer; }
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync ConsoleVRDPServer *consoleVRDPServer() { return mConsoleVRDPServer; }
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync HRESULT updateMachineState (MachineState_T aMachineState);
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync // events from IInternalSessionControl
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync HRESULT onDVDDriveChange();
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync HRESULT onFloppyDriveChange();
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync HRESULT onVRDPServerChange();
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync HRESULT onUSBControllerChange();
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync HRESULT onUSBDeviceAttach(IUSBDevice *aDevice);
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync HRESULT onUSBDeviceDetach(INPTR GUIDPARAM aId);
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync VMMDev *getVMMDev() { return mVMMDev; }
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync AudioSniffer *getAudioSniffer () { return mAudioSniffer; }
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync static VRDPSERVERCALLBACK *getVrdpServerCallback () { return &sVrdpServerCallback; };
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync#ifdef VRDP_MC
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync void processRemoteUSBDevices (uint32_t u32ClientId, VRDPUSBDEVICEDESC *pDevList, uint32_t cbDevList);
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync#else
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync void processRemoteUSBDevices (VRDPUSBDEVICEDESC *pDevList, uint32_t cbDevList);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync#endif /* VRDP_MC */
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync // callback callers
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync void onMousePointerShapeChange(bool fVisible, bool fAlpha,
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync uint32_t xHot, uint32_t yHot,
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync uint32_t width, uint32_t height,
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync void *pShape);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync void onMouseCapabilityChange (BOOL supportsAbsolute, BOOL needsHostCursor);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync void onStateChange (MachineState_T aMachineState);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync void onAdditionsStateChange();
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync void onAdditionsOutdated();
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync void onKeyboardLedsChange (bool fNumLock, bool fCapsLock, bool fScrollLock);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync void onRuntimeError (BOOL aFatal, INPTR BSTR aErrorID, INPTR BSTR aMessage);
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync static const PDMDRVREG DrvStatusReg;
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync void reportAuthLibraryError (const char *filename, int rc)
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync {
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync setError (E_FAIL, tr("Could not load the external authentication library '%s' (%Vrc)"), filename, rc);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync }
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync // for VirtualBoxSupportErrorInfoImpl
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync static const wchar_t *getComponentName() { return L"Console"; }
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync
37c53e9b2c955f92dff6f11aff63809004945f17vboxsyncprivate:
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync
1df46139c7299e5fbb38e49955bce0c8ad972330vboxsync /**
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync * Base template for AutoVMCaller and SaveVMPtr. Template arguments
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync * have the same meaning as arguments of Console::addVMCaller().
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync */
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync template <bool taQuiet = false, bool taAllowNullVM = false>
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync class AutoVMCallerBase
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync {
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync public:
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync AutoVMCallerBase (Console *aThat) : mThat (aThat), mRC (S_OK)
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync {
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync Assert (aThat);
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync mRC = aThat->addVMCaller (taQuiet, taAllowNullVM);
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync }
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync ~AutoVMCallerBase()
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync {
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync if (SUCCEEDED (mRC))
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync mThat->releaseVMCaller();
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync }
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync /** Decreases the number of callers before the instance is destroyed. */
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync void release()
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync {
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync AssertReturnVoid (SUCCEEDED (mRC));
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync mThat->releaseVMCaller();
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync mRC = E_FAIL;
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync }
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync /** Restores the number of callers after by #release(). #rc() must be
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync * rechecked to ensure the operation succeeded. */
1d7eb4842eb34752cbc8655fc26097b97806314dvboxsync void add()
{
AssertReturnVoid (!SUCCEEDED (mRC));
mRC = mThat->addVMCaller (taQuiet, taAllowNullVM);
}
/** Returns the result of Console::addVMCaller() */
HRESULT rc() const { return mRC; }
/** Shortcut to SUCCEEDED (rc()) */
bool isOk() const { return SUCCEEDED (mRC); }
protected:
Console *mThat;
HRESULT mRC;
private:
DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP (AutoVMCallerBase)
DECLARE_CLS_NEW_DELETE_NOOP (AutoVMCallerBase)
};
/**
* 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);
* CheckComRCReturnRC (autoVMCaller.rc());
* ...
* VMR3ReqCall (mpVM, ...
* </code>
*
* @sa SafeVMPtr, SafeVMPtrQuiet
*/
typedef AutoVMCallerBase <false, false> AutoVMCaller;
/**
* Base template for SaveVMPtr and SaveVMPtrQuiet.
*/
template <bool taQuiet = false>
class SafeVMPtrBase : public AutoVMCallerBase <taQuiet, true>
{
typedef AutoVMCallerBase <taQuiet, true> Base;
public:
SafeVMPtrBase (Console *aThat) : Base (aThat), mpVM (NULL)
{
if (SUCCEEDED (Base::mRC))
mpVM = aThat->mpVM;
}
/** Smart SaveVMPtr to PVM cast operator */
operator PVM() const { return mpVM; }
/** Direct PVM access for printf()-like functions */
PVM raw() const { return mpVM; }
private:
PVM mpVM;
DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP (SafeVMPtrBase)
DECLARE_CLS_NEW_DELETE_NOOP (SafeVMPtrBase)
};
public:
/**
* 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);
* CheckComRCReturnRC (pVM.rc());
* ...
* VMR3ReqCall (pVM, ...
* ...
* printf ("%p\n", pVM.raw());
* </code>
*
* @sa SafeVMPtrQuiet, AutoVMCaller
*/
typedef SafeVMPtrBase <false> SafeVMPtr;
/**
* A deviation of SaveVMPtr that doesn't set the error info on failure.
* Intenede 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>
*
* @sa SafeVMPtr, AutoVMCaller
*/
typedef SafeVMPtrBase <true> SafeVMPtrQuiet;
private:
typedef std::list <ComObjPtr <OUSBDevice> > USBDeviceList;
typedef std::list <ComObjPtr <RemoteUSBDevice> > RemoteUSBDeviceList;
typedef std::list <ComObjPtr <SharedFolder> > SharedFolderList;
HRESULT addVMCaller (bool aQuiet = false, bool aAllowNullVM = false);
void releaseVMCaller();
HRESULT powerDown();
HRESULT attachToHostInterface(INetworkAdapter *networkAdapter);
HRESULT detachFromHostInterface(INetworkAdapter *networkAdapter);
HRESULT powerDownHostInterfaces();
HRESULT setMachineState (MachineState_T aMachineState, bool aUpdateServer = true);
HRESULT setMachineStateLocally (MachineState_T aMachineState)
{
return setMachineState (aMachineState, false /* aUpdateServer */);
}
HRESULT findSharedFolder (const BSTR aName,
ComObjPtr <SharedFolder> &aSharedFolder,
bool aSetError = false);
static DECLCALLBACK(int) configConstructor(PVM pVM, void *pvConsole);
static DECLCALLBACK(void) vmstateChangeCallback(PVM aVM, VMSTATE aState,
VMSTATE aOldState, void *aUser);
HRESULT doDriveChange (const char *pszDevice, unsigned uInstance,
unsigned uLun, DriveState_T eState,
DriveState_T *peState, const char *pszPath,
bool fPassthrough);
static DECLCALLBACK(int) changeDrive (Console *pThis, const char *pszDevice,
unsigned uInstance, unsigned uLun,
DriveState_T eState, DriveState_T *peState,
const char *pszPath, bool fPassthrough);
HRESULT attachUSBDevice (IUSBDevice *aHostDevice, bool aManual,
PVUSBIRHCONFIG aConfig);
static DECLCALLBACK(int)
usbAttachCallback (Console *that, IUSBDevice *aHostDevice,
PVUSBIRHCONFIG aConfig, PCRTUUID aUuid, bool aRemote,
const char *aAddress, void *aRemoteBackend);
static DECLCALLBACK(int)
usbDetachCallback (Console *that, USBDeviceList::iterator *aIt,
bool aManual, PVUSBIRHCONFIG aConfig, PCRTUUID aUuid);
static DECLCALLBACK (int)
stateProgressCallback (PVM pVM, unsigned uPercent, void *pvUser);
static DECLCALLBACK(void)
setVMErrorCallback (PVM pVM, void *pvUser, int rc, RT_SRC_POS_DECL,
const char *pszFormat, va_list args);
static DECLCALLBACK(void)
setVMRuntimeErrorCallback (PVM pVM, void *pvUser, bool fFatal,
const char *pszErrorID,
const char *pszFormat, va_list args);
HRESULT captureUSBDevices (PVM pVM);
void releaseAllUSBDevices (void);
static DECLCALLBACK (int) powerUpThread (RTTHREAD Thread, void *pvUser);
static DECLCALLBACK (int) saveStateThread (RTTHREAD Thread, void *pvUser);
static DECLCALLBACK (int) powerDownThread (RTTHREAD Thread, void *pvUser);
static DECLCALLBACK(void *) drvStatus_QueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface);
static DECLCALLBACK(void) drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
static DECLCALLBACK(void) drvStatus_Destruct(PPDMDRVINS pDrvIns);
static DECLCALLBACK(int) drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle);
#ifdef VRDP_MC
int m_cAudioRefs;
static DECLCALLBACK(int) vrdp_ClientLogon (void *pvUser, uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
static DECLCALLBACK(void) vrdp_ClientConnect (void *pvUser, uint32_t u32ClientId);
static DECLCALLBACK(void) vrdp_ClientDisconnect (void *pvUser, uint32_t u32ClientId, uint32_t fu32Intercepted);
static DECLCALLBACK(void) vrdp_InterceptAudio (void *pvUser, uint32_t u32ClientId);
static DECLCALLBACK(void) vrdp_InterceptUSB (void *pvUser, uint32_t u32ClientId, PFNVRDPUSBCALLBACK *ppfn, void **ppv);
#else
static DECLCALLBACK(int) vrdp_ClientLogon (void *pvUser, const char *pszUser, const char *pszPassword, const char *pszDomain);
static DECLCALLBACK(void) vrdp_ClientConnect (void *pvUser, uint32_t fu32SupportedOrders);
static DECLCALLBACK(void) vrdp_ClientDisconnect (void *pvUser);
static DECLCALLBACK(void) vrdp_InterceptAudio (void *pvUser, bool keepHostAudio);
static DECLCALLBACK(void) vrdp_InterceptUSB (void *pvUser, PFNVRDPUSBCALLBACK *ppfn, void **ppv);
#endif /* VRDP_MC */
static VRDPSERVERCALLBACK sVrdpServerCallback;
static char *sSSMConsoleUnit;
static uint32_t sSSMConsoleVer;
HRESULT loadDataFromSavedState();
static DECLCALLBACK(void) saveStateFileExec (PSSMHANDLE pSSM, void *pvUser);
static DECLCALLBACK(int) loadStateFileExec (PSSMHANDLE pSSM, void *pvUser, uint32_t u32Version);
bool mSavedStateDataLoaded : 1;
const ComPtr <IMachine> mMachine;
const ComPtr <IInternalMachineControl> mControl;
const ComPtr <IVRDPServer> mVRDPServer;
const ComPtr <IDVDDrive> mDVDDrive;
const ComPtr <IFloppyDrive> mFloppyDrive;
ConsoleVRDPServer * const mConsoleVRDPServer;
const ComObjPtr <Guest> mGuest;
const ComObjPtr <Keyboard> mKeyboard;
const ComObjPtr <Mouse> mMouse;
const ComObjPtr <Display> mDisplay;
const ComObjPtr <MachineDebugger> mDebugger;
const ComObjPtr <RemoteDisplayInfo> mRemoteDisplayInfo;
USBDeviceList mUSBDevices;
RemoteUSBDeviceList mRemoteUSBDevices;
SharedFolderList mSharedFolders;
/** The VM instance handle. */
PVM mpVM;
/** Holds the number of "readonly" mpVM callers (users) */
uint32_t mVMCallers;
/** Semaphore posted when the number of mpVM callers drops to zero */
RTSEMEVENT mVMZeroCallersSem;
/** true when Console has entered the mpVM destruction phase */
bool mVMDestroying : 1;
/** The current DVD drive state in the VM.
* This does not have to match the state maintained in the DVD. */
DriveState_T meDVDState;
/** The current Floppy drive state in the VM.
* This does not have to match the state maintained in the Floppy. */
DriveState_T meFloppyState;
VMMDev * const mVMMDev;
AudioSniffer * const mAudioSniffer;
PPDMLED mapFDLeds[2];
PPDMLED mapIDELeds[4];
PPDMLED mapNetworkLeds[8];
#ifdef VBOX_WITH_UNIXY_TAP_NETWORKING
Utf8Str maTAPDeviceName[8];
RTFILE maTapFD[8];
#endif
bool mVMStateChangeCallbackDisabled;
// local state value
MachineState_T mMachineState;
typedef std::list <ComPtr <IConsoleCallback> > CallbackList;
CallbackList mCallbacks;
friend struct VMTask;
};
#endif // ____H_CONSOLEIMPL