VirtualBox

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

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

Main/DrvIntNet: pass IgnoreConnectFailure to the driver to make it ignore connection errors only if the VM is restoring from a saved state

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette