VirtualBox

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

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

Main: avoid clearing vtable with memset

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