VirtualBox

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

Last change on this file since 37813 was 37813, checked in by vboxsync, 14 years ago

Main: check for the existance of the extension pack for PCI passthrough

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