VirtualBox

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

Last change on this file since 87093 was 86506, checked in by vboxsync, 4 years ago

Main/VBoxC: Fix Medium::parent reference leaks in Console::i_configMedium(). bugref:9841

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