VirtualBox

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

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

Main/Console+Machine: move PowerDown progress object to VBoxSVC, plus VMTask cleanup

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