VirtualBox

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

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

Main: use settings struct for machine user data; remove iprt::MiniString::raw() and change all occurences to c_str()

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