VirtualBox

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

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

Main/VPX: introduced onVideoCaptureChange event

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