VirtualBox

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

Last change on this file since 48983 was 48983, checked in by vboxsync, 11 years ago

Main,Frontends: Support for the USB storage controller

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