VirtualBox

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

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

Main/CHECK_CONSOLE_DRV: Add function name to give more of a context.

  • 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 90187 2021-07-14 15:42:43Z 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 else return setError(E_ACCESSDENIED, tr("The console is not powered up (%Rfn)"), __FUNCTION__); \
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 static DECLCALLBACK(int) i_configConstructor(PUVM pUVM, PVM pVM, void *pvConsole);
676 void i_configAudioDriver(IVirtualBox *pVirtualBox, IMachine *pMachine, PCFGMNODE pLUN, const char *pszDriverName,
677 bool fAudioEnabledIn, bool fAudioEnabledOut);
678 int i_configConstructorInner(PUVM pUVM, PVM pVM, AutoWriteLock *pAlock);
679 int i_configCfgmOverlay(PCFGMNODE pRoot, IVirtualBox *pVirtualBox, IMachine *pMachine);
680 int i_configDumpAPISettingsTweaks(IVirtualBox *pVirtualBox, IMachine *pMachine);
681
682 int i_configGraphicsController(PCFGMNODE pDevices,
683 const GraphicsControllerType_T graphicsController,
684 BusAssignmentManager *pBusMgr,
685 const ComPtr<IMachine> &ptrMachine,
686 const ComPtr<IGraphicsAdapter> &ptrGraphicsAdapter,
687 const ComPtr<IBIOSSettings> &ptrBiosSettings,
688 bool fHMEnabled);
689 int i_checkMediumLocation(IMedium *pMedium, bool *pfUseHostIOCache);
690 int i_unmountMediumFromGuest(PUVM pUVM, StorageBus_T enmBus, DeviceType_T enmDevType,
691 const char *pcszDevice, unsigned uInstance, unsigned uLUN,
692 bool fForceUnmount);
693 int i_removeMediumDriverFromVm(PCFGMNODE pCtlInst,
694 const char *pcszDevice,
695 unsigned uInstance,
696 unsigned uLUN,
697 StorageBus_T enmBus,
698 bool fAttachDetach,
699 bool fHotplug,
700 bool fForceUnmount,
701 PUVM pUVM,
702 DeviceType_T enmDevType,
703 PCFGMNODE *ppLunL0);
704 int i_configMediumAttachment(const char *pcszDevice,
705 unsigned uInstance,
706 StorageBus_T enmBus,
707 bool fUseHostIOCache,
708 bool fBuiltinIoCache,
709 bool fInsertDiskIntegrityDrv,
710 bool fSetupMerge,
711 unsigned uMergeSource,
712 unsigned uMergeTarget,
713 IMediumAttachment *pMediumAtt,
714 MachineState_T aMachineState,
715 HRESULT *phrc,
716 bool fAttachDetach,
717 bool fForceUnmount,
718 bool fHotplug,
719 PUVM pUVM,
720 DeviceType_T *paLedDevType,
721 PCFGMNODE *ppLunL0);
722 int i_configMedium(PCFGMNODE pLunL0,
723 bool fPassthrough,
724 DeviceType_T enmType,
725 bool fUseHostIOCache,
726 bool fBuiltinIoCache,
727 bool fInsertDiskIntegrityDrv,
728 bool fSetupMerge,
729 unsigned uMergeSource,
730 unsigned uMergeTarget,
731 const char *pcszBwGroup,
732 bool fDiscard,
733 bool fNonRotational,
734 ComPtr<IMedium> ptrMedium,
735 MachineState_T aMachineState,
736 HRESULT *phrc);
737 int i_configMediumProperties(PCFGMNODE pCur, IMedium *pMedium, bool *pfHostIP, bool *pfEncrypted);
738 static DECLCALLBACK(int) i_reconfigureMediumAttachment(Console *pThis,
739 PUVM pUVM,
740 const char *pcszDevice,
741 unsigned uInstance,
742 StorageBus_T enmBus,
743 bool fUseHostIOCache,
744 bool fBuiltinIoCache,
745 bool fInsertDiskIntegrityDrv,
746 bool fSetupMerge,
747 unsigned uMergeSource,
748 unsigned uMergeTarget,
749 IMediumAttachment *aMediumAtt,
750 MachineState_T aMachineState,
751 HRESULT *phrc);
752 static DECLCALLBACK(int) i_changeRemovableMedium(Console *pThis,
753 PUVM pUVM,
754 const char *pcszDevice,
755 unsigned uInstance,
756 StorageBus_T enmBus,
757 bool fUseHostIOCache,
758 IMediumAttachment *aMediumAtt,
759 bool fForce);
760
761 HRESULT i_attachRawPCIDevices(PUVM pUVM, BusAssignmentManager *BusMgr, PCFGMNODE pDevices);
762 struct LEDSET;
763 typedef struct LEDSET *PLEDSET;
764 PLEDSET i_allocateDriverLeds(uint32_t cLeds, DeviceType_T enmType, DeviceType_T **ppSubTypes);
765 void i_attachStatusDriver(PCFGMNODE pCtlInst, DeviceType_T enmType,
766 uint32_t uFirst, uint32_t uLast,
767 DeviceType_T **ppaSubTypes,
768 Console::MediumAttachmentMap *pmapMediumAttachments,
769 const char *pcszDevice, unsigned uInstance);
770
771 int i_configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun,
772 INetworkAdapter *aNetworkAdapter, PCFGMNODE pCfg,
773 PCFGMNODE pLunL0, PCFGMNODE pInst,
774 bool fAttachDetach, bool fIgnoreConnectFailure);
775 int i_configSerialPort(PCFGMNODE pInst, PortMode_T ePortMode, const char *pszPath, bool fServer);
776 static DECLCALLBACK(void) i_vmstateChangeCallback(PUVM pUVM, VMSTATE enmState, VMSTATE enmOldState, void *pvUser);
777 static DECLCALLBACK(int) i_unplugCpu(Console *pThis, PUVM pUVM, VMCPUID idCpu);
778 static DECLCALLBACK(int) i_plugCpu(Console *pThis, PUVM pUVM, VMCPUID idCpu);
779 HRESULT i_doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PUVM pUVM);
780 HRESULT i_doCPURemove(ULONG aCpu, PUVM pUVM);
781 HRESULT i_doCPUAdd(ULONG aCpu, PUVM pUVM);
782
783 HRESULT i_doNetworkAdapterChange(PUVM pUVM, const char *pszDevice, unsigned uInstance,
784 unsigned uLun, INetworkAdapter *aNetworkAdapter);
785 static DECLCALLBACK(int) i_changeNetworkAttachment(Console *pThis, PUVM pUVM, const char *pszDevice,
786 unsigned uInstance, unsigned uLun,
787 INetworkAdapter *aNetworkAdapter);
788 static DECLCALLBACK(int) i_changeSerialPortAttachment(Console *pThis, PUVM pUVM,
789 ISerialPort *pSerialPort);
790
791 int i_changeClipboardMode(ClipboardMode_T aClipboardMode);
792 int i_changeClipboardFileTransferMode(bool aEnabled);
793 int i_changeDnDMode(DnDMode_T aDnDMode);
794
795#ifdef VBOX_WITH_USB
796 HRESULT i_attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs, const Utf8Str &aCaptureFilename);
797 HRESULT i_detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice);
798
799 static DECLCALLBACK(int) i_usbAttachCallback(Console *that, PUVM pUVM, IUSBDevice *aHostDevice, PCRTUUID aUuid,
800 const char *aBackend, const char *aAddress, void *pvRemoteBackend,
801 USBConnectionSpeed_T enmSpeed, ULONG aMaskedIfs,
802 const char *pszCaptureFilename);
803 static DECLCALLBACK(int) i_usbDetachCallback(Console *that, PUVM pUVM, PCRTUUID aUuid);
804#endif
805
806 static DECLCALLBACK(int) i_attachStorageDevice(Console *pThis,
807 PUVM pUVM,
808 const char *pcszDevice,
809 unsigned uInstance,
810 StorageBus_T enmBus,
811 bool fUseHostIOCache,
812 IMediumAttachment *aMediumAtt,
813 bool fSilent);
814 static DECLCALLBACK(int) i_detachStorageDevice(Console *pThis,
815 PUVM pUVM,
816 const char *pcszDevice,
817 unsigned uInstance,
818 StorageBus_T enmBus,
819 IMediumAttachment *aMediumAtt,
820 bool fSilent);
821 HRESULT i_doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PUVM pUVM, bool fSilent);
822 HRESULT i_doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PUVM pUVM, bool fSilent);
823
824 static DECLCALLBACK(int) i_stateProgressCallback(PUVM pUVM, unsigned uPercent, void *pvUser);
825
826 static DECLCALLBACK(void) i_genericVMSetErrorCallback(PUVM pUVM, void *pvUser, int rc, RT_SRC_POS_DECL,
827 const char *pszErrorFmt, va_list va);
828
829 void i_atVMRuntimeErrorCallbackF(uint32_t fFatal, const char *pszErrorId, const char *pszFormat, ...);
830 static DECLCALLBACK(void) i_atVMRuntimeErrorCallback(PUVM pUVM, void *pvUser, uint32_t fFatal,
831 const char *pszErrorId, const char *pszFormat, va_list va);
832
833 HRESULT i_captureUSBDevices(PUVM pUVM);
834 void i_detachAllUSBDevices(bool aDone);
835
836
837 static DECLCALLBACK(int) i_vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
838 static DECLCALLBACK(void) i_vmm2User_NotifyEmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
839 static DECLCALLBACK(void) i_vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
840 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM);
841 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM);
842 static DECLCALLBACK(void) i_vmm2User_NotifyResetTurnedIntoPowerOff(PCVMM2USERMETHODS pThis, PUVM pUVM);
843 static DECLCALLBACK(void *) i_vmm2User_QueryGenericObject(PCVMM2USERMETHODS pThis, PUVM pUVM, PCRTUUID pUuid);
844
845 static DECLCALLBACK(void *) i_drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
846 static DECLCALLBACK(void) i_drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
847 static DECLCALLBACK(int) i_drvStatus_MediumEjected(PPDMIMEDIANOTIFY pInterface, unsigned iLUN);
848 static DECLCALLBACK(void) i_drvStatus_Destruct(PPDMDRVINS pDrvIns);
849 static DECLCALLBACK(int) i_drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
850
851 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRetain(PPDMISECKEY pInterface, const char *pszId, const uint8_t **ppbKey,
852 size_t *pcbKey);
853 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRelease(PPDMISECKEY pInterface, const char *pszId);
854 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRetain(PPDMISECKEY pInterface, const char *pszId, const char **ppszPassword);
855 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRelease(PPDMISECKEY pInterface, const char *pszId);
856
857 static DECLCALLBACK(int) i_pdmIfSecKeyHlp_KeyMissingNotify(PPDMISECKEYHLP pInterface);
858
859 int mcAudioRefs;
860 volatile uint32_t mcVRDPClients;
861 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
862 volatile bool mcGuestCredentialsProvided;
863
864 static const char *sSSMConsoleUnit;
865
866 HRESULT i_loadDataFromSavedState();
867 int i_loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
868
869 static DECLCALLBACK(void) i_saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
870 static DECLCALLBACK(int) i_loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
871
872#ifdef VBOX_WITH_GUEST_PROPS
873 HRESULT i_doEnumerateGuestProperties(const Utf8Str &aPatterns,
874 std::vector<Utf8Str> &aNames,
875 std::vector<Utf8Str> &aValues,
876 std::vector<LONG64> &aTimestamps,
877 std::vector<Utf8Str> &aFlags);
878
879 void i_guestPropertiesHandleVMReset(void);
880 bool i_guestPropertiesVRDPEnabled(void);
881 void i_guestPropertiesVRDPUpdateLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
882 void i_guestPropertiesVRDPUpdateActiveClient(uint32_t u32ClientId);
883 void i_guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached);
884 void i_guestPropertiesVRDPUpdateNameChange(uint32_t u32ClientId, const char *pszName);
885 void i_guestPropertiesVRDPUpdateIPAddrChange(uint32_t u32ClientId, const char *pszIPAddr);
886 void i_guestPropertiesVRDPUpdateLocationChange(uint32_t u32ClientId, const char *pszLocation);
887 void i_guestPropertiesVRDPUpdateOtherInfoChange(uint32_t u32ClientId, const char *pszOtherInfo);
888 void i_guestPropertiesVRDPUpdateDisconnect(uint32_t u32ClientId);
889#endif
890
891 /** @name Disk encryption support
892 * @{ */
893 HRESULT i_consoleParseDiskEncryption(const char *psz, const char **ppszEnd);
894 HRESULT i_configureEncryptionForDisk(const Utf8Str &strId, unsigned *pcDisksConfigured);
895 HRESULT i_clearDiskEncryptionKeysOnAllAttachmentsWithKeyId(const Utf8Str &strId);
896 HRESULT i_initSecretKeyIfOnAllAttachments(void);
897 int i_consoleParseKeyValue(const char *psz, const char **ppszEnd,
898 char **ppszKey, char **ppszVal);
899 void i_removeSecretKeysOnSuspend();
900 /** @} */
901
902 /** @name Teleporter support
903 * @{ */
904 static DECLCALLBACK(int) i_teleporterSrcThreadWrapper(RTTHREAD hThreadSelf, void *pvUser);
905 HRESULT i_teleporterSrc(TeleporterStateSrc *pState);
906 HRESULT i_teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
907 HRESULT i_teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
908 HRESULT i_teleporterTrg(PUVM pUVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
909 Progress *pProgress, bool *pfPowerOffOnFailure);
910 static DECLCALLBACK(int) i_teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
911 /** @} */
912
913 bool mSavedStateDataLoaded : 1;
914
915 const ComPtr<IMachine> mMachine;
916 const ComPtr<IInternalMachineControl> mControl;
917
918 const ComPtr<IVRDEServer> mVRDEServer;
919
920 ConsoleVRDPServer * const mConsoleVRDPServer;
921 bool mfVRDEChangeInProcess;
922 bool mfVRDEChangePending;
923 const ComObjPtr<Guest> mGuest;
924 const ComObjPtr<Keyboard> mKeyboard;
925 const ComObjPtr<Mouse> mMouse;
926 const ComObjPtr<Display> mDisplay;
927 const ComObjPtr<MachineDebugger> mDebugger;
928 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
929 /** This can safely be used without holding any locks.
930 * An AutoCaller suffices to prevent it being destroy while in use and
931 * internally there is a lock providing the necessary serialization. */
932 const ComObjPtr<EventSource> mEventSource;
933#ifdef VBOX_WITH_EXTPACK
934 const ComObjPtr<ExtPackManager> mptrExtPackManager;
935#endif
936 const ComObjPtr<EmulatedUSB> mEmulatedUSB;
937
938 USBDeviceList mUSBDevices;
939 RemoteUSBDeviceList mRemoteUSBDevices;
940
941 SharedFolderDataMap m_mapGlobalSharedFolders;
942 SharedFolderDataMap m_mapMachineSharedFolders;
943 SharedFolderMap m_mapSharedFolders; // the console instances
944
945 /** The user mode VM handle. */
946 PUVM mpUVM;
947 /** Holds the number of "readonly" mpUVM callers (users). */
948 uint32_t mVMCallers;
949 /** Semaphore posted when the number of mpUVM callers drops to zero. */
950 RTSEMEVENT mVMZeroCallersSem;
951 /** true when Console has entered the mpUVM destruction phase. */
952 bool mVMDestroying : 1;
953 /** true when power down is initiated by vmstateChangeCallback (EMT). */
954 bool mVMPoweredOff : 1;
955 /** true when vmstateChangeCallback shouldn't initiate a power down. */
956 bool mVMIsAlreadyPoweringOff : 1;
957 /** true if we already showed the snapshot folder size warning. */
958 bool mfSnapshotFolderSizeWarningShown : 1;
959 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
960 bool mfSnapshotFolderExt4WarningShown : 1;
961 /** true if we already listed the disk type of the snapshot folder. */
962 bool mfSnapshotFolderDiskTypeShown : 1;
963 /** true if a USB controller is available (i.e. USB devices can be attached). */
964 bool mfVMHasUsbController : 1;
965 /** Shadow of the VBoxInternal2/TurnResetIntoPowerOff extra data setting.
966 * This is initialized by Console::i_configConstructorInner(). */
967 bool mfTurnResetIntoPowerOff : 1;
968 /** true if the VM power off was caused by reset. */
969 bool mfPowerOffCausedByReset : 1;
970
971 /** Pointer to the VMM -> User (that's us) callbacks. */
972 struct MYVMM2USERMETHODS : public VMM2USERMETHODS
973 {
974 Console *pConsole;
975 /** The in-progress snapshot. */
976 ISnapshot *pISnapshot;
977 } *mpVmm2UserMethods;
978
979 /** The current network attachment type in the VM.
980 * This doesn't have to match the network attachment type maintained in the
981 * NetworkAdapter. This is needed to change the network attachment
982 * dynamically.
983 */
984 typedef std::vector<NetworkAttachmentType_T> NetworkAttachmentTypeVector;
985 NetworkAttachmentTypeVector meAttachmentType;
986
987 VMMDev * m_pVMMDev;
988 AudioVRDE * const mAudioVRDE;
989#ifdef VBOX_WITH_USB_CARDREADER
990 UsbCardReader * const mUsbCardReader;
991#endif
992 BusAssignmentManager* mBusMgr;
993
994 /** @name LEDs and their management
995 * @{ */
996 /** Number of LED sets in use in maLedSets. */
997 uint32_t mcLedSets;
998 /** LED sets. */
999 struct LEDSET
1000 {
1001 PPDMLED *papLeds;
1002 uint32_t cLeds;
1003 DeviceType_T enmType;
1004 DeviceType_T *paSubTypes; /**< Optionally, device types for each individual LED. Runs parallel to papLeds. */
1005 } maLedSets[32];
1006 /** @} */
1007
1008 MediumAttachmentMap mapMediumAttachments;
1009
1010 /** List of attached USB storage devices. */
1011 USBStorageDeviceList mUSBStorageDevices;
1012
1013 /** Store for secret keys. */
1014 SecretKeyStore * const m_pKeyStore;
1015 /** Number of disks configured for encryption. */
1016 unsigned m_cDisksEncrypted;
1017 /** Number of disks which have the key in the map. */
1018 unsigned m_cDisksPwProvided;
1019
1020 /** Current active port modes of the supported serial ports. */
1021 PortMode_T m_aeSerialPortMode[4];
1022
1023 /** Pointer to the key consumer -> provider (that's us) callbacks. */
1024 struct MYPDMISECKEY : public PDMISECKEY
1025 {
1026 Console *pConsole;
1027 } *mpIfSecKey;
1028
1029 /** Pointer to the key helpers -> provider (that's us) callbacks. */
1030 struct MYPDMISECKEYHLP : public PDMISECKEYHLP
1031 {
1032 Console *pConsole;
1033 } *mpIfSecKeyHlp;
1034
1035/* Note: FreeBSD needs this whether netflt is used or not. */
1036#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
1037 Utf8Str maTAPDeviceName[8];
1038 RTFILE maTapFD[8];
1039#endif
1040
1041 bool mVMStateChangeCallbackDisabled;
1042
1043 bool mfUseHostClipboard;
1044
1045 /** Local machine state value. */
1046 MachineState_T mMachineState;
1047
1048 /** Machine uuid string. */
1049 Bstr mstrUuid;
1050
1051#ifdef VBOX_WITH_DRAG_AND_DROP
1052 HGCMSVCEXTHANDLE m_hHgcmSvcExtDragAndDrop;
1053#endif
1054
1055 /** Pointer to the progress object of a live cancelable task.
1056 *
1057 * This is currently only used by Console::Teleport(), but is intended to later
1058 * be used by the live snapshot code path as well. Actions like
1059 * Console::PowerDown, which automatically cancels out the running snapshot /
1060 * teleportation operation, will cancel the teleportation / live snapshot
1061 * operation before starting. */
1062 ComPtr<IProgress> mptrCancelableProgress;
1063
1064 ComPtr<IEventListener> mVmListener;
1065
1066#ifdef VBOX_WITH_RECORDING
1067 struct Recording
1068 {
1069 Recording()
1070 : mpCtx(NULL)
1071# ifdef VBOX_WITH_AUDIO_RECORDING
1072 , mAudioRec(NULL)
1073# endif
1074 { }
1075
1076 /** The recording context. */
1077 RecordingContext *mpCtx;
1078# ifdef VBOX_WITH_AUDIO_RECORDING
1079 /** Pointer to capturing audio backend. */
1080 AudioVideoRec * const mAudioRec;
1081# endif
1082 } Recording;
1083#endif /* VBOX_WITH_RECORDING */
1084
1085#ifdef VBOX_WITH_CLOUD_NET
1086 GatewayInfo mGateways;
1087#endif /* VBOX_WITH_CLOUD_NET */
1088
1089 friend class VMTask;
1090 friend class ConsoleVRDPServer;
1091};
1092
1093#endif /* !MAIN_INCLUDED_ConsoleImpl_h */
1094/* 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