VirtualBox

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

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

Main,VBoxManage: Implemented IConsole::EmulatedUSB. Removed IMachine::emulatedUSBWebcameraEnabled.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 38.2 KB
Line 
1/* $Id: ConsoleImpl.h 48406 2013-09-10 12:53:50Z 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.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ____H_CONSOLEIMPL
19#define ____H_CONSOLEIMPL
20
21#include "VirtualBoxBase.h"
22#include "VBox/com/array.h"
23#include "EventImpl.h"
24
25class Guest;
26class Keyboard;
27class Mouse;
28class Display;
29class MachineDebugger;
30class TeleporterStateSrc;
31class OUSBDevice;
32class RemoteUSBDevice;
33class SharedFolder;
34class VRDEServerInfo;
35class EmulatedUSB;
36class AudioSniffer;
37class Nvram;
38class EmWebcam;
39#ifdef VBOX_WITH_USB_CARDREADER
40class UsbCardReader;
41#endif
42class ConsoleVRDPServer;
43class VMMDev;
44class Progress;
45class BusAssignmentManager;
46COM_STRUCT_OR_CLASS(IEventListener);
47#ifdef VBOX_WITH_EXTPACK
48class ExtPackManager;
49#endif
50class VMMDevMouseInterface;
51class DisplayMouseInterface;
52
53#include <VBox/RemoteDesktop/VRDE.h>
54#include <VBox/vmm/pdmdrv.h>
55#ifdef VBOX_WITH_GUEST_PROPS
56# include <VBox/HostServices/GuestPropertySvc.h> /* For the property notification callback */
57#endif
58
59#ifdef RT_OS_WINDOWS
60# include "../src-server/win/VBoxComEvents.h"
61#endif
62
63struct VUSBIRHCONFIG;
64typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
65
66#include <list>
67#include <vector>
68
69// defines
70///////////////////////////////////////////////////////////////////////////////
71
72/**
73 * Checks the availability of the underlying VM device driver corresponding
74 * to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
75 * not available (NULL), sets error info and returns returns E_ACCESSDENIED.
76 * The translatable error message is defined in null context.
77 *
78 * Intended to used only within Console children (i.e. Keyboard, Mouse,
79 * Display, etc.).
80 *
81 * @param drv driver pointer to check (compare it with NULL)
82 */
83#define CHECK_CONSOLE_DRV(drv) \
84 do { \
85 if (!(drv)) \
86 return setError(E_ACCESSDENIED, tr("The console is not powered up")); \
87 } while (0)
88
89// Console
90///////////////////////////////////////////////////////////////////////////////
91
92class ConsoleMouseInterface
93{
94public:
95 virtual VMMDevMouseInterface *getVMMDevMouseInterface() = 0;
96 virtual DisplayMouseInterface *getDisplayMouseInterface() = 0;
97 virtual void onMouseCapabilityChange(BOOL supportsAbsolute,
98 BOOL supportsRelative,
99 BOOL supportsMT,
100 BOOL needsHostCursor) = 0;
101};
102
103/** IConsole implementation class */
104class ATL_NO_VTABLE Console :
105 public VirtualBoxBase,
106 VBOX_SCRIPTABLE_IMPL(IConsole), public ConsoleMouseInterface
107{
108 Q_OBJECT
109
110public:
111
112 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Console, IConsole)
113
114 DECLARE_NOT_AGGREGATABLE(Console)
115
116 DECLARE_PROTECT_FINAL_CONSTRUCT()
117
118 BEGIN_COM_MAP(Console)
119 VBOX_DEFAULT_INTERFACE_ENTRIES(IConsole)
120 END_COM_MAP()
121
122 Console();
123 ~Console();
124
125 HRESULT FinalConstruct();
126 void FinalRelease();
127
128 // public initializers/uninitializers for internal purposes only
129 HRESULT init(IMachine *aMachine, IInternalMachineControl *aControl, LockType_T aLockType);
130 void uninit();
131
132 // IConsole properties
133 STDMETHOD(COMGETTER(Machine))(IMachine **aMachine);
134 STDMETHOD(COMGETTER(State))(MachineState_T *aMachineState);
135 STDMETHOD(COMGETTER(Guest))(IGuest **aGuest);
136 STDMETHOD(COMGETTER(Keyboard))(IKeyboard **aKeyboard);
137 STDMETHOD(COMGETTER(Mouse))(IMouse **aMouse);
138 STDMETHOD(COMGETTER(Display))(IDisplay **aDisplay);
139 STDMETHOD(COMGETTER(Debugger))(IMachineDebugger **aDebugger);
140 STDMETHOD(COMGETTER(USBDevices))(ComSafeArrayOut(IUSBDevice *, aUSBDevices));
141 STDMETHOD(COMGETTER(RemoteUSBDevices))(ComSafeArrayOut(IHostUSBDevice *, aRemoteUSBDevices));
142 STDMETHOD(COMGETTER(VRDEServerInfo))(IVRDEServerInfo **aVRDEServerInfo);
143 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
144 STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
145 STDMETHOD(COMGETTER(AttachedPCIDevices))(ComSafeArrayOut(IPCIDeviceAttachment *, aAttachments));
146 STDMETHOD(COMGETTER(UseHostClipboard))(BOOL *aUseHostClipboard);
147 STDMETHOD(COMSETTER(UseHostClipboard))(BOOL aUseHostClipboard);
148 STDMETHOD(COMGETTER(EmulatedUSB))(IEmulatedUSB **aEmulatedUSB);
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
224 HRESULT getGuestProperty(IN_BSTR aKey, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
225 HRESULT setGuestProperty(IN_BSTR aKey, IN_BSTR aValue, IN_BSTR aFlags);
226 HRESULT enumerateGuestProperties(IN_BSTR aPatterns,
227 ComSafeArrayOut(BSTR, aNames),
228 ComSafeArrayOut(BSTR, aValues),
229 ComSafeArrayOut(LONG64, aTimestamps),
230 ComSafeArrayOut(BSTR, aFlags));
231 HRESULT onlineMergeMedium(IMediumAttachment *aMediumAttachment,
232 ULONG aSourceIdx, ULONG aTargetIdx,
233 IProgress *aProgress);
234 int hgcmLoadService(const char *pszServiceLibrary, const char *pszServiceName);
235 VMMDev *getVMMDev() { return m_pVMMDev; }
236 AudioSniffer *getAudioSniffer() { return mAudioSniffer; }
237#ifdef VBOX_WITH_EXTPACK
238 ExtPackManager *getExtPackManager();
239#endif
240 EventSource *getEventSource() { return mEventSource; }
241#ifdef VBOX_WITH_USB_CARDREADER
242 UsbCardReader *getUsbCardReader() { return mUsbCardReader; }
243#endif
244 EmWebcam *getEmWebcam() { return mEmWebcam; }
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 const ComObjPtr<EmulatedUSB> mEmulatedUSB;
763
764 USBDeviceList mUSBDevices;
765 RemoteUSBDeviceList mRemoteUSBDevices;
766
767 SharedFolderDataMap m_mapGlobalSharedFolders;
768 SharedFolderDataMap m_mapMachineSharedFolders;
769 SharedFolderMap m_mapSharedFolders; // the console instances
770
771 /** The user mode VM handle. */
772 PUVM mpUVM;
773 /** Holds the number of "readonly" mpUVM callers (users). */
774 uint32_t mVMCallers;
775 /** Semaphore posted when the number of mpUVM callers drops to zero. */
776 RTSEMEVENT mVMZeroCallersSem;
777 /** true when Console has entered the mpUVM destruction phase. */
778 bool mVMDestroying : 1;
779 /** true when power down is initiated by vmstateChangeCallback (EMT). */
780 bool mVMPoweredOff : 1;
781 /** true when vmstateChangeCallback shouldn't initiate a power down. */
782 bool mVMIsAlreadyPoweringOff : 1;
783 /** true if we already showed the snapshot folder size warning. */
784 bool mfSnapshotFolderSizeWarningShown : 1;
785 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
786 bool mfSnapshotFolderExt4WarningShown : 1;
787 /** true if we already listed the disk type of the snapshot folder. */
788 bool mfSnapshotFolderDiskTypeShown : 1;
789 /** true if a USB controller is available (i.e. USB devices can be attached). */
790 bool mfVMHasUsbController : 1;
791
792 /** Pointer to the VMM -> User (that's us) callbacks. */
793 struct MYVMM2USERMETHODS : public VMM2USERMETHODS
794 {
795 Console *pConsole;
796 } *mpVmm2UserMethods;
797
798 /** The current network attachment type in the VM.
799 * This doesn't have to match the network attachment type maintained in the
800 * NetworkAdapter. This is needed to change the network attachment
801 * dynamically.
802 */
803 typedef std::vector<NetworkAttachmentType_T> NetworkAttachmentTypeVector;
804 NetworkAttachmentTypeVector meAttachmentType;
805
806 VMMDev * m_pVMMDev;
807 AudioSniffer * const mAudioSniffer;
808 Nvram * const mNvram;
809 EmWebcam * const mEmWebcam;
810#ifdef VBOX_WITH_USB_CARDREADER
811 UsbCardReader * const mUsbCardReader;
812#endif
813 BusAssignmentManager* mBusMgr;
814
815 enum
816 {
817 iLedFloppy = 0,
818 cLedFloppy = 2,
819 iLedIde = iLedFloppy + cLedFloppy,
820 cLedIde = 4,
821 iLedSata = iLedIde + cLedIde,
822 cLedSata = 30,
823 iLedScsi = iLedSata + cLedSata,
824 cLedScsi = 16,
825 iLedSas = iLedScsi + cLedScsi,
826 cLedSas = 8,
827 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas
828 };
829 DeviceType_T maStorageDevType[cLedStorage];
830 PPDMLED mapStorageLeds[cLedStorage];
831 PPDMLED mapNetworkLeds[36]; /**< @todo adapt this to the maximum network card count */
832 PPDMLED mapSharedFolderLed;
833 PPDMLED mapUSBLed[2];
834
835 MediumAttachmentMap mapMediumAttachments;
836
837/* Note: FreeBSD needs this whether netflt is used or not. */
838#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
839 Utf8Str maTAPDeviceName[8];
840 RTFILE maTapFD[8];
841#endif
842
843 bool mVMStateChangeCallbackDisabled;
844
845 bool mfUseHostClipboard;
846
847 /** Local machine state value. */
848 MachineState_T mMachineState;
849
850 /** Pointer to the progress object of a live cancelable task.
851 *
852 * This is currently only used by Console::Teleport(), but is intended to later
853 * be used by the live snapshot code path as well. Actions like
854 * Console::PowerDown, which automatically cancels out the running snapshot /
855 * teleportation operation, will cancel the teleportation / live snapshot
856 * operation before starting. */
857 ComObjPtr<Progress> mptrCancelableProgress;
858
859 /* The purpose of caching of some events is probably in order to
860 automatically fire them at new event listeners. However, there is no
861 (longer?) any code making use of this... */
862#ifdef CONSOLE_WITH_EVENT_CACHE
863 struct
864 {
865 /** OnMousePointerShapeChange() cache */
866 struct
867 {
868 bool valid;
869 bool visible;
870 bool alpha;
871 uint32_t xHot;
872 uint32_t yHot;
873 uint32_t width;
874 uint32_t height;
875 com::SafeArray<BYTE> shape;
876 } mpsc;
877
878 /** OnMouseCapabilityChange() cache */
879 struct
880 {
881 bool valid;
882 BOOL supportsAbsolute;
883 BOOL supportsRelative;
884 BOOL needsHostCursor;
885 } mcc;
886
887 /** OnKeyboardLedsChange() cache */
888 struct
889 {
890 bool valid;
891 bool numLock;
892 bool capsLock;
893 bool scrollLock;
894 } klc;
895
896 void clear()
897 {
898 RT_ZERO(mcc);
899 RT_ZERO(klc);
900
901 /* We cannot RT_ZERO mpsc because of shape's vtable. */
902 mpsc.shape.setNull();
903 mpsc.valid = mpsc.visible = mpsc.alpha = false;
904 mpsc.xHot = mpsc.yHot = mpsc.width = mpsc.height = 0;
905 }
906 } mCallbackData;
907#endif
908 ComPtr<IEventListener> mVmListener;
909
910 friend struct VMTask;
911};
912
913#endif // !____H_CONSOLEIMPL
914/* 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