VirtualBox

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

Last change on this file since 33907 was 33825, checked in by vboxsync, 15 years ago

Main,NAT: Managing port-forwarding at runtime. (xTracker/#4835).

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