VirtualBox

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

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

Main,ExtPacks/Puel/UsbWebcam: UsbWebcam intergration.

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