VirtualBox

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

Last change on this file since 34286 was 34244, checked in by vboxsync, 14 years ago

Main,Config.kmk,VBoxManage,ExtPacks: Moved the VRDE bits from IVirtualBox to the extension packs; changed ISystemProperties and IVRDEServer to talk about VRDE extension packs instead of VRDE libraries.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.8 KB
Line 
1/* $Id: ConsoleImpl.h 34244 2010-11-22 14:31:02Z 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#ifdef VBOX_WITH_EXTPACK
210 ExtPackManager *getExtPackManager();
211#endif
212
213 int VRDPClientLogon(uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
214 void VRDPClientConnect(uint32_t u32ClientId);
215 void VRDPClientDisconnect(uint32_t u32ClientId, uint32_t fu32Intercepted);
216 void VRDPInterceptAudio(uint32_t u32ClientId);
217 void VRDPInterceptUSB(uint32_t u32ClientId, void **ppvIntercept);
218 void VRDPInterceptClipboard(uint32_t u32ClientId);
219
220 void processRemoteUSBDevices(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevList, uint32_t cbDevList);
221
222 // callback callers (partly; for some events console callbacks are notified
223 // directly from IInternalSessionControl event handlers declared above)
224 void onMousePointerShapeChange(bool fVisible, bool fAlpha,
225 uint32_t xHot, uint32_t yHot,
226 uint32_t width, uint32_t height,
227 ComSafeArrayIn(uint8_t, aShape));
228 void onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative, BOOL needsHostCursor);
229 void onStateChange(MachineState_T aMachineState);
230 void onAdditionsStateChange();
231 void onAdditionsOutdated();
232 void onKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock);
233 void onUSBDeviceStateChange(IUSBDevice *aDevice, bool aAttached,
234 IVirtualBoxErrorInfo *aError);
235 void onRuntimeError(BOOL aFatal, IN_BSTR aErrorID, IN_BSTR aMessage);
236 HRESULT onShowWindow(BOOL aCheck, BOOL *aCanShow, LONG64 *aWinId);
237 void onVRDEServerInfoChange();
238
239 static const PDMDRVREG DrvStatusReg;
240
241 static HRESULT setErrorStatic(HRESULT aResultCode, const char *pcsz, ...);
242 HRESULT setInvalidMachineStateError();
243
244 static HRESULT handleUnexpectedExceptions(RT_SRC_POS_DECL);
245
246 static const char *convertControllerTypeToDev(StorageControllerType_T enmCtrlType);
247 static HRESULT convertBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
248 // Called from event listener
249 HRESULT onNATRedirectRuleChange(ULONG ulInstance, BOOL aNatRuleRemove,
250 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
251
252private:
253
254 /**
255 * Base template for AutoVMCaller and SaveVMPtr. Template arguments
256 * have the same meaning as arguments of Console::addVMCaller().
257 */
258 template <bool taQuiet = false, bool taAllowNullVM = false>
259 class AutoVMCallerBase
260 {
261 public:
262 AutoVMCallerBase(Console *aThat) : mThat(aThat), mRC(S_OK)
263 {
264 Assert(aThat);
265 mRC = aThat->addVMCaller(taQuiet, taAllowNullVM);
266 }
267 ~AutoVMCallerBase()
268 {
269 if (SUCCEEDED(mRC))
270 mThat->releaseVMCaller();
271 }
272 /** Decreases the number of callers before the instance is destroyed. */
273 void release()
274 {
275 AssertReturnVoid(SUCCEEDED(mRC));
276 mThat->releaseVMCaller();
277 mRC = E_FAIL;
278 }
279 /** Restores the number of callers after by #release(). #rc() must be
280 * rechecked to ensure the operation succeeded. */
281 void add()
282 {
283 AssertReturnVoid(!SUCCEEDED(mRC));
284 mRC = mThat->addVMCaller(taQuiet, taAllowNullVM);
285 }
286 /** Returns the result of Console::addVMCaller() */
287 HRESULT rc() const { return mRC; }
288 /** Shortcut to SUCCEEDED(rc()) */
289 bool isOk() const { return SUCCEEDED(mRC); }
290 protected:
291 Console *mThat;
292 HRESULT mRC;
293 private:
294 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoVMCallerBase)
295 DECLARE_CLS_NEW_DELETE_NOOP(AutoVMCallerBase)
296 };
297
298 /**
299 * Helper class that protects sections of code using the mpVM pointer by
300 * automatically calling addVMCaller() on construction and
301 * releaseVMCaller() on destruction. Intended for Console methods dealing
302 * with mpVM. The usage pattern is:
303 * <code>
304 * AutoVMCaller autoVMCaller(this);
305 * if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();
306 * ...
307 * VMR3ReqCall (mpVM, ...
308 * </code>
309 *
310 * @note Temporarily locks the argument for writing.
311 *
312 * @sa SafeVMPtr, SafeVMPtrQuiet
313 */
314 typedef AutoVMCallerBase <false, false> AutoVMCaller;
315
316 /**
317 * Same as AutoVMCaller but doesn't set extended error info on failure.
318 *
319 * @note Temporarily locks the argument for writing.
320 */
321 typedef AutoVMCallerBase <true, false> AutoVMCallerQuiet;
322
323 /**
324 * Same as AutoVMCaller but allows a null VM pointer (to trigger an error
325 * instead of assertion).
326 *
327 * @note Temporarily locks the argument for writing.
328 */
329 typedef AutoVMCallerBase <false, true> AutoVMCallerWeak;
330
331 /**
332 * Same as AutoVMCaller but doesn't set extended error info on failure
333 * and allows a null VM pointer (to trigger an error instead of
334 * assertion).
335 *
336 * @note Temporarily locks the argument for writing.
337 */
338 typedef AutoVMCallerBase <true, true> AutoVMCallerQuietWeak;
339
340 /**
341 * Base template for SaveVMPtr and SaveVMPtrQuiet.
342 */
343 template <bool taQuiet = false>
344 class SafeVMPtrBase : public AutoVMCallerBase <taQuiet, true>
345 {
346 typedef AutoVMCallerBase <taQuiet, true> Base;
347 public:
348 SafeVMPtrBase(Console *aThat) : Base(aThat), mpVM(NULL)
349 {
350 if (SUCCEEDED(Base::mRC))
351 mpVM = aThat->mpVM;
352 }
353 /** Smart SaveVMPtr to PVM cast operator */
354 operator PVM() const { return mpVM; }
355 /** Direct PVM access for printf()-like functions */
356 PVM raw() const { return mpVM; }
357 private:
358 PVM mpVM;
359 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(SafeVMPtrBase)
360 DECLARE_CLS_NEW_DELETE_NOOP(SafeVMPtrBase)
361 };
362
363public:
364
365 /**
366 * Helper class that safely manages the Console::mpVM pointer
367 * by calling addVMCaller() on construction and releaseVMCaller() on
368 * destruction. Intended for Console children. The usage pattern is:
369 * <code>
370 * Console::SaveVMPtr pVM(mParent);
371 * if (FAILED(pVM.rc())) return pVM.rc();
372 * ...
373 * VMR3ReqCall(pVM, ...
374 * ...
375 * printf("%p\n", pVM.raw());
376 * </code>
377 *
378 * @note Temporarily locks the argument for writing.
379 *
380 * @sa SafeVMPtrQuiet, AutoVMCaller
381 */
382 typedef SafeVMPtrBase <false> SafeVMPtr;
383
384 /**
385 * A deviation of SaveVMPtr that doesn't set the error info on failure.
386 * Intended for pieces of code that don't need to return the VM access
387 * failure to the caller. The usage pattern is:
388 * <code>
389 * Console::SaveVMPtrQuiet pVM(mParent);
390 * if (pVM.rc())
391 * VMR3ReqCall(pVM, ...
392 * return S_OK;
393 * </code>
394 *
395 * @note Temporarily locks the argument for writing.
396 *
397 * @sa SafeVMPtr, AutoVMCaller
398 */
399 typedef SafeVMPtrBase <true> SafeVMPtrQuiet;
400
401 class SharedFolderData
402 {
403 public:
404 SharedFolderData() {}
405 SharedFolderData(Bstr aHostPath, BOOL aWritable, BOOL aAutoMount)
406 : mHostPath(aHostPath)
407 , mWritable(aWritable)
408 , mAutoMount(aAutoMount) {}
409 SharedFolderData(const SharedFolderData& aThat)
410 : mHostPath(aThat.mHostPath)
411 , mWritable(aThat.mWritable)
412 , mAutoMount(aThat.mAutoMount) {}
413 Bstr mHostPath;
414 BOOL mWritable;
415 BOOL mAutoMount;
416 };
417 typedef std::map <Bstr, ComObjPtr<SharedFolder> > SharedFolderMap;
418 typedef std::map <Bstr, SharedFolderData> SharedFolderDataMap;
419
420private:
421
422 typedef std::list <ComObjPtr<OUSBDevice> > USBDeviceList;
423 typedef std::list <ComObjPtr<RemoteUSBDevice> > RemoteUSBDeviceList;
424
425 HRESULT addVMCaller(bool aQuiet = false, bool aAllowNullVM = false);
426 void releaseVMCaller();
427
428 HRESULT consoleInitReleaseLog(const ComPtr<IMachine> aMachine);
429
430 HRESULT powerUp(IProgress **aProgress, bool aPaused);
431 HRESULT powerDown(Progress *aProgress = NULL);
432
433 HRESULT callTapSetupApplication(bool isStatic, RTFILE tapFD, Bstr &tapDevice,
434 Bstr &tapSetupApplication);
435#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
436 HRESULT attachToTapInterface(INetworkAdapter *networkAdapter);
437 HRESULT detachFromTapInterface(INetworkAdapter *networkAdapter);
438#endif
439 HRESULT powerDownHostInterfaces();
440
441 HRESULT setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
442 HRESULT setMachineStateLocally(MachineState_T aMachineState)
443 {
444 return setMachineState(aMachineState, false /* aUpdateServer */);
445 }
446
447 HRESULT findSharedFolder(CBSTR aName,
448 ComObjPtr<SharedFolder> &aSharedFolder,
449 bool aSetError = false);
450
451 HRESULT fetchSharedFolders(BOOL aGlobal);
452 bool findOtherSharedFolder(IN_BSTR aName,
453 SharedFolderDataMap::const_iterator &aIt);
454
455 HRESULT createSharedFolder(CBSTR aName, SharedFolderData aData);
456 HRESULT removeSharedFolder(CBSTR aName);
457
458 static DECLCALLBACK(int) configConstructor(PVM pVM, void *pvConsole);
459
460 int configMediumAttachment(PCFGMNODE pCtlInst,
461 const char *pcszDevice,
462 unsigned uInstance,
463 StorageBus_T enmBus,
464 bool fUseHostIOCache,
465 bool fSetupMerge,
466 unsigned uMergeSource,
467 unsigned uMergeTarget,
468 IMediumAttachment *pMediumAtt,
469 MachineState_T aMachineState,
470 HRESULT *phrc,
471 bool fAttachDetach,
472 bool fForceUnmount,
473 PVM pVM,
474 DeviceType_T *paLedDevType);
475 int configMedium(PCFGMNODE pLunL0,
476 bool fPassthrough,
477 DeviceType_T enmType,
478 bool fUseHostIOCache,
479 bool fSetupMerge,
480 unsigned uMergeSource,
481 unsigned uMergeTarget,
482 IMedium *pMedium,
483 MachineState_T aMachineState,
484 HRESULT *phrc);
485 static DECLCALLBACK(int) reconfigureMediumAttachment(Console *pConsole,
486 PVM pVM,
487 const char *pcszDevice,
488 unsigned uInstance,
489 StorageBus_T enmBus,
490 bool fUseHostIOCache,
491 bool fSetupMerge,
492 unsigned uMergeSource,
493 unsigned uMergeTarget,
494 IMediumAttachment *aMediumAtt,
495 MachineState_T aMachineState,
496 HRESULT *phrc);
497 static DECLCALLBACK(int) changeRemovableMedium(Console *pThis,
498 const char *pcszDevice,
499 unsigned uInstance,
500 StorageBus_T enmBus,
501 bool fUseHostIOCache,
502 IMediumAttachment *aMediumAtt,
503 bool fForce);
504
505 int configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun,
506 INetworkAdapter *aNetworkAdapter, PCFGMNODE pCfg,
507 PCFGMNODE pLunL0, PCFGMNODE pInst, bool fAttachDetach);
508
509 static DECLCALLBACK(int) configGuestProperties(void *pvConsole);
510 static DECLCALLBACK(int) configGuestControl(void *pvConsole);
511 static DECLCALLBACK(void) vmstateChangeCallback(PVM aVM, VMSTATE aState,
512 VMSTATE aOldState, void *aUser);
513 static DECLCALLBACK(int) unplugCpu(Console *pThis, unsigned uCpu);
514 static DECLCALLBACK(int) plugCpu(Console *pThis, unsigned uCpu);
515 HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce);
516 HRESULT doCPURemove(ULONG aCpu);
517 HRESULT doCPUAdd(ULONG aCpu);
518
519 HRESULT doNetworkAdapterChange(const char *pszDevice, unsigned uInstance,
520 unsigned uLun, INetworkAdapter *aNetworkAdapter);
521 static DECLCALLBACK(int) changeNetworkAttachment(Console *pThis, const char *pszDevice,
522 unsigned uInstance, unsigned uLun,
523 INetworkAdapter *aNetworkAdapter);
524
525#ifdef VBOX_WITH_USB
526 HRESULT attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs);
527 HRESULT detachUSBDevice(USBDeviceList::iterator &aIt);
528
529 static DECLCALLBACK(int) usbAttachCallback(Console *that, IUSBDevice *aHostDevice, PCRTUUID aUuid,
530 bool aRemote, const char *aAddress, ULONG aMaskedIfs);
531 static DECLCALLBACK(int) usbDetachCallback(Console *that, USBDeviceList::iterator *aIt, PCRTUUID aUuid);
532#endif
533
534 static DECLCALLBACK(int) fntTakeSnapshotWorker(RTTHREAD Thread, void *pvUser);
535
536 static DECLCALLBACK(int) stateProgressCallback(PVM pVM, unsigned uPercent, void *pvUser);
537
538 static DECLCALLBACK(void) genericVMSetErrorCallback(PVM pVM, void *pvUser, int rc, RT_SRC_POS_DECL,
539 const char *pszErrorFmt, va_list va);
540
541 static DECLCALLBACK(void) setVMRuntimeErrorCallbackF(PVM pVM, void *pvUser, uint32_t fFatal,
542 const char *pszErrorId,
543 const char *pszFormat, ...);
544 static DECLCALLBACK(void) setVMRuntimeErrorCallback(PVM pVM, void *pvUser, uint32_t fFatal,
545 const char *pszErrorId,
546 const char *pszFormat, va_list va);
547
548 HRESULT captureUSBDevices(PVM pVM);
549 void detachAllUSBDevices(bool aDone);
550
551 static DECLCALLBACK(int) powerUpThread(RTTHREAD Thread, void *pvUser);
552 static DECLCALLBACK(int) saveStateThread(RTTHREAD Thread, void *pvUser);
553 static DECLCALLBACK(int) powerDownThread(RTTHREAD Thread, void *pvUser);
554
555 static DECLCALLBACK(int) vmm2User_SaveState(PCVMM2USERMETHODS pThis, PVM pVM);
556
557 static DECLCALLBACK(void *) drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
558 static DECLCALLBACK(void) drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
559 static DECLCALLBACK(void) drvStatus_Destruct(PPDMDRVINS pDrvIns);
560 static DECLCALLBACK(int) drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
561
562 int mcAudioRefs;
563 volatile uint32_t mcVRDPClients;
564 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
565 volatile bool mcGuestCredentialsProvided;
566
567 static const char *sSSMConsoleUnit;
568 static uint32_t sSSMConsoleVer;
569
570 HRESULT loadDataFromSavedState();
571 int loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
572
573 static DECLCALLBACK(void) saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
574 static DECLCALLBACK(int) loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
575
576#ifdef VBOX_WITH_GUEST_PROPS
577 static DECLCALLBACK(int) doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
578 HRESULT doEnumerateGuestProperties(CBSTR aPatterns,
579 ComSafeArrayOut(BSTR, aNames),
580 ComSafeArrayOut(BSTR, aValues),
581 ComSafeArrayOut(LONG64, aTimestamps),
582 ComSafeArrayOut(BSTR, aFlags));
583
584 bool enabledGuestPropertiesVRDP(void);
585 void updateGuestPropertiesVRDPLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
586 void updateGuestPropertiesVRDPDisconnect(uint32_t u32ClientId);
587#endif
588
589 /** @name Teleporter support
590 * @{ */
591 static DECLCALLBACK(int) teleporterSrcThreadWrapper(RTTHREAD hThread, void *pvUser);
592 HRESULT teleporterSrc(TeleporterStateSrc *pState);
593 HRESULT teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
594 HRESULT teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
595 HRESULT teleporterTrg(PVM pVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
596 Progress *pProgress, bool *pfPowerOffOnFailure);
597 static DECLCALLBACK(int) teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
598 /** @} */
599
600 bool mSavedStateDataLoaded : 1;
601
602 const ComPtr<IMachine> mMachine;
603 const ComPtr<IInternalMachineControl> mControl;
604
605 const ComPtr<IVRDEServer> mVRDEServer;
606
607 ConsoleVRDPServer * const mConsoleVRDPServer;
608
609 const ComObjPtr<Guest> mGuest;
610 const ComObjPtr<Keyboard> mKeyboard;
611 const ComObjPtr<Mouse> mMouse;
612 const ComObjPtr<Display> mDisplay;
613 const ComObjPtr<MachineDebugger> mDebugger;
614 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
615 const ComObjPtr<EventSource> mEventSource;
616#ifdef VBOX_WITH_EXTPACK
617 const ComObjPtr<ExtPackManager> mptrExtPackManager;
618#endif
619
620 USBDeviceList mUSBDevices;
621 RemoteUSBDeviceList mRemoteUSBDevices;
622
623 SharedFolderMap mSharedFolders;
624 SharedFolderDataMap mMachineSharedFolders;
625 SharedFolderDataMap mGlobalSharedFolders;
626
627 /** The VM instance handle. */
628 PVM mpVM;
629 /** Holds the number of "readonly" mpVM callers (users) */
630 uint32_t mVMCallers;
631 /** Semaphore posted when the number of mpVM callers drops to zero */
632 RTSEMEVENT mVMZeroCallersSem;
633 /** true when Console has entered the mpVM destruction phase */
634 bool mVMDestroying : 1;
635 /** true when power down is initiated by vmstateChangeCallback (EMT) */
636 bool mVMPoweredOff : 1;
637 /** true when vmstateChangeCallback shouldn't initiate a power down. */
638 bool mVMIsAlreadyPoweringOff : 1;
639 /** true if we already showed the snapshot folder size warning. */
640 bool mfSnapshotFolderSizeWarningShown : 1;
641 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
642 bool mfSnapshotFolderExt4WarningShown : 1;
643
644 /** Pointer to the VMM -> User (that's us) callbacks.
645 * This structure is followed by a pointer to the Console object. */
646 PCVMM2USERMETHODS mpVmm2UserMethods;
647
648 /** The current network attachment type in the VM.
649 * This doesn't have to match the network attachment type maintained in the
650 * NetworkAdapter. This is needed to change the network attachment
651 * dynamically.
652 */
653 NetworkAttachmentType_T meAttachmentType[SchemaDefs::NetworkAdapterCount];
654
655 VMMDev * m_pVMMDev;
656 AudioSniffer * const mAudioSniffer;
657
658 enum
659 {
660 iLedFloppy = 0,
661 cLedFloppy = 1,
662 iLedIde = iLedFloppy + cLedFloppy,
663 cLedIde = 4,
664 iLedSata = iLedIde + cLedIde,
665 cLedSata = 30,
666 iLedScsi = iLedSata + cLedSata,
667 cLedScsi = 16,
668 iLedSas = iLedScsi + cLedScsi,
669 cLedSas = 8,
670 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas
671 };
672 DeviceType_T maStorageDevType[cLedStorage];
673 PPDMLED mapStorageLeds[cLedStorage];
674 PPDMLED mapNetworkLeds[SchemaDefs::NetworkAdapterCount];
675 PPDMLED mapSharedFolderLed;
676 PPDMLED mapUSBLed[2];
677#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
678 Utf8Str maTAPDeviceName[8];
679 RTFILE maTapFD[8];
680#endif
681
682 bool mVMStateChangeCallbackDisabled;
683
684 /** Local machine state value. */
685 MachineState_T mMachineState;
686
687 /** Pointer to the progress object of a live cancelable task.
688 *
689 * This is currently only used by Console::Teleport(), but is intended to later
690 * be used by the live snapshot code path as well. Actions like
691 * Console::PowerDown, which automatically cancels out the running snapshot /
692 * teleportation operation, will cancel the teleportation / live snapshot
693 * operation before starting. */
694 ComObjPtr<Progress> mptrCancelableProgress;
695
696 struct
697 {
698 /** OnMousePointerShapeChange() cache */
699 struct
700 {
701 bool valid;
702 bool visible;
703 bool alpha;
704 uint32_t xHot;
705 uint32_t yHot;
706 uint32_t width;
707 uint32_t height;
708 com::SafeArray<BYTE> shape;
709 }
710 mpsc;
711
712 /** OnMouseCapabilityChange() cache */
713 struct
714 {
715 bool valid;
716 BOOL supportsAbsolute;
717 BOOL supportsRelative;
718 BOOL needsHostCursor;
719 }
720 mcc;
721
722 /** OnKeyboardLedsChange() cache */
723 struct
724 {
725 bool valid;
726 bool numLock;
727 bool capsLock;
728 bool scrollLock;
729 }
730 klc;
731
732 void clear()
733 {
734 /* We cannot do memset() on mpsc to avoid cleaning shape's vtable */
735 mpsc.shape.setNull();
736 mpsc.valid = mpsc.visible = mpsc.alpha = false;
737 mpsc.xHot = mpsc.yHot = mpsc.width = mpsc.height = 0;
738 ::memset(&mcc, 0, sizeof mcc);
739 ::memset(&klc, 0, sizeof klc);
740 }
741 }
742 mCallbackData;
743 COM_STRUCT_OR_CLASS(IEventListener) *mVmListner;
744
745 friend struct VMTask;
746};
747
748#endif // !____H_CONSOLEIMPL
749/* 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