VirtualBox

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

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

Main: Clear Console::mpVM on config constructor failure.

  • 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 35872 2011-02-07 13:43:33Z 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 HRESULT callTapSetupApplication(bool isStatic, RTFILE tapFD, Bstr &tapDevice,
448 Bstr &tapSetupApplication);
449#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
450 HRESULT attachToTapInterface(INetworkAdapter *networkAdapter);
451 HRESULT detachFromTapInterface(INetworkAdapter *networkAdapter);
452#endif
453 HRESULT powerDownHostInterfaces();
454
455 HRESULT setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
456 HRESULT setMachineStateLocally(MachineState_T aMachineState)
457 {
458 return setMachineState(aMachineState, false /* aUpdateServer */);
459 }
460
461 HRESULT findSharedFolder(const Utf8Str &strName,
462 ComObjPtr<SharedFolder> &aSharedFolder,
463 bool aSetError = false);
464
465 HRESULT fetchSharedFolders(BOOL aGlobal);
466 bool findOtherSharedFolder(const Utf8Str &straName,
467 SharedFolderDataMap::const_iterator &aIt);
468
469 HRESULT createSharedFolder(const Utf8Str &strName, const SharedFolderData &aData);
470 HRESULT removeSharedFolder(const Utf8Str &strName);
471
472 static DECLCALLBACK(int) configConstructor(PVM pVM, void *pvConsole);
473 int configConstructorInner(PVM pVM, AutoWriteLock *pAlock);
474 int configCfgmOverlay(PVM pVM, IVirtualBox *pVirtualBox, IMachine *pMachine);
475
476 int configMediumAttachment(PCFGMNODE pCtlInst,
477 const char *pcszDevice,
478 unsigned uInstance,
479 StorageBus_T enmBus,
480 bool fUseHostIOCache,
481 bool fBuiltinIoCache,
482 bool fSetupMerge,
483 unsigned uMergeSource,
484 unsigned uMergeTarget,
485 IMediumAttachment *pMediumAtt,
486 MachineState_T aMachineState,
487 HRESULT *phrc,
488 bool fAttachDetach,
489 bool fForceUnmount,
490 PVM pVM,
491 DeviceType_T *paLedDevType);
492 int configMedium(PCFGMNODE pLunL0,
493 bool fPassthrough,
494 DeviceType_T enmType,
495 bool fUseHostIOCache,
496 bool fBuiltinIoCache,
497 bool fSetupMerge,
498 unsigned uMergeSource,
499 unsigned uMergeTarget,
500 const char *pcszBwGroup,
501 IMedium *pMedium,
502 MachineState_T aMachineState,
503 HRESULT *phrc);
504 static DECLCALLBACK(int) reconfigureMediumAttachment(Console *pConsole,
505 PVM pVM,
506 const char *pcszDevice,
507 unsigned uInstance,
508 StorageBus_T enmBus,
509 bool fUseHostIOCache,
510 bool fBuiltinIoCache,
511 bool fSetupMerge,
512 unsigned uMergeSource,
513 unsigned uMergeTarget,
514 IMediumAttachment *aMediumAtt,
515 MachineState_T aMachineState,
516 HRESULT *phrc);
517 static DECLCALLBACK(int) changeRemovableMedium(Console *pThis,
518 const char *pcszDevice,
519 unsigned uInstance,
520 StorageBus_T enmBus,
521 bool fUseHostIOCache,
522 IMediumAttachment *aMediumAtt,
523 bool fForce);
524
525 int configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun,
526 INetworkAdapter *aNetworkAdapter, PCFGMNODE pCfg,
527 PCFGMNODE pLunL0, PCFGMNODE pInst,
528 bool fAttachDetach, bool fIgnoreConnectFailure);
529
530 static DECLCALLBACK(int) configGuestProperties(void *pvConsole);
531 static DECLCALLBACK(int) configGuestControl(void *pvConsole);
532 static DECLCALLBACK(void) vmstateChangeCallback(PVM aVM, VMSTATE aState,
533 VMSTATE aOldState, void *aUser);
534 static DECLCALLBACK(int) unplugCpu(Console *pThis, unsigned uCpu);
535 static DECLCALLBACK(int) plugCpu(Console *pThis, unsigned uCpu);
536 HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce);
537 HRESULT doCPURemove(ULONG aCpu);
538 HRESULT doCPUAdd(ULONG aCpu);
539
540 HRESULT doNetworkAdapterChange(const char *pszDevice, unsigned uInstance,
541 unsigned uLun, INetworkAdapter *aNetworkAdapter);
542 static DECLCALLBACK(int) changeNetworkAttachment(Console *pThis, const char *pszDevice,
543 unsigned uInstance, unsigned uLun,
544 INetworkAdapter *aNetworkAdapter);
545
546#ifdef VBOX_WITH_USB
547 HRESULT attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs);
548 HRESULT detachUSBDevice(USBDeviceList::iterator &aIt);
549
550 static DECLCALLBACK(int) usbAttachCallback(Console *that, IUSBDevice *aHostDevice, PCRTUUID aUuid,
551 bool aRemote, const char *aAddress, ULONG aMaskedIfs);
552 static DECLCALLBACK(int) usbDetachCallback(Console *that, USBDeviceList::iterator *aIt, PCRTUUID aUuid);
553#endif
554
555 static DECLCALLBACK(int) fntTakeSnapshotWorker(RTTHREAD Thread, void *pvUser);
556
557 static DECLCALLBACK(int) stateProgressCallback(PVM pVM, unsigned uPercent, void *pvUser);
558
559 static DECLCALLBACK(void) genericVMSetErrorCallback(PVM pVM, void *pvUser, int rc, RT_SRC_POS_DECL,
560 const char *pszErrorFmt, va_list va);
561
562 static DECLCALLBACK(void) setVMRuntimeErrorCallbackF(PVM pVM, void *pvUser, uint32_t fFatal,
563 const char *pszErrorId,
564 const char *pszFormat, ...);
565 static DECLCALLBACK(void) setVMRuntimeErrorCallback(PVM pVM, void *pvUser, uint32_t fFatal,
566 const char *pszErrorId,
567 const char *pszFormat, va_list va);
568
569 HRESULT captureUSBDevices(PVM pVM);
570 void detachAllUSBDevices(bool aDone);
571
572 static DECLCALLBACK(int) powerUpThread(RTTHREAD Thread, void *pvUser);
573 static DECLCALLBACK(int) saveStateThread(RTTHREAD Thread, void *pvUser);
574 static DECLCALLBACK(int) powerDownThread(RTTHREAD Thread, void *pvUser);
575
576 static DECLCALLBACK(int) vmm2User_SaveState(PCVMM2USERMETHODS pThis, PVM pVM);
577
578 static DECLCALLBACK(void *) drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
579 static DECLCALLBACK(void) drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
580 static DECLCALLBACK(void) drvStatus_Destruct(PPDMDRVINS pDrvIns);
581 static DECLCALLBACK(int) drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
582
583 int mcAudioRefs;
584 volatile uint32_t mcVRDPClients;
585 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
586 volatile bool mcGuestCredentialsProvided;
587
588 static const char *sSSMConsoleUnit;
589 static uint32_t sSSMConsoleVer;
590
591 HRESULT loadDataFromSavedState();
592 int loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
593
594 static DECLCALLBACK(void) saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
595 static DECLCALLBACK(int) loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
596
597#ifdef VBOX_WITH_GUEST_PROPS
598 static DECLCALLBACK(int) doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
599 HRESULT doEnumerateGuestProperties(CBSTR aPatterns,
600 ComSafeArrayOut(BSTR, aNames),
601 ComSafeArrayOut(BSTR, aValues),
602 ComSafeArrayOut(LONG64, aTimestamps),
603 ComSafeArrayOut(BSTR, aFlags));
604
605 bool enabledGuestPropertiesVRDP(void);
606 void updateGuestPropertiesVRDPLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
607 void updateGuestPropertiesVRDPDisconnect(uint32_t u32ClientId);
608#endif
609
610 /** @name Teleporter support
611 * @{ */
612 static DECLCALLBACK(int) teleporterSrcThreadWrapper(RTTHREAD hThread, void *pvUser);
613 HRESULT teleporterSrc(TeleporterStateSrc *pState);
614 HRESULT teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
615 HRESULT teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
616 HRESULT teleporterTrg(PVM pVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
617 Progress *pProgress, bool *pfPowerOffOnFailure);
618 static DECLCALLBACK(int) teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
619 /** @} */
620
621 bool mSavedStateDataLoaded : 1;
622
623 const ComPtr<IMachine> mMachine;
624 const ComPtr<IInternalMachineControl> mControl;
625
626 const ComPtr<IVRDEServer> mVRDEServer;
627
628 ConsoleVRDPServer * const mConsoleVRDPServer;
629
630 const ComObjPtr<Guest> mGuest;
631 const ComObjPtr<Keyboard> mKeyboard;
632 const ComObjPtr<Mouse> mMouse;
633 const ComObjPtr<Display> mDisplay;
634 const ComObjPtr<MachineDebugger> mDebugger;
635 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
636 const ComObjPtr<EventSource> mEventSource;
637#ifdef VBOX_WITH_EXTPACK
638 const ComObjPtr<ExtPackManager> mptrExtPackManager;
639#endif
640
641 USBDeviceList mUSBDevices;
642 RemoteUSBDeviceList mRemoteUSBDevices;
643
644 SharedFolderDataMap m_mapGlobalSharedFolders;
645 SharedFolderDataMap m_mapMachineSharedFolders;
646 SharedFolderMap m_mapSharedFolders; // the console instances
647
648 /** The VM instance handle. */
649 PVM mpVM;
650 /** Holds the number of "readonly" mpVM callers (users) */
651 uint32_t mVMCallers;
652 /** Semaphore posted when the number of mpVM callers drops to zero */
653 RTSEMEVENT mVMZeroCallersSem;
654 /** true when Console has entered the mpVM destruction phase */
655 bool mVMDestroying : 1;
656 /** true when power down is initiated by vmstateChangeCallback (EMT) */
657 bool mVMPoweredOff : 1;
658 /** true when vmstateChangeCallback shouldn't initiate a power down. */
659 bool mVMIsAlreadyPoweringOff : 1;
660 /** true if we already showed the snapshot folder size warning. */
661 bool mfSnapshotFolderSizeWarningShown : 1;
662 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
663 bool mfSnapshotFolderExt4WarningShown : 1;
664 /** true if we already listed the disk type of the snapshot folder. */
665 bool mfSnapshotFolderDiskTypeShown : 1;
666
667 /** Pointer to the VMM -> User (that's us) callbacks.
668 * This structure is followed by a pointer to the Console object. */
669 PCVMM2USERMETHODS mpVmm2UserMethods;
670
671 /** The current network attachment type in the VM.
672 * This doesn't have to match the network attachment type maintained in the
673 * NetworkAdapter. This is needed to change the network attachment
674 * dynamically.
675 */
676 NetworkAttachmentType_T meAttachmentType[SchemaDefs::NetworkAdapterCount];
677
678 VMMDev * m_pVMMDev;
679 AudioSniffer * const mAudioSniffer;
680 BusAssignmentManager* mBusMgr;
681
682 enum
683 {
684 iLedFloppy = 0,
685 cLedFloppy = 1,
686 iLedIde = iLedFloppy + cLedFloppy,
687 cLedIde = 4,
688 iLedSata = iLedIde + cLedIde,
689 cLedSata = 30,
690 iLedScsi = iLedSata + cLedSata,
691 cLedScsi = 16,
692 iLedSas = iLedScsi + cLedScsi,
693 cLedSas = 8,
694 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas
695 };
696 DeviceType_T maStorageDevType[cLedStorage];
697 PPDMLED mapStorageLeds[cLedStorage];
698 PPDMLED mapNetworkLeds[SchemaDefs::NetworkAdapterCount];
699 PPDMLED mapSharedFolderLed;
700 PPDMLED mapUSBLed[2];
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.

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