VirtualBox

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

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

Support passing cpu priority change to a running guest.

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