VirtualBox

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

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

Main/Machine+Console+Display+VRDEServer,VBoxManage: allow VMs without graphics controller, eliminate annoying spurious error messages about Console not yet powered up when taking screenshots, getting/setting guest properties and updating metrics, make as many parameters to modifyvm as possible case insensitive

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