VirtualBox

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

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

Main: remove SupportErrorInfo template magic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.6 KB
Line 
1/* $Id: ConsoleImpl.h 30714 2010-07-07 16:20:03Z vboxsync $ */
2/** @file
3 * VBox Console COM Class definition
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.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 public VirtualBoxSupportTranslation<Console>,
84 VBOX_SCRIPTABLE_IMPL(IConsole)
85#ifdef RT_OS_WINDOWS
86 , public CComCoClass<Console, &CLSID_Console>
87 , public IConnectionPointContainerImpl<Console>
88 , public IConnectionPointImpl<Console, &IID_IConsoleCallback, CComDynamicUnkArray>
89#endif
90{
91 Q_OBJECT
92
93public:
94
95 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Console, IConsole)
96
97 DECLARE_NOT_AGGREGATABLE(Console)
98
99 DECLARE_PROTECT_FINAL_CONSTRUCT()
100
101 BEGIN_COM_MAP(Console)
102 COM_INTERFACE_ENTRY(ISupportErrorInfo)
103 COM_INTERFACE_ENTRY(IConsole)
104 COM_INTERFACE_ENTRY(IDispatch)
105 COM_INTERFACE_ENTRY(IConnectionPointContainer)
106 END_COM_MAP()
107
108#ifdef RT_OS_WINDOWS
109 BEGIN_CONNECTION_POINT_MAP(Console)
110 CONNECTION_POINT_ENTRY(IID_IConsoleCallback)
111 END_CONNECTION_POINT_MAP()
112#endif
113
114
115 Console();
116 ~Console();
117
118 HRESULT FinalConstruct();
119 void FinalRelease();
120
121 // public initializers/uninitializers for internal purposes only
122 HRESULT init(IMachine *aMachine, IInternalMachineControl *aControl);
123 void uninit();
124
125 // IConsole properties
126 STDMETHOD(COMGETTER(Machine))(IMachine **aMachine);
127 STDMETHOD(COMGETTER(State))(MachineState_T *aMachineState);
128 STDMETHOD(COMGETTER(Guest))(IGuest **aGuest);
129 STDMETHOD(COMGETTER(Keyboard))(IKeyboard **aKeyboard);
130 STDMETHOD(COMGETTER(Mouse))(IMouse **aMouse);
131 STDMETHOD(COMGETTER(Display))(IDisplay **aDisplay);
132 STDMETHOD(COMGETTER(Debugger))(IMachineDebugger **aDebugger);
133 STDMETHOD(COMGETTER(USBDevices))(ComSafeArrayOut(IUSBDevice *, aUSBDevices));
134 STDMETHOD(COMGETTER(RemoteUSBDevices))(ComSafeArrayOut(IHostUSBDevice *, aRemoteUSBDevices));
135 STDMETHOD(COMGETTER(RemoteDisplayInfo))(IRemoteDisplayInfo **aRemoteDisplayInfo);
136 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
137 STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
138
139 // IConsole methods
140 STDMETHOD(PowerUp)(IProgress **aProgress);
141 STDMETHOD(PowerUpPaused)(IProgress **aProgress);
142 STDMETHOD(PowerDown)(IProgress **aProgress);
143 STDMETHOD(Reset)();
144 STDMETHOD(Pause)();
145 STDMETHOD(Resume)();
146 STDMETHOD(PowerButton)();
147 STDMETHOD(SleepButton)();
148 STDMETHOD(GetPowerButtonHandled)(BOOL *aHandled);
149 STDMETHOD(GetGuestEnteredACPIMode)(BOOL *aEntered);
150 STDMETHOD(SaveState)(IProgress **aProgress);
151 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
152 STDMETHOD(ForgetSavedState)(BOOL aRemove);
153 STDMETHOD(GetDeviceActivity)(DeviceType_T aDeviceType,
154 DeviceActivity_T *aDeviceActivity);
155 STDMETHOD(AttachUSBDevice)(IN_BSTR aId);
156 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, IUSBDevice **aDevice);
157 STDMETHOD(FindUSBDeviceByAddress)(IN_BSTR aAddress, IUSBDevice **aDevice);
158 STDMETHOD(FindUSBDeviceById)(IN_BSTR aId, IUSBDevice **aDevice);
159 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
160 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
161 STDMETHOD(TakeSnapshot)(IN_BSTR aName, IN_BSTR aDescription,
162 IProgress **aProgress);
163 STDMETHOD(DeleteSnapshot)(IN_BSTR aId, IProgress **aProgress);
164 STDMETHOD(RestoreSnapshot)(ISnapshot *aSnapshot, IProgress **aProgress);
165 STDMETHOD(Teleport)(IN_BSTR aHostname, ULONG aPort, IN_BSTR aPassword, ULONG aMaxDowntime, IProgress **aProgress);
166 STDMETHOD(RegisterCallback)(IConsoleCallback *aCallback);
167 STDMETHOD(UnregisterCallback)(IConsoleCallback *aCallback);
168
169 // public methods for internal purposes only
170
171 /*
172 * Note: the following methods do not increase refcount. intended to be
173 * called only by the VM execution thread.
174 */
175
176 Guest *getGuest() const { return mGuest; }
177 Keyboard *getKeyboard() const { return mKeyboard; }
178 Mouse *getMouse() const { return mMouse; }
179 Display *getDisplay() const { return mDisplay; }
180 MachineDebugger *getMachineDebugger() const { return mDebugger; }
181
182 const ComPtr<IMachine> &machine() const { return mMachine; }
183
184 /** Method is called only from ConsoleVRDPServer */
185 IVRDPServer *getVRDPServer() const { return mVRDPServer; }
186
187 ConsoleVRDPServer *consoleVRDPServer() const { return mConsoleVRDPServer; }
188
189 HRESULT updateMachineState(MachineState_T aMachineState);
190
191 // events from IInternalSessionControl
192 HRESULT onNetworkAdapterChange(INetworkAdapter *aNetworkAdapter, BOOL changeAdapter);
193 HRESULT onSerialPortChange(ISerialPort *aSerialPort);
194 HRESULT onParallelPortChange(IParallelPort *aParallelPort);
195 HRESULT onStorageControllerChange();
196 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
197 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
198 HRESULT onVRDPServerChange(BOOL aRestart);
199 HRESULT onUSBControllerChange();
200 HRESULT onSharedFolderChange(BOOL aGlobal);
201 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice, IVirtualBoxErrorInfo *aError, ULONG aMaskedIfs);
202 HRESULT onUSBDeviceDetach(IN_BSTR aId, IVirtualBoxErrorInfo *aError);
203 HRESULT getGuestProperty(IN_BSTR aKey, BSTR *aValue, ULONG64 *aTimestamp, BSTR *aFlags);
204 HRESULT setGuestProperty(IN_BSTR aKey, IN_BSTR aValue, IN_BSTR aFlags);
205 HRESULT enumerateGuestProperties(IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(ULONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
206 HRESULT onlineMergeMedium(IMediumAttachment *aMediumAttachment,
207 ULONG aSourceIdx, ULONG aTargetIdx,
208 IMedium *aSource, IMedium *aTarget,
209 BOOL aMergeForward, IMedium *aParentForTarget,
210 ComSafeArrayIn(IMedium *, aChildrenToReparent),
211 IProgress *aProgress);
212 VMMDev *getVMMDev() { return mVMMDev; }
213 AudioSniffer *getAudioSniffer() { return mAudioSniffer; }
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, VRDPUSBDEVICEDESC *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, ULONG64 *aWinId);
239 void onRemoteDisplayInfoChange();
240
241 static const PDMDRVREG DrvStatusReg;
242
243 static HRESULT setErrorStatic(HRESULT aResultCode, const char *pcsz, ...);
244 HRESULT setAuthLibraryError(const char *filename, int rc);
245 HRESULT setInvalidMachineStateError();
246
247 static HRESULT handleUnexpectedExceptions(RT_SRC_POS_DECL);
248
249 static const char *convertControllerTypeToDev(StorageControllerType_T enmCtrlType);
250 static HRESULT convertBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
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 mpVM = aThat->mpVM;
352 }
353 /** Smart SaveVMPtr to PVM cast operator */
354 operator PVM() const { return mpVM; }
355 /** Direct PVM access for printf()-like functions */
356 PVM raw() const { return mpVM; }
357 private:
358 PVM mpVM;
359 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(SafeVMPtrBase)
360 DECLARE_CLS_NEW_DELETE_NOOP(SafeVMPtrBase)
361 };
362
363public:
364
365 /**
366 * Helper class that safely manages the Console::mpVM pointer
367 * by calling addVMCaller() on construction and releaseVMCaller() on
368 * destruction. Intended for Console children. The usage pattern is:
369 * <code>
370 * Console::SaveVMPtr pVM(mParent);
371 * if (FAILED(pVM.rc())) return pVM.rc();
372 * ...
373 * VMR3ReqCall(pVM, ...
374 * ...
375 * printf("%p\n", pVM.raw());
376 * </code>
377 *
378 * @note Temporarily locks the argument for writing.
379 *
380 * @sa SafeVMPtrQuiet, AutoVMCaller
381 */
382 typedef SafeVMPtrBase <false> SafeVMPtr;
383
384 /**
385 * A deviation of SaveVMPtr that doesn't set the error info on failure.
386 * Intended for pieces of code that don't need to return the VM access
387 * failure to the caller. The usage pattern is:
388 * <code>
389 * Console::SaveVMPtrQuiet pVM(mParent);
390 * if (pVM.rc())
391 * VMR3ReqCall(pVM, ...
392 * return S_OK;
393 * </code>
394 *
395 * @note Temporarily locks the argument for writing.
396 *
397 * @sa SafeVMPtr, AutoVMCaller
398 */
399 typedef SafeVMPtrBase <true> SafeVMPtrQuiet;
400
401 class SharedFolderData
402 {
403 public:
404 SharedFolderData() {}
405 SharedFolderData(Bstr aHostPath, BOOL aWritable)
406 : mHostPath(aHostPath)
407 , mWritable(aWritable) {}
408 SharedFolderData(const SharedFolderData& aThat)
409 : mHostPath(aThat.mHostPath)
410 , mWritable(aThat.mWritable) {}
411 Bstr mHostPath;
412 BOOL mWritable;
413 };
414 typedef std::map <Bstr, ComObjPtr<SharedFolder> > SharedFolderMap;
415 typedef std::map <Bstr, SharedFolderData> SharedFolderDataMap;
416
417private:
418
419 typedef std::list <ComObjPtr<OUSBDevice> > USBDeviceList;
420 typedef std::list <ComObjPtr<RemoteUSBDevice> > RemoteUSBDeviceList;
421
422 HRESULT addVMCaller(bool aQuiet = false, bool aAllowNullVM = false);
423 void releaseVMCaller();
424
425 HRESULT consoleInitReleaseLog(const ComPtr<IMachine> aMachine);
426
427 HRESULT powerUp(IProgress **aProgress, bool aPaused);
428 HRESULT powerDown(Progress *aProgress = NULL);
429
430 HRESULT callTapSetupApplication(bool isStatic, RTFILE tapFD, Bstr &tapDevice,
431 Bstr &tapSetupApplication);
432#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
433 HRESULT attachToTapInterface(INetworkAdapter *networkAdapter);
434 HRESULT detachFromTapInterface(INetworkAdapter *networkAdapter);
435#endif
436 HRESULT powerDownHostInterfaces();
437
438 HRESULT setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
439 HRESULT setMachineStateLocally(MachineState_T aMachineState)
440 {
441 return setMachineState(aMachineState, false /* aUpdateServer */);
442 }
443
444 HRESULT findSharedFolder(CBSTR aName,
445 ComObjPtr<SharedFolder> &aSharedFolder,
446 bool aSetError = false);
447
448 HRESULT fetchSharedFolders(BOOL aGlobal);
449 bool findOtherSharedFolder(IN_BSTR aName,
450 SharedFolderDataMap::const_iterator &aIt);
451
452 HRESULT createSharedFolder(CBSTR aName, SharedFolderData aData);
453 HRESULT removeSharedFolder(CBSTR aName);
454
455 static DECLCALLBACK(int) configConstructor(PVM pVM, void *pvConsole);
456
457 int configMediumAttachment(PCFGMNODE pCtlInst,
458 const char *pcszDevice,
459 unsigned uInstance,
460 StorageBus_T enmBus,
461 bool fUseHostIOCache,
462 bool fSetupMerge,
463 unsigned uMergeSource,
464 unsigned uMergeTarget,
465 IMediumAttachment *pMediumAtt,
466 MachineState_T aMachineState,
467 HRESULT *phrc,
468 bool fAttachDetach,
469 bool fForceUnmount,
470 PVM pVM,
471 DeviceType_T *paLedDevType);
472 int configMedium(PCFGMNODE pLunL0,
473 bool fPassthrough,
474 DeviceType_T enmType,
475 bool fUseHostIOCache,
476 bool fSetupMerge,
477 unsigned uMergeSource,
478 unsigned uMergeTarget,
479 IMedium *pMedium,
480 MachineState_T aMachineState,
481 HRESULT *phrc);
482 static DECLCALLBACK(int) reconfigureMediumAttachment(Console *pConsole,
483 PVM pVM,
484 const char *pcszDevice,
485 unsigned uInstance,
486 StorageBus_T enmBus,
487 bool fUseHostIOCache,
488 bool fSetupMerge,
489 unsigned uMergeSource,
490 unsigned uMergeTarget,
491 IMediumAttachment *aMediumAtt,
492 MachineState_T aMachineState,
493 HRESULT *phrc);
494 static DECLCALLBACK(int) changeRemovableMedium(Console *pThis,
495 const char *pcszDevice,
496 unsigned uInstance,
497 StorageBus_T enmBus,
498 bool fUseHostIOCache,
499 IMediumAttachment *aMediumAtt,
500 bool fForce);
501
502 int configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun,
503 INetworkAdapter *aNetworkAdapter, PCFGMNODE pCfg,
504 PCFGMNODE pLunL0, PCFGMNODE pInst, bool fAttachDetach);
505
506 static DECLCALLBACK(int) configGuestProperties(void *pvConsole);
507 static DECLCALLBACK(int) configGuestControl(void *pvConsole);
508 static DECLCALLBACK(void) vmstateChangeCallback(PVM aVM, VMSTATE aState,
509 VMSTATE aOldState, void *aUser);
510 static DECLCALLBACK(int) unplugCpu(Console *pThis, unsigned uCpu);
511 static DECLCALLBACK(int) plugCpu(Console *pThis, unsigned uCpu);
512 HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce);
513 HRESULT doCPURemove(ULONG aCpu);
514 HRESULT doCPUAdd(ULONG aCpu);
515
516#ifdef VBOX_DYNAMIC_NET_ATTACH
517 HRESULT doNetworkAdapterChange(const char *pszDevice, unsigned uInstance,
518 unsigned uLun, INetworkAdapter *aNetworkAdapter);
519 static DECLCALLBACK(int) changeNetworkAttachment(Console *pThis, const char *pszDevice,
520 unsigned uInstance, unsigned uLun,
521 INetworkAdapter *aNetworkAdapter);
522#endif /* VBOX_DYNAMIC_NET_ATTACH */
523
524#ifdef VBOX_WITH_USB
525 HRESULT attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs);
526 HRESULT detachUSBDevice(USBDeviceList::iterator &aIt);
527
528 static DECLCALLBACK(int) usbAttachCallback(Console *that, IUSBDevice *aHostDevice, PCRTUUID aUuid,
529 bool aRemote, const char *aAddress, ULONG aMaskedIfs);
530 static DECLCALLBACK(int) usbDetachCallback(Console *that, USBDeviceList::iterator *aIt, PCRTUUID aUuid);
531#endif
532
533 static DECLCALLBACK(int) fntTakeSnapshotWorker(RTTHREAD Thread, void *pvUser);
534
535 static DECLCALLBACK(int) stateProgressCallback(PVM pVM, unsigned uPercent, void *pvUser);
536
537 static DECLCALLBACK(void) genericVMSetErrorCallback(PVM pVM, void *pvUser, int rc, RT_SRC_POS_DECL,
538 const char *pszErrorFmt, va_list va);
539
540 static DECLCALLBACK(void) setVMRuntimeErrorCallbackF(PVM pVM, void *pvUser, uint32_t fFatal,
541 const char *pszErrorId,
542 const char *pszFormat, ...);
543 static DECLCALLBACK(void) setVMRuntimeErrorCallback(PVM pVM, void *pvUser, uint32_t fFatal,
544 const char *pszErrorId,
545 const char *pszFormat, va_list va);
546
547 HRESULT captureUSBDevices(PVM pVM);
548 void detachAllUSBDevices(bool aDone);
549
550 static DECLCALLBACK(int) powerUpThread(RTTHREAD Thread, void *pvUser);
551 static DECLCALLBACK(int) saveStateThread(RTTHREAD Thread, void *pvUser);
552 static DECLCALLBACK(int) powerDownThread(RTTHREAD Thread, void *pvUser);
553
554 static DECLCALLBACK(void *) drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
555 static DECLCALLBACK(void) drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
556 static DECLCALLBACK(void) drvStatus_Destruct(PPDMDRVINS pDrvIns);
557 static DECLCALLBACK(int) drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
558
559 int mcAudioRefs;
560 volatile uint32_t mcVRDPClients;
561 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
562
563 static const char *sSSMConsoleUnit;
564 static uint32_t sSSMConsoleVer;
565
566 HRESULT loadDataFromSavedState();
567 int loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
568
569 static DECLCALLBACK(void) saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
570 static DECLCALLBACK(int) loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
571
572#ifdef VBOX_WITH_GUEST_PROPS
573 static DECLCALLBACK(int) doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
574 HRESULT doEnumerateGuestProperties(CBSTR aPatterns,
575 ComSafeArrayOut(BSTR, aNames),
576 ComSafeArrayOut(BSTR, aValues),
577 ComSafeArrayOut(ULONG64, aTimestamps),
578 ComSafeArrayOut(BSTR, aFlags));
579
580 bool enabledGuestPropertiesVRDP(void);
581 void updateGuestPropertiesVRDPLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
582 void updateGuestPropertiesVRDPDisconnect(uint32_t u32ClientId);
583#endif
584
585 /** @name Teleporter support
586 * @{ */
587 static DECLCALLBACK(int) teleporterSrcThreadWrapper(RTTHREAD hThread, void *pvUser);
588 HRESULT teleporterSrc(TeleporterStateSrc *pState);
589 HRESULT teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
590 HRESULT teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
591 HRESULT teleporterTrg(PVM pVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
592 Progress *pProgress, bool *pfPowerOffOnFailure);
593 static DECLCALLBACK(int) teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
594 /** @} */
595
596 bool mSavedStateDataLoaded : 1;
597
598 const ComPtr<IMachine> mMachine;
599 const ComPtr<IInternalMachineControl> mControl;
600
601 const ComPtr <IVRDPServer> mVRDPServer;
602
603 ConsoleVRDPServer * const mConsoleVRDPServer;
604
605 const ComObjPtr<Guest> mGuest;
606 const ComObjPtr<Keyboard> mKeyboard;
607 const ComObjPtr<Mouse> mMouse;
608 const ComObjPtr<Display> mDisplay;
609 const ComObjPtr<MachineDebugger> mDebugger;
610 const ComObjPtr<RemoteDisplayInfo> mRemoteDisplayInfo;
611 const ComObjPtr<EventSource> mEventSource;
612
613 USBDeviceList mUSBDevices;
614 RemoteUSBDeviceList mRemoteUSBDevices;
615
616 SharedFolderMap mSharedFolders;
617 SharedFolderDataMap mMachineSharedFolders;
618 SharedFolderDataMap mGlobalSharedFolders;
619
620 /** The VM instance handle. */
621 PVM mpVM;
622 /** Holds the number of "readonly" mpVM callers (users) */
623 uint32_t mVMCallers;
624 /** Semaphore posted when the number of mpVM callers drops to zero */
625 RTSEMEVENT mVMZeroCallersSem;
626 /** true when Console has entered the mpVM destruction phase */
627 bool mVMDestroying : 1;
628 /** true when power down is initiated by vmstateChangeCallback (EMT) */
629 bool mVMPoweredOff : 1;
630 /** true when vmstateChangeCallback shouldn't initiate a power down. */
631 bool mVMIsAlreadyPoweringOff : 1;
632 /** true if we already showed the snapshot folder size warning. */
633 bool mfSnapshotFolderSizeWarningShown : 1;
634 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
635 bool mfSnapshotFolderExt4WarningShown : 1;
636
637 /** The current network attachment type in the VM.
638 * This doesn't have to match the network attachment type
639 * maintained in the NetworkAdapter. This is needed to
640 * change the network attachment dynamically.
641 */
642 NetworkAttachmentType_T meAttachmentType[SchemaDefs::NetworkAdapterCount];
643
644 VMMDev * const mVMMDev;
645 AudioSniffer * const mAudioSniffer;
646
647 enum
648 {
649 iLedFloppy = 0,
650 cLedFloppy = 1,
651 iLedIde = iLedFloppy + cLedFloppy,
652 cLedIde = 4,
653 iLedSata = iLedIde + cLedIde,
654 cLedSata = 30,
655 iLedScsi = iLedSata + cLedSata,
656 cLedScsi = 16,
657 iLedSas = iLedScsi + cLedScsi,
658 cLedSas = 8,
659 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas
660 };
661 DeviceType_T maStorageDevType[cLedStorage];
662 PPDMLED mapStorageLeds[cLedStorage];
663 PPDMLED mapNetworkLeds[SchemaDefs::NetworkAdapterCount];
664 PPDMLED mapSharedFolderLed;
665 PPDMLED mapUSBLed[2];
666#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
667 Utf8Str maTAPDeviceName[8];
668 RTFILE maTapFD[8];
669#endif
670
671 bool mVMStateChangeCallbackDisabled;
672
673 /** Local machine state value. */
674 MachineState_T mMachineState;
675
676 /** Pointer to the progress object of a live cancelable task.
677 *
678 * This is currently only used by Console::Teleport(), but is intended to later
679 * be used by the live snapshot code path as well. Actions like
680 * Console::PowerDown, which automatically cancels out the running snapshot /
681 * teleportion operation, will cancel the teleportation / live snapshot
682 * operation before starting. */
683 ComObjPtr<Progress> mptrCancelableProgress;
684
685 typedef std::list<ConsoleCallbackRegistration> CallbackList;
686 CallbackList mCallbacks;
687
688 struct
689 {
690 /** OnMousePointerShapeChange() cache */
691 struct
692 {
693 bool valid;
694 bool visible;
695 bool alpha;
696 uint32_t xHot;
697 uint32_t yHot;
698 uint32_t width;
699 uint32_t height;
700 com::SafeArray<BYTE> shape;
701 }
702 mpsc;
703
704 /** OnMouseCapabilityChange() cache */
705 struct
706 {
707 bool valid;
708 BOOL supportsAbsolute;
709 BOOL supportsRelative;
710 BOOL needsHostCursor;
711 }
712 mcc;
713
714 /** OnKeyboardLedsChange() cache */
715 struct
716 {
717 bool valid;
718 bool numLock;
719 bool capsLock;
720 bool scrollLock;
721 }
722 klc;
723
724 void clear()
725 {
726 /* We cannot do memset() on mpsc to avoid cleaning shape's vtable */
727 mpsc.shape.setNull();
728 mpsc.valid = mpsc.visible = mpsc.alpha = false;
729 mpsc.xHot = mpsc.yHot = mpsc.width = mpsc.height = 0;
730 ::memset(&mcc, 0, sizeof mcc);
731 ::memset(&klc, 0, sizeof klc);
732 }
733 }
734 mCallbackData;
735
736#ifdef RT_OS_WINDOWS
737 ComEventsHelper mComEvHelper;
738#endif
739
740 friend struct VMTask;
741};
742
743#endif // !____H_CONSOLEIMPL
744/* 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