VirtualBox

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

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

Main: emulated webcam updates.

  • 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 49120 2013-10-15 15:12:06Z 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;
38#ifdef VBOX_WITH_USB_CARDREADER
39class UsbCardReader;
40#endif
41class ConsoleVRDPServer;
42class VMMDev;
43class Progress;
44class BusAssignmentManager;
45COM_STRUCT_OR_CLASS(IEventListener);
46#ifdef VBOX_WITH_EXTPACK
47class ExtPackManager;
48#endif
49class VMMDevMouseInterface;
50class DisplayMouseInterface;
51
52#include <iprt/uuid.h>
53#include <VBox/RemoteDesktop/VRDE.h>
54#include <VBox/vmm/pdmdrv.h>
55#ifdef VBOX_WITH_GUEST_PROPS
56# include <VBox/HostServices/GuestPropertySvc.h> /* For the property notification callback */
57#endif
58
59#ifdef RT_OS_WINDOWS
60# include "../src-server/win/VBoxComEvents.h"
61#endif
62
63struct VUSBIRHCONFIG;
64typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
65
66#include <list>
67#include <vector>
68
69// defines
70///////////////////////////////////////////////////////////////////////////////
71
72/**
73 * Checks the availability of the underlying VM device driver corresponding
74 * to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
75 * not available (NULL), sets error info and returns returns E_ACCESSDENIED.
76 * The translatable error message is defined in null context.
77 *
78 * Intended to used only within Console children (i.e. Keyboard, Mouse,
79 * Display, etc.).
80 *
81 * @param drv driver pointer to check (compare it with NULL)
82 */
83#define CHECK_CONSOLE_DRV(drv) \
84 do { \
85 if (!(drv)) \
86 return setError(E_ACCESSDENIED, tr("The console is not powered up")); \
87 } while (0)
88
89// Console
90///////////////////////////////////////////////////////////////////////////////
91
92class ConsoleMouseInterface
93{
94public:
95 virtual VMMDevMouseInterface *getVMMDevMouseInterface() = 0;
96 virtual DisplayMouseInterface *getDisplayMouseInterface() = 0;
97 virtual void onMouseCapabilityChange(BOOL supportsAbsolute,
98 BOOL supportsRelative,
99 BOOL supportsMT,
100 BOOL needsHostCursor) = 0;
101};
102
103/** IConsole implementation class */
104class ATL_NO_VTABLE Console :
105 public VirtualBoxBase,
106 VBOX_SCRIPTABLE_IMPL(IConsole), public ConsoleMouseInterface
107{
108 Q_OBJECT
109
110public:
111
112 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Console, IConsole)
113
114 DECLARE_NOT_AGGREGATABLE(Console)
115
116 DECLARE_PROTECT_FINAL_CONSTRUCT()
117
118 BEGIN_COM_MAP(Console)
119 VBOX_DEFAULT_INTERFACE_ENTRIES(IConsole)
120 END_COM_MAP()
121
122 Console();
123 ~Console();
124
125 HRESULT FinalConstruct();
126 void FinalRelease();
127
128 // public initializers/uninitializers for internal purposes only
129 HRESULT init(IMachine *aMachine, IInternalMachineControl *aControl, LockType_T aLockType);
130 void uninit();
131
132 // IConsole properties
133 STDMETHOD(COMGETTER(Machine))(IMachine **aMachine);
134 STDMETHOD(COMGETTER(State))(MachineState_T *aMachineState);
135 STDMETHOD(COMGETTER(Guest))(IGuest **aGuest);
136 STDMETHOD(COMGETTER(Keyboard))(IKeyboard **aKeyboard);
137 STDMETHOD(COMGETTER(Mouse))(IMouse **aMouse);
138 STDMETHOD(COMGETTER(Display))(IDisplay **aDisplay);
139 STDMETHOD(COMGETTER(Debugger))(IMachineDebugger **aDebugger);
140 STDMETHOD(COMGETTER(USBDevices))(ComSafeArrayOut(IUSBDevice *, aUSBDevices));
141 STDMETHOD(COMGETTER(RemoteUSBDevices))(ComSafeArrayOut(IHostUSBDevice *, aRemoteUSBDevices));
142 STDMETHOD(COMGETTER(VRDEServerInfo))(IVRDEServerInfo **aVRDEServerInfo);
143 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
144 STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
145 STDMETHOD(COMGETTER(AttachedPCIDevices))(ComSafeArrayOut(IPCIDeviceAttachment *, aAttachments));
146 STDMETHOD(COMGETTER(UseHostClipboard))(BOOL *aUseHostClipboard);
147 STDMETHOD(COMSETTER(UseHostClipboard))(BOOL aUseHostClipboard);
148 STDMETHOD(COMGETTER(EmulatedUSB))(IEmulatedUSB **aEmulatedUSB);
149
150 // IConsole methods
151 STDMETHOD(PowerUp)(IProgress **aProgress);
152 STDMETHOD(PowerUpPaused)(IProgress **aProgress);
153 STDMETHOD(PowerDown)(IProgress **aProgress);
154 STDMETHOD(Reset)();
155 STDMETHOD(Pause)();
156 STDMETHOD(Resume)();
157 STDMETHOD(PowerButton)();
158 STDMETHOD(SleepButton)();
159 STDMETHOD(GetPowerButtonHandled)(BOOL *aHandled);
160 STDMETHOD(GetGuestEnteredACPIMode)(BOOL *aEntered);
161 STDMETHOD(SaveState)(IProgress **aProgress);
162 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
163 STDMETHOD(DiscardSavedState)(BOOL aRemoveFile);
164 STDMETHOD(GetDeviceActivity)(DeviceType_T aDeviceType,
165 DeviceActivity_T *aDeviceActivity);
166 STDMETHOD(AttachUSBDevice)(IN_BSTR aId);
167 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, IUSBDevice **aDevice);
168 STDMETHOD(FindUSBDeviceByAddress)(IN_BSTR aAddress, IUSBDevice **aDevice);
169 STDMETHOD(FindUSBDeviceById)(IN_BSTR aId, IUSBDevice **aDevice);
170 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
171 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
172 STDMETHOD(TakeSnapshot)(IN_BSTR aName, IN_BSTR aDescription,
173 IProgress **aProgress);
174 STDMETHOD(DeleteSnapshot)(IN_BSTR aId, IProgress **aProgress);
175 STDMETHOD(DeleteSnapshotAndAllChildren)(IN_BSTR aId, IProgress **aProgress);
176 STDMETHOD(DeleteSnapshotRange)(IN_BSTR aStartId, IN_BSTR aEndId, IProgress **aProgress);
177 STDMETHOD(RestoreSnapshot)(ISnapshot *aSnapshot, IProgress **aProgress);
178 STDMETHOD(Teleport)(IN_BSTR aHostname, ULONG aPort, IN_BSTR aPassword, ULONG aMaxDowntime, IProgress **aProgress);
179
180 // public methods for internal purposes only
181
182 /*
183 * Note: the following methods do not increase refcount. intended to be
184 * called only by the VM execution thread.
185 */
186
187 Guest *getGuest() const { return mGuest; }
188 Keyboard *getKeyboard() const { return mKeyboard; }
189 Mouse *getMouse() const { return mMouse; }
190 Display *getDisplay() const { return mDisplay; }
191 MachineDebugger *getMachineDebugger() const { return mDebugger; }
192 AudioSniffer *getAudioSniffer() const { return mAudioSniffer; }
193
194 const ComPtr<IMachine> &machine() const { return mMachine; }
195
196 bool useHostClipboard() { return mfUseHostClipboard; }
197
198 /** Method is called only from ConsoleVRDPServer */
199 IVRDEServer *getVRDEServer() const { return mVRDEServer; }
200
201 ConsoleVRDPServer *consoleVRDPServer() const { return mConsoleVRDPServer; }
202
203 HRESULT updateMachineState(MachineState_T aMachineState);
204
205 // events from IInternalSessionControl
206 HRESULT onNetworkAdapterChange(INetworkAdapter *aNetworkAdapter, BOOL changeAdapter);
207 HRESULT onSerialPortChange(ISerialPort *aSerialPort);
208 HRESULT onParallelPortChange(IParallelPort *aParallelPort);
209 HRESULT onStorageControllerChange();
210 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
211 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
212 HRESULT onCPUExecutionCapChange(ULONG aExecutionCap);
213 HRESULT onClipboardModeChange(ClipboardMode_T aClipboardMode);
214 HRESULT onDragAndDropModeChange(DragAndDropMode_T aDragAndDropMode);
215 HRESULT onVRDEServerChange(BOOL aRestart);
216 HRESULT onVideoCaptureChange();
217 HRESULT onUSBControllerChange();
218 HRESULT onSharedFolderChange(BOOL aGlobal);
219 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice, IVirtualBoxErrorInfo *aError, ULONG aMaskedIfs);
220 HRESULT onUSBDeviceDetach(IN_BSTR aId, IVirtualBoxErrorInfo *aError);
221 HRESULT onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
222 HRESULT onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
223
224 HRESULT getGuestProperty(IN_BSTR aKey, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
225 HRESULT setGuestProperty(IN_BSTR aKey, IN_BSTR aValue, IN_BSTR aFlags);
226 HRESULT enumerateGuestProperties(IN_BSTR aPatterns,
227 ComSafeArrayOut(BSTR, aNames),
228 ComSafeArrayOut(BSTR, aValues),
229 ComSafeArrayOut(LONG64, aTimestamps),
230 ComSafeArrayOut(BSTR, aFlags));
231 HRESULT onlineMergeMedium(IMediumAttachment *aMediumAttachment,
232 ULONG aSourceIdx, ULONG aTargetIdx,
233 IProgress *aProgress);
234 int hgcmLoadService(const char *pszServiceLibrary, const char *pszServiceName);
235 VMMDev *getVMMDev() { return m_pVMMDev; }
236 AudioSniffer *getAudioSniffer() { return mAudioSniffer; }
237#ifdef VBOX_WITH_EXTPACK
238 ExtPackManager *getExtPackManager();
239#endif
240 EventSource *getEventSource() { return mEventSource; }
241#ifdef VBOX_WITH_USB_CARDREADER
242 UsbCardReader *getUsbCardReader() { return mUsbCardReader; }
243#endif
244
245 int VRDPClientLogon(uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
246 void VRDPClientStatusChange(uint32_t u32ClientId, const char *pszStatus);
247 void VRDPClientConnect(uint32_t u32ClientId);
248 void VRDPClientDisconnect(uint32_t u32ClientId, uint32_t fu32Intercepted);
249 void VRDPInterceptAudio(uint32_t u32ClientId);
250 void VRDPInterceptUSB(uint32_t u32ClientId, void **ppvIntercept);
251 void VRDPInterceptClipboard(uint32_t u32ClientId);
252
253 void processRemoteUSBDevices(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevList, uint32_t cbDevList, bool fDescExt);
254 void reportVmStatistics(ULONG aValidStats, ULONG aCpuUser,
255 ULONG aCpuKernel, ULONG aCpuIdle,
256 ULONG aMemTotal, ULONG aMemFree,
257 ULONG aMemBalloon, ULONG aMemShared,
258 ULONG aMemCache, ULONG aPageTotal,
259 ULONG aAllocVMM, ULONG aFreeVMM,
260 ULONG aBalloonedVMM, ULONG aSharedVMM,
261 ULONG aVmNetRx, ULONG aVmNetTx)
262 {
263 mControl->ReportVmStatistics(aValidStats, aCpuUser, aCpuKernel, aCpuIdle,
264 aMemTotal, aMemFree, aMemBalloon, aMemShared,
265 aMemCache, aPageTotal, aAllocVMM, aFreeVMM,
266 aBalloonedVMM, aSharedVMM, aVmNetRx, aVmNetTx);
267 }
268 void enableVMMStatistics(BOOL aEnable);
269
270 HRESULT pause(Reason_T aReason);
271 HRESULT resume(Reason_T aReason);
272 HRESULT saveState(Reason_T aReason, IProgress **aProgress);
273
274 // callback callers (partly; for some events console callbacks are notified
275 // directly from IInternalSessionControl event handlers declared above)
276 void onMousePointerShapeChange(bool fVisible, bool fAlpha,
277 uint32_t xHot, uint32_t yHot,
278 uint32_t width, uint32_t height,
279 ComSafeArrayIn(uint8_t, aShape));
280 void onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative,
281 BOOL supportsMT, BOOL needsHostCursor);
282 void onStateChange(MachineState_T aMachineState);
283 void onAdditionsStateChange();
284 void onAdditionsOutdated();
285 void onKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock);
286 void onUSBDeviceStateChange(IUSBDevice *aDevice, bool aAttached,
287 IVirtualBoxErrorInfo *aError);
288 void onRuntimeError(BOOL aFatal, IN_BSTR aErrorID, IN_BSTR aMessage);
289 HRESULT onShowWindow(BOOL aCheck, BOOL *aCanShow, LONG64 *aWinId);
290 void onVRDEServerInfoChange();
291
292 static const PDMDRVREG DrvStatusReg;
293
294 static HRESULT setErrorStatic(HRESULT aResultCode, const char *pcsz, ...);
295 HRESULT setInvalidMachineStateError();
296
297 static const char *convertControllerTypeToDev(StorageControllerType_T enmCtrlType);
298 static HRESULT convertBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
299 // Called from event listener
300 HRESULT onNATRedirectRuleChange(ULONG ulInstance, BOOL aNatRuleRemove,
301 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
302
303 // Mouse interface
304 VMMDevMouseInterface *getVMMDevMouseInterface();
305 DisplayMouseInterface *getDisplayMouseInterface();
306
307 EmulatedUSB *getEmulatedUSB(void) { return mEmulatedUSB; }
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#ifdef VBOX_WITH_USB_CARDREADER
828 UsbCardReader * const mUsbCardReader;
829#endif
830 BusAssignmentManager* mBusMgr;
831
832 enum
833 {
834 iLedFloppy = 0,
835 cLedFloppy = 2,
836 iLedIde = iLedFloppy + cLedFloppy,
837 cLedIde = 4,
838 iLedSata = iLedIde + cLedIde,
839 cLedSata = 30,
840 iLedScsi = iLedSata + cLedSata,
841 cLedScsi = 16,
842 iLedSas = iLedScsi + cLedScsi,
843 cLedSas = 8,
844 iLedUsb = iLedSas + cLedSas,
845 cLedUsb = 8,
846 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas + cLedUsb
847 };
848 DeviceType_T maStorageDevType[cLedStorage];
849 PPDMLED mapStorageLeds[cLedStorage];
850 PPDMLED mapNetworkLeds[36]; /**< @todo adapt this to the maximum network card count */
851 PPDMLED mapSharedFolderLed;
852 PPDMLED mapUSBLed[2];
853
854 MediumAttachmentMap mapMediumAttachments;
855
856 /** List of attached USB storage devices. */
857 USBStorageDeviceList mUSBStorageDevices;
858
859/* Note: FreeBSD needs this whether netflt is used or not. */
860#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
861 Utf8Str maTAPDeviceName[8];
862 RTFILE maTapFD[8];
863#endif
864
865 bool mVMStateChangeCallbackDisabled;
866
867 bool mfUseHostClipboard;
868
869 /** Local machine state value. */
870 MachineState_T mMachineState;
871
872 /** Pointer to the progress object of a live cancelable task.
873 *
874 * This is currently only used by Console::Teleport(), but is intended to later
875 * be used by the live snapshot code path as well. Actions like
876 * Console::PowerDown, which automatically cancels out the running snapshot /
877 * teleportation operation, will cancel the teleportation / live snapshot
878 * operation before starting. */
879 ComObjPtr<Progress> mptrCancelableProgress;
880
881 /* The purpose of caching of some events is probably in order to
882 automatically fire them at new event listeners. However, there is no
883 (longer?) any code making use of this... */
884#ifdef CONSOLE_WITH_EVENT_CACHE
885 struct
886 {
887 /** OnMousePointerShapeChange() cache */
888 struct
889 {
890 bool valid;
891 bool visible;
892 bool alpha;
893 uint32_t xHot;
894 uint32_t yHot;
895 uint32_t width;
896 uint32_t height;
897 com::SafeArray<BYTE> shape;
898 } mpsc;
899
900 /** OnMouseCapabilityChange() cache */
901 struct
902 {
903 bool valid;
904 BOOL supportsAbsolute;
905 BOOL supportsRelative;
906 BOOL needsHostCursor;
907 } mcc;
908
909 /** OnKeyboardLedsChange() cache */
910 struct
911 {
912 bool valid;
913 bool numLock;
914 bool capsLock;
915 bool scrollLock;
916 } klc;
917
918 void clear()
919 {
920 RT_ZERO(mcc);
921 RT_ZERO(klc);
922
923 /* We cannot RT_ZERO mpsc because of shape's vtable. */
924 mpsc.shape.setNull();
925 mpsc.valid = mpsc.visible = mpsc.alpha = false;
926 mpsc.xHot = mpsc.yHot = mpsc.width = mpsc.height = 0;
927 }
928 } mCallbackData;
929#endif
930 ComPtr<IEventListener> mVmListener;
931
932 friend struct VMTask;
933};
934
935#endif // !____H_CONSOLEIMPL
936/* 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