VirtualBox

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

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

Runtime: new guest OS type for Solaris 11
Frontends/VirtualBox: add new patterns for Solaris 11 guest OS type, reuse the icon
Frontends/VBoxManage: more details for "list ostypes"
Main/xml: make guest OS type in config file an arbitrary string (still validated/mapped in the old way in the settings code), remove hardcoded limit of 8 network adapters
Main/Global: move list of valid guest OS types into a single place, add function to get the network adapter limit for each chipset type
Main/Console+Machine+Snapshot+NetworkAdapter+Appliance+VirtualBox+Guest+SystemProperties: consistently use the appropriate network adapter limit so that ICH9 chipset can use 36 network adapters, adapt to cleaned up guest OS type handling, remove leftover rendundant guest OS mapping, whitespace
Network/NAT: release log message cosmetics, allow unlimited number of instances, fix maxconn clamping
Network/PCNet+VirtioNet+E1000: allow unlimited number of instances

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette