VirtualBox

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

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

ConsoleImpl.h: Made the SafeVMPtr and SafeVMPtrQuiet safer by checking that the VM pointer isn't NULL after retriving it.

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