VirtualBox

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

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

6813 Use of server side API wrapper code - ConsoleImpl.cpp

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