VirtualBox

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

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

Main: remove VirtualBoxSupportTranslation template, add translation support to generic base class, clean up COM headers more, remove SupportErrorInfo.cpp|h

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.5 KB
Line 
1/* $Id: ConsoleImpl.h 30739 2010-07-08 12:27:42Z 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 RemoteDisplayInfo;
36class AudioSniffer;
37class ConsoleVRDPServer;
38class ConsoleCallbackRegistration; /* See ConsoleImpl.cpp. */
39class VMMDev;
40class Progress;
41
42#include <VBox/vrdpapi.h>
43#include <VBox/pdmdrv.h>
44#ifdef VBOX_WITH_GUEST_PROPS
45# include <VBox/HostServices/GuestPropertySvc.h> /* For the property notification callback */
46#endif
47
48#ifdef RT_OS_WINDOWS
49# include "win/VBoxComEvents.h"
50#endif
51
52struct VUSBIRHCONFIG;
53typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
54
55#include <list>
56
57// defines
58///////////////////////////////////////////////////////////////////////////////
59
60/**
61 * Checks the availability of the underlying VM device driver corresponding
62 * to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
63 * not available (NULL), sets error info and returns returns E_ACCESSDENIED.
64 * The translatable error message is defined in null context.
65 *
66 * Intended to used only within Console children (i.e. Keyboard, Mouse,
67 * Display, etc.).
68 *
69 * @param drv driver pointer to check (compare it with NULL)
70 */
71#define CHECK_CONSOLE_DRV(drv) \
72 do { \
73 if (!(drv)) \
74 return setError(E_ACCESSDENIED, tr("The console is not powered up")); \
75 } while (0)
76
77// Console
78///////////////////////////////////////////////////////////////////////////////
79
80/** IConsole implementation class */
81class ATL_NO_VTABLE Console :
82 public VirtualBoxBaseWithChildrenNEXT,
83 VBOX_SCRIPTABLE_IMPL(IConsole)
84#ifdef RT_OS_WINDOWS
85 , public CComCoClass<Console, &CLSID_Console>
86 , public IConnectionPointContainerImpl<Console>
87 , public IConnectionPointImpl<Console, &IID_IConsoleCallback, CComDynamicUnkArray>
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 COM_INTERFACE_ENTRY(IConnectionPointContainer)
105 END_COM_MAP()
106
107#ifdef RT_OS_WINDOWS
108 BEGIN_CONNECTION_POINT_MAP(Console)
109 CONNECTION_POINT_ENTRY(IID_IConsoleCallback)
110 END_CONNECTION_POINT_MAP()
111#endif
112
113
114 Console();
115 ~Console();
116
117 HRESULT FinalConstruct();
118 void FinalRelease();
119
120 // public initializers/uninitializers for internal purposes only
121 HRESULT init(IMachine *aMachine, IInternalMachineControl *aControl);
122 void uninit();
123
124 // IConsole properties
125 STDMETHOD(COMGETTER(Machine))(IMachine **aMachine);
126 STDMETHOD(COMGETTER(State))(MachineState_T *aMachineState);
127 STDMETHOD(COMGETTER(Guest))(IGuest **aGuest);
128 STDMETHOD(COMGETTER(Keyboard))(IKeyboard **aKeyboard);
129 STDMETHOD(COMGETTER(Mouse))(IMouse **aMouse);
130 STDMETHOD(COMGETTER(Display))(IDisplay **aDisplay);
131 STDMETHOD(COMGETTER(Debugger))(IMachineDebugger **aDebugger);
132 STDMETHOD(COMGETTER(USBDevices))(ComSafeArrayOut(IUSBDevice *, aUSBDevices));
133 STDMETHOD(COMGETTER(RemoteUSBDevices))(ComSafeArrayOut(IHostUSBDevice *, aRemoteUSBDevices));
134 STDMETHOD(COMGETTER(RemoteDisplayInfo))(IRemoteDisplayInfo **aRemoteDisplayInfo);
135 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
136 STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
137
138 // IConsole methods
139 STDMETHOD(PowerUp)(IProgress **aProgress);
140 STDMETHOD(PowerUpPaused)(IProgress **aProgress);
141 STDMETHOD(PowerDown)(IProgress **aProgress);
142 STDMETHOD(Reset)();
143 STDMETHOD(Pause)();
144 STDMETHOD(Resume)();
145 STDMETHOD(PowerButton)();
146 STDMETHOD(SleepButton)();
147 STDMETHOD(GetPowerButtonHandled)(BOOL *aHandled);
148 STDMETHOD(GetGuestEnteredACPIMode)(BOOL *aEntered);
149 STDMETHOD(SaveState)(IProgress **aProgress);
150 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
151 STDMETHOD(ForgetSavedState)(BOOL aRemove);
152 STDMETHOD(GetDeviceActivity)(DeviceType_T aDeviceType,
153 DeviceActivity_T *aDeviceActivity);
154 STDMETHOD(AttachUSBDevice)(IN_BSTR aId);
155 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, IUSBDevice **aDevice);
156 STDMETHOD(FindUSBDeviceByAddress)(IN_BSTR aAddress, IUSBDevice **aDevice);
157 STDMETHOD(FindUSBDeviceById)(IN_BSTR aId, IUSBDevice **aDevice);
158 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
159 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
160 STDMETHOD(TakeSnapshot)(IN_BSTR aName, IN_BSTR aDescription,
161 IProgress **aProgress);
162 STDMETHOD(DeleteSnapshot)(IN_BSTR aId, IProgress **aProgress);
163 STDMETHOD(RestoreSnapshot)(ISnapshot *aSnapshot, IProgress **aProgress);
164 STDMETHOD(Teleport)(IN_BSTR aHostname, ULONG aPort, IN_BSTR aPassword, ULONG aMaxDowntime, IProgress **aProgress);
165 STDMETHOD(RegisterCallback)(IConsoleCallback *aCallback);
166 STDMETHOD(UnregisterCallback)(IConsoleCallback *aCallback);
167
168 // public methods for internal purposes only
169
170 /*
171 * Note: the following methods do not increase refcount. intended to be
172 * called only by the VM execution thread.
173 */
174
175 Guest *getGuest() const { return mGuest; }
176 Keyboard *getKeyboard() const { return mKeyboard; }
177 Mouse *getMouse() const { return mMouse; }
178 Display *getDisplay() const { return mDisplay; }
179 MachineDebugger *getMachineDebugger() const { return mDebugger; }
180
181 const ComPtr<IMachine> &machine() const { return mMachine; }
182
183 /** Method is called only from ConsoleVRDPServer */
184 IVRDPServer *getVRDPServer() const { return mVRDPServer; }
185
186 ConsoleVRDPServer *consoleVRDPServer() const { return mConsoleVRDPServer; }
187
188 HRESULT updateMachineState(MachineState_T aMachineState);
189
190 // events from IInternalSessionControl
191 HRESULT onNetworkAdapterChange(INetworkAdapter *aNetworkAdapter, BOOL changeAdapter);
192 HRESULT onSerialPortChange(ISerialPort *aSerialPort);
193 HRESULT onParallelPortChange(IParallelPort *aParallelPort);
194 HRESULT onStorageControllerChange();
195 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
196 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
197 HRESULT onVRDPServerChange(BOOL aRestart);
198 HRESULT onUSBControllerChange();
199 HRESULT onSharedFolderChange(BOOL aGlobal);
200 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice, IVirtualBoxErrorInfo *aError, ULONG aMaskedIfs);
201 HRESULT onUSBDeviceDetach(IN_BSTR aId, IVirtualBoxErrorInfo *aError);
202 HRESULT getGuestProperty(IN_BSTR aKey, BSTR *aValue, ULONG64 *aTimestamp, BSTR *aFlags);
203 HRESULT setGuestProperty(IN_BSTR aKey, IN_BSTR aValue, IN_BSTR aFlags);
204 HRESULT enumerateGuestProperties(IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(ULONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
205 HRESULT onlineMergeMedium(IMediumAttachment *aMediumAttachment,
206 ULONG aSourceIdx, ULONG aTargetIdx,
207 IMedium *aSource, IMedium *aTarget,
208 BOOL aMergeForward, IMedium *aParentForTarget,
209 ComSafeArrayIn(IMedium *, aChildrenToReparent),
210 IProgress *aProgress);
211 VMMDev *getVMMDev() { return mVMMDev; }
212 AudioSniffer *getAudioSniffer() { return mAudioSniffer; }
213
214 int VRDPClientLogon(uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
215 void VRDPClientConnect(uint32_t u32ClientId);
216 void VRDPClientDisconnect(uint32_t u32ClientId, uint32_t fu32Intercepted);
217 void VRDPInterceptAudio(uint32_t u32ClientId);
218 void VRDPInterceptUSB(uint32_t u32ClientId, void **ppvIntercept);
219 void VRDPInterceptClipboard(uint32_t u32ClientId);
220
221 void processRemoteUSBDevices(uint32_t u32ClientId, VRDPUSBDEVICEDESC *pDevList, uint32_t cbDevList);
222
223 // callback callers (partly; for some events console callbacks are notified
224 // directly from IInternalSessionControl event handlers declared above)
225 void onMousePointerShapeChange(bool fVisible, bool fAlpha,
226 uint32_t xHot, uint32_t yHot,
227 uint32_t width, uint32_t height,
228 ComSafeArrayIn(uint8_t, aShape));
229 void onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative, BOOL needsHostCursor);
230 void onStateChange(MachineState_T aMachineState);
231 void onAdditionsStateChange();
232 void onAdditionsOutdated();
233 void onKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock);
234 void onUSBDeviceStateChange(IUSBDevice *aDevice, bool aAttached,
235 IVirtualBoxErrorInfo *aError);
236 void onRuntimeError(BOOL aFatal, IN_BSTR aErrorID, IN_BSTR aMessage);
237 HRESULT onShowWindow(BOOL aCheck, BOOL *aCanShow, ULONG64 *aWinId);
238 void onRemoteDisplayInfoChange();
239
240 static const PDMDRVREG DrvStatusReg;
241
242 static HRESULT setErrorStatic(HRESULT aResultCode, const char *pcsz, ...);
243 HRESULT setAuthLibraryError(const char *filename, int rc);
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
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)
405 : mHostPath(aHostPath)
406 , mWritable(aWritable) {}
407 SharedFolderData(const SharedFolderData& aThat)
408 : mHostPath(aThat.mHostPath)
409 , mWritable(aThat.mWritable) {}
410 Bstr mHostPath;
411 BOOL mWritable;
412 };
413 typedef std::map <Bstr, ComObjPtr<SharedFolder> > SharedFolderMap;
414 typedef std::map <Bstr, SharedFolderData> SharedFolderDataMap;
415
416private:
417
418 typedef std::list <ComObjPtr<OUSBDevice> > USBDeviceList;
419 typedef std::list <ComObjPtr<RemoteUSBDevice> > RemoteUSBDeviceList;
420
421 HRESULT addVMCaller(bool aQuiet = false, bool aAllowNullVM = false);
422 void releaseVMCaller();
423
424 HRESULT consoleInitReleaseLog(const ComPtr<IMachine> aMachine);
425
426 HRESULT powerUp(IProgress **aProgress, bool aPaused);
427 HRESULT powerDown(Progress *aProgress = NULL);
428
429 HRESULT callTapSetupApplication(bool isStatic, RTFILE tapFD, Bstr &tapDevice,
430 Bstr &tapSetupApplication);
431#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
432 HRESULT attachToTapInterface(INetworkAdapter *networkAdapter);
433 HRESULT detachFromTapInterface(INetworkAdapter *networkAdapter);
434#endif
435 HRESULT powerDownHostInterfaces();
436
437 HRESULT setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
438 HRESULT setMachineStateLocally(MachineState_T aMachineState)
439 {
440 return setMachineState(aMachineState, false /* aUpdateServer */);
441 }
442
443 HRESULT findSharedFolder(CBSTR aName,
444 ComObjPtr<SharedFolder> &aSharedFolder,
445 bool aSetError = false);
446
447 HRESULT fetchSharedFolders(BOOL aGlobal);
448 bool findOtherSharedFolder(IN_BSTR aName,
449 SharedFolderDataMap::const_iterator &aIt);
450
451 HRESULT createSharedFolder(CBSTR aName, SharedFolderData aData);
452 HRESULT removeSharedFolder(CBSTR aName);
453
454 static DECLCALLBACK(int) configConstructor(PVM pVM, void *pvConsole);
455
456 int configMediumAttachment(PCFGMNODE pCtlInst,
457 const char *pcszDevice,
458 unsigned uInstance,
459 StorageBus_T enmBus,
460 bool fUseHostIOCache,
461 bool fSetupMerge,
462 unsigned uMergeSource,
463 unsigned uMergeTarget,
464 IMediumAttachment *pMediumAtt,
465 MachineState_T aMachineState,
466 HRESULT *phrc,
467 bool fAttachDetach,
468 bool fForceUnmount,
469 PVM pVM,
470 DeviceType_T *paLedDevType);
471 int configMedium(PCFGMNODE pLunL0,
472 bool fPassthrough,
473 DeviceType_T enmType,
474 bool fUseHostIOCache,
475 bool fSetupMerge,
476 unsigned uMergeSource,
477 unsigned uMergeTarget,
478 IMedium *pMedium,
479 MachineState_T aMachineState,
480 HRESULT *phrc);
481 static DECLCALLBACK(int) reconfigureMediumAttachment(Console *pConsole,
482 PVM pVM,
483 const char *pcszDevice,
484 unsigned uInstance,
485 StorageBus_T enmBus,
486 bool fUseHostIOCache,
487 bool fSetupMerge,
488 unsigned uMergeSource,
489 unsigned uMergeTarget,
490 IMediumAttachment *aMediumAtt,
491 MachineState_T aMachineState,
492 HRESULT *phrc);
493 static DECLCALLBACK(int) changeRemovableMedium(Console *pThis,
494 const char *pcszDevice,
495 unsigned uInstance,
496 StorageBus_T enmBus,
497 bool fUseHostIOCache,
498 IMediumAttachment *aMediumAtt,
499 bool fForce);
500
501 int configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun,
502 INetworkAdapter *aNetworkAdapter, PCFGMNODE pCfg,
503 PCFGMNODE pLunL0, PCFGMNODE pInst, bool fAttachDetach);
504
505 static DECLCALLBACK(int) configGuestProperties(void *pvConsole);
506 static DECLCALLBACK(int) configGuestControl(void *pvConsole);
507 static DECLCALLBACK(void) vmstateChangeCallback(PVM aVM, VMSTATE aState,
508 VMSTATE aOldState, void *aUser);
509 static DECLCALLBACK(int) unplugCpu(Console *pThis, unsigned uCpu);
510 static DECLCALLBACK(int) plugCpu(Console *pThis, unsigned uCpu);
511 HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce);
512 HRESULT doCPURemove(ULONG aCpu);
513 HRESULT doCPUAdd(ULONG aCpu);
514
515#ifdef VBOX_DYNAMIC_NET_ATTACH
516 HRESULT doNetworkAdapterChange(const char *pszDevice, unsigned uInstance,
517 unsigned uLun, INetworkAdapter *aNetworkAdapter);
518 static DECLCALLBACK(int) changeNetworkAttachment(Console *pThis, const char *pszDevice,
519 unsigned uInstance, unsigned uLun,
520 INetworkAdapter *aNetworkAdapter);
521#endif /* VBOX_DYNAMIC_NET_ATTACH */
522
523#ifdef VBOX_WITH_USB
524 HRESULT attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs);
525 HRESULT detachUSBDevice(USBDeviceList::iterator &aIt);
526
527 static DECLCALLBACK(int) usbAttachCallback(Console *that, IUSBDevice *aHostDevice, PCRTUUID aUuid,
528 bool aRemote, const char *aAddress, ULONG aMaskedIfs);
529 static DECLCALLBACK(int) usbDetachCallback(Console *that, USBDeviceList::iterator *aIt, PCRTUUID aUuid);
530#endif
531
532 static DECLCALLBACK(int) fntTakeSnapshotWorker(RTTHREAD Thread, void *pvUser);
533
534 static DECLCALLBACK(int) stateProgressCallback(PVM pVM, unsigned uPercent, void *pvUser);
535
536 static DECLCALLBACK(void) genericVMSetErrorCallback(PVM pVM, void *pvUser, int rc, RT_SRC_POS_DECL,
537 const char *pszErrorFmt, va_list va);
538
539 static DECLCALLBACK(void) setVMRuntimeErrorCallbackF(PVM pVM, void *pvUser, uint32_t fFatal,
540 const char *pszErrorId,
541 const char *pszFormat, ...);
542 static DECLCALLBACK(void) setVMRuntimeErrorCallback(PVM pVM, void *pvUser, uint32_t fFatal,
543 const char *pszErrorId,
544 const char *pszFormat, va_list va);
545
546 HRESULT captureUSBDevices(PVM pVM);
547 void detachAllUSBDevices(bool aDone);
548
549 static DECLCALLBACK(int) powerUpThread(RTTHREAD Thread, void *pvUser);
550 static DECLCALLBACK(int) saveStateThread(RTTHREAD Thread, void *pvUser);
551 static DECLCALLBACK(int) powerDownThread(RTTHREAD Thread, void *pvUser);
552
553 static DECLCALLBACK(void *) drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
554 static DECLCALLBACK(void) drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
555 static DECLCALLBACK(void) drvStatus_Destruct(PPDMDRVINS pDrvIns);
556 static DECLCALLBACK(int) drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
557
558 int mcAudioRefs;
559 volatile uint32_t mcVRDPClients;
560 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
561
562 static const char *sSSMConsoleUnit;
563 static uint32_t sSSMConsoleVer;
564
565 HRESULT loadDataFromSavedState();
566 int loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
567
568 static DECLCALLBACK(void) saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
569 static DECLCALLBACK(int) loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
570
571#ifdef VBOX_WITH_GUEST_PROPS
572 static DECLCALLBACK(int) doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
573 HRESULT doEnumerateGuestProperties(CBSTR aPatterns,
574 ComSafeArrayOut(BSTR, aNames),
575 ComSafeArrayOut(BSTR, aValues),
576 ComSafeArrayOut(ULONG64, aTimestamps),
577 ComSafeArrayOut(BSTR, aFlags));
578
579 bool enabledGuestPropertiesVRDP(void);
580 void updateGuestPropertiesVRDPLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
581 void updateGuestPropertiesVRDPDisconnect(uint32_t u32ClientId);
582#endif
583
584 /** @name Teleporter support
585 * @{ */
586 static DECLCALLBACK(int) teleporterSrcThreadWrapper(RTTHREAD hThread, void *pvUser);
587 HRESULT teleporterSrc(TeleporterStateSrc *pState);
588 HRESULT teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
589 HRESULT teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
590 HRESULT teleporterTrg(PVM pVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
591 Progress *pProgress, bool *pfPowerOffOnFailure);
592 static DECLCALLBACK(int) teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
593 /** @} */
594
595 bool mSavedStateDataLoaded : 1;
596
597 const ComPtr<IMachine> mMachine;
598 const ComPtr<IInternalMachineControl> mControl;
599
600 const ComPtr <IVRDPServer> mVRDPServer;
601
602 ConsoleVRDPServer * const mConsoleVRDPServer;
603
604 const ComObjPtr<Guest> mGuest;
605 const ComObjPtr<Keyboard> mKeyboard;
606 const ComObjPtr<Mouse> mMouse;
607 const ComObjPtr<Display> mDisplay;
608 const ComObjPtr<MachineDebugger> mDebugger;
609 const ComObjPtr<RemoteDisplayInfo> mRemoteDisplayInfo;
610 const ComObjPtr<EventSource> mEventSource;
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 /** The current network attachment type in the VM.
637 * This doesn't have to match the network attachment type
638 * maintained in the NetworkAdapter. This is needed to
639 * change the network attachment dynamically.
640 */
641 NetworkAttachmentType_T meAttachmentType[SchemaDefs::NetworkAdapterCount];
642
643 VMMDev * const mVMMDev;
644 AudioSniffer * const mAudioSniffer;
645
646 enum
647 {
648 iLedFloppy = 0,
649 cLedFloppy = 1,
650 iLedIde = iLedFloppy + cLedFloppy,
651 cLedIde = 4,
652 iLedSata = iLedIde + cLedIde,
653 cLedSata = 30,
654 iLedScsi = iLedSata + cLedSata,
655 cLedScsi = 16,
656 iLedSas = iLedScsi + cLedScsi,
657 cLedSas = 8,
658 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas
659 };
660 DeviceType_T maStorageDevType[cLedStorage];
661 PPDMLED mapStorageLeds[cLedStorage];
662 PPDMLED mapNetworkLeds[SchemaDefs::NetworkAdapterCount];
663 PPDMLED mapSharedFolderLed;
664 PPDMLED mapUSBLed[2];
665#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
666 Utf8Str maTAPDeviceName[8];
667 RTFILE maTapFD[8];
668#endif
669
670 bool mVMStateChangeCallbackDisabled;
671
672 /** Local machine state value. */
673 MachineState_T mMachineState;
674
675 /** Pointer to the progress object of a live cancelable task.
676 *
677 * This is currently only used by Console::Teleport(), but is intended to later
678 * be used by the live snapshot code path as well. Actions like
679 * Console::PowerDown, which automatically cancels out the running snapshot /
680 * teleportion operation, will cancel the teleportation / live snapshot
681 * operation before starting. */
682 ComObjPtr<Progress> mptrCancelableProgress;
683
684 typedef std::list<ConsoleCallbackRegistration> CallbackList;
685 CallbackList mCallbacks;
686
687 struct
688 {
689 /** OnMousePointerShapeChange() cache */
690 struct
691 {
692 bool valid;
693 bool visible;
694 bool alpha;
695 uint32_t xHot;
696 uint32_t yHot;
697 uint32_t width;
698 uint32_t height;
699 com::SafeArray<BYTE> shape;
700 }
701 mpsc;
702
703 /** OnMouseCapabilityChange() cache */
704 struct
705 {
706 bool valid;
707 BOOL supportsAbsolute;
708 BOOL supportsRelative;
709 BOOL needsHostCursor;
710 }
711 mcc;
712
713 /** OnKeyboardLedsChange() cache */
714 struct
715 {
716 bool valid;
717 bool numLock;
718 bool capsLock;
719 bool scrollLock;
720 }
721 klc;
722
723 void clear()
724 {
725 /* We cannot do memset() on mpsc to avoid cleaning shape's vtable */
726 mpsc.shape.setNull();
727 mpsc.valid = mpsc.visible = mpsc.alpha = false;
728 mpsc.xHot = mpsc.yHot = mpsc.width = mpsc.height = 0;
729 ::memset(&mcc, 0, sizeof mcc);
730 ::memset(&klc, 0, sizeof klc);
731 }
732 }
733 mCallbackData;
734
735#ifdef RT_OS_WINDOWS
736 ComEventsHelper mComEvHelper;
737#endif
738
739 friend struct VMTask;
740};
741
742#endif // !____H_CONSOLEIMPL
743/* 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