VirtualBox

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

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

Main/VMM: Use UVM w/ refcounting - part 1.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 31.6 KB
Line 
1/* $Id: ConsoleImpl.h 36041 2011-02-21 16:04:53Z 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, PVM pVM);
593
594 static DECLCALLBACK(void *) drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
595 static DECLCALLBACK(void) drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
596 static DECLCALLBACK(void) drvStatus_Destruct(PPDMDRVINS pDrvIns);
597 static DECLCALLBACK(int) drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
598
599 int mcAudioRefs;
600 volatile uint32_t mcVRDPClients;
601 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
602 volatile bool mcGuestCredentialsProvided;
603
604 static const char *sSSMConsoleUnit;
605 static uint32_t sSSMConsoleVer;
606
607 HRESULT loadDataFromSavedState();
608 int loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
609
610 static DECLCALLBACK(void) saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
611 static DECLCALLBACK(int) loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
612
613#ifdef VBOX_WITH_GUEST_PROPS
614 static DECLCALLBACK(int) doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
615 HRESULT doEnumerateGuestProperties(CBSTR aPatterns,
616 ComSafeArrayOut(BSTR, aNames),
617 ComSafeArrayOut(BSTR, aValues),
618 ComSafeArrayOut(LONG64, aTimestamps),
619 ComSafeArrayOut(BSTR, aFlags));
620
621 bool enabledGuestPropertiesVRDP(void);
622 void updateGuestPropertiesVRDPLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
623 void updateGuestPropertiesVRDPDisconnect(uint32_t u32ClientId);
624#endif
625
626 /** @name Teleporter support
627 * @{ */
628 static DECLCALLBACK(int) teleporterSrcThreadWrapper(RTTHREAD hThread, void *pvUser);
629 HRESULT teleporterSrc(TeleporterStateSrc *pState);
630 HRESULT teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
631 HRESULT teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
632 HRESULT teleporterTrg(PUVM pUVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
633 Progress *pProgress, bool *pfPowerOffOnFailure);
634 static DECLCALLBACK(int) teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
635 /** @} */
636
637 bool mSavedStateDataLoaded : 1;
638
639 const ComPtr<IMachine> mMachine;
640 const ComPtr<IInternalMachineControl> mControl;
641
642 const ComPtr<IVRDEServer> mVRDEServer;
643
644 ConsoleVRDPServer * const mConsoleVRDPServer;
645
646 const ComObjPtr<Guest> mGuest;
647 const ComObjPtr<Keyboard> mKeyboard;
648 const ComObjPtr<Mouse> mMouse;
649 const ComObjPtr<Display> mDisplay;
650 const ComObjPtr<MachineDebugger> mDebugger;
651 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
652 const ComObjPtr<EventSource> mEventSource;
653#ifdef VBOX_WITH_EXTPACK
654 const ComObjPtr<ExtPackManager> mptrExtPackManager;
655#endif
656
657 USBDeviceList mUSBDevices;
658 RemoteUSBDeviceList mRemoteUSBDevices;
659
660 SharedFolderDataMap m_mapGlobalSharedFolders;
661 SharedFolderDataMap m_mapMachineSharedFolders;
662 SharedFolderMap m_mapSharedFolders; // the console instances
663
664 /** The user mode VM handle. */
665 PUVM mpUVM;
666 /** Holds the number of "readonly" mpVM callers (users) */
667 uint32_t mVMCallers;
668 /** Semaphore posted when the number of mpVM callers drops to zero */
669 RTSEMEVENT mVMZeroCallersSem;
670 /** true when Console has entered the mpVM destruction phase */
671 bool mVMDestroying : 1;
672 /** true when power down is initiated by vmstateChangeCallback (EMT) */
673 bool mVMPoweredOff : 1;
674 /** true when vmstateChangeCallback shouldn't initiate a power down. */
675 bool mVMIsAlreadyPoweringOff : 1;
676 /** true if we already showed the snapshot folder size warning. */
677 bool mfSnapshotFolderSizeWarningShown : 1;
678 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
679 bool mfSnapshotFolderExt4WarningShown : 1;
680 /** true if we already listed the disk type of the snapshot folder. */
681 bool mfSnapshotFolderDiskTypeShown : 1;
682
683 /** Pointer to the VMM -> User (that's us) callbacks.
684 * This structure is followed by a pointer to the Console object. */
685 PCVMM2USERMETHODS mpVmm2UserMethods;
686
687 /** The current network attachment type in the VM.
688 * This doesn't have to match the network attachment type maintained in the
689 * NetworkAdapter. This is needed to change the network attachment
690 * dynamically.
691 */
692 NetworkAttachmentType_T meAttachmentType[SchemaDefs::NetworkAdapterCount];
693
694 VMMDev * m_pVMMDev;
695 AudioSniffer * const mAudioSniffer;
696 BusAssignmentManager* mBusMgr;
697
698 enum
699 {
700 iLedFloppy = 0,
701 cLedFloppy = 1,
702 iLedIde = iLedFloppy + cLedFloppy,
703 cLedIde = 4,
704 iLedSata = iLedIde + cLedIde,
705 cLedSata = 30,
706 iLedScsi = iLedSata + cLedSata,
707 cLedScsi = 16,
708 iLedSas = iLedScsi + cLedScsi,
709 cLedSas = 8,
710 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas
711 };
712 DeviceType_T maStorageDevType[cLedStorage];
713 PPDMLED mapStorageLeds[cLedStorage];
714 PPDMLED mapNetworkLeds[SchemaDefs::NetworkAdapterCount];
715 PPDMLED mapSharedFolderLed;
716 PPDMLED mapUSBLed[2];
717/* Note: FreeBSD needs this whether netflt is used or not. */
718#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
719 Utf8Str maTAPDeviceName[8];
720 RTFILE maTapFD[8];
721#endif
722
723 bool mVMStateChangeCallbackDisabled;
724
725 /** Local machine state value. */
726 MachineState_T mMachineState;
727
728 /** Pointer to the progress object of a live cancelable task.
729 *
730 * This is currently only used by Console::Teleport(), but is intended to later
731 * be used by the live snapshot code path as well. Actions like
732 * Console::PowerDown, which automatically cancels out the running snapshot /
733 * teleportation operation, will cancel the teleportation / live snapshot
734 * operation before starting. */
735 ComObjPtr<Progress> mptrCancelableProgress;
736
737 struct
738 {
739 /** OnMousePointerShapeChange() cache */
740 struct
741 {
742 bool valid;
743 bool visible;
744 bool alpha;
745 uint32_t xHot;
746 uint32_t yHot;
747 uint32_t width;
748 uint32_t height;
749 com::SafeArray<BYTE> shape;
750 }
751 mpsc;
752
753 /** OnMouseCapabilityChange() cache */
754 struct
755 {
756 bool valid;
757 BOOL supportsAbsolute;
758 BOOL supportsRelative;
759 BOOL needsHostCursor;
760 }
761 mcc;
762
763 /** OnKeyboardLedsChange() cache */
764 struct
765 {
766 bool valid;
767 bool numLock;
768 bool capsLock;
769 bool scrollLock;
770 }
771 klc;
772
773 void clear()
774 {
775 /* We cannot do memset() on mpsc to avoid cleaning shape's vtable */
776 mpsc.shape.setNull();
777 mpsc.valid = mpsc.visible = mpsc.alpha = false;
778 mpsc.xHot = mpsc.yHot = mpsc.width = mpsc.height = 0;
779 ::memset(&mcc, 0, sizeof mcc);
780 ::memset(&klc, 0, sizeof klc);
781 }
782 }
783 mCallbackData;
784 ComPtr<IEventListener> mVmListener;
785
786 friend struct VMTask;
787};
788
789#endif // !____H_CONSOLEIMPL
790/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette