VirtualBox

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

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

src/VBox/Devices/Audio, src/VBox/Main/src-client, include/VBox/vmm:

src/VBox/Devices/Audio: part of restructuring of audio code. Devices files correspondin to Hda, AC97 and SB16 audio. The structure of files have been modifed as per PDM specs. The modified code is under #ifdef VBOX_WITH_PDM_AUDIO_DRIVER

src/VBox/Main/src-client: Driver for the VRDE that interacts with DrvAudio. Enhancement of the CFGM tree for audio.

Config.kmk : addition of one configuration parameter that will control whether new audio code is disabled or enabled. "VBOX_WITH_PDM_AUDIO_DRIVER"

pdmaudioifs.h: common header file between Device , Intermediate audio driver and Backends specific to audio.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 39.3 KB
Line 
1/* $Id: ConsoleImpl.h 50686 2014-03-04 19:21:18Z vboxsync $ */
2/** @file
3 * VBox Console COM Class definition
4 */
5
6/*
7 * Copyright (C) 2005-2013 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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
323private:
324
325 /**
326 * Base template for AutoVMCaller and SafeVMPtr. Template arguments
327 * have the same meaning as arguments of Console::addVMCaller().
328 */
329 template <bool taQuiet = false, bool taAllowNullVM = false>
330 class AutoVMCallerBase
331 {
332 public:
333 AutoVMCallerBase(Console *aThat) : mThat(aThat), mRC(S_OK)
334 {
335 Assert(aThat);
336 mRC = aThat->addVMCaller(taQuiet, taAllowNullVM);
337 }
338 ~AutoVMCallerBase()
339 {
340 if (SUCCEEDED(mRC))
341 mThat->releaseVMCaller();
342 }
343 /** Decreases the number of callers before the instance is destroyed. */
344 void releaseCaller()
345 {
346 AssertReturnVoid(SUCCEEDED(mRC));
347 mThat->releaseVMCaller();
348 mRC = E_FAIL;
349 }
350 /** Restores the number of callers after by #release(). #rc() must be
351 * rechecked to ensure the operation succeeded. */
352 void addYY()
353 {
354 AssertReturnVoid(!SUCCEEDED(mRC));
355 mRC = mThat->addVMCaller(taQuiet, taAllowNullVM);
356 }
357 /** Returns the result of Console::addVMCaller() */
358 HRESULT rc() const { return mRC; }
359 /** Shortcut to SUCCEEDED(rc()) */
360 bool isOk() const { return SUCCEEDED(mRC); }
361 protected:
362 Console *mThat;
363 HRESULT mRC;
364 private:
365 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoVMCallerBase)
366 };
367
368#if 0
369 /**
370 * Helper class that protects sections of code using the mpUVM pointer by
371 * automatically calling addVMCaller() on construction and
372 * releaseVMCaller() on destruction. Intended for Console methods dealing
373 * with mpUVM. The usage pattern is:
374 * <code>
375 * AutoVMCaller autoVMCaller(this);
376 * if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();
377 * ...
378 * VMR3ReqCall (mpUVM, ...
379 * </code>
380 *
381 * @note Temporarily locks the argument for writing.
382 *
383 * @sa SafeVMPtr, SafeVMPtrQuiet
384 * @obsolete Use SafeVMPtr
385 */
386 typedef AutoVMCallerBase<false, false> AutoVMCaller;
387#endif
388
389 /**
390 * Same as AutoVMCaller but doesn't set extended error info on failure.
391 *
392 * @note Temporarily locks the argument for writing.
393 * @obsolete Use SafeVMPtrQuiet
394 */
395 typedef AutoVMCallerBase<true, false> AutoVMCallerQuiet;
396
397 /**
398 * Same as AutoVMCaller but allows a null VM pointer (to trigger an error
399 * instead of assertion).
400 *
401 * @note Temporarily locks the argument for writing.
402 * @obsolete Use SafeVMPtr
403 */
404 typedef AutoVMCallerBase<false, true> AutoVMCallerWeak;
405
406 /**
407 * Same as AutoVMCaller but doesn't set extended error info on failure
408 * and allows a null VM pointer (to trigger an error instead of
409 * assertion).
410 *
411 * @note Temporarily locks the argument for writing.
412 * @obsolete Use SafeVMPtrQuiet
413 */
414 typedef AutoVMCallerBase<true, true> AutoVMCallerQuietWeak;
415
416 /**
417 * Base template for SafeVMPtr and SafeVMPtrQuiet.
418 */
419 template<bool taQuiet = false>
420 class SafeVMPtrBase : public AutoVMCallerBase<taQuiet, true>
421 {
422 typedef AutoVMCallerBase<taQuiet, true> Base;
423 public:
424 SafeVMPtrBase(Console *aThat) : Base(aThat), mpUVM(NULL)
425 {
426 if (SUCCEEDED(Base::mRC))
427 Base::mRC = aThat->safeVMPtrRetainer(&mpUVM, taQuiet);
428 }
429 ~SafeVMPtrBase()
430 {
431 if (SUCCEEDED(Base::mRC))
432 release();
433 }
434 /** Direct PUVM access. */
435 PUVM rawUVM() const { return mpUVM; }
436 /** Release the handles. */
437 void release()
438 {
439 AssertReturnVoid(SUCCEEDED(Base::mRC));
440 Base::mThat->safeVMPtrReleaser(&mpUVM);
441 Base::releaseCaller();
442 }
443
444 private:
445 PUVM mpUVM;
446 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(SafeVMPtrBase)
447 };
448
449public:
450
451 /*
452 * Helper class that safely manages the Console::mpUVM pointer
453 * by calling addVMCaller() on construction and releaseVMCaller() on
454 * destruction. Intended for Console children. The usage pattern is:
455 * <code>
456 * Console::SafeVMPtr ptrVM(mParent);
457 * if (!ptrVM.isOk())
458 * return ptrVM.rc();
459 * ...
460 * VMR3ReqCall(ptrVM.rawUVM(), ...
461 * ...
462 * printf("%p\n", ptrVM.rawUVM());
463 * </code>
464 *
465 * @note Temporarily locks the argument for writing.
466 *
467 * @sa SafeVMPtrQuiet, AutoVMCaller
468 */
469 typedef SafeVMPtrBase<false> SafeVMPtr;
470
471 /**
472 * A deviation of SafeVMPtr that doesn't set the error info on failure.
473 * Intended for pieces of code that don't need to return the VM access
474 * failure to the caller. The usage pattern is:
475 * <code>
476 * Console::SafeVMPtrQuiet pVM(mParent);
477 * if (pVM.rc())
478 * VMR3ReqCall(pVM, ...
479 * return S_OK;
480 * </code>
481 *
482 * @note Temporarily locks the argument for writing.
483 *
484 * @sa SafeVMPtr, AutoVMCaller
485 */
486 typedef SafeVMPtrBase<true> SafeVMPtrQuiet;
487
488 class SharedFolderData
489 {
490 public:
491 SharedFolderData()
492 { }
493
494 SharedFolderData(const Utf8Str &aHostPath,
495 bool aWritable,
496 bool aAutoMount)
497 : m_strHostPath(aHostPath),
498 m_fWritable(aWritable),
499 m_fAutoMount(aAutoMount)
500 { }
501
502 // copy constructor
503 SharedFolderData(const SharedFolderData& aThat)
504 : m_strHostPath(aThat.m_strHostPath),
505 m_fWritable(aThat.m_fWritable),
506 m_fAutoMount(aThat.m_fAutoMount)
507 { }
508
509 Utf8Str m_strHostPath;
510 bool m_fWritable;
511 bool m_fAutoMount;
512 };
513
514 /**
515 * Class for managing emulated USB MSDs.
516 */
517 class USBStorageDevice
518 {
519 public:
520 USBStorageDevice()
521 { }
522 /** The UUID associated with the USB device. */
523 RTUUID mUuid;
524 /** Port of the storage device. */
525 LONG iPort;
526 };
527
528 typedef std::map<Utf8Str, ComObjPtr<SharedFolder> > SharedFolderMap;
529 typedef std::map<Utf8Str, SharedFolderData> SharedFolderDataMap;
530 typedef std::map<Utf8Str, ComPtr<IMediumAttachment> > MediumAttachmentMap;
531 typedef std::list <USBStorageDevice> USBStorageDeviceList;
532
533private:
534
535 typedef std::list <ComObjPtr<OUSBDevice> > USBDeviceList;
536 typedef std::list <ComObjPtr<RemoteUSBDevice> > RemoteUSBDeviceList;
537
538 HRESULT addVMCaller(bool aQuiet = false, bool aAllowNullVM = false);
539 void releaseVMCaller();
540 HRESULT safeVMPtrRetainer(PUVM *a_ppUVM, bool aQuiet);
541 void safeVMPtrReleaser(PUVM *a_ppUVM);
542
543 HRESULT consoleInitReleaseLog(const ComPtr<IMachine> aMachine);
544
545 HRESULT powerUp(IProgress **aProgress, bool aPaused);
546 HRESULT powerDown(IProgress *aProgress = NULL);
547
548/* Note: FreeBSD needs this whether netflt is used or not. */
549#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
550 HRESULT attachToTapInterface(INetworkAdapter *networkAdapter);
551 HRESULT detachFromTapInterface(INetworkAdapter *networkAdapter);
552#endif
553 HRESULT powerDownHostInterfaces();
554
555 HRESULT setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
556 HRESULT setMachineStateLocally(MachineState_T aMachineState)
557 {
558 return setMachineState(aMachineState, false /* aUpdateServer */);
559 }
560
561 HRESULT findSharedFolder(const Utf8Str &strName,
562 ComObjPtr<SharedFolder> &aSharedFolder,
563 bool aSetError = false);
564
565 HRESULT fetchSharedFolders(BOOL aGlobal);
566 bool findOtherSharedFolder(const Utf8Str &straName,
567 SharedFolderDataMap::const_iterator &aIt);
568
569 HRESULT createSharedFolder(const Utf8Str &strName, const SharedFolderData &aData);
570 HRESULT removeSharedFolder(const Utf8Str &strName);
571
572 static DECLCALLBACK(int) configConstructor(PUVM pUVM, PVM pVM, void *pvConsole);
573 int configConstructorInner(PUVM pUVM, PVM pVM, AutoWriteLock *pAlock);
574 int configCfgmOverlay(PCFGMNODE pRoot, IVirtualBox *pVirtualBox, IMachine *pMachine);
575 int configDumpAPISettingsTweaks(IVirtualBox *pVirtualBox, IMachine *pMachine);
576
577 int configGraphicsController(PCFGMNODE pDevices,
578 const GraphicsControllerType_T graphicsController,
579 BusAssignmentManager *pBusMgr,
580 const ComPtr<IMachine> &pMachine,
581 const ComPtr<IBIOSSettings> &biosSettings,
582 bool fHMEnabled);
583 int configMediumAttachment(PCFGMNODE pCtlInst,
584 const char *pcszDevice,
585 unsigned uInstance,
586 StorageBus_T enmBus,
587 bool fUseHostIOCache,
588 bool fBuiltinIoCache,
589 bool fSetupMerge,
590 unsigned uMergeSource,
591 unsigned uMergeTarget,
592 IMediumAttachment *pMediumAtt,
593 MachineState_T aMachineState,
594 HRESULT *phrc,
595 bool fAttachDetach,
596 bool fForceUnmount,
597 bool fHotplug,
598 PUVM pUVM,
599 DeviceType_T *paLedDevType);
600 int configMedium(PCFGMNODE pLunL0,
601 bool fPassthrough,
602 DeviceType_T enmType,
603 bool fUseHostIOCache,
604 bool fBuiltinIoCache,
605 bool fSetupMerge,
606 unsigned uMergeSource,
607 unsigned uMergeTarget,
608 const char *pcszBwGroup,
609 bool fDiscard,
610 IMedium *pMedium,
611 MachineState_T aMachineState,
612 HRESULT *phrc);
613 static DECLCALLBACK(int) reconfigureMediumAttachment(Console *pConsole,
614 PUVM pUVM,
615 const char *pcszDevice,
616 unsigned uInstance,
617 StorageBus_T enmBus,
618 bool fUseHostIOCache,
619 bool fBuiltinIoCache,
620 bool fSetupMerge,
621 unsigned uMergeSource,
622 unsigned uMergeTarget,
623 IMediumAttachment *aMediumAtt,
624 MachineState_T aMachineState,
625 HRESULT *phrc);
626 static DECLCALLBACK(int) changeRemovableMedium(Console *pThis,
627 PUVM pUVM,
628 const char *pcszDevice,
629 unsigned uInstance,
630 StorageBus_T enmBus,
631 bool fUseHostIOCache,
632 IMediumAttachment *aMediumAtt,
633 bool fForce);
634
635 HRESULT attachRawPCIDevices(PUVM pUVM, BusAssignmentManager *BusMgr, PCFGMNODE pDevices);
636 void attachStatusDriver(PCFGMNODE pCtlInst, PPDMLED *papLeds,
637 uint64_t uFirst, uint64_t uLast,
638 Console::MediumAttachmentMap *pmapMediumAttachments,
639 const char *pcszDevice, unsigned uInstance);
640
641 int configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun,
642 INetworkAdapter *aNetworkAdapter, PCFGMNODE pCfg,
643 PCFGMNODE pLunL0, PCFGMNODE pInst,
644 bool fAttachDetach, bool fIgnoreConnectFailure);
645
646 static DECLCALLBACK(int) configGuestProperties(void *pvConsole, PUVM pUVM);
647 static DECLCALLBACK(int) configGuestControl(void *pvConsole);
648 static DECLCALLBACK(void) vmstateChangeCallback(PUVM pUVM, VMSTATE enmState, VMSTATE enmOldState, void *pvUser);
649 static DECLCALLBACK(int) unplugCpu(Console *pThis, PUVM pUVM, VMCPUID idCpu);
650 static DECLCALLBACK(int) plugCpu(Console *pThis, PUVM pUVM, VMCPUID idCpu);
651 HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PUVM pUVM);
652 HRESULT doCPURemove(ULONG aCpu, PUVM pUVM);
653 HRESULT doCPUAdd(ULONG aCpu, PUVM pUVM);
654
655 HRESULT doNetworkAdapterChange(PUVM pUVM, const char *pszDevice, unsigned uInstance,
656 unsigned uLun, INetworkAdapter *aNetworkAdapter);
657 static DECLCALLBACK(int) changeNetworkAttachment(Console *pThis, PUVM pUVM, const char *pszDevice,
658 unsigned uInstance, unsigned uLun,
659 INetworkAdapter *aNetworkAdapter);
660
661 void changeClipboardMode(ClipboardMode_T aClipboardMode);
662 void changeDragAndDropMode(DragAndDropMode_T aDragAndDropMode);
663
664#ifdef VBOX_WITH_USB
665 HRESULT attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs);
666 HRESULT detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice);
667
668 static DECLCALLBACK(int) usbAttachCallback(Console *that, PUVM pUVM, IUSBDevice *aHostDevice, PCRTUUID aUuid,
669 bool aRemote, const char *aAddress, void *pvRemoteBackend, USHORT aPortVersion, ULONG aMaskedIfs);
670 static DECLCALLBACK(int) usbDetachCallback(Console *that, PUVM pUVM, PCRTUUID aUuid);
671#endif
672
673 static DECLCALLBACK(int) attachStorageDevice(Console *pThis,
674 PUVM pUVM,
675 const char *pcszDevice,
676 unsigned uInstance,
677 StorageBus_T enmBus,
678 bool fUseHostIOCache,
679 IMediumAttachment *aMediumAtt,
680 bool fSilent);
681 static DECLCALLBACK(int) detachStorageDevice(Console *pThis,
682 PUVM pUVM,
683 const char *pcszDevice,
684 unsigned uInstance,
685 StorageBus_T enmBus,
686 IMediumAttachment *aMediumAtt,
687 bool fSilent);
688 HRESULT doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PUVM pUVM, bool fSilent);
689 HRESULT doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PUVM pUVM, bool fSilent);
690
691 static DECLCALLBACK(int) fntTakeSnapshotWorker(RTTHREAD Thread, void *pvUser);
692
693 static DECLCALLBACK(int) stateProgressCallback(PUVM pUVM, unsigned uPercent, void *pvUser);
694
695 static DECLCALLBACK(void) genericVMSetErrorCallback(PUVM pUVM, void *pvUser, int rc, RT_SRC_POS_DECL,
696 const char *pszErrorFmt, va_list va);
697
698 void setVMRuntimeErrorCallbackF(uint32_t fFatal, const char *pszErrorId, const char *pszFormat, ...);
699 static DECLCALLBACK(void) setVMRuntimeErrorCallback(PUVM pUVM, void *pvUser, uint32_t fFatal,
700 const char *pszErrorId, const char *pszFormat, va_list va);
701
702 HRESULT captureUSBDevices(PUVM pUVM);
703 void detachAllUSBDevices(bool aDone);
704
705 static DECLCALLBACK(int) powerUpThread(RTTHREAD Thread, void *pvUser);
706 static DECLCALLBACK(int) saveStateThread(RTTHREAD Thread, void *pvUser);
707 static DECLCALLBACK(int) powerDownThread(RTTHREAD Thread, void *pvUser);
708
709 static DECLCALLBACK(int) vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
710 static DECLCALLBACK(void) vmm2User_NotifyEmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
711 static DECLCALLBACK(void) vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
712 static DECLCALLBACK(void) vmm2User_NotifyPdmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM);
713 static DECLCALLBACK(void) vmm2User_NotifyPdmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM);
714 static DECLCALLBACK(void) vmm2User_NotifyResetTurnedIntoPowerOff(PCVMM2USERMETHODS pThis, PUVM pUVM);
715
716 static DECLCALLBACK(void *) drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
717 static DECLCALLBACK(void) drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
718 static DECLCALLBACK(int) drvStatus_MediumEjected(PPDMIMEDIANOTIFY pInterface, unsigned iLUN);
719 static DECLCALLBACK(void) drvStatus_Destruct(PPDMDRVINS pDrvIns);
720 static DECLCALLBACK(int) drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
721
722 int mcAudioRefs;
723 volatile uint32_t mcVRDPClients;
724 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
725 volatile bool mcGuestCredentialsProvided;
726
727 static const char *sSSMConsoleUnit;
728 static uint32_t sSSMConsoleVer;
729
730 HRESULT loadDataFromSavedState();
731 int loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
732
733 static DECLCALLBACK(void) saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
734 static DECLCALLBACK(int) loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
735
736#ifdef VBOX_WITH_GUEST_PROPS
737 static DECLCALLBACK(int) doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
738 HRESULT doEnumerateGuestProperties(CBSTR aPatterns,
739 ComSafeArrayOut(BSTR, aNames),
740 ComSafeArrayOut(BSTR, aValues),
741 ComSafeArrayOut(LONG64, aTimestamps),
742 ComSafeArrayOut(BSTR, aFlags));
743
744 void guestPropertiesHandleVMReset(void);
745 bool guestPropertiesVRDPEnabled(void);
746 void guestPropertiesVRDPUpdateLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
747 void guestPropertiesVRDPUpdateActiveClient(uint32_t u32ClientId);
748 void guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached);
749 void guestPropertiesVRDPUpdateNameChange(uint32_t u32ClientId, const char *pszName);
750 void guestPropertiesVRDPUpdateIPAddrChange(uint32_t u32ClientId, const char *pszIPAddr);
751 void guestPropertiesVRDPUpdateLocationChange(uint32_t u32ClientId, const char *pszLocation);
752 void guestPropertiesVRDPUpdateOtherInfoChange(uint32_t u32ClientId, const char *pszOtherInfo);
753 void guestPropertiesVRDPUpdateDisconnect(uint32_t u32ClientId);
754#endif
755
756 bool isResetTurnedIntoPowerOff(void);
757
758 /** @name Teleporter support
759 * @{ */
760 static DECLCALLBACK(int) teleporterSrcThreadWrapper(RTTHREAD hThread, void *pvUser);
761 HRESULT teleporterSrc(TeleporterStateSrc *pState);
762 HRESULT teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
763 HRESULT teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
764 HRESULT teleporterTrg(PUVM pUVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
765 Progress *pProgress, bool *pfPowerOffOnFailure);
766 static DECLCALLBACK(int) teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
767 /** @} */
768
769 bool mSavedStateDataLoaded : 1;
770
771 const ComPtr<IMachine> mMachine;
772 const ComPtr<IInternalMachineControl> mControl;
773
774 const ComPtr<IVRDEServer> mVRDEServer;
775
776 ConsoleVRDPServer * const mConsoleVRDPServer;
777 bool mfVRDEChangeInProcess;
778 bool mfVRDEChangePending;
779
780 const ComObjPtr<Guest> mGuest;
781 const ComObjPtr<Keyboard> mKeyboard;
782 const ComObjPtr<Mouse> mMouse;
783 const ComObjPtr<Display> mDisplay;
784 const ComObjPtr<MachineDebugger> mDebugger;
785 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
786 /** This can safely be used without holding any locks.
787 * An AutoCaller suffices to prevent it being destroy while in use and
788 * internally there is a lock providing the necessary serialization. */
789 const ComObjPtr<EventSource> mEventSource;
790#ifdef VBOX_WITH_EXTPACK
791 const ComObjPtr<ExtPackManager> mptrExtPackManager;
792#endif
793 const ComObjPtr<EmulatedUSB> mEmulatedUSB;
794
795 USBDeviceList mUSBDevices;
796 RemoteUSBDeviceList mRemoteUSBDevices;
797
798 SharedFolderDataMap m_mapGlobalSharedFolders;
799 SharedFolderDataMap m_mapMachineSharedFolders;
800 SharedFolderMap m_mapSharedFolders; // the console instances
801
802 /** The user mode VM handle. */
803 PUVM mpUVM;
804 /** Holds the number of "readonly" mpUVM callers (users). */
805 uint32_t mVMCallers;
806 /** Semaphore posted when the number of mpUVM callers drops to zero. */
807 RTSEMEVENT mVMZeroCallersSem;
808 /** true when Console has entered the mpUVM destruction phase. */
809 bool mVMDestroying : 1;
810 /** true when power down is initiated by vmstateChangeCallback (EMT). */
811 bool mVMPoweredOff : 1;
812 /** true when vmstateChangeCallback shouldn't initiate a power down. */
813 bool mVMIsAlreadyPoweringOff : 1;
814 /** true if we already showed the snapshot folder size warning. */
815 bool mfSnapshotFolderSizeWarningShown : 1;
816 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
817 bool mfSnapshotFolderExt4WarningShown : 1;
818 /** true if we already listed the disk type of the snapshot folder. */
819 bool mfSnapshotFolderDiskTypeShown : 1;
820 /** true if a USB controller is available (i.e. USB devices can be attached). */
821 bool mfVMHasUsbController : 1;
822 /** true if the VM power off was caused by reset. */
823 bool mfPowerOffCausedByReset : 1;
824
825 /** Pointer to the VMM -> User (that's us) callbacks. */
826 struct MYVMM2USERMETHODS : public VMM2USERMETHODS
827 {
828 Console *pConsole;
829 } *mpVmm2UserMethods;
830
831 /** The current network attachment type in the VM.
832 * This doesn't have to match the network attachment type maintained in the
833 * NetworkAdapter. This is needed to change the network attachment
834 * dynamically.
835 */
836 typedef std::vector<NetworkAttachmentType_T> NetworkAttachmentTypeVector;
837 NetworkAttachmentTypeVector meAttachmentType;
838
839 VMMDev * m_pVMMDev;
840#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
841 AudioVRDE * const mAudioVRDE;
842#else
843 AudioSniffer * const mAudioSniffer;
844#endif
845 Nvram * const mNvram;
846#ifdef VBOX_WITH_USB_CARDREADER
847 UsbCardReader * const mUsbCardReader;
848#endif
849 BusAssignmentManager* mBusMgr;
850
851 enum
852 {
853 iLedFloppy = 0,
854 cLedFloppy = 2,
855 iLedIde = iLedFloppy + cLedFloppy,
856 cLedIde = 4,
857 iLedSata = iLedIde + cLedIde,
858 cLedSata = 30,
859 iLedScsi = iLedSata + cLedSata,
860 cLedScsi = 16,
861 iLedSas = iLedScsi + cLedScsi,
862 cLedSas = 8,
863 iLedUsb = iLedSas + cLedSas,
864 cLedUsb = 8,
865 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas + cLedUsb
866 };
867 DeviceType_T maStorageDevType[cLedStorage];
868 PPDMLED mapStorageLeds[cLedStorage];
869 PPDMLED mapNetworkLeds[36]; /**< @todo adapt this to the maximum network card count */
870 PPDMLED mapSharedFolderLed;
871 PPDMLED mapUSBLed[2];
872
873 MediumAttachmentMap mapMediumAttachments;
874
875 /** List of attached USB storage devices. */
876 USBStorageDeviceList mUSBStorageDevices;
877
878/* Note: FreeBSD needs this whether netflt is used or not. */
879#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
880 Utf8Str maTAPDeviceName[8];
881 RTFILE maTapFD[8];
882#endif
883
884 bool mVMStateChangeCallbackDisabled;
885
886 bool mfUseHostClipboard;
887
888 /** Local machine state value. */
889 MachineState_T mMachineState;
890
891 /** Pointer to the progress object of a live cancelable task.
892 *
893 * This is currently only used by Console::Teleport(), but is intended to later
894 * be used by the live snapshot code path as well. Actions like
895 * Console::PowerDown, which automatically cancels out the running snapshot /
896 * teleportation operation, will cancel the teleportation / live snapshot
897 * operation before starting. */
898 ComObjPtr<Progress> mptrCancelableProgress;
899
900 /* The purpose of caching of some events is probably in order to
901 automatically fire them at new event listeners. However, there is no
902 (longer?) any code making use of this... */
903#ifdef CONSOLE_WITH_EVENT_CACHE
904 struct
905 {
906 /** OnMousePointerShapeChange() cache */
907 struct
908 {
909 bool valid;
910 bool visible;
911 bool alpha;
912 uint32_t xHot;
913 uint32_t yHot;
914 uint32_t width;
915 uint32_t height;
916 com::SafeArray<BYTE> shape;
917 } mpsc;
918
919 /** OnMouseCapabilityChange() cache */
920 struct
921 {
922 bool valid;
923 BOOL supportsAbsolute;
924 BOOL supportsRelative;
925 BOOL needsHostCursor;
926 } mcc;
927
928 /** OnKeyboardLedsChange() cache */
929 struct
930 {
931 bool valid;
932 bool numLock;
933 bool capsLock;
934 bool scrollLock;
935 } klc;
936
937 void clear()
938 {
939 RT_ZERO(mcc);
940 RT_ZERO(klc);
941
942 /* We cannot RT_ZERO mpsc because of shape's vtable. */
943 mpsc.shape.setNull();
944 mpsc.valid = mpsc.visible = mpsc.alpha = false;
945 mpsc.xHot = mpsc.yHot = mpsc.width = mpsc.height = 0;
946 }
947 } mCallbackData;
948#endif
949 ComPtr<IEventListener> mVmListener;
950
951 friend struct VMTask;
952};
953
954#endif // !____H_CONSOLEIMPL
955/* 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