VirtualBox

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

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

Main/Console+InternalMachineControl: add a (not yet implemented) method which deletes a snapshot including all children. While I was at it I cleaned up the hyperlinks and method/attribute naming, and also marked a few more methods as const.

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