VirtualBox

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

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

Main: Added ExtPackManager to Console and implemented the Console and VirtualBox hooks.

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