VirtualBox

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

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

Main: live snapshot merging. initially limited to forward merging (i.e. everything but the first snapshot can be deleted)

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