VirtualBox

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

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

Main/Console: resurrect strange tap/bridge hybrid optimization

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette