VirtualBox

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

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

Main: Add new extradata setting VBoxInternal2/TurnResetIntoPowerOff to power off the VM when it is reset. Add guest property to reflect the last power off reason

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