VirtualBox

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

最後變更 在這個檔案從28727是 28727,由 vboxsync 提交於 15 年 前

Main/Console: clean up CFGM handling for medium attachments, make one implementation out of 2.5 previous ones

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette