VirtualBox

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

Last change on this file since 82427 was 81964, checked in by vboxsync, 5 years ago

Main/GraphicsAdapter: Split off a few attributes from Machine interface, which affects quite a few other interfaces.
Frontends/VirtualBox+VBoxManage+VBoxSDL+VBoxShell: Adapt accordingly.

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