VirtualBox

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

Last change on this file since 93115 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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

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