VirtualBox

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

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

Init COM for all EMTS and PDMThreads.

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