VirtualBox

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

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

ConsoleImpl: SafeVMPtr mRC priority.

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