VirtualBox

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

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

Devices/Input: most of the Main plumbing for guest multi-touch.

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