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