VirtualBox

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

Last change on this file since 79812 was 78916, checked in by vboxsync, 6 years ago

Main/src-client,Main/include: Unregister HGCM service extensions on shutdown instead of leaking the handle [build fix]

  • 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 78916 2019-06-01 17:43:28Z 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
48class Nvram;
49#ifdef VBOX_WITH_USB_CARDREADER
50class UsbCardReader;
51#endif
52class ConsoleVRDPServer;
53class VMMDev;
54class Progress;
55class BusAssignmentManager;
56COM_STRUCT_OR_CLASS(IEventListener);
57#ifdef VBOX_WITH_EXTPACK
58class ExtPackManager;
59#endif
60class VMMDevMouseInterface;
61class DisplayMouseInterface;
62class VMPowerUpTask;
63class VMPowerDownTask;
64
65#include <iprt/uuid.h>
66#include <iprt/memsafer.h>
67#include <VBox/RemoteDesktop/VRDE.h>
68#include <VBox/vmm/pdmdrv.h>
69#ifdef VBOX_WITH_GUEST_PROPS
70# include <VBox/HostServices/GuestPropertySvc.h> /* For the property notification callback */
71#endif
72
73#if defined(VBOX_WITH_GUEST_PROPS) || defined(VBOX_WITH_SHARED_CLIPBOARD) \
74 || defined(VBOX_WITH_DRAG_AND_DROP)
75# include "HGCM.h" /** @todo It should be possible to register a service
76 * extension using a VMMDev callback. */
77#endif
78
79struct VUSBIRHCONFIG;
80typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
81
82#include <list>
83#include <vector>
84
85// defines
86///////////////////////////////////////////////////////////////////////////////
87
88/**
89 * Checks the availability of the underlying VM device driver corresponding
90 * to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
91 * not available (NULL), sets error info and returns returns E_ACCESSDENIED.
92 * The translatable error message is defined in null context.
93 *
94 * Intended to used only within Console children (i.e. Keyboard, Mouse,
95 * Display, etc.).
96 *
97 * @param drv driver pointer to check (compare it with NULL)
98 */
99#define CHECK_CONSOLE_DRV(drv) \
100 do { \
101 if (!(drv)) \
102 return setError(E_ACCESSDENIED, tr("The console is not powered up")); \
103 } while (0)
104
105// Console
106///////////////////////////////////////////////////////////////////////////////
107
108class ConsoleMouseInterface
109{
110public:
111 virtual VMMDevMouseInterface *i_getVMMDevMouseInterface(){return NULL;}
112 virtual DisplayMouseInterface *i_getDisplayMouseInterface(){return NULL;}
113 virtual void i_onMouseCapabilityChange(BOOL supportsAbsolute,
114 BOOL supportsRelative,
115 BOOL supportsMT,
116 BOOL needsHostCursor){NOREF(supportsAbsolute); NOREF(supportsRelative); NOREF(supportsMT); NOREF(needsHostCursor);}
117};
118
119/** IConsole implementation class */
120class ATL_NO_VTABLE Console :
121 public ConsoleWrap,
122 public ConsoleMouseInterface
123{
124
125public:
126
127 DECLARE_EMPTY_CTOR_DTOR(Console)
128
129 HRESULT FinalConstruct();
130 void FinalRelease();
131
132 // public initializers/uninitializers for internal purposes only
133 HRESULT init(IMachine *aMachine, IInternalMachineControl *aControl, LockType_T aLockType);
134 void uninit();
135
136
137 // public methods for internal purposes only
138
139 /*
140 * Note: the following methods do not increase refcount. intended to be
141 * called only by the VM execution thread.
142 */
143
144 Guest *i_getGuest() const { return mGuest; }
145 Keyboard *i_getKeyboard() const { return mKeyboard; }
146 Mouse *i_getMouse() const { return mMouse; }
147 Display *i_getDisplay() const { return mDisplay; }
148 MachineDebugger *i_getMachineDebugger() const { return mDebugger; }
149#ifdef VBOX_WITH_AUDIO_VRDE
150 AudioVRDE *i_getAudioVRDE() const { return mAudioVRDE; }
151#endif
152#ifdef VBOX_WITH_RECORDING
153 int i_recordingCreate(void);
154 void i_recordingDestroy(void);
155 int i_recordingEnable(BOOL fEnable, util::AutoWriteLock *pAutoLock);
156 int i_recordingGetSettings(settings::RecordingSettings &Settings);
157 int i_recordingStart(util::AutoWriteLock *pAutoLock = NULL);
158 int i_recordingStop(util::AutoWriteLock *pAutoLock = NULL);
159# ifdef VBOX_WITH_AUDIO_RECORDING
160 AudioVideoRec *i_recordingGetAudioDrv(void) const { return Recording.mAudioRec; }
161# endif
162 RecordingContext *i_recordingGetContext(void) const { return Recording.mpCtx; }
163# ifdef VBOX_WITH_AUDIO_RECORDING
164 HRESULT i_recordingSendAudio(const void *pvData, size_t cbData, uint64_t uDurationMs);
165# endif
166#endif
167
168 const ComPtr<IMachine> &i_machine() const { return mMachine; }
169 const Bstr &i_getId() const { return mstrUuid; }
170
171 bool i_useHostClipboard() { return mfUseHostClipboard; }
172
173 /** Method is called only from ConsoleVRDPServer */
174 IVRDEServer *i_getVRDEServer() const { return mVRDEServer; }
175
176 ConsoleVRDPServer *i_consoleVRDPServer() const { return mConsoleVRDPServer; }
177
178 HRESULT i_updateMachineState(MachineState_T aMachineState);
179 HRESULT i_getNominalState(MachineState_T &aNominalState);
180 Utf8Str i_getAudioAdapterDeviceName(IAudioAdapter *aAudioAdapter);
181
182 // events from IInternalSessionControl
183 HRESULT i_onNetworkAdapterChange(INetworkAdapter *aNetworkAdapter, BOOL changeAdapter);
184 HRESULT i_onAudioAdapterChange(IAudioAdapter *aAudioAdapter);
185 HRESULT i_onSerialPortChange(ISerialPort *aSerialPort);
186 HRESULT i_onParallelPortChange(IParallelPort *aParallelPort);
187 HRESULT i_onStorageControllerChange(const com::Guid& aMachineId, const com::Utf8Str& aControllerName);
188 HRESULT i_onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
189 HRESULT i_onCPUChange(ULONG aCPU, BOOL aRemove);
190 HRESULT i_onCPUExecutionCapChange(ULONG aExecutionCap);
191 HRESULT i_onClipboardModeChange(ClipboardMode_T aClipboardMode);
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 Utf8Str m_strHostPath;
591 bool m_fWritable;
592 bool m_fAutoMount;
593 Utf8Str m_strAutoMountPoint;
594 };
595
596 /**
597 * Class for managing emulated USB MSDs.
598 */
599 class USBStorageDevice
600 {
601 public:
602 USBStorageDevice()
603 { }
604 /** The UUID associated with the USB device. */
605 RTUUID mUuid;
606 /** Port of the storage device. */
607 LONG iPort;
608 };
609
610 typedef std::map<Utf8Str, ComObjPtr<SharedFolder> > SharedFolderMap;
611 typedef std::map<Utf8Str, SharedFolderData> SharedFolderDataMap;
612 typedef std::map<Utf8Str, ComPtr<IMediumAttachment> > MediumAttachmentMap;
613 typedef std::list <USBStorageDevice> USBStorageDeviceList;
614
615 static void i_powerUpThreadTask(VMPowerUpTask *pTask);
616 static void i_powerDownThreadTask(VMPowerDownTask *pTask);
617
618private:
619
620 typedef std::list <ComObjPtr<OUSBDevice> > USBDeviceList;
621 typedef std::list <ComObjPtr<RemoteUSBDevice> > RemoteUSBDeviceList;
622
623 HRESULT i_addVMCaller(bool aQuiet = false, bool aAllowNullVM = false);
624 void i_releaseVMCaller();
625 HRESULT i_safeVMPtrRetainer(PUVM *a_ppUVM, bool aQuiet);
626 void i_safeVMPtrReleaser(PUVM *a_ppUVM);
627
628 HRESULT i_consoleInitReleaseLog(const ComPtr<IMachine> aMachine);
629
630 HRESULT i_powerUp(IProgress **aProgress, bool aPaused);
631 HRESULT i_powerDown(IProgress *aProgress = NULL);
632
633/* Note: FreeBSD needs this whether netflt is used or not. */
634#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
635 HRESULT i_attachToTapInterface(INetworkAdapter *networkAdapter);
636 HRESULT i_detachFromTapInterface(INetworkAdapter *networkAdapter);
637#endif
638 HRESULT i_powerDownHostInterfaces();
639
640 HRESULT i_setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
641 HRESULT i_setMachineStateLocally(MachineState_T aMachineState)
642 {
643 return i_setMachineState(aMachineState, false /* aUpdateServer */);
644 }
645
646 HRESULT i_findSharedFolder(const Utf8Str &strName,
647 ComObjPtr<SharedFolder> &aSharedFolder,
648 bool aSetError = false);
649
650 HRESULT i_fetchSharedFolders(BOOL aGlobal);
651 bool i_findOtherSharedFolder(const Utf8Str &straName,
652 SharedFolderDataMap::const_iterator &aIt);
653
654 HRESULT i_createSharedFolder(const Utf8Str &strName, const SharedFolderData &aData);
655 HRESULT i_removeSharedFolder(const Utf8Str &strName);
656
657 HRESULT i_suspendBeforeConfigChange(PUVM pUVM, AutoWriteLock *pAlock, bool *pfResume);
658 void i_resumeAfterConfigChange(PUVM pUVM);
659
660 uint32_t i_getAudioDriverValU32(IVirtualBox *pVirtualBox, IMachine *pMachine,
661 const char *pszDriverName, const char *pszValue, uint32_t uDefault);
662
663 static DECLCALLBACK(int) i_configConstructor(PUVM pUVM, PVM pVM, void *pvConsole);
664 int i_configAudioDriver(IAudioAdapter *pAudioAdapter, IVirtualBox *pVirtualBox, IMachine *pMachine,
665 PCFGMNODE pLUN, const char *pszDriverName);
666 int i_configConstructorInner(PUVM pUVM, PVM pVM, AutoWriteLock *pAlock);
667 int i_configCfgmOverlay(PCFGMNODE pRoot, IVirtualBox *pVirtualBox, IMachine *pMachine);
668 int i_configDumpAPISettingsTweaks(IVirtualBox *pVirtualBox, IMachine *pMachine);
669
670 int i_configGraphicsController(PCFGMNODE pDevices,
671 const GraphicsControllerType_T graphicsController,
672 BusAssignmentManager *pBusMgr,
673 const ComPtr<IMachine> &ptrMachine,
674 const ComPtr<IBIOSSettings> &ptrBiosSettings,
675 bool fHMEnabled);
676 int i_checkMediumLocation(IMedium *pMedium, bool *pfUseHostIOCache);
677 int i_unmountMediumFromGuest(PUVM pUVM, StorageBus_T enmBus, DeviceType_T enmDevType,
678 const char *pcszDevice, unsigned uInstance, unsigned uLUN,
679 bool fForceUnmount);
680 int i_removeMediumDriverFromVm(PCFGMNODE pCtlInst,
681 const char *pcszDevice,
682 unsigned uInstance,
683 unsigned uLUN,
684 StorageBus_T enmBus,
685 bool fAttachDetach,
686 bool fHotplug,
687 bool fForceUnmount,
688 PUVM pUVM,
689 DeviceType_T enmDevType,
690 PCFGMNODE *ppLunL0);
691 int i_configMediumAttachment(const char *pcszDevice,
692 unsigned uInstance,
693 StorageBus_T enmBus,
694 bool fUseHostIOCache,
695 bool fBuiltinIoCache,
696 bool fInsertDiskIntegrityDrv,
697 bool fSetupMerge,
698 unsigned uMergeSource,
699 unsigned uMergeTarget,
700 IMediumAttachment *pMediumAtt,
701 MachineState_T aMachineState,
702 HRESULT *phrc,
703 bool fAttachDetach,
704 bool fForceUnmount,
705 bool fHotplug,
706 PUVM pUVM,
707 DeviceType_T *paLedDevType,
708 PCFGMNODE *ppLunL0);
709 int i_configMedium(PCFGMNODE pLunL0,
710 bool fPassthrough,
711 DeviceType_T enmType,
712 bool fUseHostIOCache,
713 bool fBuiltinIoCache,
714 bool fInsertDiskIntegrityDrv,
715 bool fSetupMerge,
716 unsigned uMergeSource,
717 unsigned uMergeTarget,
718 const char *pcszBwGroup,
719 bool fDiscard,
720 bool fNonRotational,
721 IMedium *pMedium,
722 MachineState_T aMachineState,
723 HRESULT *phrc);
724 int i_configMediumProperties(PCFGMNODE pCur, IMedium *pMedium, bool *pfHostIP, bool *pfEncrypted);
725 static DECLCALLBACK(int) i_reconfigureMediumAttachment(Console *pThis,
726 PUVM pUVM,
727 const char *pcszDevice,
728 unsigned uInstance,
729 StorageBus_T enmBus,
730 bool fUseHostIOCache,
731 bool fBuiltinIoCache,
732 bool fInsertDiskIntegrityDrv,
733 bool fSetupMerge,
734 unsigned uMergeSource,
735 unsigned uMergeTarget,
736 IMediumAttachment *aMediumAtt,
737 MachineState_T aMachineState,
738 HRESULT *phrc);
739 static DECLCALLBACK(int) i_changeRemovableMedium(Console *pThis,
740 PUVM pUVM,
741 const char *pcszDevice,
742 unsigned uInstance,
743 StorageBus_T enmBus,
744 bool fUseHostIOCache,
745 IMediumAttachment *aMediumAtt,
746 bool fForce);
747
748 HRESULT i_attachRawPCIDevices(PUVM pUVM, BusAssignmentManager *BusMgr, PCFGMNODE pDevices);
749 void i_attachStatusDriver(PCFGMNODE pCtlInst, PPDMLED *papLeds,
750 uint64_t uFirst, uint64_t uLast,
751 Console::MediumAttachmentMap *pmapMediumAttachments,
752 const char *pcszDevice, unsigned uInstance);
753
754 int i_configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun,
755 INetworkAdapter *aNetworkAdapter, PCFGMNODE pCfg,
756 PCFGMNODE pLunL0, PCFGMNODE pInst,
757 bool fAttachDetach, bool fIgnoreConnectFailure);
758 int i_configSerialPort(PCFGMNODE pInst, PortMode_T ePortMode, const char *pszPath, bool fServer);
759 static DECLCALLBACK(void) i_vmstateChangeCallback(PUVM pUVM, VMSTATE enmState, VMSTATE enmOldState, void *pvUser);
760 static DECLCALLBACK(int) i_unplugCpu(Console *pThis, PUVM pUVM, VMCPUID idCpu);
761 static DECLCALLBACK(int) i_plugCpu(Console *pThis, PUVM pUVM, VMCPUID idCpu);
762 HRESULT i_doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PUVM pUVM);
763 HRESULT i_doCPURemove(ULONG aCpu, PUVM pUVM);
764 HRESULT i_doCPUAdd(ULONG aCpu, PUVM pUVM);
765
766 HRESULT i_doNetworkAdapterChange(PUVM pUVM, const char *pszDevice, unsigned uInstance,
767 unsigned uLun, INetworkAdapter *aNetworkAdapter);
768 static DECLCALLBACK(int) i_changeNetworkAttachment(Console *pThis, PUVM pUVM, const char *pszDevice,
769 unsigned uInstance, unsigned uLun,
770 INetworkAdapter *aNetworkAdapter);
771 static DECLCALLBACK(int) i_changeSerialPortAttachment(Console *pThis, PUVM pUVM,
772 ISerialPort *pSerialPort);
773
774 int i_changeClipboardMode(ClipboardMode_T aClipboardMode);
775 int i_changeDnDMode(DnDMode_T aDnDMode);
776
777#ifdef VBOX_WITH_USB
778 HRESULT i_attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs, const Utf8Str &aCaptureFilename);
779 HRESULT i_detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice);
780
781 static DECLCALLBACK(int) i_usbAttachCallback(Console *that, PUVM pUVM, IUSBDevice *aHostDevice, PCRTUUID aUuid,
782 const char *aBackend, const char *aAddress, void *pvRemoteBackend,
783 USBConnectionSpeed_T enmSpeed, ULONG aMaskedIfs,
784 const char *pszCaptureFilename);
785 static DECLCALLBACK(int) i_usbDetachCallback(Console *that, PUVM pUVM, PCRTUUID aUuid);
786#endif
787
788 static DECLCALLBACK(int) i_attachStorageDevice(Console *pThis,
789 PUVM pUVM,
790 const char *pcszDevice,
791 unsigned uInstance,
792 StorageBus_T enmBus,
793 bool fUseHostIOCache,
794 IMediumAttachment *aMediumAtt,
795 bool fSilent);
796 static DECLCALLBACK(int) i_detachStorageDevice(Console *pThis,
797 PUVM pUVM,
798 const char *pcszDevice,
799 unsigned uInstance,
800 StorageBus_T enmBus,
801 IMediumAttachment *aMediumAtt,
802 bool fSilent);
803 HRESULT i_doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PUVM pUVM, bool fSilent);
804 HRESULT i_doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PUVM pUVM, bool fSilent);
805
806 static DECLCALLBACK(int) i_stateProgressCallback(PUVM pUVM, unsigned uPercent, void *pvUser);
807
808 static DECLCALLBACK(void) i_genericVMSetErrorCallback(PUVM pUVM, void *pvUser, int rc, RT_SRC_POS_DECL,
809 const char *pszErrorFmt, va_list va);
810
811 void i_atVMRuntimeErrorCallbackF(uint32_t fFatal, const char *pszErrorId, const char *pszFormat, ...);
812 static DECLCALLBACK(void) i_atVMRuntimeErrorCallback(PUVM pUVM, void *pvUser, uint32_t fFatal,
813 const char *pszErrorId, const char *pszFormat, va_list va);
814
815 HRESULT i_captureUSBDevices(PUVM pUVM);
816 void i_detachAllUSBDevices(bool aDone);
817
818
819 static DECLCALLBACK(int) i_vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
820 static DECLCALLBACK(void) i_vmm2User_NotifyEmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
821 static DECLCALLBACK(void) i_vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
822 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM);
823 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM);
824 static DECLCALLBACK(void) i_vmm2User_NotifyResetTurnedIntoPowerOff(PCVMM2USERMETHODS pThis, PUVM pUVM);
825 static DECLCALLBACK(void *) i_vmm2User_QueryGenericObject(PCVMM2USERMETHODS pThis, PUVM pUVM, PCRTUUID pUuid);
826
827 static DECLCALLBACK(void *) i_drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
828 static DECLCALLBACK(void) i_drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
829 static DECLCALLBACK(int) i_drvStatus_MediumEjected(PPDMIMEDIANOTIFY pInterface, unsigned iLUN);
830 static DECLCALLBACK(void) i_drvStatus_Destruct(PPDMDRVINS pDrvIns);
831 static DECLCALLBACK(int) i_drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
832
833 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRetain(PPDMISECKEY pInterface, const char *pszId, const uint8_t **ppbKey,
834 size_t *pcbKey);
835 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRelease(PPDMISECKEY pInterface, const char *pszId);
836 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRetain(PPDMISECKEY pInterface, const char *pszId, const char **ppszPassword);
837 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRelease(PPDMISECKEY pInterface, const char *pszId);
838
839 static DECLCALLBACK(int) i_pdmIfSecKeyHlp_KeyMissingNotify(PPDMISECKEYHLP pInterface);
840
841 int mcAudioRefs;
842 volatile uint32_t mcVRDPClients;
843 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
844 volatile bool mcGuestCredentialsProvided;
845
846 static const char *sSSMConsoleUnit;
847
848 HRESULT i_loadDataFromSavedState();
849 int i_loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
850
851 static DECLCALLBACK(void) i_saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
852 static DECLCALLBACK(int) i_loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
853
854#ifdef VBOX_WITH_GUEST_PROPS
855 HRESULT i_doEnumerateGuestProperties(const Utf8Str &aPatterns,
856 std::vector<Utf8Str> &aNames,
857 std::vector<Utf8Str> &aValues,
858 std::vector<LONG64> &aTimestamps,
859 std::vector<Utf8Str> &aFlags);
860
861 void i_guestPropertiesHandleVMReset(void);
862 bool i_guestPropertiesVRDPEnabled(void);
863 void i_guestPropertiesVRDPUpdateLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
864 void i_guestPropertiesVRDPUpdateActiveClient(uint32_t u32ClientId);
865 void i_guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached);
866 void i_guestPropertiesVRDPUpdateNameChange(uint32_t u32ClientId, const char *pszName);
867 void i_guestPropertiesVRDPUpdateIPAddrChange(uint32_t u32ClientId, const char *pszIPAddr);
868 void i_guestPropertiesVRDPUpdateLocationChange(uint32_t u32ClientId, const char *pszLocation);
869 void i_guestPropertiesVRDPUpdateOtherInfoChange(uint32_t u32ClientId, const char *pszOtherInfo);
870 void i_guestPropertiesVRDPUpdateDisconnect(uint32_t u32ClientId);
871#endif
872
873#ifdef VBOX_WITH_SHARED_CLIPBOARD
874 /** @name Shared Clipboard support
875 * @{ */
876 static DECLCALLBACK(int) i_sharedClipboardServiceCallback(void *pvExtension, uint32_t u32Function,
877 void *pvParms, uint32_t cbParms);
878 /** @} */
879#endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
880
881 /** @name Disk encryption support
882 * @{ */
883 HRESULT i_consoleParseDiskEncryption(const char *psz, const char **ppszEnd);
884 HRESULT i_configureEncryptionForDisk(const Utf8Str &strId, unsigned *pcDisksConfigured);
885 HRESULT i_clearDiskEncryptionKeysOnAllAttachmentsWithKeyId(const Utf8Str &strId);
886 HRESULT i_initSecretKeyIfOnAllAttachments(void);
887 int i_consoleParseKeyValue(const char *psz, const char **ppszEnd,
888 char **ppszKey, char **ppszVal);
889 void i_removeSecretKeysOnSuspend();
890 /** @} */
891
892 /** @name Teleporter support
893 * @{ */
894 static DECLCALLBACK(int) i_teleporterSrcThreadWrapper(RTTHREAD hThreadSelf, void *pvUser);
895 HRESULT i_teleporterSrc(TeleporterStateSrc *pState);
896 HRESULT i_teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
897 HRESULT i_teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
898 HRESULT i_teleporterTrg(PUVM pUVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
899 Progress *pProgress, bool *pfPowerOffOnFailure);
900 static DECLCALLBACK(int) i_teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
901 /** @} */
902
903 bool mSavedStateDataLoaded : 1;
904
905 const ComPtr<IMachine> mMachine;
906 const ComPtr<IInternalMachineControl> mControl;
907
908 const ComPtr<IVRDEServer> mVRDEServer;
909
910 ConsoleVRDPServer * const mConsoleVRDPServer;
911 bool mfVRDEChangeInProcess;
912 bool mfVRDEChangePending;
913 const ComObjPtr<Guest> mGuest;
914 const ComObjPtr<Keyboard> mKeyboard;
915 const ComObjPtr<Mouse> mMouse;
916 const ComObjPtr<Display> mDisplay;
917 const ComObjPtr<MachineDebugger> mDebugger;
918 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
919 /** This can safely be used without holding any locks.
920 * An AutoCaller suffices to prevent it being destroy while in use and
921 * internally there is a lock providing the necessary serialization. */
922 const ComObjPtr<EventSource> mEventSource;
923#ifdef VBOX_WITH_EXTPACK
924 const ComObjPtr<ExtPackManager> mptrExtPackManager;
925#endif
926 const ComObjPtr<EmulatedUSB> mEmulatedUSB;
927
928 USBDeviceList mUSBDevices;
929 RemoteUSBDeviceList mRemoteUSBDevices;
930
931 SharedFolderDataMap m_mapGlobalSharedFolders;
932 SharedFolderDataMap m_mapMachineSharedFolders;
933 SharedFolderMap m_mapSharedFolders; // the console instances
934
935 /** The user mode VM handle. */
936 PUVM mpUVM;
937 /** Holds the number of "readonly" mpUVM callers (users). */
938 uint32_t mVMCallers;
939 /** Semaphore posted when the number of mpUVM callers drops to zero. */
940 RTSEMEVENT mVMZeroCallersSem;
941 /** true when Console has entered the mpUVM destruction phase. */
942 bool mVMDestroying : 1;
943 /** true when power down is initiated by vmstateChangeCallback (EMT). */
944 bool mVMPoweredOff : 1;
945 /** true when vmstateChangeCallback shouldn't initiate a power down. */
946 bool mVMIsAlreadyPoweringOff : 1;
947 /** true if we already showed the snapshot folder size warning. */
948 bool mfSnapshotFolderSizeWarningShown : 1;
949 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
950 bool mfSnapshotFolderExt4WarningShown : 1;
951 /** true if we already listed the disk type of the snapshot folder. */
952 bool mfSnapshotFolderDiskTypeShown : 1;
953 /** true if a USB controller is available (i.e. USB devices can be attached). */
954 bool mfVMHasUsbController : 1;
955 /** Shadow of the VBoxInternal2/TurnResetIntoPowerOff extra data setting.
956 * This is initialized by Console::i_configConstructorInner(). */
957 bool mfTurnResetIntoPowerOff : 1;
958 /** true if the VM power off was caused by reset. */
959 bool mfPowerOffCausedByReset : 1;
960
961 /** Pointer to the VMM -> User (that's us) callbacks. */
962 struct MYVMM2USERMETHODS : public VMM2USERMETHODS
963 {
964 Console *pConsole;
965 /** The in-progress snapshot. */
966 ISnapshot *pISnapshot;
967 } *mpVmm2UserMethods;
968
969 /** The current network attachment type in the VM.
970 * This doesn't have to match the network attachment type maintained in the
971 * NetworkAdapter. This is needed to change the network attachment
972 * dynamically.
973 */
974 typedef std::vector<NetworkAttachmentType_T> NetworkAttachmentTypeVector;
975 NetworkAttachmentTypeVector meAttachmentType;
976
977 VMMDev * m_pVMMDev;
978 AudioVRDE * const mAudioVRDE;
979 Nvram * const mNvram;
980#ifdef VBOX_WITH_USB_CARDREADER
981 UsbCardReader * const mUsbCardReader;
982#endif
983 BusAssignmentManager* mBusMgr;
984
985 enum
986 {
987 iLedFloppy = 0,
988 cLedFloppy = 2,
989 iLedIde = iLedFloppy + cLedFloppy,
990 cLedIde = 4,
991 iLedSata = iLedIde + cLedIde,
992 cLedSata = 30,
993 iLedScsi = iLedSata + cLedSata,
994 cLedScsi = 16,
995 iLedSas = iLedScsi + cLedScsi,
996 cLedSas = 8,
997 iLedUsb = iLedSas + cLedSas,
998 cLedUsb = 8,
999 iLedNvme = iLedUsb + cLedUsb,
1000 cLedNvme = 30,
1001 iLedVirtio = iLedNvme + cLedNvme,
1002 cLedVirtio = 16,
1003 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas + cLedUsb + cLedNvme + cLedVirtio
1004 };
1005 DeviceType_T maStorageDevType[cLedStorage];
1006 PPDMLED mapStorageLeds[cLedStorage];
1007 PPDMLED mapNetworkLeds[36]; /**< @todo adapt this to the maximum network card count */
1008 PPDMLED mapSharedFolderLed;
1009 PPDMLED mapUSBLed[2];
1010 PPDMLED mapCrOglLed;
1011
1012 MediumAttachmentMap mapMediumAttachments;
1013
1014 /** List of attached USB storage devices. */
1015 USBStorageDeviceList mUSBStorageDevices;
1016
1017 /** Store for secret keys. */
1018 SecretKeyStore * const m_pKeyStore;
1019 /** Number of disks configured for encryption. */
1020 unsigned m_cDisksEncrypted;
1021 /** Number of disks which have the key in the map. */
1022 unsigned m_cDisksPwProvided;
1023
1024 /** Current active port modes of the supported serial ports. */
1025 PortMode_T m_aeSerialPortMode[4];
1026
1027 /** Pointer to the key consumer -> provider (that's us) callbacks. */
1028 struct MYPDMISECKEY : public PDMISECKEY
1029 {
1030 Console *pConsole;
1031 } *mpIfSecKey;
1032
1033 /** Pointer to the key helpers -> provider (that's us) callbacks. */
1034 struct MYPDMISECKEYHLP : public PDMISECKEYHLP
1035 {
1036 Console *pConsole;
1037 } *mpIfSecKeyHlp;
1038
1039/* Note: FreeBSD needs this whether netflt is used or not. */
1040#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
1041 Utf8Str maTAPDeviceName[8];
1042 RTFILE maTapFD[8];
1043#endif
1044
1045 bool mVMStateChangeCallbackDisabled;
1046
1047 bool mfUseHostClipboard;
1048
1049 /** Local machine state value. */
1050 MachineState_T mMachineState;
1051
1052 /** Machine uuid string. */
1053 Bstr mstrUuid;
1054
1055#ifdef VBOX_WITH_SHARED_CLIPBOARD
1056 HGCMSVCEXTHANDLE m_hHgcmSvcExtShrdClipboard;
1057#endif
1058#ifdef VBOX_WITH_DRAG_AND_DROP
1059 HGCMSVCEXTHANDLE m_hHgcmSvcExtDragAndDrop;
1060#endif
1061
1062 /** Pointer to the progress object of a live cancelable task.
1063 *
1064 * This is currently only used by Console::Teleport(), but is intended to later
1065 * be used by the live snapshot code path as well. Actions like
1066 * Console::PowerDown, which automatically cancels out the running snapshot /
1067 * teleportation operation, will cancel the teleportation / live snapshot
1068 * operation before starting. */
1069 ComPtr<IProgress> mptrCancelableProgress;
1070
1071 ComPtr<IEventListener> mVmListener;
1072
1073#ifdef VBOX_WITH_RECORDING
1074 struct Recording
1075 {
1076 Recording()
1077 : mpCtx(NULL)
1078# ifdef VBOX_WITH_AUDIO_RECORDING
1079 , mAudioRec(NULL)
1080# endif
1081 { }
1082
1083 /** The recording context. */
1084 RecordingContext *mpCtx;
1085# ifdef VBOX_WITH_AUDIO_RECORDING
1086 /** Pointer to capturing audio backend. */
1087 AudioVideoRec * const mAudioRec;
1088# endif
1089 } Recording;
1090#endif /* VBOX_WITH_RECORDING */
1091
1092 friend class VMTask;
1093 friend class ConsoleVRDPServer;
1094};
1095
1096#endif /* !MAIN_INCLUDED_ConsoleImpl_h */
1097/* 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