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