VirtualBox

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

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

Main: separate internal machine data structs into MachineImplPrivate.h to significantly speed up compilation and for better interface separation; remove obsolete ConsoleEvents.h file

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