VirtualBox

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

Last change on this file since 81913 was 81674, checked in by vboxsync, 5 years ago

Main: Fixes for deprecated implicit copy operators (GCC 9).

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

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