VirtualBox

source: vbox/trunk/src/VBox/Main/include/ConsoleImpl.h@ 95376

最後變更 在這個檔案從95376是 95368,由 vboxsync 提交於 3 年 前

FE/Qt, Main/Console+Mouse, VBoxManage: Touchpad support, should be functional now. bugref:9891

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 52.7 KB
 
1/* $Id: ConsoleImpl.h 95368 2022-06-24 19:41:25Z vboxsync $ */
2/** @file
3 * VBox Console COM Class definition
4 */
5
6/*
7 * Copyright (C) 2005-2022 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef MAIN_INCLUDED_ConsoleImpl_h
19#define MAIN_INCLUDED_ConsoleImpl_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "VirtualBoxBase.h"
25#include "VBox/com/array.h"
26#include "EventImpl.h"
27#include "SecretKeyStore.h"
28#include "ConsoleWrap.h"
29#ifdef VBOX_WITH_RECORDING
30# include "Recording.h"
31#endif
32#ifdef VBOX_WITH_CLOUD_NET
33#include "CloudGateway.h"
34#endif /* VBOX_WITH_CLOUD_NET */
35
36class Guest;
37class Keyboard;
38class Mouse;
39class Display;
40class MachineDebugger;
41class TeleporterStateSrc;
42class OUSBDevice;
43class RemoteUSBDevice;
44class SharedFolder;
45class VRDEServerInfo;
46class EmulatedUSB;
47class AudioVRDE;
48#ifdef VBOX_WITH_AUDIO_RECORDING
49class AudioVideoRec;
50#endif
51#ifdef VBOX_WITH_USB_CARDREADER
52class UsbCardReader;
53#endif
54class ConsoleVRDPServer;
55class VMMDev;
56class Progress;
57class BusAssignmentManager;
58COM_STRUCT_OR_CLASS(IEventListener);
59#ifdef VBOX_WITH_EXTPACK
60class ExtPackManager;
61#endif
62class VMMDevMouseInterface;
63class DisplayMouseInterface;
64class VMPowerUpTask;
65class VMPowerDownTask;
66class NvramStore;
67
68#include <iprt/uuid.h>
69#include <iprt/log.h>
70#include <iprt/memsafer.h>
71#include <VBox/RemoteDesktop/VRDE.h>
72#include <VBox/vmm/pdmdrv.h>
73#ifdef VBOX_WITH_GUEST_PROPS
74# include <VBox/HostServices/GuestPropertySvc.h> /* For the property notification callback */
75#endif
76#ifdef VBOX_WITH_USB
77# include <VBox/vrdpusb.h>
78#endif
79#include <VBox/VBoxCryptoIf.h>
80
81#if defined(VBOX_WITH_GUEST_PROPS) || defined(VBOX_WITH_SHARED_CLIPBOARD) \
82 || defined(VBOX_WITH_DRAG_AND_DROP)
83# include "HGCM.h" /** @todo It should be possible to register a service
84 * extension using a VMMDev callback. */
85#endif
86
87struct VUSBIRHCONFIG;
88typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
89
90#include <list>
91#include <vector>
92
93// defines
94///////////////////////////////////////////////////////////////////////////////
95
96/**
97 * Checks the availability of the underlying VM device driver corresponding
98 * to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
99 * not available (NULL), sets error info and returns returns E_ACCESSDENIED.
100 * The translatable error message is defined in null context.
101 *
102 * Intended to used only within Console children (i.e. Keyboard, Mouse,
103 * Display, etc.).
104 *
105 * @param drv driver pointer to check (compare it with NULL)
106 */
107#define CHECK_CONSOLE_DRV(drv) \
108 do { \
109 if (!!(drv)) {} \
110 else return setError(E_ACCESSDENIED, Console::tr("The console is not powered up (%Rfn)"), __FUNCTION__); \
111 } while (0)
112
113// Console
114///////////////////////////////////////////////////////////////////////////////
115
116class ConsoleMouseInterface
117{
118public:
119 virtual ~ConsoleMouseInterface() { }
120 virtual VMMDevMouseInterface *i_getVMMDevMouseInterface(){return NULL;}
121 virtual DisplayMouseInterface *i_getDisplayMouseInterface(){return NULL;}
122 virtual void i_onMouseCapabilityChange(BOOL supportsAbsolute,
123 BOOL supportsRelative,
124 BOOL supportsTouchScreen,
125 BOOL supportsTouchPad,
126 BOOL needsHostCursor)
127 {
128 RT_NOREF(supportsAbsolute, supportsRelative, supportsTouchScreen, supportsTouchPad, needsHostCursor);
129 }
130};
131
132/** IConsole implementation class */
133class ATL_NO_VTABLE Console :
134 public ConsoleWrap,
135 public ConsoleMouseInterface
136{
137
138public:
139
140 DECLARE_COMMON_CLASS_METHODS(Console)
141
142 HRESULT FinalConstruct();
143 void FinalRelease();
144
145 // public initializers/uninitializers for internal purposes only
146 HRESULT initWithMachine(IMachine *aMachine, IInternalMachineControl *aControl, LockType_T aLockType);
147 void uninit();
148
149
150 // public methods for internal purposes only
151
152 /*
153 * Note: the following methods do not increase refcount. intended to be
154 * called only by the VM execution thread.
155 */
156
157 PCVMMR3VTABLE i_getVMMVTable() const RT_NOEXCEPT { return mpVMM; }
158 Guest *i_getGuest() const { return mGuest; }
159 Keyboard *i_getKeyboard() const { return mKeyboard; }
160 Mouse *i_getMouse() const { return mMouse; }
161 Display *i_getDisplay() const { return mDisplay; }
162 MachineDebugger *i_getMachineDebugger() const { return mDebugger; }
163#ifdef VBOX_WITH_AUDIO_VRDE
164 AudioVRDE *i_getAudioVRDE() const { return mAudioVRDE; }
165#endif
166#ifdef VBOX_WITH_RECORDING
167 int i_recordingCreate(void);
168 void i_recordingDestroy(void);
169 int i_recordingEnable(BOOL fEnable, util::AutoWriteLock *pAutoLock);
170 int i_recordingGetSettings(settings::RecordingSettings &Settings);
171 int i_recordingStart(util::AutoWriteLock *pAutoLock = NULL);
172 int i_recordingStop(util::AutoWriteLock *pAutoLock = NULL);
173# ifdef VBOX_WITH_AUDIO_RECORDING
174 AudioVideoRec *i_recordingGetAudioDrv(void) const { return mRecording.mAudioRec; }
175# endif
176 RecordingContext *i_recordingGetContext(void) const { return mRecording.mpCtx; }
177# ifdef VBOX_WITH_AUDIO_RECORDING
178 HRESULT i_recordingSendAudio(const void *pvData, size_t cbData, uint64_t uDurationMs);
179# endif
180#endif
181
182 const ComPtr<IMachine> &i_machine() const { return mMachine; }
183 const Bstr &i_getId() const { return mstrUuid; }
184
185 bool i_useHostClipboard() { return mfUseHostClipboard; }
186
187 /** Method is called only from ConsoleVRDPServer */
188 IVRDEServer *i_getVRDEServer() const { return mVRDEServer; }
189
190 ConsoleVRDPServer *i_consoleVRDPServer() const { return mConsoleVRDPServer; }
191
192 HRESULT i_updateMachineState(MachineState_T aMachineState);
193 HRESULT i_getNominalState(MachineState_T &aNominalState);
194 Utf8Str i_getAudioAdapterDeviceName(IAudioAdapter *aAudioAdapter);
195
196 // events from IInternalSessionControl
197 HRESULT i_onNetworkAdapterChange(INetworkAdapter *aNetworkAdapter, BOOL changeAdapter);
198 HRESULT i_onAudioAdapterChange(IAudioAdapter *aAudioAdapter);
199 HRESULT i_onSerialPortChange(ISerialPort *aSerialPort);
200 HRESULT i_onParallelPortChange(IParallelPort *aParallelPort);
201 HRESULT i_onStorageControllerChange(const com::Guid& aMachineId, const com::Utf8Str& aControllerName);
202 HRESULT i_onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
203 HRESULT i_onCPUChange(ULONG aCPU, BOOL aRemove);
204 HRESULT i_onCPUExecutionCapChange(ULONG aExecutionCap);
205 HRESULT i_onClipboardModeChange(ClipboardMode_T aClipboardMode);
206 HRESULT i_onClipboardFileTransferModeChange(bool aEnabled);
207 HRESULT i_onDnDModeChange(DnDMode_T aDnDMode);
208 HRESULT i_onVRDEServerChange(BOOL aRestart);
209 HRESULT i_onRecordingChange(BOOL fEnable);
210 HRESULT i_onUSBControllerChange();
211 HRESULT i_onSharedFolderChange(BOOL aGlobal);
212 HRESULT i_onUSBDeviceAttach(IUSBDevice *aDevice, IVirtualBoxErrorInfo *aError, ULONG aMaskedIfs,
213 const Utf8Str &aCaptureFilename);
214 HRESULT i_onUSBDeviceDetach(IN_BSTR aId, IVirtualBoxErrorInfo *aError);
215 HRESULT i_onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
216 HRESULT i_onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
217 HRESULT i_onExtraDataChange(const Bstr &aMachineId, const Bstr &aKey, const Bstr &aVal);
218
219 HRESULT i_getGuestProperty(const Utf8Str &aName, Utf8Str *aValue, LONG64 *aTimestamp, Utf8Str *aFlags);
220 HRESULT i_setGuestProperty(const Utf8Str &aName, const Utf8Str &aValue, const Utf8Str &aFlags);
221 HRESULT i_deleteGuestProperty(const Utf8Str &aName);
222 HRESULT i_enumerateGuestProperties(const Utf8Str &aPatterns,
223 std::vector<Utf8Str> &aNames,
224 std::vector<Utf8Str> &aValues,
225 std::vector<LONG64> &aTimestamps,
226 std::vector<Utf8Str> &aFlags);
227 HRESULT i_onlineMergeMedium(IMediumAttachment *aMediumAttachment,
228 ULONG aSourceIdx, ULONG aTargetIdx,
229 IProgress *aProgress);
230 HRESULT i_reconfigureMediumAttachments(const std::vector<ComPtr<IMediumAttachment> > &aAttachments);
231 HRESULT i_onVMProcessPriorityChange(VMProcPriority_T priority);
232 int i_hgcmLoadService(const char *pszServiceLibrary, const char *pszServiceName);
233 VMMDev *i_getVMMDev() { return m_pVMMDev; }
234
235#ifdef VBOX_WITH_EXTPACK
236 ExtPackManager *i_getExtPackManager();
237#endif
238 EventSource *i_getEventSource() { return mEventSource; }
239#ifdef VBOX_WITH_USB_CARDREADER
240 UsbCardReader *i_getUsbCardReader() { return mUsbCardReader; }
241#endif
242
243 int i_VRDPClientLogon(uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
244 void i_VRDPClientStatusChange(uint32_t u32ClientId, const char *pszStatus);
245 void i_VRDPClientConnect(uint32_t u32ClientId);
246 void i_VRDPClientDisconnect(uint32_t u32ClientId, uint32_t fu32Intercepted);
247 void i_VRDPInterceptAudio(uint32_t u32ClientId);
248 void i_VRDPInterceptUSB(uint32_t u32ClientId, void **ppvIntercept);
249 void i_VRDPInterceptClipboard(uint32_t u32ClientId);
250
251 void i_processRemoteUSBDevices(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevList, uint32_t cbDevList, bool fDescExt);
252 void i_reportVmStatistics(ULONG aValidStats, ULONG aCpuUser,
253 ULONG aCpuKernel, ULONG aCpuIdle,
254 ULONG aMemTotal, ULONG aMemFree,
255 ULONG aMemBalloon, ULONG aMemShared,
256 ULONG aMemCache, ULONG aPageTotal,
257 ULONG aAllocVMM, ULONG aFreeVMM,
258 ULONG aBalloonedVMM, ULONG aSharedVMM,
259 ULONG aVmNetRx, ULONG aVmNetTx)
260 {
261 mControl->ReportVmStatistics(aValidStats, aCpuUser, aCpuKernel, aCpuIdle,
262 aMemTotal, aMemFree, aMemBalloon, aMemShared,
263 aMemCache, aPageTotal, aAllocVMM, aFreeVMM,
264 aBalloonedVMM, aSharedVMM, aVmNetRx, aVmNetTx);
265 }
266 void i_enableVMMStatistics(BOOL aEnable);
267
268 HRESULT i_pause(Reason_T aReason);
269 HRESULT i_resume(Reason_T aReason, AutoWriteLock &alock);
270 HRESULT i_saveState(Reason_T aReason, const ComPtr<IProgress> &aProgress,
271 const ComPtr<ISnapshot> &aSnapshot,
272 const Utf8Str &aStateFilePath, bool fPauseVM, bool &fLeftPaused);
273 HRESULT i_cancelSaveState();
274
275 // callback callers (partly; for some events console callbacks are notified
276 // directly from IInternalSessionControl event handlers declared above)
277 void i_onMousePointerShapeChange(bool fVisible, bool fAlpha,
278 uint32_t xHot, uint32_t yHot,
279 uint32_t width, uint32_t height,
280 const uint8_t *pu8Shape,
281 uint32_t cbShape);
282 void i_onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative,
283 BOOL supportsTouchScreen, BOOL supportsTouchPad,
284 BOOL needsHostCursor);
285 void i_onStateChange(MachineState_T aMachineState);
286 void i_onAdditionsStateChange();
287 void i_onAdditionsOutdated();
288 void i_onKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock);
289 void i_onUSBDeviceStateChange(IUSBDevice *aDevice, bool aAttached,
290 IVirtualBoxErrorInfo *aError);
291 void i_onRuntimeError(BOOL aFatal, IN_BSTR aErrorID, IN_BSTR aMessage);
292 HRESULT i_onShowWindow(BOOL aCheck, BOOL *aCanShow, LONG64 *aWinId);
293 void i_onVRDEServerInfoChange();
294 HRESULT i_sendACPIMonitorHotPlugEvent();
295
296 static const PDMDRVREG DrvStatusReg;
297
298 static HRESULT i_setErrorStatic(HRESULT aResultCode, const char *pcsz, ...);
299 static HRESULT i_setErrorStaticBoth(HRESULT aResultCode, int vrc, const char *pcsz, ...);
300 HRESULT i_setInvalidMachineStateError();
301
302 static const char *i_storageControllerTypeToStr(StorageControllerType_T enmCtrlType);
303 static HRESULT i_storageBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
304 // Called from event listener
305 HRESULT i_onNATRedirectRuleChanged(ULONG ulInstance, BOOL aNatRuleRemove,
306 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
307 HRESULT i_onNATDnsChanged();
308
309 // Mouse interface
310 VMMDevMouseInterface *i_getVMMDevMouseInterface();
311 DisplayMouseInterface *i_getDisplayMouseInterface();
312
313 EmulatedUSB *i_getEmulatedUSB(void) { return mEmulatedUSB; }
314
315 /**
316 * Sets the disk encryption keys.
317 *
318 * @returns COM status code.
319 * @param strCfg The config for the disks.
320 *
321 * @note One line in the config string contains all required data for one disk.
322 * The format for one disk is some sort of comma separated value using
323 * key=value pairs.
324 * There are two keys defined at the moment:
325 * - uuid: The uuid of the base image the key is for (with or without)
326 * the curly braces.
327 * - dek: The data encryption key in base64 encoding
328 */
329 HRESULT i_setDiskEncryptionKeys(const Utf8Str &strCfg);
330
331 int i_retainCryptoIf(PCVBOXCRYPTOIF *ppCryptoIf);
332 int i_releaseCryptoIf(PCVBOXCRYPTOIF pCryptoIf);
333 HRESULT i_unloadCryptoIfModule(void);
334
335#ifdef VBOX_WITH_GUEST_PROPS
336 // VMMDev needs:
337 HRESULT i_pullGuestProperties(ComSafeArrayOut(BSTR, names), ComSafeArrayOut(BSTR, values),
338 ComSafeArrayOut(LONG64, timestamps), ComSafeArrayOut(BSTR, flags));
339 static DECLCALLBACK(int) i_doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
340#endif
341
342private:
343
344 // wrapped IConsole properties
345 HRESULT getMachine(ComPtr<IMachine> &aMachine);
346 HRESULT getState(MachineState_T *aState);
347 HRESULT getGuest(ComPtr<IGuest> &aGuest);
348 HRESULT getKeyboard(ComPtr<IKeyboard> &aKeyboard);
349 HRESULT getMouse(ComPtr<IMouse> &aMouse);
350 HRESULT getDisplay(ComPtr<IDisplay> &aDisplay);
351 HRESULT getDebugger(ComPtr<IMachineDebugger> &aDebugger);
352 HRESULT getUSBDevices(std::vector<ComPtr<IUSBDevice> > &aUSBDevices);
353 HRESULT getRemoteUSBDevices(std::vector<ComPtr<IHostUSBDevice> > &aRemoteUSBDevices);
354 HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
355 HRESULT getVRDEServerInfo(ComPtr<IVRDEServerInfo> &aVRDEServerInfo);
356 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
357 HRESULT getAttachedPCIDevices(std::vector<ComPtr<IPCIDeviceAttachment> > &aAttachedPCIDevices);
358 HRESULT getUseHostClipboard(BOOL *aUseHostClipboard);
359 HRESULT setUseHostClipboard(BOOL aUseHostClipboard);
360 HRESULT getEmulatedUSB(ComPtr<IEmulatedUSB> &aEmulatedUSB);
361
362 // wrapped IConsole methods
363 HRESULT powerUp(ComPtr<IProgress> &aProgress);
364 HRESULT powerUpPaused(ComPtr<IProgress> &aProgress);
365 HRESULT powerDown(ComPtr<IProgress> &aProgress);
366 HRESULT reset();
367 HRESULT pause();
368 HRESULT resume();
369 HRESULT powerButton();
370 HRESULT sleepButton();
371 HRESULT getPowerButtonHandled(BOOL *aHandled);
372 HRESULT getGuestEnteredACPIMode(BOOL *aEntered);
373 HRESULT getDeviceActivity(const std::vector<DeviceType_T> &aType,
374 std::vector<DeviceActivity_T> &aActivity);
375 HRESULT attachUSBDevice(const com::Guid &aId, const com::Utf8Str &aCaptureFilename);
376 HRESULT detachUSBDevice(const com::Guid &aId,
377 ComPtr<IUSBDevice> &aDevice);
378 HRESULT findUSBDeviceByAddress(const com::Utf8Str &aName,
379 ComPtr<IUSBDevice> &aDevice);
380 HRESULT findUSBDeviceById(const com::Guid &aId,
381 ComPtr<IUSBDevice> &aDevice);
382 HRESULT createSharedFolder(const com::Utf8Str &aName,
383 const com::Utf8Str &aHostPath,
384 BOOL aWritable,
385 BOOL aAutomount,
386 const com::Utf8Str &aAutoMountPoint);
387 HRESULT removeSharedFolder(const com::Utf8Str &aName);
388 HRESULT teleport(const com::Utf8Str &aHostname,
389 ULONG aTcpport,
390 const com::Utf8Str &aPassword,
391 ULONG aMaxDowntime,
392 ComPtr<IProgress> &aProgress);
393 HRESULT addEncryptionPassword(const com::Utf8Str &aId, const com::Utf8Str &aPassword,
394 BOOL aClearOnSuspend);
395 HRESULT addEncryptionPasswords(const std::vector<com::Utf8Str> &aIds, const std::vector<com::Utf8Str> &aPasswords,
396 BOOL aClearOnSuspend);
397 HRESULT removeEncryptionPassword(const com::Utf8Str &aId);
398 HRESULT clearAllEncryptionPasswords();
399
400 void notifyNatDnsChange(PUVM pUVM, PCVMMR3VTABLE pVMM, const char *pszDevice, ULONG ulInstanceMax);
401 Utf8Str VRDPServerErrorToMsg(int vrc);
402
403 /**
404 * Base template for AutoVMCaller and SafeVMPtr. Template arguments
405 * have the same meaning as arguments of Console::addVMCaller().
406 */
407 template <bool taQuiet = false, bool taAllowNullVM = false>
408 class AutoVMCallerBase
409 {
410 public:
411 AutoVMCallerBase(Console *aThat) : mThat(aThat), mRC(E_FAIL)
412 {
413 Assert(aThat);
414 mRC = aThat->i_addVMCaller(taQuiet, taAllowNullVM);
415 }
416 ~AutoVMCallerBase()
417 {
418 doRelease();
419 }
420 /** Decreases the number of callers before the instance is destroyed. */
421 void releaseCaller()
422 {
423 Assert(SUCCEEDED(mRC));
424 doRelease();
425 }
426 /** Restores the number of callers after by #release(). #rc() must be
427 * rechecked to ensure the operation succeeded. */
428 void addYY()
429 {
430 AssertReturnVoid(!SUCCEEDED(mRC));
431 mRC = mThat->i_addVMCaller(taQuiet, taAllowNullVM);
432 }
433 /** Returns the result of Console::addVMCaller() */
434 HRESULT rc() const { return mRC; }
435 /** Shortcut to SUCCEEDED(rc()) */
436 bool isOk() const { return SUCCEEDED(mRC); }
437 protected:
438 Console *mThat;
439 void doRelease()
440 {
441 if (SUCCEEDED(mRC))
442 {
443 mThat->i_releaseVMCaller();
444 mRC = E_FAIL;
445 }
446 }
447 private:
448 HRESULT mRC; /* Whether the caller was added. */
449 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoVMCallerBase);
450 };
451
452#if 0
453 /**
454 * Helper class that protects sections of code using the mpUVM pointer by
455 * automatically calling addVMCaller() on construction and
456 * releaseVMCaller() on destruction. Intended for Console methods dealing
457 * with mpUVM. The usage pattern is:
458 * <code>
459 * AutoVMCaller autoVMCaller(this);
460 * if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();
461 * ...
462 * VMR3ReqCall (mpUVM, ...
463 * </code>
464 *
465 * @note Temporarily locks the argument for writing.
466 *
467 * @sa SafeVMPtr, SafeVMPtrQuiet
468 * @note Obsolete, use SafeVMPtr
469 */
470 typedef AutoVMCallerBase<false, false> AutoVMCaller;
471#endif
472
473 /**
474 * Same as AutoVMCaller but doesn't set extended error info on failure.
475 *
476 * @note Temporarily locks the argument for writing.
477 * @note Obsolete, use SafeVMPtrQuiet
478 */
479 typedef AutoVMCallerBase<true, false> AutoVMCallerQuiet;
480
481 /**
482 * Same as AutoVMCaller but allows a null VM pointer (to trigger an error
483 * instead of assertion).
484 *
485 * @note Temporarily locks the argument for writing.
486 * @note Obsolete, use SafeVMPtr
487 */
488 typedef AutoVMCallerBase<false, true> AutoVMCallerWeak;
489
490 /**
491 * Same as AutoVMCaller but doesn't set extended error info on failure
492 * and allows a null VM pointer (to trigger an error instead of
493 * assertion).
494 *
495 * @note Temporarily locks the argument for writing.
496 * @note Obsolete, use SafeVMPtrQuiet
497 */
498 typedef AutoVMCallerBase<true, true> AutoVMCallerQuietWeak;
499
500 /**
501 * Base template for SafeVMPtr and SafeVMPtrQuiet.
502 */
503 template<bool taQuiet = false>
504 class SafeVMPtrBase : public AutoVMCallerBase<taQuiet, true>
505 {
506 typedef AutoVMCallerBase<taQuiet, true> Base;
507 public:
508 SafeVMPtrBase(Console *aThat) : Base(aThat), mRC(E_FAIL), mpUVM(NULL), mpVMM(NULL)
509 {
510 if (Base::isOk())
511 mRC = aThat->i_safeVMPtrRetainer(&mpUVM, &mpVMM, taQuiet);
512 }
513 ~SafeVMPtrBase()
514 {
515 doRelease();
516 }
517 /** Direct PUVM access. */
518 PUVM rawUVM() const { return mpUVM; }
519 /** Direct PCVMMR3VTABLE access. */
520 PCVMMR3VTABLE vtable() const { return mpVMM; }
521 /** Release the handles. */
522 void release()
523 {
524 Assert(SUCCEEDED(mRC));
525 doRelease();
526 }
527
528 /** The combined result of Console::addVMCaller() and Console::safeVMPtrRetainer */
529 HRESULT rc() const { return Base::isOk()? mRC: Base::rc(); }
530 /** Shortcut to SUCCEEDED(rc()) */
531 bool isOk() const { return SUCCEEDED(mRC) && Base::isOk(); }
532
533 private:
534 void doRelease()
535 {
536 if (SUCCEEDED(mRC))
537 {
538 Base::mThat->i_safeVMPtrReleaser(&mpUVM);
539 mRC = E_FAIL;
540 }
541 Base::doRelease();
542 }
543 HRESULT mRC; /* Whether the VM ptr was retained. */
544 PUVM mpUVM;
545 PCVMMR3VTABLE mpVMM;
546 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(SafeVMPtrBase);
547 };
548
549public:
550
551 /*
552 * Helper class that safely manages the Console::mpUVM pointer
553 * by calling addVMCaller() on construction and releaseVMCaller() on
554 * destruction. Intended for Console children. The usage pattern is:
555 * <code>
556 * Console::SafeVMPtr ptrVM(mParent);
557 * if (!ptrVM.isOk())
558 * return ptrVM.rc();
559 * ...
560 * VMR3ReqCall(ptrVM.rawUVM(), ...
561 * ...
562 * printf("%p\n", ptrVM.rawUVM());
563 * </code>
564 *
565 * @note Temporarily locks the argument for writing.
566 *
567 * @sa SafeVMPtrQuiet, AutoVMCaller
568 */
569 typedef SafeVMPtrBase<false> SafeVMPtr;
570
571 /**
572 * A deviation of SafeVMPtr that doesn't set the error info on failure.
573 * Intended for pieces of code that don't need to return the VM access
574 * failure to the caller. The usage pattern is:
575 * <code>
576 * Console::SafeVMPtrQuiet pVM(mParent);
577 * if (pVM.rc())
578 * VMR3ReqCall(pVM, ...
579 * return S_OK;
580 * </code>
581 *
582 * @note Temporarily locks the argument for writing.
583 *
584 * @sa SafeVMPtr, AutoVMCaller
585 */
586 typedef SafeVMPtrBase<true> SafeVMPtrQuiet;
587
588 class SharedFolderData
589 {
590 public:
591 SharedFolderData()
592 { }
593
594 SharedFolderData(const Utf8Str &aHostPath,
595 bool aWritable,
596 bool aAutoMount,
597 const Utf8Str &aAutoMountPoint)
598 : m_strHostPath(aHostPath)
599 , m_fWritable(aWritable)
600 , m_fAutoMount(aAutoMount)
601 , m_strAutoMountPoint(aAutoMountPoint)
602 { }
603
604 /** Copy constructor. */
605 SharedFolderData(const SharedFolderData& aThat)
606 : m_strHostPath(aThat.m_strHostPath)
607 , m_fWritable(aThat.m_fWritable)
608 , m_fAutoMount(aThat.m_fAutoMount)
609 , m_strAutoMountPoint(aThat.m_strAutoMountPoint)
610 { }
611
612 /** Copy assignment operator. */
613 SharedFolderData &operator=(SharedFolderData const &a_rThat) RT_NOEXCEPT
614 {
615 m_strHostPath = a_rThat.m_strHostPath;
616 m_fWritable = a_rThat.m_fWritable;
617 m_fAutoMount = a_rThat.m_fAutoMount;
618 m_strAutoMountPoint = a_rThat.m_strAutoMountPoint;
619
620 return *this;
621 }
622
623 Utf8Str m_strHostPath;
624 bool m_fWritable;
625 bool m_fAutoMount;
626 Utf8Str m_strAutoMountPoint;
627 };
628
629 /**
630 * Class for managing emulated USB MSDs.
631 */
632 class USBStorageDevice
633 {
634 public:
635 USBStorageDevice()
636 { }
637 /** The UUID associated with the USB device. */
638 RTUUID mUuid;
639 /** Port of the storage device. */
640 LONG iPort;
641 };
642
643 typedef std::map<Utf8Str, ComObjPtr<SharedFolder> > SharedFolderMap;
644 typedef std::map<Utf8Str, SharedFolderData> SharedFolderDataMap;
645 typedef std::map<Utf8Str, ComPtr<IMediumAttachment> > MediumAttachmentMap;
646 typedef std::list <USBStorageDevice> USBStorageDeviceList;
647
648 static void i_powerUpThreadTask(VMPowerUpTask *pTask);
649 static void i_powerDownThreadTask(VMPowerDownTask *pTask);
650
651private:
652
653 typedef std::list <ComObjPtr<OUSBDevice> > USBDeviceList;
654 typedef std::list <ComObjPtr<RemoteUSBDevice> > RemoteUSBDeviceList;
655
656 HRESULT i_loadVMM(void) RT_NOEXCEPT;
657 HRESULT i_addVMCaller(bool aQuiet = false, bool aAllowNullVM = false);
658 void i_releaseVMCaller();
659 HRESULT i_safeVMPtrRetainer(PUVM *a_ppUVM, PCVMMR3VTABLE *a_ppVMM, bool aQuiet) RT_NOEXCEPT;
660 void i_safeVMPtrReleaser(PUVM *a_ppUVM);
661
662 HRESULT i_consoleInitReleaseLog(const ComPtr<IMachine> aMachine);
663
664 HRESULT i_powerUp(IProgress **aProgress, bool aPaused);
665 HRESULT i_powerDown(IProgress *aProgress = NULL);
666
667/* Note: FreeBSD needs this whether netflt is used or not. */
668#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
669 HRESULT i_attachToTapInterface(INetworkAdapter *networkAdapter);
670 HRESULT i_detachFromTapInterface(INetworkAdapter *networkAdapter);
671#endif
672 HRESULT i_powerDownHostInterfaces();
673
674 HRESULT i_setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
675 HRESULT i_setMachineStateLocally(MachineState_T aMachineState)
676 {
677 return i_setMachineState(aMachineState, false /* aUpdateServer */);
678 }
679
680 HRESULT i_findSharedFolder(const Utf8Str &strName,
681 ComObjPtr<SharedFolder> &aSharedFolder,
682 bool aSetError = false);
683
684 HRESULT i_fetchSharedFolders(BOOL aGlobal);
685 bool i_findOtherSharedFolder(const Utf8Str &straName,
686 SharedFolderDataMap::const_iterator &aIt);
687
688 HRESULT i_createSharedFolder(const Utf8Str &strName, const SharedFolderData &aData);
689 HRESULT i_removeSharedFolder(const Utf8Str &strName);
690
691 HRESULT i_suspendBeforeConfigChange(PUVM pUVM, PCVMMR3VTABLE pVMM, AutoWriteLock *pAlock, bool *pfResume);
692 void i_resumeAfterConfigChange(PUVM pUVM, PCVMMR3VTABLE pVMM);
693
694 static DECLCALLBACK(int) i_configConstructor(PUVM pUVM, PVM pVM, PCVMMR3VTABLE pVMM, void *pvConsole);
695 void InsertConfigString(PCFGMNODE pNode, const char *pcszName, const char *pcszValue);
696 void InsertConfigString(PCFGMNODE pNode, const char *pcszName, const Utf8Str &rStrValue);
697 void InsertConfigString(PCFGMNODE pNode, const char *pcszName, const Bstr &rBstrValue);
698 void InsertConfigPassword(PCFGMNODE pNode, const char *pcszName, const Utf8Str &rStrValue);
699 void InsertConfigBytes(PCFGMNODE pNode, const char *pcszName, const void *pvBytes, size_t cbBytes);
700 void InsertConfigInteger(PCFGMNODE pNode, const char *pcszName, uint64_t u64Integer);
701 void InsertConfigNode(PCFGMNODE pNode, const char *pcszName, PCFGMNODE *ppChild);
702 void InsertConfigNodeF(PCFGMNODE pNode, PCFGMNODE *ppChild, const char *pszNameFormat, ...);
703 void RemoveConfigValue(PCFGMNODE pNode, const char *pcszName);
704 int SetBiosDiskInfo(ComPtr<IMachine> pMachine, PCFGMNODE pCfg, PCFGMNODE pBiosCfg,
705 Bstr controllerName, const char * const s_apszBiosConfig[4]);
706 void i_configAudioDriver(IVirtualBox *pVirtualBox, IMachine *pMachine, PCFGMNODE pLUN, const char *pszDriverName,
707 bool fAudioEnabledIn, bool fAudioEnabledOut);
708 int i_configConstructorInner(PUVM pUVM, PVM pVM, PCVMMR3VTABLE pVMM, AutoWriteLock *pAlock);
709 int i_configCfgmOverlay(PCFGMNODE pRoot, IVirtualBox *pVirtualBox, IMachine *pMachine);
710 int i_configDumpAPISettingsTweaks(IVirtualBox *pVirtualBox, IMachine *pMachine);
711
712 int i_configGraphicsController(PCFGMNODE pDevices,
713 const GraphicsControllerType_T graphicsController,
714 BusAssignmentManager *pBusMgr,
715 const ComPtr<IMachine> &ptrMachine,
716 const ComPtr<IGraphicsAdapter> &ptrGraphicsAdapter,
717 const ComPtr<IBIOSSettings> &ptrBiosSettings,
718 bool fHMEnabled);
719 int i_checkMediumLocation(IMedium *pMedium, bool *pfUseHostIOCache);
720 int i_unmountMediumFromGuest(PUVM pUVM, PCVMMR3VTABLE pVMM, StorageBus_T enmBus, DeviceType_T enmDevType,
721 const char *pcszDevice, unsigned uInstance, unsigned uLUN,
722 bool fForceUnmount) RT_NOEXCEPT;
723 int i_removeMediumDriverFromVm(PCFGMNODE pCtlInst,
724 const char *pcszDevice,
725 unsigned uInstance,
726 unsigned uLUN,
727 StorageBus_T enmBus,
728 bool fAttachDetach,
729 bool fHotplug,
730 bool fForceUnmount,
731 PUVM pUVM,
732 PCVMMR3VTABLE pVMM,
733 DeviceType_T enmDevType,
734 PCFGMNODE *ppLunL0);
735 int i_configMediumAttachment(const char *pcszDevice,
736 unsigned uInstance,
737 StorageBus_T enmBus,
738 bool fUseHostIOCache,
739 bool fBuiltinIoCache,
740 bool fInsertDiskIntegrityDrv,
741 bool fSetupMerge,
742 unsigned uMergeSource,
743 unsigned uMergeTarget,
744 IMediumAttachment *pMediumAtt,
745 MachineState_T aMachineState,
746 HRESULT *phrc,
747 bool fAttachDetach,
748 bool fForceUnmount,
749 bool fHotplug,
750 PUVM pUVM,
751 PCVMMR3VTABLE pVMM,
752 DeviceType_T *paLedDevType,
753 PCFGMNODE *ppLunL0);
754 int i_configMedium(PCFGMNODE pLunL0,
755 bool fPassthrough,
756 DeviceType_T enmType,
757 bool fUseHostIOCache,
758 bool fBuiltinIoCache,
759 bool fInsertDiskIntegrityDrv,
760 bool fSetupMerge,
761 unsigned uMergeSource,
762 unsigned uMergeTarget,
763 const char *pcszBwGroup,
764 bool fDiscard,
765 bool fNonRotational,
766 ComPtr<IMedium> ptrMedium,
767 MachineState_T aMachineState,
768 HRESULT *phrc);
769 int i_configMediumProperties(PCFGMNODE pCur, IMedium *pMedium, bool *pfHostIP, bool *pfEncrypted);
770 static DECLCALLBACK(int) i_reconfigureMediumAttachment(Console *pThis,
771 PUVM pUVM,
772 PCVMMR3VTABLE pVMM,
773 const char *pcszDevice,
774 unsigned uInstance,
775 StorageBus_T enmBus,
776 bool fUseHostIOCache,
777 bool fBuiltinIoCache,
778 bool fInsertDiskIntegrityDrv,
779 bool fSetupMerge,
780 unsigned uMergeSource,
781 unsigned uMergeTarget,
782 IMediumAttachment *aMediumAtt,
783 MachineState_T aMachineState,
784 HRESULT *phrc);
785 static DECLCALLBACK(int) i_changeRemovableMedium(Console *pThis,
786 PUVM pUVM,
787 PCVMMR3VTABLE pVMM,
788 const char *pcszDevice,
789 unsigned uInstance,
790 StorageBus_T enmBus,
791 bool fUseHostIOCache,
792 IMediumAttachment *aMediumAtt,
793 bool fForce);
794
795 HRESULT i_attachRawPCIDevices(PUVM pUVM, BusAssignmentManager *BusMgr, PCFGMNODE pDevices);
796 struct LEDSET;
797 typedef struct LEDSET *PLEDSET;
798 PPDMLED *i_getLedSet(uint32_t iLedSet);
799 uint32_t i_allocateDriverLeds(uint32_t cLeds, DeviceType_T enmType, DeviceType_T **ppSubTypes);
800 void i_attachStatusDriver(PCFGMNODE pCtlInst, DeviceType_T enmType,
801 uint32_t uFirst, uint32_t uLast,
802 DeviceType_T **ppaSubTypes,
803 Console::MediumAttachmentMap *pmapMediumAttachments,
804 const char *pcszDevice, unsigned uInstance);
805
806 int i_configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun, INetworkAdapter *aNetworkAdapter,
807 PCFGMNODE pCfg, PCFGMNODE pLunL0, PCFGMNODE pInst, bool fAttachDetach, bool fIgnoreConnectFailure,
808 PUVM pUVM, PCVMMR3VTABLE pVMM);
809 int i_configProxy(ComPtr<IVirtualBox> virtualBox, PCFGMNODE pCfg, const char *pcszPrefix, const com::Utf8Str &strIpAddr);
810
811 int i_configSerialPort(PCFGMNODE pInst, PortMode_T ePortMode, const char *pszPath, bool fServer);
812 static DECLCALLBACK(void) i_vmstateChangeCallback(PUVM pUVM, PCVMMR3VTABLE pVMM, VMSTATE enmState,
813 VMSTATE enmOldState, void *pvUser);
814 static DECLCALLBACK(int) i_unplugCpu(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, VMCPUID idCpu);
815 static DECLCALLBACK(int) i_plugCpu(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, VMCPUID idCpu);
816 HRESULT i_doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PUVM pUVM, PCVMMR3VTABLE pVMM);
817 HRESULT i_doCPURemove(ULONG aCpu, PUVM pUVM, PCVMMR3VTABLE pVMM);
818 HRESULT i_doCPUAdd(ULONG aCpu, PUVM pUVM, PCVMMR3VTABLE pVMM);
819
820 HRESULT i_doNetworkAdapterChange(PUVM pUVM, PCVMMR3VTABLE pVMM, const char *pszDevice, unsigned uInstance,
821 unsigned uLun, INetworkAdapter *aNetworkAdapter);
822 static DECLCALLBACK(int) i_changeNetworkAttachment(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, const char *pszDevice,
823 unsigned uInstance, unsigned uLun, INetworkAdapter *aNetworkAdapter);
824 static DECLCALLBACK(int) i_changeSerialPortAttachment(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, ISerialPort *pSerialPort);
825
826 int i_changeClipboardMode(ClipboardMode_T aClipboardMode);
827 int i_changeClipboardFileTransferMode(bool aEnabled);
828 int i_changeDnDMode(DnDMode_T aDnDMode);
829
830#ifdef VBOX_WITH_USB
831 HRESULT i_attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs, const Utf8Str &aCaptureFilename);
832 HRESULT i_detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice);
833
834 static DECLCALLBACK(int) i_usbAttachCallback(Console *that, PUVM pUVM, PCVMMR3VTABLE pVMM, IUSBDevice *aHostDevice,
835 PCRTUUID aUuid, const char *aBackend, const char *aAddress,
836 PCFGMNODE pRemoteCfg, USBConnectionSpeed_T enmSpeed, ULONG aMaskedIfs,
837 const char *pszCaptureFilename);
838 static DECLCALLBACK(int) i_usbDetachCallback(Console *that, PUVM pUVM, PCVMMR3VTABLE pVMM, PCRTUUID aUuid);
839 static DECLCALLBACK(PREMOTEUSBCALLBACK) i_usbQueryRemoteUsbBackend(void *pvUser, PCRTUUID pUuid, uint32_t idClient);
840
841 /** Interface for the VRDP USB proxy backend to query for a device remote callback table. */
842 REMOTEUSBIF mRemoteUsbIf;
843#endif
844
845 static DECLCALLBACK(int) i_attachStorageDevice(Console *pThis,
846 PUVM pUVM,
847 PCVMMR3VTABLE pVMM,
848 const char *pcszDevice,
849 unsigned uInstance,
850 StorageBus_T enmBus,
851 bool fUseHostIOCache,
852 IMediumAttachment *aMediumAtt,
853 bool fSilent);
854 static DECLCALLBACK(int) i_detachStorageDevice(Console *pThis,
855 PUVM pUVM,
856 PCVMMR3VTABLE pVMM,
857 const char *pcszDevice,
858 unsigned uInstance,
859 StorageBus_T enmBus,
860 IMediumAttachment *aMediumAtt,
861 bool fSilent);
862 HRESULT i_doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PUVM pUVM, PCVMMR3VTABLE pVMM, bool fSilent);
863 HRESULT i_doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PUVM pUVM, PCVMMR3VTABLE pVMM, bool fSilent);
864
865 static DECLCALLBACK(int) i_stateProgressCallback(PUVM pUVM, unsigned uPercent, void *pvUser);
866
867 static DECLCALLBACK(void) i_genericVMSetErrorCallback(PUVM pUVM, void *pvUser, int rc, RT_SRC_POS_DECL,
868 const char *pszErrorFmt, va_list va);
869
870 void i_atVMRuntimeErrorCallbackF(uint32_t fFatal, const char *pszErrorId, const char *pszFormat, ...);
871 static DECLCALLBACK(void) i_atVMRuntimeErrorCallback(PUVM pUVM, void *pvUser, uint32_t fFatal,
872 const char *pszErrorId, const char *pszFormat, va_list va);
873
874 HRESULT i_captureUSBDevices(PUVM pUVM);
875 void i_detachAllUSBDevices(bool aDone);
876
877
878 static DECLCALLBACK(int) i_vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
879 static DECLCALLBACK(void) i_vmm2User_NotifyEmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
880 static DECLCALLBACK(void) i_vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
881 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM);
882 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM);
883 static DECLCALLBACK(void) i_vmm2User_NotifyResetTurnedIntoPowerOff(PCVMM2USERMETHODS pThis, PUVM pUVM);
884 static DECLCALLBACK(void *) i_vmm2User_QueryGenericObject(PCVMM2USERMETHODS pThis, PUVM pUVM, PCRTUUID pUuid);
885
886 static DECLCALLBACK(void *) i_drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
887 static DECLCALLBACK(void) i_drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
888 static DECLCALLBACK(int) i_drvStatus_MediumEjected(PPDMIMEDIANOTIFY pInterface, unsigned iLUN);
889 static DECLCALLBACK(void) i_drvStatus_Destruct(PPDMDRVINS pDrvIns);
890 static DECLCALLBACK(int) i_drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
891
892 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRetain(PPDMISECKEY pInterface, const char *pszId, const uint8_t **ppbKey,
893 size_t *pcbKey);
894 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRelease(PPDMISECKEY pInterface, const char *pszId);
895 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRetain(PPDMISECKEY pInterface, const char *pszId, const char **ppszPassword);
896 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRelease(PPDMISECKEY pInterface, const char *pszId);
897
898 static DECLCALLBACK(int) i_pdmIfSecKeyHlp_KeyMissingNotify(PPDMISECKEYHLP pInterface);
899
900 int mcAudioRefs;
901 volatile uint32_t mcVRDPClients;
902 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
903 volatile bool mcGuestCredentialsProvided;
904
905 static const char *sSSMConsoleUnit;
906
907 HRESULT i_loadDataFromSavedState();
908 int i_loadStateFileExecInternal(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, uint32_t u32Version);
909
910 static DECLCALLBACK(int) i_saveStateFileExec(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, void *pvUser);
911 static DECLCALLBACK(int) i_loadStateFileExec(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, void *pvUser,
912 uint32_t uVersion, uint32_t uPass);
913
914#ifdef VBOX_WITH_GUEST_PROPS
915 HRESULT i_doEnumerateGuestProperties(const Utf8Str &aPatterns,
916 std::vector<Utf8Str> &aNames,
917 std::vector<Utf8Str> &aValues,
918 std::vector<LONG64> &aTimestamps,
919 std::vector<Utf8Str> &aFlags);
920
921 void i_guestPropertiesHandleVMReset(void);
922 bool i_guestPropertiesVRDPEnabled(void);
923 void i_guestPropertiesVRDPUpdateLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
924 void i_guestPropertiesVRDPUpdateActiveClient(uint32_t u32ClientId);
925 void i_guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached);
926 void i_guestPropertiesVRDPUpdateNameChange(uint32_t u32ClientId, const char *pszName);
927 void i_guestPropertiesVRDPUpdateIPAddrChange(uint32_t u32ClientId, const char *pszIPAddr);
928 void i_guestPropertiesVRDPUpdateLocationChange(uint32_t u32ClientId, const char *pszLocation);
929 void i_guestPropertiesVRDPUpdateOtherInfoChange(uint32_t u32ClientId, const char *pszOtherInfo);
930 void i_guestPropertiesVRDPUpdateDisconnect(uint32_t u32ClientId);
931#endif
932
933 /** @name Disk encryption support
934 * @{ */
935 HRESULT i_consoleParseDiskEncryption(const char *psz, const char **ppszEnd);
936 HRESULT i_configureEncryptionForDisk(const Utf8Str &strId, unsigned *pcDisksConfigured);
937 HRESULT i_clearDiskEncryptionKeysOnAllAttachmentsWithKeyId(const Utf8Str &strId);
938 HRESULT i_initSecretKeyIfOnAllAttachments(void);
939 int i_consoleParseKeyValue(const char *psz, const char **ppszEnd,
940 char **ppszKey, char **ppszVal);
941 void i_removeSecretKeysOnSuspend();
942 /** @} */
943
944 /** @name Teleporter support
945 * @{ */
946 static DECLCALLBACK(int) i_teleporterSrcThreadWrapper(RTTHREAD hThreadSelf, void *pvUser);
947 HRESULT i_teleporterSrc(TeleporterStateSrc *pState);
948 HRESULT i_teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
949 HRESULT i_teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
950 HRESULT i_teleporterTrg(PUVM pUVM, PCVMMR3VTABLE pVMM, IMachine *pMachine, Utf8Str *pErrorMsg,
951 bool fStartPaused, Progress *pProgress, bool *pfPowerOffOnFailure);
952 static DECLCALLBACK(int) i_teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
953 /** @} */
954
955#ifdef VBOX_WITH_FULL_VM_ENCRYPTION
956 /** @name Encrypted log interface
957 * @{ */
958 static DECLCALLBACK(int) i_logEncryptedOpen(PCRTLOGOUTPUTIF pIf, void *pvUser, const char *pszFilename, uint32_t fFlags);
959 static DECLCALLBACK(int) i_logEncryptedClose(PCRTLOGOUTPUTIF pIf, void *pvUser);
960 static DECLCALLBACK(int) i_logEncryptedDelete(PCRTLOGOUTPUTIF pIf, void *pvUser, const char *pszFilename);
961 static DECLCALLBACK(int) i_logEncryptedRename(PCRTLOGOUTPUTIF pIf, void *pvUser, const char *pszFilenameOld,
962 const char *pszFilenameNew, uint32_t fFlags);
963 static DECLCALLBACK(int) i_logEncryptedQuerySize(PCRTLOGOUTPUTIF pIf, void *pvUser, uint64_t *pcbSize);
964 static DECLCALLBACK(int) i_logEncryptedWrite(PCRTLOGOUTPUTIF pIf, void *pvUser, const void *pvBuf,
965 size_t cbWrite, size_t *pcbWritten);
966 static DECLCALLBACK(int) i_logEncryptedFlush(PCRTLOGOUTPUTIF pIf, void *pvUser);
967 /** @} */
968#endif
969
970 bool mSavedStateDataLoaded : 1;
971
972 const ComPtr<IMachine> mMachine;
973 const ComPtr<IInternalMachineControl> mControl;
974
975 const ComPtr<IVRDEServer> mVRDEServer;
976
977 ConsoleVRDPServer * const mConsoleVRDPServer;
978 bool mfVRDEChangeInProcess;
979 bool mfVRDEChangePending;
980 const ComObjPtr<Guest> mGuest;
981 const ComObjPtr<Keyboard> mKeyboard;
982 const ComObjPtr<Mouse> mMouse;
983 const ComObjPtr<Display> mDisplay;
984 const ComObjPtr<MachineDebugger> mDebugger;
985 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
986 /** This can safely be used without holding any locks.
987 * An AutoCaller suffices to prevent it being destroy while in use and
988 * internally there is a lock providing the necessary serialization. */
989 const ComObjPtr<EventSource> mEventSource;
990#ifdef VBOX_WITH_EXTPACK
991 const ComObjPtr<ExtPackManager> mptrExtPackManager;
992#endif
993 const ComObjPtr<EmulatedUSB> mEmulatedUSB;
994 const ComObjPtr<NvramStore> mptrNvramStore;
995
996 USBDeviceList mUSBDevices;
997 RemoteUSBDeviceList mRemoteUSBDevices;
998
999 SharedFolderDataMap m_mapGlobalSharedFolders;
1000 SharedFolderDataMap m_mapMachineSharedFolders;
1001 SharedFolderMap m_mapSharedFolders; // the console instances
1002
1003 /** VMM loader handle. */
1004 RTLDRMOD mhModVMM;
1005 /** The VMM vtable. */
1006 PCVMMR3VTABLE mpVMM;
1007 /** The user mode VM handle. */
1008 PUVM mpUVM;
1009 /** Holds the number of "readonly" mpUVM callers (users). */
1010 uint32_t mVMCallers;
1011 /** Semaphore posted when the number of mpUVM callers drops to zero. */
1012 RTSEMEVENT mVMZeroCallersSem;
1013 /** true when Console has entered the mpUVM destruction phase. */
1014 bool mVMDestroying : 1;
1015 /** true when power down is initiated by vmstateChangeCallback (EMT). */
1016 bool mVMPoweredOff : 1;
1017 /** true when vmstateChangeCallback shouldn't initiate a power down. */
1018 bool mVMIsAlreadyPoweringOff : 1;
1019 /** true if we already showed the snapshot folder size warning. */
1020 bool mfSnapshotFolderSizeWarningShown : 1;
1021 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
1022 bool mfSnapshotFolderExt4WarningShown : 1;
1023 /** true if we already listed the disk type of the snapshot folder. */
1024 bool mfSnapshotFolderDiskTypeShown : 1;
1025 /** true if a USB controller is available (i.e. USB devices can be attached). */
1026 bool mfVMHasUsbController : 1;
1027 /** Shadow of the VBoxInternal2/TurnResetIntoPowerOff extra data setting.
1028 * This is initialized by Console::i_configConstructorInner(). */
1029 bool mfTurnResetIntoPowerOff : 1;
1030 /** true if the VM power off was caused by reset. */
1031 bool mfPowerOffCausedByReset : 1;
1032
1033 /** Pointer to the VMM -> User (that's us) callbacks. */
1034 struct MYVMM2USERMETHODS : public VMM2USERMETHODS
1035 {
1036 Console *pConsole;
1037 /** The in-progress snapshot. */
1038 ISnapshot *pISnapshot;
1039 } *mpVmm2UserMethods;
1040
1041 /** The current network attachment type in the VM.
1042 * This doesn't have to match the network attachment type maintained in the
1043 * NetworkAdapter. This is needed to change the network attachment
1044 * dynamically.
1045 */
1046 typedef std::vector<NetworkAttachmentType_T> NetworkAttachmentTypeVector;
1047 NetworkAttachmentTypeVector meAttachmentType;
1048
1049 VMMDev * m_pVMMDev;
1050 AudioVRDE * const mAudioVRDE;
1051#ifdef VBOX_WITH_USB_CARDREADER
1052 UsbCardReader * const mUsbCardReader;
1053#endif
1054 BusAssignmentManager* mBusMgr;
1055
1056 /** @name LEDs and their management
1057 * @{ */
1058 /** Number of LED sets in use in maLedSets. */
1059 uint32_t mcLedSets;
1060 /** LED sets. */
1061 struct LEDSET
1062 {
1063 PPDMLED *papLeds;
1064 uint32_t cLeds;
1065 DeviceType_T enmType;
1066 DeviceType_T *paSubTypes; /**< Optionally, device types for each individual LED. Runs parallel to papLeds. */
1067 } maLedSets[32];
1068 /** @} */
1069
1070 MediumAttachmentMap mapMediumAttachments;
1071
1072 /** List of attached USB storage devices. */
1073 USBStorageDeviceList mUSBStorageDevices;
1074
1075 /** Store for secret keys. */
1076 SecretKeyStore * const m_pKeyStore;
1077 /** Number of disks configured for encryption. */
1078 unsigned m_cDisksEncrypted;
1079 /** Number of disks which have the key in the map. */
1080 unsigned m_cDisksPwProvided;
1081
1082 /** Current active port modes of the supported serial ports. */
1083 PortMode_T m_aeSerialPortMode[4];
1084
1085 /** Pointer to the key consumer -> provider (that's us) callbacks. */
1086 struct MYPDMISECKEY : public PDMISECKEY
1087 {
1088 Console *pConsole;
1089 } *mpIfSecKey;
1090
1091 /** Pointer to the key helpers -> provider (that's us) callbacks. */
1092 struct MYPDMISECKEYHLP : public PDMISECKEYHLP
1093 {
1094 Console *pConsole;
1095 } *mpIfSecKeyHlp;
1096
1097/* Note: FreeBSD needs this whether netflt is used or not. */
1098#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
1099 Utf8Str maTAPDeviceName[8];
1100 RTFILE maTapFD[8];
1101#endif
1102
1103 bool mVMStateChangeCallbackDisabled;
1104
1105 bool mfUseHostClipboard;
1106
1107 /** Local machine state value. */
1108 MachineState_T mMachineState;
1109
1110 /** Machine uuid string. */
1111 Bstr mstrUuid;
1112
1113 /** @name Members related to the cryptographic support interface.
1114 * @{ */
1115 /** The loaded module handle if loaded. */
1116 RTLDRMOD mhLdrModCrypto;
1117 /** Reference counter tracking how many users of the cryptographic support
1118 * are there currently. */
1119 volatile uint32_t mcRefsCrypto;
1120 /** Pointer to the cryptographic support interface. */
1121 PCVBOXCRYPTOIF mpCryptoIf;
1122 /** @} */
1123
1124#ifdef VBOX_WITH_FULL_VM_ENCRYPTION
1125 /** Flag whether the log is encrypted. */
1126 bool m_fEncryptedLog;
1127 /** The file handle of the encrypted log. */
1128 RTVFSFILE m_hVfsFileLog;
1129 /** The logging output interface for encrypted logs. */
1130 RTLOGOUTPUTIF m_LogOutputIf;
1131 /** The log file key ID. */
1132 Utf8Str m_strLogKeyId;
1133 /** The log file key store. */
1134 Utf8Str m_strLogKeyStore;
1135#endif
1136
1137#ifdef VBOX_WITH_DRAG_AND_DROP
1138 HGCMSVCEXTHANDLE m_hHgcmSvcExtDragAndDrop;
1139#endif
1140
1141 /** Pointer to the progress object of a live cancelable task.
1142 *
1143 * This is currently only used by Console::Teleport(), but is intended to later
1144 * be used by the live snapshot code path as well. Actions like
1145 * Console::PowerDown, which automatically cancels out the running snapshot /
1146 * teleportation operation, will cancel the teleportation / live snapshot
1147 * operation before starting. */
1148 ComPtr<IProgress> mptrCancelableProgress;
1149
1150 ComPtr<IEventListener> mVmListener;
1151
1152#ifdef VBOX_WITH_RECORDING
1153 struct Recording
1154 {
1155 Recording()
1156 : mpCtx(NULL)
1157# ifdef VBOX_WITH_AUDIO_RECORDING
1158 , mAudioRec(NULL)
1159# endif
1160 { }
1161
1162 /** The recording context. */
1163 RecordingContext *mpCtx;
1164# ifdef VBOX_WITH_AUDIO_RECORDING
1165 /** Pointer to capturing audio backend. */
1166 AudioVideoRec * const mAudioRec;
1167# endif
1168 } mRecording;
1169#endif /* VBOX_WITH_RECORDING */
1170
1171#ifdef VBOX_WITH_CLOUD_NET
1172 GatewayInfo mGateway;
1173#endif /* VBOX_WITH_CLOUD_NET */
1174
1175 friend class VMTask;
1176 friend class ConsoleVRDPServer;
1177};
1178
1179#endif /* !MAIN_INCLUDED_ConsoleImpl_h */
1180/* vi: set tabstop=4 shiftwidth=4 expandtab: */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette