VirtualBox

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

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

Main: remove dead and obsolete code

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