VirtualBox

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

Last change on this file since 31733 was 31698, checked in by vboxsync, 14 years ago

Main, frontends: unsigned long long -> long long

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