VirtualBox

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

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

Main/Console: dump the VBoxInternal2 extradata settings since they influence the API behavior and are not visible elsewhere

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