VirtualBox

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

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

Main. QT/FE: fix long standing COM issue

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