VirtualBox

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

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

Main: events work, firing of events enabled

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.7 KB
Line 
1/* $Id: ConsoleImpl.h 30510 2010-06-29 16:05:38Z 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 VirtualBoxSupportErrorInfoImpl<Console, IConsole>,
84 public VirtualBoxSupportTranslation<Console>,
85 VBOX_SCRIPTABLE_IMPL(IConsole)
86#ifdef RT_OS_WINDOWS
87 , public CComCoClass<Console, &CLSID_Console>
88 , public IConnectionPointContainerImpl<Console>
89 , public IConnectionPointImpl<Console, &IID_IConsoleCallback, CComDynamicUnkArray>
90#endif
91{
92 Q_OBJECT
93
94public:
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 void reportAuthLibraryError(const char *filename, int rc)
243 {
244 setError(E_FAIL, tr("Could not load the external authentication library '%s' (%Rrc)"), filename, rc);
245 }
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
252 // for VirtualBoxSupportErrorInfoImpl
253 static const wchar_t *getComponentName() { return L"Console"; }
254
255private:
256
257 /**
258 * Base template for AutoVMCaller and SaveVMPtr. Template arguments
259 * have the same meaning as arguments of Console::addVMCaller().
260 */
261 template <bool taQuiet = false, bool taAllowNullVM = false>
262 class AutoVMCallerBase
263 {
264 public:
265 AutoVMCallerBase(Console *aThat) : mThat(aThat), mRC(S_OK)
266 {
267 Assert(aThat);
268 mRC = aThat->addVMCaller(taQuiet, taAllowNullVM);
269 }
270 ~AutoVMCallerBase()
271 {
272 if (SUCCEEDED(mRC))
273 mThat->releaseVMCaller();
274 }
275 /** Decreases the number of callers before the instance is destroyed. */
276 void release()
277 {
278 AssertReturnVoid(SUCCEEDED(mRC));
279 mThat->releaseVMCaller();
280 mRC = E_FAIL;
281 }
282 /** Restores the number of callers after by #release(). #rc() must be
283 * rechecked to ensure the operation succeeded. */
284 void add()
285 {
286 AssertReturnVoid(!SUCCEEDED(mRC));
287 mRC = mThat->addVMCaller(taQuiet, taAllowNullVM);
288 }
289 /** Returns the result of Console::addVMCaller() */
290 HRESULT rc() const { return mRC; }
291 /** Shortcut to SUCCEEDED(rc()) */
292 bool isOk() const { return SUCCEEDED(mRC); }
293 protected:
294 Console *mThat;
295 HRESULT mRC;
296 private:
297 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoVMCallerBase)
298 DECLARE_CLS_NEW_DELETE_NOOP(AutoVMCallerBase)
299 };
300
301 /**
302 * Helper class that protects sections of code using the mpVM pointer by
303 * automatically calling addVMCaller() on construction and
304 * releaseVMCaller() on destruction. Intended for Console methods dealing
305 * with mpVM. The usage pattern is:
306 * <code>
307 * AutoVMCaller autoVMCaller(this);
308 * if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();
309 * ...
310 * VMR3ReqCall (mpVM, ...
311 * </code>
312 *
313 * @note Temporarily locks the argument for writing.
314 *
315 * @sa SafeVMPtr, SafeVMPtrQuiet
316 */
317 typedef AutoVMCallerBase <false, false> AutoVMCaller;
318
319 /**
320 * Same as AutoVMCaller but doesn't set extended error info on failure.
321 *
322 * @note Temporarily locks the argument for writing.
323 */
324 typedef AutoVMCallerBase <true, false> AutoVMCallerQuiet;
325
326 /**
327 * Same as AutoVMCaller but allows a null VM pointer (to trigger an error
328 * instead of assertion).
329 *
330 * @note Temporarily locks the argument for writing.
331 */
332 typedef AutoVMCallerBase <false, true> AutoVMCallerWeak;
333
334 /**
335 * Same as AutoVMCaller but doesn't set extended error info on failure
336 * and allows a null VM pointer (to trigger an error instead of
337 * assertion).
338 *
339 * @note Temporarily locks the argument for writing.
340 */
341 typedef AutoVMCallerBase <true, true> AutoVMCallerQuietWeak;
342
343 /**
344 * Base template for SaveVMPtr and SaveVMPtrQuiet.
345 */
346 template <bool taQuiet = false>
347 class SafeVMPtrBase : public AutoVMCallerBase <taQuiet, true>
348 {
349 typedef AutoVMCallerBase <taQuiet, true> Base;
350 public:
351 SafeVMPtrBase(Console *aThat) : Base(aThat), mpVM(NULL)
352 {
353 if (SUCCEEDED(Base::mRC))
354 mpVM = aThat->mpVM;
355 }
356 /** Smart SaveVMPtr to PVM cast operator */
357 operator PVM() const { return mpVM; }
358 /** Direct PVM access for printf()-like functions */
359 PVM raw() const { return mpVM; }
360 private:
361 PVM mpVM;
362 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(SafeVMPtrBase)
363 DECLARE_CLS_NEW_DELETE_NOOP(SafeVMPtrBase)
364 };
365
366public:
367
368 /**
369 * Helper class that safely manages the Console::mpVM pointer
370 * by calling addVMCaller() on construction and releaseVMCaller() on
371 * destruction. Intended for Console children. The usage pattern is:
372 * <code>
373 * Console::SaveVMPtr pVM(mParent);
374 * if (FAILED(pVM.rc())) return pVM.rc();
375 * ...
376 * VMR3ReqCall(pVM, ...
377 * ...
378 * printf("%p\n", pVM.raw());
379 * </code>
380 *
381 * @note Temporarily locks the argument for writing.
382 *
383 * @sa SafeVMPtrQuiet, AutoVMCaller
384 */
385 typedef SafeVMPtrBase <false> SafeVMPtr;
386
387 /**
388 * A deviation of SaveVMPtr that doesn't set the error info on failure.
389 * Intended for pieces of code that don't need to return the VM access
390 * failure to the caller. The usage pattern is:
391 * <code>
392 * Console::SaveVMPtrQuiet pVM(mParent);
393 * if (pVM.rc())
394 * VMR3ReqCall(pVM, ...
395 * return S_OK;
396 * </code>
397 *
398 * @note Temporarily locks the argument for writing.
399 *
400 * @sa SafeVMPtr, AutoVMCaller
401 */
402 typedef SafeVMPtrBase <true> SafeVMPtrQuiet;
403
404 class SharedFolderData
405 {
406 public:
407 SharedFolderData() {}
408 SharedFolderData(Bstr aHostPath, BOOL aWritable)
409 : mHostPath(aHostPath)
410 , mWritable(aWritable) {}
411 SharedFolderData(const SharedFolderData& aThat)
412 : mHostPath(aThat.mHostPath)
413 , mWritable(aThat.mWritable) {}
414 Bstr mHostPath;
415 BOOL mWritable;
416 };
417 typedef std::map <Bstr, ComObjPtr<SharedFolder> > SharedFolderMap;
418 typedef std::map <Bstr, SharedFolderData> SharedFolderDataMap;
419
420private:
421
422 typedef std::list <ComObjPtr<OUSBDevice> > USBDeviceList;
423 typedef std::list <ComObjPtr<RemoteUSBDevice> > RemoteUSBDeviceList;
424
425 HRESULT addVMCaller(bool aQuiet = false, bool aAllowNullVM = false);
426 void releaseVMCaller();
427
428 HRESULT consoleInitReleaseLog(const ComPtr<IMachine> aMachine);
429
430 HRESULT powerUp(IProgress **aProgress, bool aPaused);
431 HRESULT powerDown(Progress *aProgress = NULL);
432
433 HRESULT callTapSetupApplication(bool isStatic, RTFILE tapFD, Bstr &tapDevice,
434 Bstr &tapSetupApplication);
435#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
436 HRESULT attachToTapInterface(INetworkAdapter *networkAdapter);
437 HRESULT detachFromTapInterface(INetworkAdapter *networkAdapter);
438#endif
439 HRESULT powerDownHostInterfaces();
440
441 HRESULT setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
442 HRESULT setMachineStateLocally(MachineState_T aMachineState)
443 {
444 return setMachineState(aMachineState, false /* aUpdateServer */);
445 }
446
447 HRESULT findSharedFolder(CBSTR aName,
448 ComObjPtr<SharedFolder> &aSharedFolder,
449 bool aSetError = false);
450
451 HRESULT fetchSharedFolders(BOOL aGlobal);
452 bool findOtherSharedFolder(IN_BSTR aName,
453 SharedFolderDataMap::const_iterator &aIt);
454
455 HRESULT createSharedFolder(CBSTR aName, SharedFolderData aData);
456 HRESULT removeSharedFolder(CBSTR aName);
457
458 static DECLCALLBACK(int) configConstructor(PVM pVM, void *pvConsole);
459
460 int configMediumAttachment(PCFGMNODE pCtlInst,
461 const char *pcszDevice,
462 unsigned uInstance,
463 StorageBus_T enmBus,
464 bool fUseHostIOCache,
465 bool fSetupMerge,
466 unsigned uMergeSource,
467 unsigned uMergeTarget,
468 IMediumAttachment *pMediumAtt,
469 MachineState_T aMachineState,
470 HRESULT *phrc,
471 bool fAttachDetach,
472 bool fForceUnmount,
473 PVM pVM,
474 DeviceType_T *paLedDevType);
475 int configMedium(PCFGMNODE pLunL0,
476 bool fPassthrough,
477 DeviceType_T enmType,
478 bool fUseHostIOCache,
479 bool fSetupMerge,
480 unsigned uMergeSource,
481 unsigned uMergeTarget,
482 IMedium *pMedium,
483 MachineState_T aMachineState,
484 HRESULT *phrc);
485 static DECLCALLBACK(int) reconfigureMediumAttachment(Console *pConsole,
486 PVM pVM,
487 const char *pcszDevice,
488 unsigned uInstance,
489 StorageBus_T enmBus,
490 bool fUseHostIOCache,
491 bool fSetupMerge,
492 unsigned uMergeSource,
493 unsigned uMergeTarget,
494 IMediumAttachment *aMediumAtt,
495 MachineState_T aMachineState,
496 HRESULT *phrc);
497 static DECLCALLBACK(int) changeRemovableMedium(Console *pThis,
498 const char *pcszDevice,
499 unsigned uInstance,
500 StorageBus_T enmBus,
501 bool fUseHostIOCache,
502 IMediumAttachment *aMediumAtt,
503 bool fForce);
504
505 int configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun,
506 INetworkAdapter *aNetworkAdapter, PCFGMNODE pCfg,
507 PCFGMNODE pLunL0, PCFGMNODE pInst, bool fAttachDetach);
508
509 static DECLCALLBACK(int) configGuestProperties(void *pvConsole);
510 static DECLCALLBACK(int) configGuestControl(void *pvConsole);
511 static DECLCALLBACK(void) vmstateChangeCallback(PVM aVM, VMSTATE aState,
512 VMSTATE aOldState, void *aUser);
513 static DECLCALLBACK(int) unplugCpu(Console *pThis, unsigned uCpu);
514 static DECLCALLBACK(int) plugCpu(Console *pThis, unsigned uCpu);
515 HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce);
516 HRESULT doCPURemove(ULONG aCpu);
517 HRESULT doCPUAdd(ULONG aCpu);
518
519#ifdef VBOX_DYNAMIC_NET_ATTACH
520 HRESULT doNetworkAdapterChange(const char *pszDevice, unsigned uInstance,
521 unsigned uLun, INetworkAdapter *aNetworkAdapter);
522 static DECLCALLBACK(int) changeNetworkAttachment(Console *pThis, const char *pszDevice,
523 unsigned uInstance, unsigned uLun,
524 INetworkAdapter *aNetworkAdapter);
525#endif /* VBOX_DYNAMIC_NET_ATTACH */
526
527#ifdef VBOX_WITH_USB
528 HRESULT attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs);
529 HRESULT detachUSBDevice(USBDeviceList::iterator &aIt);
530
531 static DECLCALLBACK(int) usbAttachCallback(Console *that, IUSBDevice *aHostDevice, PCRTUUID aUuid,
532 bool aRemote, const char *aAddress, ULONG aMaskedIfs);
533 static DECLCALLBACK(int) usbDetachCallback(Console *that, USBDeviceList::iterator *aIt, PCRTUUID aUuid);
534#endif
535
536 static DECLCALLBACK(int) fntTakeSnapshotWorker(RTTHREAD Thread, void *pvUser);
537
538 static DECLCALLBACK(int) stateProgressCallback(PVM pVM, unsigned uPercent, void *pvUser);
539
540 static DECLCALLBACK(void) genericVMSetErrorCallback(PVM pVM, void *pvUser, int rc, RT_SRC_POS_DECL,
541 const char *pszErrorFmt, va_list va);
542
543 static DECLCALLBACK(void) setVMRuntimeErrorCallbackF(PVM pVM, void *pvUser, uint32_t fFatal,
544 const char *pszErrorId,
545 const char *pszFormat, ...);
546 static DECLCALLBACK(void) setVMRuntimeErrorCallback(PVM pVM, void *pvUser, uint32_t fFatal,
547 const char *pszErrorId,
548 const char *pszFormat, va_list va);
549
550 HRESULT captureUSBDevices(PVM pVM);
551 void detachAllUSBDevices(bool aDone);
552
553 static DECLCALLBACK(int) powerUpThread(RTTHREAD Thread, void *pvUser);
554 static DECLCALLBACK(int) saveStateThread(RTTHREAD Thread, void *pvUser);
555 static DECLCALLBACK(int) powerDownThread(RTTHREAD Thread, void *pvUser);
556
557 static DECLCALLBACK(void *) drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
558 static DECLCALLBACK(void) drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
559 static DECLCALLBACK(void) drvStatus_Destruct(PPDMDRVINS pDrvIns);
560 static DECLCALLBACK(int) drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
561
562 int mcAudioRefs;
563 volatile uint32_t mcVRDPClients;
564 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
565
566 static const char *sSSMConsoleUnit;
567 static uint32_t sSSMConsoleVer;
568
569 HRESULT loadDataFromSavedState();
570 int loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
571
572 static DECLCALLBACK(void) saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
573 static DECLCALLBACK(int) loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
574
575#ifdef VBOX_WITH_GUEST_PROPS
576 static DECLCALLBACK(int) doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
577 HRESULT doEnumerateGuestProperties(CBSTR aPatterns,
578 ComSafeArrayOut(BSTR, aNames),
579 ComSafeArrayOut(BSTR, aValues),
580 ComSafeArrayOut(ULONG64, aTimestamps),
581 ComSafeArrayOut(BSTR, aFlags));
582
583 bool enabledGuestPropertiesVRDP(void);
584 void updateGuestPropertiesVRDPLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
585 void updateGuestPropertiesVRDPDisconnect(uint32_t u32ClientId);
586#endif
587
588 /** @name Teleporter support
589 * @{ */
590 static DECLCALLBACK(int) teleporterSrcThreadWrapper(RTTHREAD hThread, void *pvUser);
591 HRESULT teleporterSrc(TeleporterStateSrc *pState);
592 HRESULT teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
593 HRESULT teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
594 HRESULT teleporterTrg(PVM pVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
595 Progress *pProgress, bool *pfPowerOffOnFailure);
596 static DECLCALLBACK(int) teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
597 /** @} */
598
599 bool mSavedStateDataLoaded : 1;
600
601 const ComPtr<IMachine> mMachine;
602 const ComPtr<IInternalMachineControl> mControl;
603
604 const ComPtr <IVRDPServer> mVRDPServer;
605
606 ConsoleVRDPServer * const mConsoleVRDPServer;
607
608 const ComObjPtr<Guest> mGuest;
609 const ComObjPtr<Keyboard> mKeyboard;
610 const ComObjPtr<Mouse> mMouse;
611 const ComObjPtr<Display> mDisplay;
612 const ComObjPtr<MachineDebugger> mDebugger;
613 const ComObjPtr<RemoteDisplayInfo> mRemoteDisplayInfo;
614 const ComObjPtr<EventSource> mEventSource;
615
616 USBDeviceList mUSBDevices;
617 RemoteUSBDeviceList mRemoteUSBDevices;
618
619 SharedFolderMap mSharedFolders;
620 SharedFolderDataMap mMachineSharedFolders;
621 SharedFolderDataMap mGlobalSharedFolders;
622
623 /** The VM instance handle. */
624 PVM mpVM;
625 /** Holds the number of "readonly" mpVM callers (users) */
626 uint32_t mVMCallers;
627 /** Semaphore posted when the number of mpVM callers drops to zero */
628 RTSEMEVENT mVMZeroCallersSem;
629 /** true when Console has entered the mpVM destruction phase */
630 bool mVMDestroying : 1;
631 /** true when power down is initiated by vmstateChangeCallback (EMT) */
632 bool mVMPoweredOff : 1;
633 /** true when vmstateChangeCallback shouldn't initiate a power down. */
634 bool mVMIsAlreadyPoweringOff : 1;
635 /** true if we already showed the snapshot folder size warning. */
636 bool mfSnapshotFolderSizeWarningShown : 1;
637 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
638 bool mfSnapshotFolderExt4WarningShown : 1;
639
640 /** The current network attachment type in the VM.
641 * This doesn't have to match the network attachment type
642 * maintained in the NetworkAdapter. This is needed to
643 * change the network attachment dynamically.
644 */
645 NetworkAttachmentType_T meAttachmentType[SchemaDefs::NetworkAdapterCount];
646
647 VMMDev * const mVMMDev;
648 AudioSniffer * const mAudioSniffer;
649
650 enum
651 {
652 iLedFloppy = 0,
653 cLedFloppy = 1,
654 iLedIde = iLedFloppy + cLedFloppy,
655 cLedIde = 4,
656 iLedSata = iLedIde + cLedIde,
657 cLedSata = 30,
658 iLedScsi = iLedSata + cLedSata,
659 cLedScsi = 16,
660 iLedSas = iLedScsi + cLedScsi,
661 cLedSas = 8,
662 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas
663 };
664 DeviceType_T maStorageDevType[cLedStorage];
665 PPDMLED mapStorageLeds[cLedStorage];
666 PPDMLED mapNetworkLeds[SchemaDefs::NetworkAdapterCount];
667 PPDMLED mapSharedFolderLed;
668 PPDMLED mapUSBLed[2];
669#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
670 Utf8Str maTAPDeviceName[8];
671 RTFILE maTapFD[8];
672#endif
673
674 bool mVMStateChangeCallbackDisabled;
675
676 /** Local machine state value. */
677 MachineState_T mMachineState;
678
679 /** Pointer to the progress object of a live cancelable task.
680 *
681 * This is currently only used by Console::Teleport(), but is intended to later
682 * be used by the live snapshot code path as well. Actions like
683 * Console::PowerDown, which automatically cancels out the running snapshot /
684 * teleportion operation, will cancel the teleportation / live snapshot
685 * operation before starting. */
686 ComObjPtr<Progress> mptrCancelableProgress;
687
688 typedef std::list<ConsoleCallbackRegistration> CallbackList;
689 CallbackList mCallbacks;
690
691 struct
692 {
693 /** OnMousePointerShapeChange() cache */
694 struct
695 {
696 bool valid;
697 bool visible;
698 bool alpha;
699 uint32_t xHot;
700 uint32_t yHot;
701 uint32_t width;
702 uint32_t height;
703 com::SafeArray<BYTE> shape;
704 }
705 mpsc;
706
707 /** OnMouseCapabilityChange() cache */
708 struct
709 {
710 bool valid;
711 BOOL supportsAbsolute;
712 BOOL supportsRelative;
713 BOOL needsHostCursor;
714 }
715 mcc;
716
717 /** OnKeyboardLedsChange() cache */
718 struct
719 {
720 bool valid;
721 bool numLock;
722 bool capsLock;
723 bool scrollLock;
724 }
725 klc;
726
727 void clear()
728 {
729 /* We cannot do memset() on mpsc to avoid cleaning shape's vtable */
730 mpsc.shape.setNull();
731 mpsc.valid = mpsc.visible = mpsc.alpha = false;
732 mpsc.xHot = mpsc.yHot = mpsc.width = mpsc.height = 0;
733 ::memset(&mcc, 0, sizeof mcc);
734 ::memset(&klc, 0, sizeof klc);
735 }
736 }
737 mCallbackData;
738
739#ifdef RT_OS_WINDOWS
740 ComEventsHelper mComEvHelper;
741#endif
742
743 friend struct VMTask;
744};
745
746#endif // !____H_CONSOLEIMPL
747/* 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