VirtualBox

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

Last change on this file since 51465 was 51342, checked in by vboxsync, 11 years ago

Main,DrvVD: Interface to pass the keys to the disk encryption module from Main

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 41.1 KB
Line 
1/* $Id: ConsoleImpl.h 51342 2014-05-22 10:24:53Z vboxsync $ */
2/** @file
3 * VBox Console COM Class definition
4 */
5
6/*
7 * Copyright (C) 2005-2014 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
25class Guest;
26class Keyboard;
27class Mouse;
28class Display;
29class MachineDebugger;
30class TeleporterStateSrc;
31class OUSBDevice;
32class RemoteUSBDevice;
33class SharedFolder;
34class VRDEServerInfo;
35class EmulatedUSB;
36#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
37class AudioVRDE;
38#else
39class AudioSniffer;
40#endif
41class Nvram;
42#ifdef VBOX_WITH_USB_CARDREADER
43class UsbCardReader;
44#endif
45class ConsoleVRDPServer;
46class VMMDev;
47class Progress;
48class BusAssignmentManager;
49COM_STRUCT_OR_CLASS(IEventListener);
50#ifdef VBOX_WITH_EXTPACK
51class ExtPackManager;
52#endif
53class VMMDevMouseInterface;
54class DisplayMouseInterface;
55
56#include <iprt/uuid.h>
57#include <VBox/RemoteDesktop/VRDE.h>
58#include <VBox/vmm/pdmdrv.h>
59#ifdef VBOX_WITH_GUEST_PROPS
60# include <VBox/HostServices/GuestPropertySvc.h> /* For the property notification callback */
61#endif
62
63#ifdef RT_OS_WINDOWS
64# include "../src-server/win/VBoxComEvents.h"
65#endif
66
67struct VUSBIRHCONFIG;
68typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
69
70#include <list>
71#include <vector>
72
73// defines
74///////////////////////////////////////////////////////////////////////////////
75
76/**
77 * Checks the availability of the underlying VM device driver corresponding
78 * to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
79 * not available (NULL), sets error info and returns returns E_ACCESSDENIED.
80 * The translatable error message is defined in null context.
81 *
82 * Intended to used only within Console children (i.e. Keyboard, Mouse,
83 * Display, etc.).
84 *
85 * @param drv driver pointer to check (compare it with NULL)
86 */
87#define CHECK_CONSOLE_DRV(drv) \
88 do { \
89 if (!(drv)) \
90 return setError(E_ACCESSDENIED, tr("The console is not powered up")); \
91 } while (0)
92
93// Console
94///////////////////////////////////////////////////////////////////////////////
95
96class ConsoleMouseInterface
97{
98public:
99 virtual VMMDevMouseInterface *getVMMDevMouseInterface() = 0;
100 virtual DisplayMouseInterface *getDisplayMouseInterface() = 0;
101 virtual void onMouseCapabilityChange(BOOL supportsAbsolute,
102 BOOL supportsRelative,
103 BOOL supportsMT,
104 BOOL needsHostCursor) = 0;
105};
106
107/** IConsole implementation class */
108class ATL_NO_VTABLE Console :
109 public VirtualBoxBase,
110 VBOX_SCRIPTABLE_IMPL(IConsole), public ConsoleMouseInterface
111{
112 Q_OBJECT
113
114public:
115
116 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Console, IConsole)
117
118 DECLARE_NOT_AGGREGATABLE(Console)
119
120 DECLARE_PROTECT_FINAL_CONSTRUCT()
121
122 BEGIN_COM_MAP(Console)
123 VBOX_DEFAULT_INTERFACE_ENTRIES(IConsole)
124 END_COM_MAP()
125
126 Console();
127 ~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 // IConsole properties
137 STDMETHOD(COMGETTER(Machine))(IMachine **aMachine);
138 STDMETHOD(COMGETTER(State))(MachineState_T *aMachineState);
139 STDMETHOD(COMGETTER(Guest))(IGuest **aGuest);
140 STDMETHOD(COMGETTER(Keyboard))(IKeyboard **aKeyboard);
141 STDMETHOD(COMGETTER(Mouse))(IMouse **aMouse);
142 STDMETHOD(COMGETTER(Display))(IDisplay **aDisplay);
143 STDMETHOD(COMGETTER(Debugger))(IMachineDebugger **aDebugger);
144 STDMETHOD(COMGETTER(USBDevices))(ComSafeArrayOut(IUSBDevice *, aUSBDevices));
145 STDMETHOD(COMGETTER(RemoteUSBDevices))(ComSafeArrayOut(IHostUSBDevice *, aRemoteUSBDevices));
146 STDMETHOD(COMGETTER(VRDEServerInfo))(IVRDEServerInfo **aVRDEServerInfo);
147 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
148 STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
149 STDMETHOD(COMGETTER(AttachedPCIDevices))(ComSafeArrayOut(IPCIDeviceAttachment *, aAttachments));
150 STDMETHOD(COMGETTER(UseHostClipboard))(BOOL *aUseHostClipboard);
151 STDMETHOD(COMSETTER(UseHostClipboard))(BOOL aUseHostClipboard);
152 STDMETHOD(COMGETTER(EmulatedUSB))(IEmulatedUSB **aEmulatedUSB);
153
154 // IConsole methods
155 STDMETHOD(PowerUp)(IProgress **aProgress);
156 STDMETHOD(PowerUpPaused)(IProgress **aProgress);
157 STDMETHOD(PowerDown)(IProgress **aProgress);
158 STDMETHOD(Reset)();
159 STDMETHOD(Pause)();
160 STDMETHOD(Resume)();
161 STDMETHOD(PowerButton)();
162 STDMETHOD(SleepButton)();
163 STDMETHOD(GetPowerButtonHandled)(BOOL *aHandled);
164 STDMETHOD(GetGuestEnteredACPIMode)(BOOL *aEntered);
165 STDMETHOD(SaveState)(IProgress **aProgress);
166 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
167 STDMETHOD(DiscardSavedState)(BOOL aRemoveFile);
168 STDMETHOD(GetDeviceActivity)(DeviceType_T aDeviceType,
169 DeviceActivity_T *aDeviceActivity);
170 STDMETHOD(AttachUSBDevice)(IN_BSTR aId);
171 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, IUSBDevice **aDevice);
172 STDMETHOD(FindUSBDeviceByAddress)(IN_BSTR aAddress, IUSBDevice **aDevice);
173 STDMETHOD(FindUSBDeviceById)(IN_BSTR aId, IUSBDevice **aDevice);
174 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
175 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
176 STDMETHOD(TakeSnapshot)(IN_BSTR aName, IN_BSTR aDescription,
177 IProgress **aProgress);
178 STDMETHOD(DeleteSnapshot)(IN_BSTR aId, IProgress **aProgress);
179 STDMETHOD(DeleteSnapshotAndAllChildren)(IN_BSTR aId, IProgress **aProgress);
180 STDMETHOD(DeleteSnapshotRange)(IN_BSTR aStartId, IN_BSTR aEndId, IProgress **aProgress);
181 STDMETHOD(RestoreSnapshot)(ISnapshot *aSnapshot, IProgress **aProgress);
182 STDMETHOD(Teleport)(IN_BSTR aHostname, ULONG aPort, IN_BSTR aPassword, ULONG aMaxDowntime, IProgress **aProgress);
183
184 // public methods for internal purposes only
185
186 /*
187 * Note: the following methods do not increase refcount. intended to be
188 * called only by the VM execution thread.
189 */
190
191 Guest *getGuest() const { return mGuest; }
192 Keyboard *getKeyboard() const { return mKeyboard; }
193 Mouse *getMouse() const { return mMouse; }
194 Display *getDisplay() const { return mDisplay; }
195 MachineDebugger *getMachineDebugger() const { return mDebugger; }
196#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
197 AudioVRDE *getAudioVRDE() const { return mAudioVRDE; }
198#else
199 AudioSniffer *getAudioSniffer() const { return mAudioSniffer; }
200#endif
201
202 const ComPtr<IMachine> &machine() const { return mMachine; }
203
204 bool useHostClipboard() { return mfUseHostClipboard; }
205
206 /** Method is called only from ConsoleVRDPServer */
207 IVRDEServer *getVRDEServer() const { return mVRDEServer; }
208
209 ConsoleVRDPServer *consoleVRDPServer() const { return mConsoleVRDPServer; }
210
211 HRESULT updateMachineState(MachineState_T aMachineState);
212
213 // events from IInternalSessionControl
214 HRESULT onNetworkAdapterChange(INetworkAdapter *aNetworkAdapter, BOOL changeAdapter);
215 HRESULT onSerialPortChange(ISerialPort *aSerialPort);
216 HRESULT onParallelPortChange(IParallelPort *aParallelPort);
217 HRESULT onStorageControllerChange();
218 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
219 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
220 HRESULT onCPUExecutionCapChange(ULONG aExecutionCap);
221 HRESULT onClipboardModeChange(ClipboardMode_T aClipboardMode);
222 HRESULT onDragAndDropModeChange(DragAndDropMode_T aDragAndDropMode);
223 HRESULT onVRDEServerChange(BOOL aRestart);
224 HRESULT onVideoCaptureChange();
225 HRESULT onUSBControllerChange();
226 HRESULT onSharedFolderChange(BOOL aGlobal);
227 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice, IVirtualBoxErrorInfo *aError, ULONG aMaskedIfs);
228 HRESULT onUSBDeviceDetach(IN_BSTR aId, IVirtualBoxErrorInfo *aError);
229 HRESULT onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
230 HRESULT onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
231 HRESULT onExtraDataChange(IN_BSTR aMachineId, IN_BSTR aKey, IN_BSTR aVal);
232
233 HRESULT getGuestProperty(IN_BSTR aKey, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
234 HRESULT setGuestProperty(IN_BSTR aKey, IN_BSTR aValue, IN_BSTR aFlags);
235 HRESULT enumerateGuestProperties(IN_BSTR aPatterns,
236 ComSafeArrayOut(BSTR, aNames),
237 ComSafeArrayOut(BSTR, aValues),
238 ComSafeArrayOut(LONG64, aTimestamps),
239 ComSafeArrayOut(BSTR, aFlags));
240 HRESULT onlineMergeMedium(IMediumAttachment *aMediumAttachment,
241 ULONG aSourceIdx, ULONG aTargetIdx,
242 IProgress *aProgress);
243 int hgcmLoadService(const char *pszServiceLibrary, const char *pszServiceName);
244 VMMDev *getVMMDev() { return m_pVMMDev; }
245#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
246 AudioVRDE *getAudioVRDE() { return mAudioVRDE; }
247#else
248 AudioSniffer *getAudioSniffer() { return mAudioSniffer; }
249#endif
250
251#ifdef VBOX_WITH_EXTPACK
252 ExtPackManager *getExtPackManager();
253#endif
254 EventSource *getEventSource() { return mEventSource; }
255#ifdef VBOX_WITH_USB_CARDREADER
256 UsbCardReader *getUsbCardReader() { return mUsbCardReader; }
257#endif
258
259 int VRDPClientLogon(uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
260 void VRDPClientStatusChange(uint32_t u32ClientId, const char *pszStatus);
261 void VRDPClientConnect(uint32_t u32ClientId);
262 void VRDPClientDisconnect(uint32_t u32ClientId, uint32_t fu32Intercepted);
263 void VRDPInterceptAudio(uint32_t u32ClientId);
264 void VRDPInterceptUSB(uint32_t u32ClientId, void **ppvIntercept);
265 void VRDPInterceptClipboard(uint32_t u32ClientId);
266
267 void processRemoteUSBDevices(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevList, uint32_t cbDevList, bool fDescExt);
268 void reportVmStatistics(ULONG aValidStats, ULONG aCpuUser,
269 ULONG aCpuKernel, ULONG aCpuIdle,
270 ULONG aMemTotal, ULONG aMemFree,
271 ULONG aMemBalloon, ULONG aMemShared,
272 ULONG aMemCache, ULONG aPageTotal,
273 ULONG aAllocVMM, ULONG aFreeVMM,
274 ULONG aBalloonedVMM, ULONG aSharedVMM,
275 ULONG aVmNetRx, ULONG aVmNetTx)
276 {
277 mControl->ReportVmStatistics(aValidStats, aCpuUser, aCpuKernel, aCpuIdle,
278 aMemTotal, aMemFree, aMemBalloon, aMemShared,
279 aMemCache, aPageTotal, aAllocVMM, aFreeVMM,
280 aBalloonedVMM, aSharedVMM, aVmNetRx, aVmNetTx);
281 }
282 void enableVMMStatistics(BOOL aEnable);
283
284 HRESULT pause(Reason_T aReason);
285 HRESULT resume(Reason_T aReason);
286 HRESULT saveState(Reason_T aReason, IProgress **aProgress);
287
288 // callback callers (partly; for some events console callbacks are notified
289 // directly from IInternalSessionControl event handlers declared above)
290 void onMousePointerShapeChange(bool fVisible, bool fAlpha,
291 uint32_t xHot, uint32_t yHot,
292 uint32_t width, uint32_t height,
293 ComSafeArrayIn(uint8_t, aShape));
294 void onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative,
295 BOOL supportsMT, BOOL needsHostCursor);
296 void onStateChange(MachineState_T aMachineState);
297 void onAdditionsStateChange();
298 void onAdditionsOutdated();
299 void onKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock);
300 void onUSBDeviceStateChange(IUSBDevice *aDevice, bool aAttached,
301 IVirtualBoxErrorInfo *aError);
302 void onRuntimeError(BOOL aFatal, IN_BSTR aErrorID, IN_BSTR aMessage);
303 HRESULT onShowWindow(BOOL aCheck, BOOL *aCanShow, LONG64 *aWinId);
304 void onVRDEServerInfoChange();
305
306 static const PDMDRVREG DrvStatusReg;
307
308 static HRESULT setErrorStatic(HRESULT aResultCode, const char *pcsz, ...);
309 HRESULT setInvalidMachineStateError();
310
311 static const char *convertControllerTypeToDev(StorageControllerType_T enmCtrlType);
312 static HRESULT convertBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
313 // Called from event listener
314 HRESULT onNATRedirectRuleChange(ULONG ulInstance, BOOL aNatRuleRemove,
315 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
316
317 // Mouse interface
318 VMMDevMouseInterface *getVMMDevMouseInterface();
319 DisplayMouseInterface *getDisplayMouseInterface();
320
321 EmulatedUSB *getEmulatedUSB(void) { return mEmulatedUSB; }
322
323 /**
324 * Sets the disk encryption keys.
325 *
326 * @returns COM status code.
327 * @þaram strCfg The config for the disks.
328 *
329 * @note: One line in the config string contains all required data for one disk.
330 * The format for one disk is some sort of comma separated value using
331 * key=value pairs.
332 * There are two keys defined at the moment:
333 * - uuid: The uuid of the base image the key is for (with or without)
334 * the curly braces.
335 * - dek: The data encryption key in base64 encoding
336 */
337 HRESULT setDiskEncryptionKeys(const Utf8Str &strCfg);
338
339private:
340
341 /**
342 * Base template for AutoVMCaller and SafeVMPtr. Template arguments
343 * have the same meaning as arguments of Console::addVMCaller().
344 */
345 template <bool taQuiet = false, bool taAllowNullVM = false>
346 class AutoVMCallerBase
347 {
348 public:
349 AutoVMCallerBase(Console *aThat) : mThat(aThat), mRC(E_FAIL)
350 {
351 Assert(aThat);
352 mRC = aThat->addVMCaller(taQuiet, taAllowNullVM);
353 }
354 ~AutoVMCallerBase()
355 {
356 doRelease();
357 }
358 /** Decreases the number of callers before the instance is destroyed. */
359 void releaseCaller()
360 {
361 Assert(SUCCEEDED(mRC));
362 doRelease();
363 }
364 /** Restores the number of callers after by #release(). #rc() must be
365 * rechecked to ensure the operation succeeded. */
366 void addYY()
367 {
368 AssertReturnVoid(!SUCCEEDED(mRC));
369 mRC = mThat->addVMCaller(taQuiet, taAllowNullVM);
370 }
371 /** Returns the result of Console::addVMCaller() */
372 HRESULT rc() const { return mRC; }
373 /** Shortcut to SUCCEEDED(rc()) */
374 bool isOk() const { return SUCCEEDED(mRC); }
375 protected:
376 Console *mThat;
377 void doRelease()
378 {
379 if (SUCCEEDED(mRC))
380 {
381 mThat->releaseVMCaller();
382 mRC = E_FAIL;
383 }
384 }
385 private:
386 HRESULT mRC; /* Whether the caller was added. */
387 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoVMCallerBase)
388 };
389
390#if 0
391 /**
392 * Helper class that protects sections of code using the mpUVM pointer by
393 * automatically calling addVMCaller() on construction and
394 * releaseVMCaller() on destruction. Intended for Console methods dealing
395 * with mpUVM. The usage pattern is:
396 * <code>
397 * AutoVMCaller autoVMCaller(this);
398 * if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();
399 * ...
400 * VMR3ReqCall (mpUVM, ...
401 * </code>
402 *
403 * @note Temporarily locks the argument for writing.
404 *
405 * @sa SafeVMPtr, SafeVMPtrQuiet
406 * @obsolete Use SafeVMPtr
407 */
408 typedef AutoVMCallerBase<false, false> AutoVMCaller;
409#endif
410
411 /**
412 * Same as AutoVMCaller but doesn't set extended error info on failure.
413 *
414 * @note Temporarily locks the argument for writing.
415 * @obsolete Use SafeVMPtrQuiet
416 */
417 typedef AutoVMCallerBase<true, false> AutoVMCallerQuiet;
418
419 /**
420 * Same as AutoVMCaller but allows a null VM pointer (to trigger an error
421 * instead of assertion).
422 *
423 * @note Temporarily locks the argument for writing.
424 * @obsolete Use SafeVMPtr
425 */
426 typedef AutoVMCallerBase<false, true> AutoVMCallerWeak;
427
428 /**
429 * Same as AutoVMCaller but doesn't set extended error info on failure
430 * and allows a null VM pointer (to trigger an error instead of
431 * assertion).
432 *
433 * @note Temporarily locks the argument for writing.
434 * @obsolete Use SafeVMPtrQuiet
435 */
436 typedef AutoVMCallerBase<true, true> AutoVMCallerQuietWeak;
437
438 /**
439 * Base template for SafeVMPtr and SafeVMPtrQuiet.
440 */
441 template<bool taQuiet = false>
442 class SafeVMPtrBase : public AutoVMCallerBase<taQuiet, true>
443 {
444 typedef AutoVMCallerBase<taQuiet, true> Base;
445 public:
446 SafeVMPtrBase(Console *aThat) : Base(aThat), mRC(E_FAIL), mpUVM(NULL)
447 {
448 if (Base::isOk())
449 mRC = aThat->safeVMPtrRetainer(&mpUVM, taQuiet);
450 }
451 ~SafeVMPtrBase()
452 {
453 doRelease();
454 }
455 /** Direct PUVM access. */
456 PUVM rawUVM() const { return mpUVM; }
457 /** Release the handles. */
458 void release()
459 {
460 Assert(SUCCEEDED(mRC));
461 doRelease();
462 }
463
464 /** The combined result of Console::addVMCaller() and Console::safeVMPtrRetainer */
465 HRESULT rc() const { return Base::isOk()? mRC: Base::rc(); }
466 /** Shortcut to SUCCEEDED(rc()) */
467 bool isOk() const { return SUCCEEDED(mRC) && Base::isOk(); }
468
469 private:
470 void doRelease()
471 {
472 if (SUCCEEDED(mRC))
473 {
474 Base::mThat->safeVMPtrReleaser(&mpUVM);
475 mRC = E_FAIL;
476 }
477 Base::doRelease();
478 }
479 HRESULT mRC; /* Whether the VM ptr was retained. */
480 PUVM mpUVM;
481 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(SafeVMPtrBase)
482 };
483
484public:
485
486 /*
487 * Helper class that safely manages the Console::mpUVM pointer
488 * by calling addVMCaller() on construction and releaseVMCaller() on
489 * destruction. Intended for Console children. The usage pattern is:
490 * <code>
491 * Console::SafeVMPtr ptrVM(mParent);
492 * if (!ptrVM.isOk())
493 * return ptrVM.rc();
494 * ...
495 * VMR3ReqCall(ptrVM.rawUVM(), ...
496 * ...
497 * printf("%p\n", ptrVM.rawUVM());
498 * </code>
499 *
500 * @note Temporarily locks the argument for writing.
501 *
502 * @sa SafeVMPtrQuiet, AutoVMCaller
503 */
504 typedef SafeVMPtrBase<false> SafeVMPtr;
505
506 /**
507 * A deviation of SafeVMPtr that doesn't set the error info on failure.
508 * Intended for pieces of code that don't need to return the VM access
509 * failure to the caller. The usage pattern is:
510 * <code>
511 * Console::SafeVMPtrQuiet pVM(mParent);
512 * if (pVM.rc())
513 * VMR3ReqCall(pVM, ...
514 * return S_OK;
515 * </code>
516 *
517 * @note Temporarily locks the argument for writing.
518 *
519 * @sa SafeVMPtr, AutoVMCaller
520 */
521 typedef SafeVMPtrBase<true> SafeVMPtrQuiet;
522
523 class SharedFolderData
524 {
525 public:
526 SharedFolderData()
527 { }
528
529 SharedFolderData(const Utf8Str &aHostPath,
530 bool aWritable,
531 bool aAutoMount)
532 : m_strHostPath(aHostPath),
533 m_fWritable(aWritable),
534 m_fAutoMount(aAutoMount)
535 { }
536
537 // copy constructor
538 SharedFolderData(const SharedFolderData& aThat)
539 : m_strHostPath(aThat.m_strHostPath),
540 m_fWritable(aThat.m_fWritable),
541 m_fAutoMount(aThat.m_fAutoMount)
542 { }
543
544 Utf8Str m_strHostPath;
545 bool m_fWritable;
546 bool m_fAutoMount;
547 };
548
549 /**
550 * Class for managing emulated USB MSDs.
551 */
552 class USBStorageDevice
553 {
554 public:
555 USBStorageDevice()
556 { }
557 /** The UUID associated with the USB device. */
558 RTUUID mUuid;
559 /** Port of the storage device. */
560 LONG iPort;
561 };
562
563 typedef std::map<Utf8Str, ComObjPtr<SharedFolder> > SharedFolderMap;
564 typedef std::map<Utf8Str, SharedFolderData> SharedFolderDataMap;
565 typedef std::map<Utf8Str, ComPtr<IMediumAttachment> > MediumAttachmentMap;
566 typedef std::list <USBStorageDevice> USBStorageDeviceList;
567
568private:
569
570 typedef std::list <ComObjPtr<OUSBDevice> > USBDeviceList;
571 typedef std::list <ComObjPtr<RemoteUSBDevice> > RemoteUSBDeviceList;
572
573 HRESULT addVMCaller(bool aQuiet = false, bool aAllowNullVM = false);
574 void releaseVMCaller();
575 HRESULT safeVMPtrRetainer(PUVM *a_ppUVM, bool aQuiet);
576 void safeVMPtrReleaser(PUVM *a_ppUVM);
577
578 HRESULT consoleInitReleaseLog(const ComPtr<IMachine> aMachine);
579
580 HRESULT powerUp(IProgress **aProgress, bool aPaused);
581 HRESULT powerDown(IProgress *aProgress = NULL);
582
583/* Note: FreeBSD needs this whether netflt is used or not. */
584#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
585 HRESULT attachToTapInterface(INetworkAdapter *networkAdapter);
586 HRESULT detachFromTapInterface(INetworkAdapter *networkAdapter);
587#endif
588 HRESULT powerDownHostInterfaces();
589
590 HRESULT setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
591 HRESULT setMachineStateLocally(MachineState_T aMachineState)
592 {
593 return setMachineState(aMachineState, false /* aUpdateServer */);
594 }
595
596 HRESULT findSharedFolder(const Utf8Str &strName,
597 ComObjPtr<SharedFolder> &aSharedFolder,
598 bool aSetError = false);
599
600 HRESULT fetchSharedFolders(BOOL aGlobal);
601 bool findOtherSharedFolder(const Utf8Str &straName,
602 SharedFolderDataMap::const_iterator &aIt);
603
604 HRESULT createSharedFolder(const Utf8Str &strName, const SharedFolderData &aData);
605 HRESULT removeSharedFolder(const Utf8Str &strName);
606
607 HRESULT suspendBeforeConfigChange(PUVM pUVM, AutoWriteLock *pAlock, bool *pfResume);
608 void resumeAfterConfigChange(PUVM pUVM);
609
610 static DECLCALLBACK(int) configConstructor(PUVM pUVM, PVM pVM, void *pvConsole);
611 int configConstructorInner(PUVM pUVM, PVM pVM, AutoWriteLock *pAlock);
612 int configCfgmOverlay(PCFGMNODE pRoot, IVirtualBox *pVirtualBox, IMachine *pMachine);
613 int configDumpAPISettingsTweaks(IVirtualBox *pVirtualBox, IMachine *pMachine);
614
615 int configGraphicsController(PCFGMNODE pDevices,
616 const GraphicsControllerType_T graphicsController,
617 BusAssignmentManager *pBusMgr,
618 const ComPtr<IMachine> &pMachine,
619 const ComPtr<IBIOSSettings> &biosSettings,
620 bool fHMEnabled);
621 int configMediumAttachment(PCFGMNODE pCtlInst,
622 const char *pcszDevice,
623 unsigned uInstance,
624 StorageBus_T enmBus,
625 bool fUseHostIOCache,
626 bool fBuiltinIoCache,
627 bool fSetupMerge,
628 unsigned uMergeSource,
629 unsigned uMergeTarget,
630 IMediumAttachment *pMediumAtt,
631 MachineState_T aMachineState,
632 HRESULT *phrc,
633 bool fAttachDetach,
634 bool fForceUnmount,
635 bool fHotplug,
636 PUVM pUVM,
637 DeviceType_T *paLedDevType,
638 PCFGMNODE *ppLunL0);
639 int configMedium(PCFGMNODE pLunL0,
640 bool fPassthrough,
641 DeviceType_T enmType,
642 bool fUseHostIOCache,
643 bool fBuiltinIoCache,
644 bool fSetupMerge,
645 unsigned uMergeSource,
646 unsigned uMergeTarget,
647 const char *pcszBwGroup,
648 bool fDiscard,
649 IMedium *pMedium,
650 MachineState_T aMachineState,
651 HRESULT *phrc);
652 static DECLCALLBACK(int) reconfigureMediumAttachment(Console *pThis,
653 PUVM pUVM,
654 const char *pcszDevice,
655 unsigned uInstance,
656 StorageBus_T enmBus,
657 bool fUseHostIOCache,
658 bool fBuiltinIoCache,
659 bool fSetupMerge,
660 unsigned uMergeSource,
661 unsigned uMergeTarget,
662 IMediumAttachment *aMediumAtt,
663 MachineState_T aMachineState,
664 HRESULT *phrc);
665 static DECLCALLBACK(int) changeRemovableMedium(Console *pThis,
666 PUVM pUVM,
667 const char *pcszDevice,
668 unsigned uInstance,
669 StorageBus_T enmBus,
670 bool fUseHostIOCache,
671 IMediumAttachment *aMediumAtt,
672 bool fForce);
673
674 HRESULT attachRawPCIDevices(PUVM pUVM, BusAssignmentManager *BusMgr, PCFGMNODE pDevices);
675 void attachStatusDriver(PCFGMNODE pCtlInst, PPDMLED *papLeds,
676 uint64_t uFirst, uint64_t uLast,
677 Console::MediumAttachmentMap *pmapMediumAttachments,
678 const char *pcszDevice, unsigned uInstance);
679
680 int configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun,
681 INetworkAdapter *aNetworkAdapter, PCFGMNODE pCfg,
682 PCFGMNODE pLunL0, PCFGMNODE pInst,
683 bool fAttachDetach, bool fIgnoreConnectFailure);
684
685 static DECLCALLBACK(int) configGuestProperties(void *pvConsole, PUVM pUVM);
686 static DECLCALLBACK(int) configGuestControl(void *pvConsole);
687 static DECLCALLBACK(void) vmstateChangeCallback(PUVM pUVM, VMSTATE enmState, VMSTATE enmOldState, void *pvUser);
688 static DECLCALLBACK(int) unplugCpu(Console *pThis, PUVM pUVM, VMCPUID idCpu);
689 static DECLCALLBACK(int) plugCpu(Console *pThis, PUVM pUVM, VMCPUID idCpu);
690 HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PUVM pUVM);
691 HRESULT doCPURemove(ULONG aCpu, PUVM pUVM);
692 HRESULT doCPUAdd(ULONG aCpu, PUVM pUVM);
693
694 HRESULT doNetworkAdapterChange(PUVM pUVM, const char *pszDevice, unsigned uInstance,
695 unsigned uLun, INetworkAdapter *aNetworkAdapter);
696 static DECLCALLBACK(int) changeNetworkAttachment(Console *pThis, PUVM pUVM, const char *pszDevice,
697 unsigned uInstance, unsigned uLun,
698 INetworkAdapter *aNetworkAdapter);
699
700 void changeClipboardMode(ClipboardMode_T aClipboardMode);
701 void changeDragAndDropMode(DragAndDropMode_T aDragAndDropMode);
702
703#ifdef VBOX_WITH_USB
704 HRESULT attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs);
705 HRESULT detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice);
706
707 static DECLCALLBACK(int) usbAttachCallback(Console *that, PUVM pUVM, IUSBDevice *aHostDevice, PCRTUUID aUuid,
708 bool aRemote, const char *aAddress, void *pvRemoteBackend, USHORT aPortVersion, ULONG aMaskedIfs);
709 static DECLCALLBACK(int) usbDetachCallback(Console *that, PUVM pUVM, PCRTUUID aUuid);
710#endif
711
712 static DECLCALLBACK(int) attachStorageDevice(Console *pThis,
713 PUVM pUVM,
714 const char *pcszDevice,
715 unsigned uInstance,
716 StorageBus_T enmBus,
717 bool fUseHostIOCache,
718 IMediumAttachment *aMediumAtt,
719 bool fSilent);
720 static DECLCALLBACK(int) detachStorageDevice(Console *pThis,
721 PUVM pUVM,
722 const char *pcszDevice,
723 unsigned uInstance,
724 StorageBus_T enmBus,
725 IMediumAttachment *aMediumAtt,
726 bool fSilent);
727 HRESULT doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PUVM pUVM, bool fSilent);
728 HRESULT doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PUVM pUVM, bool fSilent);
729
730 static DECLCALLBACK(int) fntTakeSnapshotWorker(RTTHREAD Thread, void *pvUser);
731
732 static DECLCALLBACK(int) stateProgressCallback(PUVM pUVM, unsigned uPercent, void *pvUser);
733
734 static DECLCALLBACK(void) genericVMSetErrorCallback(PUVM pUVM, void *pvUser, int rc, RT_SRC_POS_DECL,
735 const char *pszErrorFmt, va_list va);
736
737 void setVMRuntimeErrorCallbackF(uint32_t fFatal, const char *pszErrorId, const char *pszFormat, ...);
738 static DECLCALLBACK(void) setVMRuntimeErrorCallback(PUVM pUVM, void *pvUser, uint32_t fFatal,
739 const char *pszErrorId, const char *pszFormat, va_list va);
740
741 HRESULT captureUSBDevices(PUVM pUVM);
742 void detachAllUSBDevices(bool aDone);
743
744 static DECLCALLBACK(int) powerUpThread(RTTHREAD Thread, void *pvUser);
745 static DECLCALLBACK(int) saveStateThread(RTTHREAD Thread, void *pvUser);
746 static DECLCALLBACK(int) powerDownThread(RTTHREAD Thread, void *pvUser);
747
748 static DECLCALLBACK(int) vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
749 static DECLCALLBACK(void) vmm2User_NotifyEmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
750 static DECLCALLBACK(void) vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
751 static DECLCALLBACK(void) vmm2User_NotifyPdmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM);
752 static DECLCALLBACK(void) vmm2User_NotifyPdmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM);
753 static DECLCALLBACK(void) vmm2User_NotifyResetTurnedIntoPowerOff(PCVMM2USERMETHODS pThis, PUVM pUVM);
754
755 static DECLCALLBACK(void *) drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
756 static DECLCALLBACK(void) drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
757 static DECLCALLBACK(int) drvStatus_MediumEjected(PPDMIMEDIANOTIFY pInterface, unsigned iLUN);
758 static DECLCALLBACK(void) drvStatus_Destruct(PPDMDRVINS pDrvIns);
759 static DECLCALLBACK(int) drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
760
761 int mcAudioRefs;
762 volatile uint32_t mcVRDPClients;
763 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
764 volatile bool mcGuestCredentialsProvided;
765
766 static const char *sSSMConsoleUnit;
767 static uint32_t sSSMConsoleVer;
768
769 HRESULT loadDataFromSavedState();
770 int loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
771
772 static DECLCALLBACK(void) saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
773 static DECLCALLBACK(int) loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
774
775#ifdef VBOX_WITH_GUEST_PROPS
776 static DECLCALLBACK(int) doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
777 HRESULT doEnumerateGuestProperties(CBSTR aPatterns,
778 ComSafeArrayOut(BSTR, aNames),
779 ComSafeArrayOut(BSTR, aValues),
780 ComSafeArrayOut(LONG64, aTimestamps),
781 ComSafeArrayOut(BSTR, aFlags));
782
783 void guestPropertiesHandleVMReset(void);
784 bool guestPropertiesVRDPEnabled(void);
785 void guestPropertiesVRDPUpdateLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
786 void guestPropertiesVRDPUpdateActiveClient(uint32_t u32ClientId);
787 void guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached);
788 void guestPropertiesVRDPUpdateNameChange(uint32_t u32ClientId, const char *pszName);
789 void guestPropertiesVRDPUpdateIPAddrChange(uint32_t u32ClientId, const char *pszIPAddr);
790 void guestPropertiesVRDPUpdateLocationChange(uint32_t u32ClientId, const char *pszLocation);
791 void guestPropertiesVRDPUpdateOtherInfoChange(uint32_t u32ClientId, const char *pszOtherInfo);
792 void guestPropertiesVRDPUpdateDisconnect(uint32_t u32ClientId);
793#endif
794
795 bool isResetTurnedIntoPowerOff(void);
796
797 /** @name Disk encryption support
798 * @{ */
799 HRESULT consoleParseDiskEncryption(const char *psz, const char **ppszEnd);
800 HRESULT configureEncryptionForDisk(const char *pszUuid, const uint8_t *pbKey, size_t cbKey);
801 int consoleParseKeyValue(const char *psz, const char **ppszEnd,
802 char **ppszKey, char **ppszVal);
803 /** @} */
804
805 /** @name Teleporter support
806 * @{ */
807 static DECLCALLBACK(int) teleporterSrcThreadWrapper(RTTHREAD hThread, void *pvUser);
808 HRESULT teleporterSrc(TeleporterStateSrc *pState);
809 HRESULT teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
810 HRESULT teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
811 HRESULT teleporterTrg(PUVM pUVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
812 Progress *pProgress, bool *pfPowerOffOnFailure);
813 static DECLCALLBACK(int) teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
814 /** @} */
815
816 bool mSavedStateDataLoaded : 1;
817
818 const ComPtr<IMachine> mMachine;
819 const ComPtr<IInternalMachineControl> mControl;
820
821 const ComPtr<IVRDEServer> mVRDEServer;
822
823 ConsoleVRDPServer * const mConsoleVRDPServer;
824 bool mfVRDEChangeInProcess;
825 bool mfVRDEChangePending;
826
827 const ComObjPtr<Guest> mGuest;
828 const ComObjPtr<Keyboard> mKeyboard;
829 const ComObjPtr<Mouse> mMouse;
830 const ComObjPtr<Display> mDisplay;
831 const ComObjPtr<MachineDebugger> mDebugger;
832 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
833 /** This can safely be used without holding any locks.
834 * An AutoCaller suffices to prevent it being destroy while in use and
835 * internally there is a lock providing the necessary serialization. */
836 const ComObjPtr<EventSource> mEventSource;
837#ifdef VBOX_WITH_EXTPACK
838 const ComObjPtr<ExtPackManager> mptrExtPackManager;
839#endif
840 const ComObjPtr<EmulatedUSB> mEmulatedUSB;
841
842 USBDeviceList mUSBDevices;
843 RemoteUSBDeviceList mRemoteUSBDevices;
844
845 SharedFolderDataMap m_mapGlobalSharedFolders;
846 SharedFolderDataMap m_mapMachineSharedFolders;
847 SharedFolderMap m_mapSharedFolders; // the console instances
848
849 /** The user mode VM handle. */
850 PUVM mpUVM;
851 /** Holds the number of "readonly" mpUVM callers (users). */
852 uint32_t mVMCallers;
853 /** Semaphore posted when the number of mpUVM callers drops to zero. */
854 RTSEMEVENT mVMZeroCallersSem;
855 /** true when Console has entered the mpUVM destruction phase. */
856 bool mVMDestroying : 1;
857 /** true when power down is initiated by vmstateChangeCallback (EMT). */
858 bool mVMPoweredOff : 1;
859 /** true when vmstateChangeCallback shouldn't initiate a power down. */
860 bool mVMIsAlreadyPoweringOff : 1;
861 /** true if we already showed the snapshot folder size warning. */
862 bool mfSnapshotFolderSizeWarningShown : 1;
863 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
864 bool mfSnapshotFolderExt4WarningShown : 1;
865 /** true if we already listed the disk type of the snapshot folder. */
866 bool mfSnapshotFolderDiskTypeShown : 1;
867 /** true if a USB controller is available (i.e. USB devices can be attached). */
868 bool mfVMHasUsbController : 1;
869 /** true if the VM power off was caused by reset. */
870 bool mfPowerOffCausedByReset : 1;
871
872 /** Pointer to the VMM -> User (that's us) callbacks. */
873 struct MYVMM2USERMETHODS : public VMM2USERMETHODS
874 {
875 Console *pConsole;
876 } *mpVmm2UserMethods;
877
878 /** The current network attachment type in the VM.
879 * This doesn't have to match the network attachment type maintained in the
880 * NetworkAdapter. This is needed to change the network attachment
881 * dynamically.
882 */
883 typedef std::vector<NetworkAttachmentType_T> NetworkAttachmentTypeVector;
884 NetworkAttachmentTypeVector meAttachmentType;
885
886 VMMDev * m_pVMMDev;
887#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
888 AudioVRDE * const mAudioVRDE;
889#else
890 AudioSniffer * const mAudioSniffer;
891#endif
892 Nvram * const mNvram;
893#ifdef VBOX_WITH_USB_CARDREADER
894 UsbCardReader * const mUsbCardReader;
895#endif
896 BusAssignmentManager* mBusMgr;
897
898 enum
899 {
900 iLedFloppy = 0,
901 cLedFloppy = 2,
902 iLedIde = iLedFloppy + cLedFloppy,
903 cLedIde = 4,
904 iLedSata = iLedIde + cLedIde,
905 cLedSata = 30,
906 iLedScsi = iLedSata + cLedSata,
907 cLedScsi = 16,
908 iLedSas = iLedScsi + cLedScsi,
909 cLedSas = 8,
910 iLedUsb = iLedSas + cLedSas,
911 cLedUsb = 8,
912 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas + cLedUsb
913 };
914 DeviceType_T maStorageDevType[cLedStorage];
915 PPDMLED mapStorageLeds[cLedStorage];
916 PPDMLED mapNetworkLeds[36]; /**< @todo adapt this to the maximum network card count */
917 PPDMLED mapSharedFolderLed;
918 PPDMLED mapUSBLed[2];
919 PPDMLED mapCrOglLed;
920
921 MediumAttachmentMap mapMediumAttachments;
922
923 /** List of attached USB storage devices. */
924 USBStorageDeviceList mUSBStorageDevices;
925
926/* Note: FreeBSD needs this whether netflt is used or not. */
927#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
928 Utf8Str maTAPDeviceName[8];
929 RTFILE maTapFD[8];
930#endif
931
932 bool mVMStateChangeCallbackDisabled;
933
934 bool mfUseHostClipboard;
935
936 /** Local machine state value. */
937 MachineState_T mMachineState;
938
939 /** Pointer to the progress object of a live cancelable task.
940 *
941 * This is currently only used by Console::Teleport(), but is intended to later
942 * be used by the live snapshot code path as well. Actions like
943 * Console::PowerDown, which automatically cancels out the running snapshot /
944 * teleportation operation, will cancel the teleportation / live snapshot
945 * operation before starting. */
946 ComObjPtr<Progress> mptrCancelableProgress;
947
948 /* The purpose of caching of some events is probably in order to
949 automatically fire them at new event listeners. However, there is no
950 (longer?) any code making use of this... */
951#ifdef CONSOLE_WITH_EVENT_CACHE
952 struct
953 {
954 /** OnMousePointerShapeChange() cache */
955 struct
956 {
957 bool valid;
958 bool visible;
959 bool alpha;
960 uint32_t xHot;
961 uint32_t yHot;
962 uint32_t width;
963 uint32_t height;
964 com::SafeArray<BYTE> shape;
965 } mpsc;
966
967 /** OnMouseCapabilityChange() cache */
968 struct
969 {
970 bool valid;
971 BOOL supportsAbsolute;
972 BOOL supportsRelative;
973 BOOL needsHostCursor;
974 } mcc;
975
976 /** OnKeyboardLedsChange() cache */
977 struct
978 {
979 bool valid;
980 bool numLock;
981 bool capsLock;
982 bool scrollLock;
983 } klc;
984
985 void clear()
986 {
987 RT_ZERO(mcc);
988 RT_ZERO(klc);
989
990 /* We cannot RT_ZERO mpsc because of shape's vtable. */
991 mpsc.shape.setNull();
992 mpsc.valid = mpsc.visible = mpsc.alpha = false;
993 mpsc.xHot = mpsc.yHot = mpsc.width = mpsc.height = 0;
994 }
995 } mCallbackData;
996#endif
997 ComPtr<IEventListener> mVmListener;
998
999 friend struct VMTask;
1000};
1001
1002#endif // !____H_CONSOLEIMPL
1003/* 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