VirtualBox

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

Last change on this file since 52926 was 52926, checked in by vboxsync, 10 years ago

ConsoleImpl: removed obsolete CONSOLE_WITH_EVENT_CACHE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.3 KB
Line 
1/* $Id: ConsoleImpl.h 52926 2014-10-02 08:41:00Z vboxsync $ */
2/** @file
3 * VBox Console COM Class definition
4 */
5
6/*
7 * Copyright (C) 2005-2014 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#include "ConsoleWrap.h"
25
26class Guest;
27class Keyboard;
28class Mouse;
29class Display;
30class MachineDebugger;
31class TeleporterStateSrc;
32class OUSBDevice;
33class RemoteUSBDevice;
34class SharedFolder;
35class VRDEServerInfo;
36class EmulatedUSB;
37#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
38class AudioVRDE;
39#else
40class AudioSniffer;
41#endif
42class Nvram;
43#ifdef VBOX_WITH_USB_CARDREADER
44class UsbCardReader;
45#endif
46class ConsoleVRDPServer;
47class VMMDev;
48class Progress;
49class BusAssignmentManager;
50COM_STRUCT_OR_CLASS(IEventListener);
51#ifdef VBOX_WITH_EXTPACK
52class ExtPackManager;
53#endif
54class VMMDevMouseInterface;
55class DisplayMouseInterface;
56
57#include <iprt/uuid.h>
58#include <iprt/memsafer.h>
59#include <VBox/RemoteDesktop/VRDE.h>
60#include <VBox/vmm/pdmdrv.h>
61#ifdef VBOX_WITH_GUEST_PROPS
62# include <VBox/HostServices/GuestPropertySvc.h> /* For the property notification callback */
63#endif
64
65#ifdef RT_OS_WINDOWS
66# include "../src-server/win/VBoxComEvents.h"
67#endif
68
69struct VUSBIRHCONFIG;
70typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
71
72#include <list>
73#include <vector>
74
75// defines
76///////////////////////////////////////////////////////////////////////////////
77
78/**
79 * Checks the availability of the underlying VM device driver corresponding
80 * to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
81 * not available (NULL), sets error info and returns returns E_ACCESSDENIED.
82 * The translatable error message is defined in null context.
83 *
84 * Intended to used only within Console children (i.e. Keyboard, Mouse,
85 * Display, etc.).
86 *
87 * @param drv driver pointer to check (compare it with NULL)
88 */
89#define CHECK_CONSOLE_DRV(drv) \
90 do { \
91 if (!(drv)) \
92 return setError(E_ACCESSDENIED, tr("The console is not powered up")); \
93 } while (0)
94
95// Console
96///////////////////////////////////////////////////////////////////////////////
97
98class ConsoleMouseInterface
99{
100public:
101 virtual VMMDevMouseInterface *i_getVMMDevMouseInterface(){return NULL;}
102 virtual DisplayMouseInterface *i_getDisplayMouseInterface(){return NULL;}
103 virtual void i_onMouseCapabilityChange(BOOL supportsAbsolute,
104 BOOL supportsRelative,
105 BOOL supportsMT,
106 BOOL needsHostCursor){NOREF(supportsAbsolute); NOREF(supportsRelative); NOREF(supportsMT); NOREF(needsHostCursor);}
107};
108
109/** IConsole implementation class */
110class ATL_NO_VTABLE Console :
111 public ConsoleWrap,
112 public ConsoleMouseInterface
113{
114
115public:
116
117 DECLARE_EMPTY_CTOR_DTOR(Console)
118
119 HRESULT FinalConstruct();
120 void FinalRelease();
121
122 // public initializers/uninitializers for internal purposes only
123 HRESULT init(IMachine *aMachine, IInternalMachineControl *aControl, LockType_T aLockType);
124 void uninit();
125
126
127 // public methods for internal purposes only
128
129 /*
130 * Note: the following methods do not increase refcount. intended to be
131 * called only by the VM execution thread.
132 */
133
134 Guest *i_getGuest() const { return mGuest; }
135 Keyboard *i_getKeyboard() const { return mKeyboard; }
136 Mouse *i_getMouse() const { return mMouse; }
137 Display *i_getDisplay() const { return mDisplay; }
138 MachineDebugger *i_getMachineDebugger() const { return mDebugger; }
139#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
140 AudioVRDE *i_getAudioVRDE() const { return mAudioVRDE; }
141#else
142 AudioSniffer *i_getAudioSniffer() const { return mAudioSniffer; }
143#endif
144
145 const ComPtr<IMachine> &i_machine() const { return mMachine; }
146
147 bool i_useHostClipboard() { return mfUseHostClipboard; }
148
149 /** Method is called only from ConsoleVRDPServer */
150 IVRDEServer *i_getVRDEServer() const { return mVRDEServer; }
151
152 ConsoleVRDPServer *i_consoleVRDPServer() const { return mConsoleVRDPServer; }
153
154 HRESULT i_updateMachineState(MachineState_T aMachineState);
155
156 // events from IInternalSessionControl
157 HRESULT i_onNetworkAdapterChange(INetworkAdapter *aNetworkAdapter, BOOL changeAdapter);
158 HRESULT i_onSerialPortChange(ISerialPort *aSerialPort);
159 HRESULT i_onParallelPortChange(IParallelPort *aParallelPort);
160 HRESULT i_onStorageControllerChange();
161 HRESULT i_onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
162 HRESULT i_onCPUChange(ULONG aCPU, BOOL aRemove);
163 HRESULT i_onCPUExecutionCapChange(ULONG aExecutionCap);
164 HRESULT i_onClipboardModeChange(ClipboardMode_T aClipboardMode);
165 HRESULT i_onDnDModeChange(DnDMode_T aDnDMode);
166 HRESULT i_onVRDEServerChange(BOOL aRestart);
167 HRESULT i_onVideoCaptureChange();
168 HRESULT i_onUSBControllerChange();
169 HRESULT i_onSharedFolderChange(BOOL aGlobal);
170 HRESULT i_onUSBDeviceAttach(IUSBDevice *aDevice, IVirtualBoxErrorInfo *aError, ULONG aMaskedIfs);
171 HRESULT i_onUSBDeviceDetach(IN_BSTR aId, IVirtualBoxErrorInfo *aError);
172 HRESULT i_onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
173 HRESULT i_onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
174 HRESULT i_onExtraDataChange(IN_BSTR aMachineId, IN_BSTR aKey, IN_BSTR aVal);
175
176 HRESULT i_getGuestProperty(const Utf8Str &aName, Utf8Str *aValue, LONG64 *aTimestamp, Utf8Str *aFlags);
177 HRESULT i_setGuestProperty(const Utf8Str &aName, const Utf8Str &aValue, const Utf8Str &aFlags);
178 HRESULT i_deleteGuestProperty(const Utf8Str &aName);
179 HRESULT i_enumerateGuestProperties(const Utf8Str &aPatterns,
180 std::vector<Utf8Str> &aNames,
181 std::vector<Utf8Str> &aValues,
182 std::vector<LONG64> &aTimestamps,
183 std::vector<Utf8Str> &aFlags);
184 HRESULT i_onlineMergeMedium(IMediumAttachment *aMediumAttachment,
185 ULONG aSourceIdx, ULONG aTargetIdx,
186 IProgress *aProgress);
187 int i_hgcmLoadService(const char *pszServiceLibrary, const char *pszServiceName);
188 VMMDev *i_getVMMDev() { return m_pVMMDev; }
189#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
190 AudioVRDE *i_getAudioVRDE() { return mAudioVRDE; }
191#else
192 AudioSniffer *i_getAudioSniffer() { return mAudioSniffer; }
193#endif
194
195#ifdef VBOX_WITH_EXTPACK
196 ExtPackManager *i_getExtPackManager();
197#endif
198 EventSource *i_getEventSource() { return mEventSource; }
199#ifdef VBOX_WITH_USB_CARDREADER
200 UsbCardReader *i_getUsbCardReader() { return mUsbCardReader; }
201#endif
202
203 int i_VRDPClientLogon(uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
204 void i_VRDPClientStatusChange(uint32_t u32ClientId, const char *pszStatus);
205 void i_VRDPClientConnect(uint32_t u32ClientId);
206 void i_VRDPClientDisconnect(uint32_t u32ClientId, uint32_t fu32Intercepted);
207 void i_VRDPInterceptAudio(uint32_t u32ClientId);
208 void i_VRDPInterceptUSB(uint32_t u32ClientId, void **ppvIntercept);
209 void i_VRDPInterceptClipboard(uint32_t u32ClientId);
210
211 void i_processRemoteUSBDevices(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevList, uint32_t cbDevList, bool fDescExt);
212 void i_reportVmStatistics(ULONG aValidStats, ULONG aCpuUser,
213 ULONG aCpuKernel, ULONG aCpuIdle,
214 ULONG aMemTotal, ULONG aMemFree,
215 ULONG aMemBalloon, ULONG aMemShared,
216 ULONG aMemCache, ULONG aPageTotal,
217 ULONG aAllocVMM, ULONG aFreeVMM,
218 ULONG aBalloonedVMM, ULONG aSharedVMM,
219 ULONG aVmNetRx, ULONG aVmNetTx)
220 {
221 mControl->ReportVmStatistics(aValidStats, aCpuUser, aCpuKernel, aCpuIdle,
222 aMemTotal, aMemFree, aMemBalloon, aMemShared,
223 aMemCache, aPageTotal, aAllocVMM, aFreeVMM,
224 aBalloonedVMM, aSharedVMM, aVmNetRx, aVmNetTx);
225 }
226 void i_enableVMMStatistics(BOOL aEnable);
227
228 HRESULT i_pause(Reason_T aReason);
229 HRESULT i_resume(Reason_T aReason);
230 HRESULT i_saveState(Reason_T aReason, IProgress **aProgress);
231
232 // callback callers (partly; for some events console callbacks are notified
233 // directly from IInternalSessionControl event handlers declared above)
234 void i_onMousePointerShapeChange(bool fVisible, bool fAlpha,
235 uint32_t xHot, uint32_t yHot,
236 uint32_t width, uint32_t height,
237 ComSafeArrayIn(uint8_t, aShape));
238 void i_onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative,
239 BOOL supportsMT, BOOL needsHostCursor);
240 void i_onStateChange(MachineState_T aMachineState);
241 void i_onAdditionsStateChange();
242 void i_onAdditionsOutdated();
243 void i_onKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock);
244 void i_onUSBDeviceStateChange(IUSBDevice *aDevice, bool aAttached,
245 IVirtualBoxErrorInfo *aError);
246 void i_onRuntimeError(BOOL aFatal, IN_BSTR aErrorID, IN_BSTR aMessage);
247 HRESULT i_onShowWindow(BOOL aCheck, BOOL *aCanShow, LONG64 *aWinId);
248 void i_onVRDEServerInfoChange();
249
250 static const PDMDRVREG DrvStatusReg;
251
252 static HRESULT i_setErrorStatic(HRESULT aResultCode, const char *pcsz, ...);
253 HRESULT i_setInvalidMachineStateError();
254
255 static const char *i_convertControllerTypeToDev(StorageControllerType_T enmCtrlType);
256 static HRESULT i_convertBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
257 // Called from event listener
258 HRESULT i_onNATRedirectRuleChange(ULONG ulInstance, BOOL aNatRuleRemove,
259 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
260
261 // Mouse interface
262 VMMDevMouseInterface *i_getVMMDevMouseInterface();
263 DisplayMouseInterface *i_getDisplayMouseInterface();
264
265 EmulatedUSB *i_getEmulatedUSB(void) { return mEmulatedUSB; }
266
267 /**
268 * Sets the disk encryption keys.
269 *
270 * @returns COM status code.
271 * @þaram strCfg The config for the disks.
272 *
273 * @note: One line in the config string contains all required data for one disk.
274 * The format for one disk is some sort of comma separated value using
275 * key=value pairs.
276 * There are two keys defined at the moment:
277 * - uuid: The uuid of the base image the key is for (with or without)
278 * the curly braces.
279 * - dek: The data encryption key in base64 encoding
280 */
281 HRESULT i_setDiskEncryptionKeys(const Utf8Str &strCfg);
282
283private:
284
285 // wraped IConsole properties
286 HRESULT getMachine(ComPtr<IMachine> &aMachine);
287 HRESULT getState(MachineState_T *aState);
288 HRESULT getGuest(ComPtr<IGuest> &aGuest);
289 HRESULT getKeyboard(ComPtr<IKeyboard> &aKeyboard);
290 HRESULT getMouse(ComPtr<IMouse> &aMouse);
291 HRESULT getDisplay(ComPtr<IDisplay> &aDisplay);
292 HRESULT getDebugger(ComPtr<IMachineDebugger> &aDebugger);
293 HRESULT getUSBDevices(std::vector<ComPtr<IUSBDevice> > &aUSBDevices);
294 HRESULT getRemoteUSBDevices(std::vector<ComPtr<IHostUSBDevice> > &aRemoteUSBDevices);
295 HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
296 HRESULT getVRDEServerInfo(ComPtr<IVRDEServerInfo> &aVRDEServerInfo);
297 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
298 HRESULT getAttachedPCIDevices(std::vector<ComPtr<IPCIDeviceAttachment> > &aAttachedPCIDevices);
299 HRESULT getUseHostClipboard(BOOL *aUseHostClipboard);
300 HRESULT setUseHostClipboard(BOOL aUseHostClipboard);
301 HRESULT getEmulatedUSB(ComPtr<IEmulatedUSB> &aEmulatedUSB);
302
303 // wraped IConsole methods
304 HRESULT powerUp(ComPtr<IProgress> &aProgress);
305 HRESULT powerUpPaused(ComPtr<IProgress> &aProgress);
306 HRESULT powerDown(ComPtr<IProgress> &aProgress);
307 HRESULT reset();
308 HRESULT pause();
309 HRESULT resume();
310 HRESULT powerButton();
311 HRESULT sleepButton();
312 HRESULT getPowerButtonHandled(BOOL *aHandled);
313 HRESULT getGuestEnteredACPIMode(BOOL *aEntered);
314 HRESULT saveState(ComPtr<IProgress> &aProgress);
315 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
316 HRESULT discardSavedState(BOOL aFRemoveFile);
317 HRESULT getDeviceActivity(const std::vector<DeviceType_T> &aType,
318 std::vector<DeviceActivity_T> &aActivity);
319 HRESULT attachUSBDevice(const com::Guid &aId);
320 HRESULT detachUSBDevice(const com::Guid &aId,
321 ComPtr<IUSBDevice> &aDevice);
322 HRESULT findUSBDeviceByAddress(const com::Utf8Str &aName,
323 ComPtr<IUSBDevice> &aDevice);
324 HRESULT findUSBDeviceById(const com::Guid &aId,
325 ComPtr<IUSBDevice> &aDevice);
326 HRESULT createSharedFolder(const com::Utf8Str &aName,
327 const com::Utf8Str &aHostPath,
328 BOOL aWritable,
329 BOOL aAutomount);
330 HRESULT removeSharedFolder(const com::Utf8Str &aName);
331 HRESULT takeSnapshot(const com::Utf8Str &aName,
332 const com::Utf8Str &aDescription,
333 ComPtr<IProgress> &aProgress);
334 HRESULT deleteSnapshot(const com::Guid &aId,
335 ComPtr<IProgress> &aProgress);
336 HRESULT deleteSnapshotAndAllChildren(const com::Guid &aId,
337 ComPtr<IProgress> &aProgress);
338 HRESULT deleteSnapshotRange(const com::Guid &aStartId,
339 const com::Guid &aEndId,
340 ComPtr<IProgress> &aProgress);
341 HRESULT restoreSnapshot(const ComPtr<ISnapshot> &aSnapshot,
342 ComPtr<IProgress> &aProgress);
343 HRESULT teleport(const com::Utf8Str &aHostname,
344 ULONG aTcpport,
345 const com::Utf8Str &aPassword,
346 ULONG aMaxDowntime,
347 ComPtr<IProgress> &aProgress);
348
349 /**
350 * Base template for AutoVMCaller and SafeVMPtr. Template arguments
351 * have the same meaning as arguments of Console::addVMCaller().
352 */
353 template <bool taQuiet = false, bool taAllowNullVM = false>
354 class AutoVMCallerBase
355 {
356 public:
357 AutoVMCallerBase(Console *aThat) : mThat(aThat), mRC(E_FAIL)
358 {
359 Assert(aThat);
360 mRC = aThat->i_addVMCaller(taQuiet, taAllowNullVM);
361 }
362 ~AutoVMCallerBase()
363 {
364 doRelease();
365 }
366 /** Decreases the number of callers before the instance is destroyed. */
367 void releaseCaller()
368 {
369 Assert(SUCCEEDED(mRC));
370 doRelease();
371 }
372 /** Restores the number of callers after by #release(). #rc() must be
373 * rechecked to ensure the operation succeeded. */
374 void addYY()
375 {
376 AssertReturnVoid(!SUCCEEDED(mRC));
377 mRC = mThat->i_addVMCaller(taQuiet, taAllowNullVM);
378 }
379 /** Returns the result of Console::addVMCaller() */
380 HRESULT rc() const { return mRC; }
381 /** Shortcut to SUCCEEDED(rc()) */
382 bool isOk() const { return SUCCEEDED(mRC); }
383 protected:
384 Console *mThat;
385 void doRelease()
386 {
387 if (SUCCEEDED(mRC))
388 {
389 mThat->i_releaseVMCaller();
390 mRC = E_FAIL;
391 }
392 }
393 private:
394 HRESULT mRC; /* Whether the caller was added. */
395 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoVMCallerBase)
396 };
397
398#if 0
399 /**
400 * Helper class that protects sections of code using the mpUVM pointer by
401 * automatically calling addVMCaller() on construction and
402 * releaseVMCaller() on destruction. Intended for Console methods dealing
403 * with mpUVM. The usage pattern is:
404 * <code>
405 * AutoVMCaller autoVMCaller(this);
406 * if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();
407 * ...
408 * VMR3ReqCall (mpUVM, ...
409 * </code>
410 *
411 * @note Temporarily locks the argument for writing.
412 *
413 * @sa SafeVMPtr, SafeVMPtrQuiet
414 * @obsolete Use SafeVMPtr
415 */
416 typedef AutoVMCallerBase<false, false> AutoVMCaller;
417#endif
418
419 /**
420 * Same as AutoVMCaller but doesn't set extended error info on failure.
421 *
422 * @note Temporarily locks the argument for writing.
423 * @obsolete Use SafeVMPtrQuiet
424 */
425 typedef AutoVMCallerBase<true, false> AutoVMCallerQuiet;
426
427 /**
428 * Same as AutoVMCaller but allows a null VM pointer (to trigger an error
429 * instead of assertion).
430 *
431 * @note Temporarily locks the argument for writing.
432 * @obsolete Use SafeVMPtr
433 */
434 typedef AutoVMCallerBase<false, true> AutoVMCallerWeak;
435
436 /**
437 * Same as AutoVMCaller but doesn't set extended error info on failure
438 * and allows a null VM pointer (to trigger an error instead of
439 * assertion).
440 *
441 * @note Temporarily locks the argument for writing.
442 * @obsolete Use SafeVMPtrQuiet
443 */
444 typedef AutoVMCallerBase<true, true> AutoVMCallerQuietWeak;
445
446 /**
447 * Base template for SafeVMPtr and SafeVMPtrQuiet.
448 */
449 template<bool taQuiet = false>
450 class SafeVMPtrBase : public AutoVMCallerBase<taQuiet, true>
451 {
452 typedef AutoVMCallerBase<taQuiet, true> Base;
453 public:
454 SafeVMPtrBase(Console *aThat) : Base(aThat), mRC(E_FAIL), mpUVM(NULL)
455 {
456 if (Base::isOk())
457 mRC = aThat->i_safeVMPtrRetainer(&mpUVM, taQuiet);
458 }
459 ~SafeVMPtrBase()
460 {
461 doRelease();
462 }
463 /** Direct PUVM access. */
464 PUVM rawUVM() const { return mpUVM; }
465 /** Release the handles. */
466 void release()
467 {
468 Assert(SUCCEEDED(mRC));
469 doRelease();
470 }
471
472 /** The combined result of Console::addVMCaller() and Console::safeVMPtrRetainer */
473 HRESULT rc() const { return Base::isOk()? mRC: Base::rc(); }
474 /** Shortcut to SUCCEEDED(rc()) */
475 bool isOk() const { return SUCCEEDED(mRC) && Base::isOk(); }
476
477 private:
478 void doRelease()
479 {
480 if (SUCCEEDED(mRC))
481 {
482 Base::mThat->i_safeVMPtrReleaser(&mpUVM);
483 mRC = E_FAIL;
484 }
485 Base::doRelease();
486 }
487 HRESULT mRC; /* Whether the VM ptr was retained. */
488 PUVM mpUVM;
489 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(SafeVMPtrBase)
490 };
491
492public:
493
494 /*
495 * Helper class that safely manages the Console::mpUVM pointer
496 * by calling addVMCaller() on construction and releaseVMCaller() on
497 * destruction. Intended for Console children. The usage pattern is:
498 * <code>
499 * Console::SafeVMPtr ptrVM(mParent);
500 * if (!ptrVM.isOk())
501 * return ptrVM.rc();
502 * ...
503 * VMR3ReqCall(ptrVM.rawUVM(), ...
504 * ...
505 * printf("%p\n", ptrVM.rawUVM());
506 * </code>
507 *
508 * @note Temporarily locks the argument for writing.
509 *
510 * @sa SafeVMPtrQuiet, AutoVMCaller
511 */
512 typedef SafeVMPtrBase<false> SafeVMPtr;
513
514 /**
515 * A deviation of SafeVMPtr that doesn't set the error info on failure.
516 * Intended for pieces of code that don't need to return the VM access
517 * failure to the caller. The usage pattern is:
518 * <code>
519 * Console::SafeVMPtrQuiet pVM(mParent);
520 * if (pVM.rc())
521 * VMR3ReqCall(pVM, ...
522 * return S_OK;
523 * </code>
524 *
525 * @note Temporarily locks the argument for writing.
526 *
527 * @sa SafeVMPtr, AutoVMCaller
528 */
529 typedef SafeVMPtrBase<true> SafeVMPtrQuiet;
530
531 class SharedFolderData
532 {
533 public:
534 SharedFolderData()
535 { }
536
537 SharedFolderData(const Utf8Str &aHostPath,
538 bool aWritable,
539 bool aAutoMount)
540 : m_strHostPath(aHostPath),
541 m_fWritable(aWritable),
542 m_fAutoMount(aAutoMount)
543 { }
544
545 // copy constructor
546 SharedFolderData(const SharedFolderData& aThat)
547 : m_strHostPath(aThat.m_strHostPath),
548 m_fWritable(aThat.m_fWritable),
549 m_fAutoMount(aThat.m_fAutoMount)
550 { }
551
552 Utf8Str m_strHostPath;
553 bool m_fWritable;
554 bool m_fAutoMount;
555 };
556
557 /**
558 * Class for managing emulated USB MSDs.
559 */
560 class USBStorageDevice
561 {
562 public:
563 USBStorageDevice()
564 { }
565 /** The UUID associated with the USB device. */
566 RTUUID mUuid;
567 /** Port of the storage device. */
568 LONG iPort;
569 };
570
571 /**
572 * Class for managing cryptographic keys.
573 * @todo: Replace with a keystore implementation once it is ready.
574 */
575 class SecretKey
576 {
577 public:
578 SecretKey() { }
579
580 SecretKey(uint8_t *pbKey, size_t cbKey)
581 : m_cRefs(0),
582 m_pbKey(pbKey),
583 m_cbKey(cbKey)
584 { }
585
586 ~SecretKey()
587 {
588 RTMemSaferFree(m_pbKey, m_cbKey);
589 m_cRefs = 0;
590 m_pbKey = NULL;
591 m_cbKey = 0;
592 }
593
594 /** Reference counter of the key. */
595 volatile uint32_t m_cRefs;
596 /** Key material. */
597 uint8_t *m_pbKey;
598 /** Size of the key in bytes. */
599 size_t m_cbKey;
600 };
601
602 typedef std::map<Utf8Str, ComObjPtr<SharedFolder> > SharedFolderMap;
603 typedef std::map<Utf8Str, SharedFolderData> SharedFolderDataMap;
604 typedef std::map<Utf8Str, ComPtr<IMediumAttachment> > MediumAttachmentMap;
605 typedef std::list <USBStorageDevice> USBStorageDeviceList;
606 typedef std::map<Utf8Str, SecretKey *> SecretKeyMap;
607
608private:
609
610 typedef std::list <ComObjPtr<OUSBDevice> > USBDeviceList;
611 typedef std::list <ComObjPtr<RemoteUSBDevice> > RemoteUSBDeviceList;
612
613 HRESULT i_addVMCaller(bool aQuiet = false, bool aAllowNullVM = false);
614 void i_releaseVMCaller();
615 HRESULT i_safeVMPtrRetainer(PUVM *a_ppUVM, bool aQuiet);
616 void i_safeVMPtrReleaser(PUVM *a_ppUVM);
617
618 HRESULT i_consoleInitReleaseLog(const ComPtr<IMachine> aMachine);
619
620 HRESULT i_powerUp(IProgress **aProgress, bool aPaused);
621 HRESULT i_powerDown(IProgress *aProgress = NULL);
622
623/* Note: FreeBSD needs this whether netflt is used or not. */
624#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
625 HRESULT i_attachToTapInterface(INetworkAdapter *networkAdapter);
626 HRESULT i_detachFromTapInterface(INetworkAdapter *networkAdapter);
627#endif
628 HRESULT i_powerDownHostInterfaces();
629
630 HRESULT i_setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
631 HRESULT i_setMachineStateLocally(MachineState_T aMachineState)
632 {
633 return i_setMachineState(aMachineState, false /* aUpdateServer */);
634 }
635
636 HRESULT i_findSharedFolder(const Utf8Str &strName,
637 ComObjPtr<SharedFolder> &aSharedFolder,
638 bool aSetError = false);
639
640 HRESULT i_fetchSharedFolders(BOOL aGlobal);
641 bool i_findOtherSharedFolder(const Utf8Str &straName,
642 SharedFolderDataMap::const_iterator &aIt);
643
644 HRESULT i_createSharedFolder(const Utf8Str &strName, const SharedFolderData &aData);
645 HRESULT i_removeSharedFolder(const Utf8Str &strName);
646
647 HRESULT i_suspendBeforeConfigChange(PUVM pUVM, AutoWriteLock *pAlock, bool *pfResume);
648 void i_resumeAfterConfigChange(PUVM pUVM);
649
650 static DECLCALLBACK(int) i_configConstructor(PUVM pUVM, PVM pVM, void *pvConsole);
651 int i_configConstructorInner(PUVM pUVM, PVM pVM, AutoWriteLock *pAlock);
652 int i_configCfgmOverlay(PCFGMNODE pRoot, IVirtualBox *pVirtualBox, IMachine *pMachine);
653 int i_configDumpAPISettingsTweaks(IVirtualBox *pVirtualBox, IMachine *pMachine);
654
655 int i_configGraphicsController(PCFGMNODE pDevices,
656 const GraphicsControllerType_T graphicsController,
657 BusAssignmentManager *pBusMgr,
658 const ComPtr<IMachine> &pMachine,
659 const ComPtr<IBIOSSettings> &biosSettings,
660 bool fHMEnabled);
661 int i_configMediumAttachment(PCFGMNODE pCtlInst,
662 const char *pcszDevice,
663 unsigned uInstance,
664 StorageBus_T enmBus,
665 bool fUseHostIOCache,
666 bool fBuiltinIoCache,
667 bool fSetupMerge,
668 unsigned uMergeSource,
669 unsigned uMergeTarget,
670 IMediumAttachment *pMediumAtt,
671 MachineState_T aMachineState,
672 HRESULT *phrc,
673 bool fAttachDetach,
674 bool fForceUnmount,
675 bool fHotplug,
676 PUVM pUVM,
677 DeviceType_T *paLedDevType,
678 PCFGMNODE *ppLunL0);
679 int i_configMedium(PCFGMNODE pLunL0,
680 bool fPassthrough,
681 DeviceType_T enmType,
682 bool fUseHostIOCache,
683 bool fBuiltinIoCache,
684 bool fSetupMerge,
685 unsigned uMergeSource,
686 unsigned uMergeTarget,
687 const char *pcszBwGroup,
688 bool fDiscard,
689 IMedium *pMedium,
690 MachineState_T aMachineState,
691 HRESULT *phrc);
692 static DECLCALLBACK(int) i_reconfigureMediumAttachment(Console *pThis,
693 PUVM pUVM,
694 const char *pcszDevice,
695 unsigned uInstance,
696 StorageBus_T enmBus,
697 bool fUseHostIOCache,
698 bool fBuiltinIoCache,
699 bool fSetupMerge,
700 unsigned uMergeSource,
701 unsigned uMergeTarget,
702 IMediumAttachment *aMediumAtt,
703 MachineState_T aMachineState,
704 HRESULT *phrc);
705 static DECLCALLBACK(int) i_changeRemovableMedium(Console *pThis,
706 PUVM pUVM,
707 const char *pcszDevice,
708 unsigned uInstance,
709 StorageBus_T enmBus,
710 bool fUseHostIOCache,
711 IMediumAttachment *aMediumAtt,
712 bool fForce);
713
714 HRESULT i_attachRawPCIDevices(PUVM pUVM, BusAssignmentManager *BusMgr, PCFGMNODE pDevices);
715 void i_attachStatusDriver(PCFGMNODE pCtlInst, PPDMLED *papLeds,
716 uint64_t uFirst, uint64_t uLast,
717 Console::MediumAttachmentMap *pmapMediumAttachments,
718 const char *pcszDevice, unsigned uInstance);
719
720 int i_configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun,
721 INetworkAdapter *aNetworkAdapter, PCFGMNODE pCfg,
722 PCFGMNODE pLunL0, PCFGMNODE pInst,
723 bool fAttachDetach, bool fIgnoreConnectFailure);
724
725 static DECLCALLBACK(int) i_configGuestProperties(void *pvConsole, PUVM pUVM);
726 static DECLCALLBACK(int) i_configGuestControl(void *pvConsole);
727 static DECLCALLBACK(void) i_vmstateChangeCallback(PUVM pUVM, VMSTATE enmState, VMSTATE enmOldState, void *pvUser);
728 static DECLCALLBACK(int) i_unplugCpu(Console *pThis, PUVM pUVM, VMCPUID idCpu);
729 static DECLCALLBACK(int) i_plugCpu(Console *pThis, PUVM pUVM, VMCPUID idCpu);
730 HRESULT i_doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PUVM pUVM);
731 HRESULT i_doCPURemove(ULONG aCpu, PUVM pUVM);
732 HRESULT i_doCPUAdd(ULONG aCpu, PUVM pUVM);
733
734 HRESULT i_doNetworkAdapterChange(PUVM pUVM, const char *pszDevice, unsigned uInstance,
735 unsigned uLun, INetworkAdapter *aNetworkAdapter);
736 static DECLCALLBACK(int) i_changeNetworkAttachment(Console *pThis, PUVM pUVM, const char *pszDevice,
737 unsigned uInstance, unsigned uLun,
738 INetworkAdapter *aNetworkAdapter);
739
740 void i_changeClipboardMode(ClipboardMode_T aClipboardMode);
741 int i_changeDnDMode(DnDMode_T aDnDMode);
742
743#ifdef VBOX_WITH_USB
744 HRESULT i_attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs);
745 HRESULT i_detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice);
746
747 static DECLCALLBACK(int) i_usbAttachCallback(Console *that, PUVM pUVM, IUSBDevice *aHostDevice, PCRTUUID aUuid,
748 bool aRemote, const char *aAddress, void *pvRemoteBackend,
749 USHORT aPortVersion, ULONG aMaskedIfs);
750 static DECLCALLBACK(int) i_usbDetachCallback(Console *that, PUVM pUVM, PCRTUUID aUuid);
751#endif
752
753 static DECLCALLBACK(int) i_attachStorageDevice(Console *pThis,
754 PUVM pUVM,
755 const char *pcszDevice,
756 unsigned uInstance,
757 StorageBus_T enmBus,
758 bool fUseHostIOCache,
759 IMediumAttachment *aMediumAtt,
760 bool fSilent);
761 static DECLCALLBACK(int) i_detachStorageDevice(Console *pThis,
762 PUVM pUVM,
763 const char *pcszDevice,
764 unsigned uInstance,
765 StorageBus_T enmBus,
766 IMediumAttachment *aMediumAtt,
767 bool fSilent);
768 HRESULT i_doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PUVM pUVM, bool fSilent);
769 HRESULT i_doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PUVM pUVM, bool fSilent);
770
771 static DECLCALLBACK(int) i_fntTakeSnapshotWorker(RTTHREAD Thread, void *pvUser);
772
773 static DECLCALLBACK(int) i_stateProgressCallback(PUVM pUVM, unsigned uPercent, void *pvUser);
774
775 static DECLCALLBACK(void) i_genericVMSetErrorCallback(PUVM pUVM, void *pvUser, int rc, RT_SRC_POS_DECL,
776 const char *pszErrorFmt, va_list va);
777
778 void i_setVMRuntimeErrorCallbackF(uint32_t fFatal, const char *pszErrorId, const char *pszFormat, ...);
779 static DECLCALLBACK(void) i_setVMRuntimeErrorCallback(PUVM pUVM, void *pvUser, uint32_t fFatal,
780 const char *pszErrorId, const char *pszFormat, va_list va);
781
782 HRESULT i_captureUSBDevices(PUVM pUVM);
783 void i_detachAllUSBDevices(bool aDone);
784
785 static DECLCALLBACK(int) i_powerUpThread(RTTHREAD Thread, void *pvUser);
786 static DECLCALLBACK(int) i_saveStateThread(RTTHREAD Thread, void *pvUser);
787 static DECLCALLBACK(int) i_powerDownThread(RTTHREAD Thread, void *pvUser);
788
789 static DECLCALLBACK(int) i_vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
790 static DECLCALLBACK(void) i_vmm2User_NotifyEmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
791 static DECLCALLBACK(void) i_vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
792 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM);
793 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM);
794 static DECLCALLBACK(void) i_vmm2User_NotifyResetTurnedIntoPowerOff(PCVMM2USERMETHODS pThis, PUVM pUVM);
795
796 static DECLCALLBACK(void *) i_drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
797 static DECLCALLBACK(void) i_drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
798 static DECLCALLBACK(int) i_drvStatus_MediumEjected(PPDMIMEDIANOTIFY pInterface, unsigned iLUN);
799 static DECLCALLBACK(void) i_drvStatus_Destruct(PPDMDRVINS pDrvIns);
800 static DECLCALLBACK(int) i_drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
801
802 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRetain(PPDMISECKEY pInterface, const char *pszId, const uint8_t **ppbKey,
803 size_t *pcbKey);
804 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRelease(PPDMISECKEY pInterface, const char *pszId);
805
806 int mcAudioRefs;
807 volatile uint32_t mcVRDPClients;
808 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
809 volatile bool mcGuestCredentialsProvided;
810
811 static const char *sSSMConsoleUnit;
812 static uint32_t sSSMConsoleVer;
813
814 HRESULT i_loadDataFromSavedState();
815 int i_loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
816
817 static DECLCALLBACK(void) i_saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
818 static DECLCALLBACK(int) i_loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
819
820#ifdef VBOX_WITH_GUEST_PROPS
821 static DECLCALLBACK(int) i_doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
822 HRESULT i_doEnumerateGuestProperties(const Utf8Str &aPatterns,
823 std::vector<Utf8Str> &aNames,
824 std::vector<Utf8Str> &aValues,
825 std::vector<LONG64> &aTimestamps,
826 std::vector<Utf8Str> &aFlags);
827
828 void i_guestPropertiesHandleVMReset(void);
829 bool i_guestPropertiesVRDPEnabled(void);
830 void i_guestPropertiesVRDPUpdateLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
831 void i_guestPropertiesVRDPUpdateActiveClient(uint32_t u32ClientId);
832 void i_guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached);
833 void i_guestPropertiesVRDPUpdateNameChange(uint32_t u32ClientId, const char *pszName);
834 void i_guestPropertiesVRDPUpdateIPAddrChange(uint32_t u32ClientId, const char *pszIPAddr);
835 void i_guestPropertiesVRDPUpdateLocationChange(uint32_t u32ClientId, const char *pszLocation);
836 void i_guestPropertiesVRDPUpdateOtherInfoChange(uint32_t u32ClientId, const char *pszOtherInfo);
837 void i_guestPropertiesVRDPUpdateDisconnect(uint32_t u32ClientId);
838#endif
839
840 bool i_isResetTurnedIntoPowerOff(void);
841
842 /** @name Disk encryption support
843 * @{ */
844 HRESULT i_consoleParseDiskEncryption(const char *psz, const char **ppszEnd);
845 HRESULT i_configureEncryptionForDisk(const char *pszUuid);
846 HRESULT i_clearDiskEncryptionKeysOnAllAttachments(void);
847 int i_consoleParseKeyValue(const char *psz, const char **ppszEnd,
848 char **ppszKey, char **ppszVal);
849 /** @} */
850
851 /** @name Teleporter support
852 * @{ */
853 static DECLCALLBACK(int) i_teleporterSrcThreadWrapper(RTTHREAD hThread, void *pvUser);
854 HRESULT i_teleporterSrc(TeleporterStateSrc *pState);
855 HRESULT i_teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
856 HRESULT i_teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
857 HRESULT i_teleporterTrg(PUVM pUVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
858 Progress *pProgress, bool *pfPowerOffOnFailure);
859 static DECLCALLBACK(int) i_teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
860 /** @} */
861
862 bool mSavedStateDataLoaded : 1;
863
864 const ComPtr<IMachine> mMachine;
865 const ComPtr<IInternalMachineControl> mControl;
866
867 const ComPtr<IVRDEServer> mVRDEServer;
868
869 ConsoleVRDPServer * const mConsoleVRDPServer;
870 bool mfVRDEChangeInProcess;
871 bool mfVRDEChangePending;
872
873 const ComObjPtr<Guest> mGuest;
874 const ComObjPtr<Keyboard> mKeyboard;
875 const ComObjPtr<Mouse> mMouse;
876 const ComObjPtr<Display> mDisplay;
877 const ComObjPtr<MachineDebugger> mDebugger;
878 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
879 /** This can safely be used without holding any locks.
880 * An AutoCaller suffices to prevent it being destroy while in use and
881 * internally there is a lock providing the necessary serialization. */
882 const ComObjPtr<EventSource> mEventSource;
883#ifdef VBOX_WITH_EXTPACK
884 const ComObjPtr<ExtPackManager> mptrExtPackManager;
885#endif
886 const ComObjPtr<EmulatedUSB> mEmulatedUSB;
887
888 USBDeviceList mUSBDevices;
889 RemoteUSBDeviceList mRemoteUSBDevices;
890
891 SharedFolderDataMap m_mapGlobalSharedFolders;
892 SharedFolderDataMap m_mapMachineSharedFolders;
893 SharedFolderMap m_mapSharedFolders; // the console instances
894
895 /** The user mode VM handle. */
896 PUVM mpUVM;
897 /** Holds the number of "readonly" mpUVM callers (users). */
898 uint32_t mVMCallers;
899 /** Semaphore posted when the number of mpUVM callers drops to zero. */
900 RTSEMEVENT mVMZeroCallersSem;
901 /** true when Console has entered the mpUVM destruction phase. */
902 bool mVMDestroying : 1;
903 /** true when power down is initiated by vmstateChangeCallback (EMT). */
904 bool mVMPoweredOff : 1;
905 /** true when vmstateChangeCallback shouldn't initiate a power down. */
906 bool mVMIsAlreadyPoweringOff : 1;
907 /** true if we already showed the snapshot folder size warning. */
908 bool mfSnapshotFolderSizeWarningShown : 1;
909 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
910 bool mfSnapshotFolderExt4WarningShown : 1;
911 /** true if we already listed the disk type of the snapshot folder. */
912 bool mfSnapshotFolderDiskTypeShown : 1;
913 /** true if a USB controller is available (i.e. USB devices can be attached). */
914 bool mfVMHasUsbController : 1;
915 /** true if the VM power off was caused by reset. */
916 bool mfPowerOffCausedByReset : 1;
917
918 /** Pointer to the VMM -> User (that's us) callbacks. */
919 struct MYVMM2USERMETHODS : public VMM2USERMETHODS
920 {
921 Console *pConsole;
922 } *mpVmm2UserMethods;
923
924 /** The current network attachment type in the VM.
925 * This doesn't have to match the network attachment type maintained in the
926 * NetworkAdapter. This is needed to change the network attachment
927 * dynamically.
928 */
929 typedef std::vector<NetworkAttachmentType_T> NetworkAttachmentTypeVector;
930 NetworkAttachmentTypeVector meAttachmentType;
931
932 VMMDev * m_pVMMDev;
933#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
934 AudioVRDE * const mAudioVRDE;
935#else
936 AudioSniffer * const mAudioSniffer;
937#endif
938 Nvram * const mNvram;
939#ifdef VBOX_WITH_USB_CARDREADER
940 UsbCardReader * const mUsbCardReader;
941#endif
942 BusAssignmentManager* mBusMgr;
943
944 enum
945 {
946 iLedFloppy = 0,
947 cLedFloppy = 2,
948 iLedIde = iLedFloppy + cLedFloppy,
949 cLedIde = 4,
950 iLedSata = iLedIde + cLedIde,
951 cLedSata = 30,
952 iLedScsi = iLedSata + cLedSata,
953 cLedScsi = 16,
954 iLedSas = iLedScsi + cLedScsi,
955 cLedSas = 8,
956 iLedUsb = iLedSas + cLedSas,
957 cLedUsb = 8,
958 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas + cLedUsb
959 };
960 DeviceType_T maStorageDevType[cLedStorage];
961 PPDMLED mapStorageLeds[cLedStorage];
962 PPDMLED mapNetworkLeds[36]; /**< @todo adapt this to the maximum network card count */
963 PPDMLED mapSharedFolderLed;
964 PPDMLED mapUSBLed[2];
965 PPDMLED mapCrOglLed;
966
967 MediumAttachmentMap mapMediumAttachments;
968
969 /** List of attached USB storage devices. */
970 USBStorageDeviceList mUSBStorageDevices;
971
972 /** Map of secret keys used for disk encryption. */
973 SecretKeyMap m_mapSecretKeys;
974
975 /** Pointer to the key consumer -> provider (that's us) callbacks. */
976 struct MYPDMISECKEY : public PDMISECKEY
977 {
978 Console *pConsole;
979 } *mpIfSecKey;
980
981/* Note: FreeBSD needs this whether netflt is used or not. */
982#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
983 Utf8Str maTAPDeviceName[8];
984 RTFILE maTapFD[8];
985#endif
986
987 bool mVMStateChangeCallbackDisabled;
988
989 bool mfUseHostClipboard;
990
991 /** Local machine state value. */
992 MachineState_T mMachineState;
993
994 /** Pointer to the progress object of a live cancelable task.
995 *
996 * This is currently only used by Console::Teleport(), but is intended to later
997 * be used by the live snapshot code path as well. Actions like
998 * Console::PowerDown, which automatically cancels out the running snapshot /
999 * teleportation operation, will cancel the teleportation / live snapshot
1000 * operation before starting. */
1001 ComObjPtr<Progress> mptrCancelableProgress;
1002
1003 ComPtr<IEventListener> mVmListener;
1004
1005 friend struct VMTask;
1006};
1007
1008#endif // !____H_CONSOLEIMPL
1009/* 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