VirtualBox

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

Last change on this file since 41214 was 41214, checked in by vboxsync, 13 years ago

Main: move handleUnexpectedExceptions method to VirtualBoxBase

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