VirtualBox

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

Last change on this file since 63183 was 62918, checked in by vboxsync, 9 years ago

Main: rip out long dead code, some leftovers from earlier event handling code

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