VirtualBox

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

Last change on this file since 49324 was 49324, checked in by vboxsync, 11 years ago

Make the TurnResetIntoPowerOff setting configurable during runtime

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