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