VirtualBox

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

Last change on this file since 40293 was 40084, checked in by vboxsync, 13 years ago

Main/Metrics: Guests now push collected metrics to VBoxSVC instead of being polled (#6029)

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