VirtualBox

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

Last change on this file since 34181 was 34111, checked in by vboxsync, 14 years ago

Pass RDP credentials to the guest only from one client, when multiple clients connect concurrently (for VDI).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.7 KB
Line 
1/* $Id: ConsoleImpl.h 34111 2010-11-16 12:43:09Z vboxsync $ */
2/** @file
3 * VBox Console COM Class definition
4 */
5
6/*
7 * Copyright (C) 2006-2010 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 "SchemaDefs.h"
23#include "VBox/com/array.h"
24#include "EventImpl.h"
25
26class Guest;
27class Keyboard;
28class Mouse;
29class Display;
30class MachineDebugger;
31class TeleporterStateSrc;
32class OUSBDevice;
33class RemoteUSBDevice;
34class SharedFolder;
35class VRDEServerInfo;
36class AudioSniffer;
37class ConsoleVRDPServer;
38class VMMDev;
39class Progress;
40COM_STRUCT_OR_CLASS(IEventListener);
41#ifdef VBOX_WITH_EXTPACK
42class ExtPackManager;
43#endif
44
45#include <VBox/RemoteDesktop/VRDE.h>
46#include <VBox/pdmdrv.h>
47#ifdef VBOX_WITH_GUEST_PROPS
48# include <VBox/HostServices/GuestPropertySvc.h> /* For the property notification callback */
49#endif
50
51#ifdef RT_OS_WINDOWS
52# include "win/VBoxComEvents.h"
53#endif
54
55struct VUSBIRHCONFIG;
56typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
57
58#include <list>
59
60// defines
61///////////////////////////////////////////////////////////////////////////////
62
63/**
64 * Checks the availability of the underlying VM device driver corresponding
65 * to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
66 * not available (NULL), sets error info and returns returns E_ACCESSDENIED.
67 * The translatable error message is defined in null context.
68 *
69 * Intended to used only within Console children (i.e. Keyboard, Mouse,
70 * Display, etc.).
71 *
72 * @param drv driver pointer to check (compare it with NULL)
73 */
74#define CHECK_CONSOLE_DRV(drv) \
75 do { \
76 if (!(drv)) \
77 return setError(E_ACCESSDENIED, tr("The console is not powered up")); \
78 } while (0)
79
80// Console
81///////////////////////////////////////////////////////////////////////////////
82
83/** IConsole implementation class */
84class ATL_NO_VTABLE Console :
85 public VirtualBoxBase,
86 VBOX_SCRIPTABLE_IMPL(IConsole)
87#ifdef RT_OS_WINDOWS
88 , public CComCoClass<Console, &CLSID_Console>
89#endif
90{
91 Q_OBJECT
92
93public:
94
95 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Console, IConsole)
96
97 DECLARE_NOT_AGGREGATABLE(Console)
98
99 DECLARE_PROTECT_FINAL_CONSTRUCT()
100
101 BEGIN_COM_MAP(Console)
102 COM_INTERFACE_ENTRY(ISupportErrorInfo)
103 COM_INTERFACE_ENTRY(IConsole)
104 COM_INTERFACE_ENTRY(IDispatch)
105 END_COM_MAP()
106
107 Console();
108 ~Console();
109
110 HRESULT FinalConstruct();
111 void FinalRelease();
112
113 // public initializers/uninitializers for internal purposes only
114 HRESULT init(IMachine *aMachine, IInternalMachineControl *aControl);
115 void uninit();
116
117 // IConsole properties
118 STDMETHOD(COMGETTER(Machine))(IMachine **aMachine);
119 STDMETHOD(COMGETTER(State))(MachineState_T *aMachineState);
120 STDMETHOD(COMGETTER(Guest))(IGuest **aGuest);
121 STDMETHOD(COMGETTER(Keyboard))(IKeyboard **aKeyboard);
122 STDMETHOD(COMGETTER(Mouse))(IMouse **aMouse);
123 STDMETHOD(COMGETTER(Display))(IDisplay **aDisplay);
124 STDMETHOD(COMGETTER(Debugger))(IMachineDebugger **aDebugger);
125 STDMETHOD(COMGETTER(USBDevices))(ComSafeArrayOut(IUSBDevice *, aUSBDevices));
126 STDMETHOD(COMGETTER(RemoteUSBDevices))(ComSafeArrayOut(IHostUSBDevice *, aRemoteUSBDevices));
127 STDMETHOD(COMGETTER(VRDEServerInfo))(IVRDEServerInfo **aVRDEServerInfo);
128 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
129 STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
130
131 // IConsole methods
132 STDMETHOD(PowerUp)(IProgress **aProgress);
133 STDMETHOD(PowerUpPaused)(IProgress **aProgress);
134 STDMETHOD(PowerDown)(IProgress **aProgress);
135 STDMETHOD(Reset)();
136 STDMETHOD(Pause)();
137 STDMETHOD(Resume)();
138 STDMETHOD(PowerButton)();
139 STDMETHOD(SleepButton)();
140 STDMETHOD(GetPowerButtonHandled)(BOOL *aHandled);
141 STDMETHOD(GetGuestEnteredACPIMode)(BOOL *aEntered);
142 STDMETHOD(SaveState)(IProgress **aProgress);
143 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
144 STDMETHOD(DiscardSavedState)(BOOL aRemoveFile);
145 STDMETHOD(GetDeviceActivity)(DeviceType_T aDeviceType,
146 DeviceActivity_T *aDeviceActivity);
147 STDMETHOD(AttachUSBDevice)(IN_BSTR aId);
148 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, IUSBDevice **aDevice);
149 STDMETHOD(FindUSBDeviceByAddress)(IN_BSTR aAddress, IUSBDevice **aDevice);
150 STDMETHOD(FindUSBDeviceById)(IN_BSTR aId, IUSBDevice **aDevice);
151 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
152 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
153 STDMETHOD(TakeSnapshot)(IN_BSTR aName, IN_BSTR aDescription,
154 IProgress **aProgress);
155 STDMETHOD(DeleteSnapshot)(IN_BSTR aId, IProgress **aProgress);
156 STDMETHOD(RestoreSnapshot)(ISnapshot *aSnapshot, IProgress **aProgress);
157 STDMETHOD(Teleport)(IN_BSTR aHostname, ULONG aPort, IN_BSTR aPassword, ULONG aMaxDowntime, IProgress **aProgress);
158
159 // public methods for internal purposes only
160
161 /*
162 * Note: the following methods do not increase refcount. intended to be
163 * called only by the VM execution thread.
164 */
165
166 Guest *getGuest() const { return mGuest; }
167 Keyboard *getKeyboard() const { return mKeyboard; }
168 Mouse *getMouse() const { return mMouse; }
169 Display *getDisplay() const { return mDisplay; }
170 MachineDebugger *getMachineDebugger() const { return mDebugger; }
171
172 const ComPtr<IMachine> &machine() const { return mMachine; }
173
174 /** Method is called only from ConsoleVRDPServer */
175 IVRDEServer *getVRDEServer() const { return mVRDEServer; }
176
177 ConsoleVRDPServer *consoleVRDPServer() const { return mConsoleVRDPServer; }
178
179 HRESULT updateMachineState(MachineState_T aMachineState);
180
181 // events from IInternalSessionControl
182 HRESULT onNetworkAdapterChange(INetworkAdapter *aNetworkAdapter, BOOL changeAdapter);
183 HRESULT onSerialPortChange(ISerialPort *aSerialPort);
184 HRESULT onParallelPortChange(IParallelPort *aParallelPort);
185 HRESULT onStorageControllerChange();
186 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
187 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
188 HRESULT onCPUExecutionCapChange(ULONG aExecutionCap);
189 HRESULT onVRDEServerChange(BOOL aRestart);
190 HRESULT onUSBControllerChange();
191 HRESULT onSharedFolderChange(BOOL aGlobal);
192 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice, IVirtualBoxErrorInfo *aError, ULONG aMaskedIfs);
193 HRESULT onUSBDeviceDetach(IN_BSTR aId, IVirtualBoxErrorInfo *aError);
194 HRESULT getGuestProperty(IN_BSTR aKey, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
195 HRESULT setGuestProperty(IN_BSTR aKey, IN_BSTR aValue, IN_BSTR aFlags);
196 HRESULT enumerateGuestProperties(IN_BSTR aPatterns,
197 ComSafeArrayOut(BSTR, aNames),
198 ComSafeArrayOut(BSTR, aValues),
199 ComSafeArrayOut(LONG64, aTimestamps),
200 ComSafeArrayOut(BSTR, aFlags));
201 HRESULT onlineMergeMedium(IMediumAttachment *aMediumAttachment,
202 ULONG aSourceIdx, ULONG aTargetIdx,
203 IMedium *aSource, IMedium *aTarget,
204 BOOL aMergeForward, IMedium *aParentForTarget,
205 ComSafeArrayIn(IMedium *, aChildrenToReparent),
206 IProgress *aProgress);
207 VMMDev *getVMMDev() { return m_pVMMDev; }
208 AudioSniffer *getAudioSniffer() { return mAudioSniffer; }
209
210 int VRDPClientLogon(uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
211 void VRDPClientConnect(uint32_t u32ClientId);
212 void VRDPClientDisconnect(uint32_t u32ClientId, uint32_t fu32Intercepted);
213 void VRDPInterceptAudio(uint32_t u32ClientId);
214 void VRDPInterceptUSB(uint32_t u32ClientId, void **ppvIntercept);
215 void VRDPInterceptClipboard(uint32_t u32ClientId);
216
217 void processRemoteUSBDevices(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevList, uint32_t cbDevList);
218
219 // callback callers (partly; for some events console callbacks are notified
220 // directly from IInternalSessionControl event handlers declared above)
221 void onMousePointerShapeChange(bool fVisible, bool fAlpha,
222 uint32_t xHot, uint32_t yHot,
223 uint32_t width, uint32_t height,
224 ComSafeArrayIn(uint8_t, aShape));
225 void onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative, BOOL needsHostCursor);
226 void onStateChange(MachineState_T aMachineState);
227 void onAdditionsStateChange();
228 void onAdditionsOutdated();
229 void onKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock);
230 void onUSBDeviceStateChange(IUSBDevice *aDevice, bool aAttached,
231 IVirtualBoxErrorInfo *aError);
232 void onRuntimeError(BOOL aFatal, IN_BSTR aErrorID, IN_BSTR aMessage);
233 HRESULT onShowWindow(BOOL aCheck, BOOL *aCanShow, LONG64 *aWinId);
234 void onVRDEServerInfoChange();
235
236 static const PDMDRVREG DrvStatusReg;
237
238 static HRESULT setErrorStatic(HRESULT aResultCode, const char *pcsz, ...);
239 HRESULT setInvalidMachineStateError();
240
241 static HRESULT handleUnexpectedExceptions(RT_SRC_POS_DECL);
242
243 static const char *convertControllerTypeToDev(StorageControllerType_T enmCtrlType);
244 static HRESULT convertBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
245 // Called from event listener
246 HRESULT onNATRedirectRuleChange(ULONG ulInstance, BOOL aNatRuleRemove,
247 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
248
249private:
250
251 /**
252 * Base template for AutoVMCaller and SaveVMPtr. Template arguments
253 * have the same meaning as arguments of Console::addVMCaller().
254 */
255 template <bool taQuiet = false, bool taAllowNullVM = false>
256 class AutoVMCallerBase
257 {
258 public:
259 AutoVMCallerBase(Console *aThat) : mThat(aThat), mRC(S_OK)
260 {
261 Assert(aThat);
262 mRC = aThat->addVMCaller(taQuiet, taAllowNullVM);
263 }
264 ~AutoVMCallerBase()
265 {
266 if (SUCCEEDED(mRC))
267 mThat->releaseVMCaller();
268 }
269 /** Decreases the number of callers before the instance is destroyed. */
270 void release()
271 {
272 AssertReturnVoid(SUCCEEDED(mRC));
273 mThat->releaseVMCaller();
274 mRC = E_FAIL;
275 }
276 /** Restores the number of callers after by #release(). #rc() must be
277 * rechecked to ensure the operation succeeded. */
278 void add()
279 {
280 AssertReturnVoid(!SUCCEEDED(mRC));
281 mRC = mThat->addVMCaller(taQuiet, taAllowNullVM);
282 }
283 /** Returns the result of Console::addVMCaller() */
284 HRESULT rc() const { return mRC; }
285 /** Shortcut to SUCCEEDED(rc()) */
286 bool isOk() const { return SUCCEEDED(mRC); }
287 protected:
288 Console *mThat;
289 HRESULT mRC;
290 private:
291 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoVMCallerBase)
292 DECLARE_CLS_NEW_DELETE_NOOP(AutoVMCallerBase)
293 };
294
295 /**
296 * Helper class that protects sections of code using the mpVM pointer by
297 * automatically calling addVMCaller() on construction and
298 * releaseVMCaller() on destruction. Intended for Console methods dealing
299 * with mpVM. The usage pattern is:
300 * <code>
301 * AutoVMCaller autoVMCaller(this);
302 * if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();
303 * ...
304 * VMR3ReqCall (mpVM, ...
305 * </code>
306 *
307 * @note Temporarily locks the argument for writing.
308 *
309 * @sa SafeVMPtr, SafeVMPtrQuiet
310 */
311 typedef AutoVMCallerBase <false, false> AutoVMCaller;
312
313 /**
314 * Same as AutoVMCaller but doesn't set extended error info on failure.
315 *
316 * @note Temporarily locks the argument for writing.
317 */
318 typedef AutoVMCallerBase <true, false> AutoVMCallerQuiet;
319
320 /**
321 * Same as AutoVMCaller but allows a null VM pointer (to trigger an error
322 * instead of assertion).
323 *
324 * @note Temporarily locks the argument for writing.
325 */
326 typedef AutoVMCallerBase <false, true> AutoVMCallerWeak;
327
328 /**
329 * Same as AutoVMCaller but doesn't set extended error info on failure
330 * and allows a null VM pointer (to trigger an error instead of
331 * assertion).
332 *
333 * @note Temporarily locks the argument for writing.
334 */
335 typedef AutoVMCallerBase <true, true> AutoVMCallerQuietWeak;
336
337 /**
338 * Base template for SaveVMPtr and SaveVMPtrQuiet.
339 */
340 template <bool taQuiet = false>
341 class SafeVMPtrBase : public AutoVMCallerBase <taQuiet, true>
342 {
343 typedef AutoVMCallerBase <taQuiet, true> Base;
344 public:
345 SafeVMPtrBase(Console *aThat) : Base(aThat), mpVM(NULL)
346 {
347 if (SUCCEEDED(Base::mRC))
348 mpVM = aThat->mpVM;
349 }
350 /** Smart SaveVMPtr to PVM cast operator */
351 operator PVM() const { return mpVM; }
352 /** Direct PVM access for printf()-like functions */
353 PVM raw() const { return mpVM; }
354 private:
355 PVM mpVM;
356 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(SafeVMPtrBase)
357 DECLARE_CLS_NEW_DELETE_NOOP(SafeVMPtrBase)
358 };
359
360public:
361
362 /**
363 * Helper class that safely manages the Console::mpVM pointer
364 * by calling addVMCaller() on construction and releaseVMCaller() on
365 * destruction. Intended for Console children. The usage pattern is:
366 * <code>
367 * Console::SaveVMPtr pVM(mParent);
368 * if (FAILED(pVM.rc())) return pVM.rc();
369 * ...
370 * VMR3ReqCall(pVM, ...
371 * ...
372 * printf("%p\n", pVM.raw());
373 * </code>
374 *
375 * @note Temporarily locks the argument for writing.
376 *
377 * @sa SafeVMPtrQuiet, AutoVMCaller
378 */
379 typedef SafeVMPtrBase <false> SafeVMPtr;
380
381 /**
382 * A deviation of SaveVMPtr that doesn't set the error info on failure.
383 * Intended for pieces of code that don't need to return the VM access
384 * failure to the caller. The usage pattern is:
385 * <code>
386 * Console::SaveVMPtrQuiet pVM(mParent);
387 * if (pVM.rc())
388 * VMR3ReqCall(pVM, ...
389 * return S_OK;
390 * </code>
391 *
392 * @note Temporarily locks the argument for writing.
393 *
394 * @sa SafeVMPtr, AutoVMCaller
395 */
396 typedef SafeVMPtrBase <true> SafeVMPtrQuiet;
397
398 class SharedFolderData
399 {
400 public:
401 SharedFolderData() {}
402 SharedFolderData(Bstr aHostPath, BOOL aWritable, BOOL aAutoMount)
403 : mHostPath(aHostPath)
404 , mWritable(aWritable)
405 , mAutoMount(aAutoMount) {}
406 SharedFolderData(const SharedFolderData& aThat)
407 : mHostPath(aThat.mHostPath)
408 , mWritable(aThat.mWritable)
409 , mAutoMount(aThat.mAutoMount) {}
410 Bstr mHostPath;
411 BOOL mWritable;
412 BOOL mAutoMount;
413 };
414 typedef std::map <Bstr, ComObjPtr<SharedFolder> > SharedFolderMap;
415 typedef std::map <Bstr, SharedFolderData> SharedFolderDataMap;
416
417private:
418
419 typedef std::list <ComObjPtr<OUSBDevice> > USBDeviceList;
420 typedef std::list <ComObjPtr<RemoteUSBDevice> > RemoteUSBDeviceList;
421
422 HRESULT addVMCaller(bool aQuiet = false, bool aAllowNullVM = false);
423 void releaseVMCaller();
424
425 HRESULT consoleInitReleaseLog(const ComPtr<IMachine> aMachine);
426
427 HRESULT powerUp(IProgress **aProgress, bool aPaused);
428 HRESULT powerDown(Progress *aProgress = NULL);
429
430 HRESULT callTapSetupApplication(bool isStatic, RTFILE tapFD, Bstr &tapDevice,
431 Bstr &tapSetupApplication);
432#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
433 HRESULT attachToTapInterface(INetworkAdapter *networkAdapter);
434 HRESULT detachFromTapInterface(INetworkAdapter *networkAdapter);
435#endif
436 HRESULT powerDownHostInterfaces();
437
438 HRESULT setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
439 HRESULT setMachineStateLocally(MachineState_T aMachineState)
440 {
441 return setMachineState(aMachineState, false /* aUpdateServer */);
442 }
443
444 HRESULT findSharedFolder(CBSTR aName,
445 ComObjPtr<SharedFolder> &aSharedFolder,
446 bool aSetError = false);
447
448 HRESULT fetchSharedFolders(BOOL aGlobal);
449 bool findOtherSharedFolder(IN_BSTR aName,
450 SharedFolderDataMap::const_iterator &aIt);
451
452 HRESULT createSharedFolder(CBSTR aName, SharedFolderData aData);
453 HRESULT removeSharedFolder(CBSTR aName);
454
455 static DECLCALLBACK(int) configConstructor(PVM pVM, void *pvConsole);
456
457 int configMediumAttachment(PCFGMNODE pCtlInst,
458 const char *pcszDevice,
459 unsigned uInstance,
460 StorageBus_T enmBus,
461 bool fUseHostIOCache,
462 bool fSetupMerge,
463 unsigned uMergeSource,
464 unsigned uMergeTarget,
465 IMediumAttachment *pMediumAtt,
466 MachineState_T aMachineState,
467 HRESULT *phrc,
468 bool fAttachDetach,
469 bool fForceUnmount,
470 PVM pVM,
471 DeviceType_T *paLedDevType);
472 int configMedium(PCFGMNODE pLunL0,
473 bool fPassthrough,
474 DeviceType_T enmType,
475 bool fUseHostIOCache,
476 bool fSetupMerge,
477 unsigned uMergeSource,
478 unsigned uMergeTarget,
479 IMedium *pMedium,
480 MachineState_T aMachineState,
481 HRESULT *phrc);
482 static DECLCALLBACK(int) reconfigureMediumAttachment(Console *pConsole,
483 PVM pVM,
484 const char *pcszDevice,
485 unsigned uInstance,
486 StorageBus_T enmBus,
487 bool fUseHostIOCache,
488 bool fSetupMerge,
489 unsigned uMergeSource,
490 unsigned uMergeTarget,
491 IMediumAttachment *aMediumAtt,
492 MachineState_T aMachineState,
493 HRESULT *phrc);
494 static DECLCALLBACK(int) changeRemovableMedium(Console *pThis,
495 const char *pcszDevice,
496 unsigned uInstance,
497 StorageBus_T enmBus,
498 bool fUseHostIOCache,
499 IMediumAttachment *aMediumAtt,
500 bool fForce);
501
502 int configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun,
503 INetworkAdapter *aNetworkAdapter, PCFGMNODE pCfg,
504 PCFGMNODE pLunL0, PCFGMNODE pInst, bool fAttachDetach);
505
506 static DECLCALLBACK(int) configGuestProperties(void *pvConsole);
507 static DECLCALLBACK(int) configGuestControl(void *pvConsole);
508 static DECLCALLBACK(void) vmstateChangeCallback(PVM aVM, VMSTATE aState,
509 VMSTATE aOldState, void *aUser);
510 static DECLCALLBACK(int) unplugCpu(Console *pThis, unsigned uCpu);
511 static DECLCALLBACK(int) plugCpu(Console *pThis, unsigned uCpu);
512 HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce);
513 HRESULT doCPURemove(ULONG aCpu);
514 HRESULT doCPUAdd(ULONG aCpu);
515
516 HRESULT doNetworkAdapterChange(const char *pszDevice, unsigned uInstance,
517 unsigned uLun, INetworkAdapter *aNetworkAdapter);
518 static DECLCALLBACK(int) changeNetworkAttachment(Console *pThis, const char *pszDevice,
519 unsigned uInstance, unsigned uLun,
520 INetworkAdapter *aNetworkAdapter);
521
522#ifdef VBOX_WITH_USB
523 HRESULT attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs);
524 HRESULT detachUSBDevice(USBDeviceList::iterator &aIt);
525
526 static DECLCALLBACK(int) usbAttachCallback(Console *that, IUSBDevice *aHostDevice, PCRTUUID aUuid,
527 bool aRemote, const char *aAddress, ULONG aMaskedIfs);
528 static DECLCALLBACK(int) usbDetachCallback(Console *that, USBDeviceList::iterator *aIt, PCRTUUID aUuid);
529#endif
530
531 static DECLCALLBACK(int) fntTakeSnapshotWorker(RTTHREAD Thread, void *pvUser);
532
533 static DECLCALLBACK(int) stateProgressCallback(PVM pVM, unsigned uPercent, void *pvUser);
534
535 static DECLCALLBACK(void) genericVMSetErrorCallback(PVM pVM, void *pvUser, int rc, RT_SRC_POS_DECL,
536 const char *pszErrorFmt, va_list va);
537
538 static DECLCALLBACK(void) setVMRuntimeErrorCallbackF(PVM pVM, void *pvUser, uint32_t fFatal,
539 const char *pszErrorId,
540 const char *pszFormat, ...);
541 static DECLCALLBACK(void) setVMRuntimeErrorCallback(PVM pVM, void *pvUser, uint32_t fFatal,
542 const char *pszErrorId,
543 const char *pszFormat, va_list va);
544
545 HRESULT captureUSBDevices(PVM pVM);
546 void detachAllUSBDevices(bool aDone);
547
548 static DECLCALLBACK(int) powerUpThread(RTTHREAD Thread, void *pvUser);
549 static DECLCALLBACK(int) saveStateThread(RTTHREAD Thread, void *pvUser);
550 static DECLCALLBACK(int) powerDownThread(RTTHREAD Thread, void *pvUser);
551
552 static DECLCALLBACK(int) vmm2User_SaveState(PCVMM2USERMETHODS pThis, PVM pVM);
553
554 static DECLCALLBACK(void *) drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
555 static DECLCALLBACK(void) drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
556 static DECLCALLBACK(void) drvStatus_Destruct(PPDMDRVINS pDrvIns);
557 static DECLCALLBACK(int) drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
558
559 int mcAudioRefs;
560 volatile uint32_t mcVRDPClients;
561 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
562 volatile bool mcGuestCredentialsProvided;
563
564 static const char *sSSMConsoleUnit;
565 static uint32_t sSSMConsoleVer;
566
567 HRESULT loadDataFromSavedState();
568 int loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
569
570 static DECLCALLBACK(void) saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
571 static DECLCALLBACK(int) loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
572
573#ifdef VBOX_WITH_GUEST_PROPS
574 static DECLCALLBACK(int) doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
575 HRESULT doEnumerateGuestProperties(CBSTR aPatterns,
576 ComSafeArrayOut(BSTR, aNames),
577 ComSafeArrayOut(BSTR, aValues),
578 ComSafeArrayOut(LONG64, aTimestamps),
579 ComSafeArrayOut(BSTR, aFlags));
580
581 bool enabledGuestPropertiesVRDP(void);
582 void updateGuestPropertiesVRDPLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
583 void updateGuestPropertiesVRDPDisconnect(uint32_t u32ClientId);
584#endif
585
586 /** @name Teleporter support
587 * @{ */
588 static DECLCALLBACK(int) teleporterSrcThreadWrapper(RTTHREAD hThread, void *pvUser);
589 HRESULT teleporterSrc(TeleporterStateSrc *pState);
590 HRESULT teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
591 HRESULT teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
592 HRESULT teleporterTrg(PVM pVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
593 Progress *pProgress, bool *pfPowerOffOnFailure);
594 static DECLCALLBACK(int) teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
595 /** @} */
596
597 bool mSavedStateDataLoaded : 1;
598
599 const ComPtr<IMachine> mMachine;
600 const ComPtr<IInternalMachineControl> mControl;
601
602 const ComPtr <IVRDEServer> mVRDEServer;
603
604 ConsoleVRDPServer * const mConsoleVRDPServer;
605
606 const ComObjPtr<Guest> mGuest;
607 const ComObjPtr<Keyboard> mKeyboard;
608 const ComObjPtr<Mouse> mMouse;
609 const ComObjPtr<Display> mDisplay;
610 const ComObjPtr<MachineDebugger> mDebugger;
611 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
612 const ComObjPtr<EventSource> mEventSource;
613#ifdef VBOX_WITH_EXTPACK
614 const ComObjPtr<ExtPackManager> mptrExtPackManager;
615#endif
616
617 USBDeviceList mUSBDevices;
618 RemoteUSBDeviceList mRemoteUSBDevices;
619
620 SharedFolderMap mSharedFolders;
621 SharedFolderDataMap mMachineSharedFolders;
622 SharedFolderDataMap mGlobalSharedFolders;
623
624 /** The VM instance handle. */
625 PVM mpVM;
626 /** Holds the number of "readonly" mpVM callers (users) */
627 uint32_t mVMCallers;
628 /** Semaphore posted when the number of mpVM callers drops to zero */
629 RTSEMEVENT mVMZeroCallersSem;
630 /** true when Console has entered the mpVM destruction phase */
631 bool mVMDestroying : 1;
632 /** true when power down is initiated by vmstateChangeCallback (EMT) */
633 bool mVMPoweredOff : 1;
634 /** true when vmstateChangeCallback shouldn't initiate a power down. */
635 bool mVMIsAlreadyPoweringOff : 1;
636 /** true if we already showed the snapshot folder size warning. */
637 bool mfSnapshotFolderSizeWarningShown : 1;
638 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
639 bool mfSnapshotFolderExt4WarningShown : 1;
640
641 /** Pointer to the VMM -> User (that's us) callbacks.
642 * This structure is followed by a pointer to the Console object. */
643 PCVMM2USERMETHODS mpVmm2UserMethods;
644
645 /** The current network attachment type in the VM.
646 * This doesn't have to match the network attachment type maintained in the
647 * NetworkAdapter. This is needed to change the network attachment
648 * dynamically.
649 */
650 NetworkAttachmentType_T meAttachmentType[SchemaDefs::NetworkAdapterCount];
651
652 VMMDev * m_pVMMDev;
653 AudioSniffer * const mAudioSniffer;
654
655 enum
656 {
657 iLedFloppy = 0,
658 cLedFloppy = 1,
659 iLedIde = iLedFloppy + cLedFloppy,
660 cLedIde = 4,
661 iLedSata = iLedIde + cLedIde,
662 cLedSata = 30,
663 iLedScsi = iLedSata + cLedSata,
664 cLedScsi = 16,
665 iLedSas = iLedScsi + cLedScsi,
666 cLedSas = 8,
667 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas
668 };
669 DeviceType_T maStorageDevType[cLedStorage];
670 PPDMLED mapStorageLeds[cLedStorage];
671 PPDMLED mapNetworkLeds[SchemaDefs::NetworkAdapterCount];
672 PPDMLED mapSharedFolderLed;
673 PPDMLED mapUSBLed[2];
674#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
675 Utf8Str maTAPDeviceName[8];
676 RTFILE maTapFD[8];
677#endif
678
679 bool mVMStateChangeCallbackDisabled;
680
681 /** Local machine state value. */
682 MachineState_T mMachineState;
683
684 /** Pointer to the progress object of a live cancelable task.
685 *
686 * This is currently only used by Console::Teleport(), but is intended to later
687 * be used by the live snapshot code path as well. Actions like
688 * Console::PowerDown, which automatically cancels out the running snapshot /
689 * teleportation operation, will cancel the teleportation / live snapshot
690 * operation before starting. */
691 ComObjPtr<Progress> mptrCancelableProgress;
692
693 struct
694 {
695 /** OnMousePointerShapeChange() cache */
696 struct
697 {
698 bool valid;
699 bool visible;
700 bool alpha;
701 uint32_t xHot;
702 uint32_t yHot;
703 uint32_t width;
704 uint32_t height;
705 com::SafeArray<BYTE> shape;
706 }
707 mpsc;
708
709 /** OnMouseCapabilityChange() cache */
710 struct
711 {
712 bool valid;
713 BOOL supportsAbsolute;
714 BOOL supportsRelative;
715 BOOL needsHostCursor;
716 }
717 mcc;
718
719 /** OnKeyboardLedsChange() cache */
720 struct
721 {
722 bool valid;
723 bool numLock;
724 bool capsLock;
725 bool scrollLock;
726 }
727 klc;
728
729 void clear()
730 {
731 /* We cannot do memset() on mpsc to avoid cleaning shape's vtable */
732 mpsc.shape.setNull();
733 mpsc.valid = mpsc.visible = mpsc.alpha = false;
734 mpsc.xHot = mpsc.yHot = mpsc.width = mpsc.height = 0;
735 ::memset(&mcc, 0, sizeof mcc);
736 ::memset(&klc, 0, sizeof klc);
737 }
738 }
739 mCallbackData;
740 COM_STRUCT_OR_CLASS(IEventListener) *mVmListner;
741
742 friend struct VMTask;
743};
744
745#endif // !____H_CONSOLEIMPL
746/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette