VirtualBox

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

Last change on this file since 43507 was 43131, checked in by vboxsync, 12 years ago

EFI: permanent NVRAM storage.

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