VirtualBox

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

Last change on this file since 37587 was 37471, checked in by vboxsync, 14 years ago

Main/IConsole: add useHostClipboard attribute

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