VirtualBox

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

Last change on this file since 48297 was 48297, checked in by vboxsync, 12 years ago

Main/Medium: redesign API level medium locking, needed conversions from MediaList to MediumLockLists in several places, forced cleanups elsewhere, too
Main/Token: introduced token objects for controlling the unlocking, will be used as a general concept in the future
Main/Snapshot: snapshot deletion needed significant cleanups as it was still using many shortcuts, directly calling the API to lock media instead of using lock lists. Now much better, and the online snapshot deletion is also a lot cleaner as it no longer passes unnecessary parameters around which are already known in the machine/snapshot code
Main/MediumLock: small improvements, now has a mode which skips locking already locked media, needed by the Snapshot code where we have overlapping lock lists and have to update the original one instead
Main/Console+Session+Machine: follow-up changes for the online snapshot merging parameter passing simplification, plus an unrelated lock order violation fix in Machine which happens only for inaccessible machines
Main/testcase: update correspondingly
doc: update SDK reference

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