VirtualBox

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

Last change on this file since 163 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.3 KB
Line 
1/** @file
2 *
3 * VBox Console COM Class definition
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#ifndef ____H_CONSOLEIMPL
23#define ____H_CONSOLEIMPL
24
25#include "VirtualBoxBase.h"
26#include "ProgressImpl.h"
27
28class Guest;
29class Keyboard;
30class Mouse;
31class Display;
32class MachineDebugger;
33class USBDevice;
34class RemoteUSBDevice;
35class SharedFolder;
36class RemoteDisplayInfo;
37class AudioSniffer;
38class ConsoleVRDPServer;
39class VMMDev;
40
41#include <VBox/vrdpapi.h>
42#include <VBox/pdm.h>
43
44struct VUSBIRHCONFIG;
45typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
46
47#include <list>
48
49// defines
50///////////////////////////////////////////////////////////////////////////////
51
52/**
53 * Checks the availability of the underlying VM device driver corresponding
54 * to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
55 * not available (NULL), sets error info and returns returns E_ACCESSDENIED.
56 * The translatable error message is defined in null context.
57 *
58 * Intended to used only within Console children (i,e. Keyboard, Mouse,
59 * Display, etc.).
60 *
61 * @param drv driver pointer to check (compare it with NULL)
62 */
63#define CHECK_CONSOLE_DRV(drv) \
64 do { \
65 if (!(drv)) \
66 return setError (E_ACCESSDENIED, tr ("The console is not powered up")); \
67 } while (0)
68
69// Console
70///////////////////////////////////////////////////////////////////////////////
71
72/** IConsole implementation class */
73class ATL_NO_VTABLE Console :
74 public VirtualBoxBaseWithChildrenNEXT,
75 public VirtualBoxSupportErrorInfoImpl <Console, IConsole>,
76 public VirtualBoxSupportTranslation <Console>,
77 public IConsole
78{
79 Q_OBJECT
80
81public:
82
83 DECLARE_NOT_AGGREGATABLE(Console)
84
85 DECLARE_PROTECT_FINAL_CONSTRUCT()
86
87 BEGIN_COM_MAP(Console)
88 COM_INTERFACE_ENTRY(ISupportErrorInfo)
89 COM_INTERFACE_ENTRY(IConsole)
90 END_COM_MAP()
91
92 NS_DECL_ISUPPORTS
93
94 Console();
95 ~Console();
96
97 HRESULT FinalConstruct();
98 void FinalRelease();
99
100 // public initializers/uninitializers for internal purposes only
101 HRESULT init (IMachine *aMachine, IInternalMachineControl *aControl);
102 void uninit();
103
104 // IConsole properties
105 STDMETHOD(COMGETTER(Machine)) (IMachine **aMachine);
106 STDMETHOD(COMGETTER(State)) (MachineState_T *aMachineState);
107 STDMETHOD(COMGETTER(Guest)) (IGuest **aGuest);
108 STDMETHOD(COMGETTER(Keyboard)) (IKeyboard **aKeyboard);
109 STDMETHOD(COMGETTER(Mouse)) (IMouse **aMouse);
110 STDMETHOD(COMGETTER(Display)) (IDisplay **aDisplay);
111 STDMETHOD(COMGETTER(Debugger)) (IMachineDebugger **aDebugger);
112 STDMETHOD(COMGETTER(USBDevices)) (IUSBDeviceCollection **aUSBDevices);
113 STDMETHOD(COMGETTER(RemoteUSBDevices)) (IHostUSBDeviceCollection **aRemoteUSBDevices);
114 STDMETHOD(COMGETTER(RemoteDisplayInfo)) (IRemoteDisplayInfo **aRemoteDisplayInfo);
115 STDMETHOD(COMGETTER(SharedFolders)) (ISharedFolderCollection **aSharedFolders);
116
117 // IConsole methods
118 STDMETHOD(PowerUp) (IProgress **aProgress);
119 STDMETHOD(PowerDown)();
120 STDMETHOD(Reset)();
121 STDMETHOD(Pause)();
122 STDMETHOD(Resume)();
123 STDMETHOD(PowerButton)();
124 STDMETHOD(SaveState) (IProgress **aProgress);
125 STDMETHOD(DiscardSavedState)();
126 STDMETHOD(GetDeviceActivity) (DeviceType_T aDeviceType,
127 DeviceActivity_T *aDeviceActivity);
128 STDMETHOD(AttachUSBDevice) (INPTR GUIDPARAM aId);
129 STDMETHOD(DetachUSBDevice) (INPTR GUIDPARAM aId, IUSBDevice **aDevice);
130 STDMETHOD(CreateSharedFolder) (INPTR BSTR aName, INPTR BSTR aHostPath);
131 STDMETHOD(RemoveSharedFolder) (INPTR BSTR aName);
132 STDMETHOD(TakeSnapshot) (INPTR BSTR aName, INPTR BSTR aDescription,
133 IProgress **aProgress);
134 STDMETHOD(DiscardSnapshot) (INPTR GUIDPARAM aId, IProgress **aProgress);
135 STDMETHOD(DiscardCurrentState) (IProgress **aProgress);
136 STDMETHOD(DiscardCurrentSnapshotAndState) (IProgress **aProgress);
137 STDMETHOD(RegisterCallback) (IConsoleCallback *aCallback);
138 STDMETHOD(UnregisterCallback)(IConsoleCallback *aCallback);
139
140 // public methods for internal purposes only
141
142 /*
143 * Note: the following methods do not increase refcount. intended to be
144 * called only by the VM execution thread.
145 */
146
147 Guest *getGuest() { return mGuest; }
148 Keyboard *getKeyboard() { return mKeyboard; }
149 Mouse *getMouse() { return mMouse; }
150 Display *getDisplay() { return mDisplay; }
151 MachineDebugger *getMachineDebugger() { return mDebugger; }
152
153 const ComPtr <IMachine> &machine() { return mMachine; }
154
155 /** Method is called only from ConsoleVRDPServer */
156 IVRDPServer *getVRDPServer() { return mVRDPServer; }
157
158 ConsoleVRDPServer *consoleVRDPServer() { return mConsoleVRDPServer; }
159
160 HRESULT updateMachineState (MachineState_T aMachineState);
161
162 // events from IInternalSessionControl
163 HRESULT onDVDDriveChange();
164 HRESULT onFloppyDriveChange();
165 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter);
166 HRESULT onVRDPServerChange();
167 HRESULT onUSBControllerChange();
168 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice);
169 HRESULT onUSBDeviceDetach(INPTR GUIDPARAM aId);
170
171 VMMDev *getVMMDev() { return mVMMDev; }
172 AudioSniffer *getAudioSniffer () { return mAudioSniffer; }
173
174 static VRDPSERVERCALLBACK *getVrdpServerCallback () { return &sVrdpServerCallback; };
175
176#ifdef VRDP_MC
177 void processRemoteUSBDevices (uint32_t u32ClientId, VRDPUSBDEVICEDESC *pDevList, uint32_t cbDevList);
178#else
179 void processRemoteUSBDevices (VRDPUSBDEVICEDESC *pDevList, uint32_t cbDevList);
180#endif /* VRDP_MC */
181
182 // callback callers
183 void onMousePointerShapeChange(bool fVisible, bool fAlpha,
184 uint32_t xHot, uint32_t yHot,
185 uint32_t width, uint32_t height,
186 void *pShape);
187 void onMouseCapabilityChange (BOOL supportsAbsolute, BOOL needsHostCursor);
188 void onStateChange (MachineState_T aMachineState);
189 void onAdditionsStateChange();
190 void onAdditionsOutdated();
191 void onKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock);
192
193 static const PDMDRVREG DrvStatusReg;
194
195 void reportAuthLibraryError (const char *filename, int rc)
196 {
197 setError (E_FAIL, tr("Could not load the external authentication library '%s' (%Vrc)"), filename, rc);
198 }
199
200 // for VirtualBoxSupportErrorInfoImpl
201 static const wchar_t *getComponentName() { return L"Console"; }
202
203private:
204
205 /**
206 * Base template for AutoVMCaller and SaveVMPtr. Template arguments
207 * have the same meaning as arguments of Console::addVMCaller().
208 */
209 template <bool taQuiet = false, bool taAllowNullVM = false>
210 class AutoVMCallerBase
211 {
212 public:
213 AutoVMCallerBase (Console *aThat) : mThat (aThat), mRC (S_OK)
214 {
215 Assert (aThat);
216 mRC = aThat->addVMCaller (taQuiet, taAllowNullVM);
217 }
218 ~AutoVMCallerBase()
219 {
220 if (SUCCEEDED (mRC))
221 mThat->releaseVMCaller();
222 }
223 /** Decreases the number of callers before the instance is destroyed. */
224 void release()
225 {
226 AssertReturnVoid (SUCCEEDED (mRC));
227 mThat->releaseVMCaller();
228 mRC = E_FAIL;
229 }
230 /** Restores the number of callers after by #release(). #rc() must be
231 * rechecked to ensure the operation succeeded. */
232 void add()
233 {
234 AssertReturnVoid (!SUCCEEDED (mRC));
235 mRC = mThat->addVMCaller (taQuiet, taAllowNullVM);
236 }
237 /** Returns the result of Console::addVMCaller() */
238 HRESULT rc() const { return mRC; }
239 /** Shortcut to SUCCEEDED (rc()) */
240 bool isOk() const { return SUCCEEDED (mRC); }
241 protected:
242 Console *mThat;
243 HRESULT mRC;
244 private:
245 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP (AutoVMCallerBase)
246 DECLARE_CLS_NEW_DELETE_NOOP (AutoVMCallerBase)
247 };
248
249 /**
250 * Helper class that protects sections of code using the mpVM pointer by
251 * automatically calling addVMCaller() on construction and
252 * releaseVMCaller() on destruction. Intended for Console methods dealing
253 * with mpVM. The usage pattern is:
254 * <code>
255 * AutoVMCaller autoVMCaller (this);
256 * CheckComRCReturnRC (autoVMCaller.rc());
257 * ...
258 * VMR3ReqCall (mpVM, ...
259 * </code>
260 *
261 * @sa SafeVMPtr, SafeVMPtrQuiet
262 */
263 typedef AutoVMCallerBase <false, false> AutoVMCaller;
264
265 /**
266 * Base template for SaveVMPtr and SaveVMPtrQuiet.
267 */
268 template <bool taQuiet = false>
269 class SafeVMPtrBase : public AutoVMCallerBase <taQuiet, true>
270 {
271 typedef AutoVMCallerBase <taQuiet, true> Base;
272 public:
273 SafeVMPtrBase (Console *aThat) : Base (aThat), mpVM (NULL)
274 {
275 if (SUCCEEDED (Base::mRC))
276 mpVM = aThat->mpVM;
277 }
278 /** Smart SaveVMPtr to PVM cast operator */
279 operator PVM() const { return mpVM; }
280 /** Direct PVM access for printf()-like functions */
281 PVM raw() const { return mpVM; }
282 private:
283 PVM mpVM;
284 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP (SafeVMPtrBase)
285 DECLARE_CLS_NEW_DELETE_NOOP (SafeVMPtrBase)
286 };
287
288public:
289
290 /**
291 * Helper class that safely manages the Console::mpVM pointer
292 * by calling addVMCaller() on construction and releaseVMCaller() on
293 * destruction. Intended for Console children. The usage pattern is:
294 * <code>
295 * Console::SaveVMPtr pVM (mParent);
296 * CheckComRCReturnRC (pVM.rc());
297 * ...
298 * VMR3ReqCall (pVM, ...
299 * ...
300 * printf ("%p\n", pVM.raw());
301 * </code>
302 *
303 * @sa SafeVMPtrQuiet, AutoVMCaller
304 */
305 typedef SafeVMPtrBase <false> SafeVMPtr;
306
307 /**
308 * A deviation of SaveVMPtr that doesn't set the error info on failure.
309 * Intenede for pieces of code that don't need to return the VM access
310 * failure to the caller. The usage pattern is:
311 * <code>
312 * Console::SaveVMPtrQuiet pVM (mParent);
313 * if (pVM.rc())
314 * VMR3ReqCall (pVM, ...
315 * return S_OK;
316 * </code>
317 *
318 * @sa SafeVMPtr, AutoVMCaller
319 */
320 typedef SafeVMPtrBase <true> SafeVMPtrQuiet;
321
322private:
323
324 typedef std::list <ComObjPtr <USBDevice> > USBDeviceList;
325 typedef std::list <ComObjPtr <RemoteUSBDevice> > RemoteUSBDeviceList;
326 typedef std::list <ComObjPtr <SharedFolder> > SharedFolderList;
327
328 HRESULT addVMCaller (bool aQuiet = false, bool aAllowNullVM = false);
329 void releaseVMCaller();
330
331 HRESULT powerDown();
332
333 HRESULT attachToHostInterface(INetworkAdapter *networkAdapter);
334 HRESULT detachFromHostInterface(INetworkAdapter *networkAdapter);
335 HRESULT powerDownHostInterfaces();
336
337 HRESULT setMachineState (MachineState_T aMachineState, bool aUpdateServer = true);
338 HRESULT setMachineStateLocally (MachineState_T aMachineState)
339 {
340 return setMachineState (aMachineState, false /* aUpdateServer */);
341 }
342
343 HRESULT findSharedFolder (const BSTR aName,
344 ComObjPtr <SharedFolder> &aSharedFolder,
345 bool aSetError = false);
346
347 static DECLCALLBACK(int) configConstructor(PVM pVM, void *pvConsole);
348 static DECLCALLBACK(void) vmstateChangeCallback(PVM aVM, VMSTATE aState,
349 VMSTATE aOldState, void *aUser);
350 HRESULT doDriveChange (const char *pszDevice, unsigned uInstance,
351 unsigned uLun, DriveState_T eState,
352 DriveState_T *peState, const char *pszPath,
353 bool fPassthrough);
354 static DECLCALLBACK(int) changeDrive (Console *pThis, const char *pszDevice,
355 unsigned uInstance, unsigned uLun,
356 DriveState_T eState, DriveState_T *peState,
357 const char *pszPath, bool fPassthrough);
358
359 HRESULT attachUSBDevice (IUSBDevice *aHostDevice, bool aManual,
360 PVUSBIRHCONFIG aConfig);
361
362 static DECLCALLBACK(int)
363 usbAttachCallback (Console *that, IUSBDevice *aHostDevice,
364 PVUSBIRHCONFIG aConfig, PCRTUUID aUuid, bool aRemote,
365 const char *aAddress, void *aRemoteBackend);
366 static DECLCALLBACK(int)
367 usbDetachCallback (Console *that, USBDeviceList::iterator *aIt,
368 bool aManual, PVUSBIRHCONFIG aConfig, PCRTUUID aUuid);
369
370 static DECLCALLBACK (int)
371 stateProgressCallback (PVM pVM, unsigned uPercent, void *pvUser);
372
373 static DECLCALLBACK(void)
374 setVMErrorCallback (PVM pVM, void *pvUser, int rc, RT_SRC_POS_DECL,
375 const char *pszFormat, va_list args);
376
377 HRESULT captureUSBDevices (PVM pVM);
378 void releaseAllUSBDevices (void);
379
380 static DECLCALLBACK (int) powerUpThread (RTTHREAD Thread, void *pvUser);
381 static DECLCALLBACK (int) saveStateThread (RTTHREAD Thread, void *pvUser);
382 static DECLCALLBACK (int) powerDownThread (RTTHREAD Thread, void *pvUser);
383
384 static DECLCALLBACK(void *) drvStatus_QueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface);
385 static DECLCALLBACK(void) drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
386 static DECLCALLBACK(void) drvStatus_Destruct(PPDMDRVINS pDrvIns);
387 static DECLCALLBACK(int) drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle);
388
389#ifdef VRDP_MC
390 int m_cAudioRefs;
391
392 static DECLCALLBACK(int) vrdp_ClientLogon (void *pvUser, uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
393 static DECLCALLBACK(void) vrdp_ClientConnect (void *pvUser, uint32_t u32ClientId);
394 static DECLCALLBACK(void) vrdp_ClientDisconnect (void *pvUser, uint32_t u32ClientId, uint32_t fu32Intercepted);
395 static DECLCALLBACK(void) vrdp_InterceptAudio (void *pvUser, uint32_t u32ClientId);
396 static DECLCALLBACK(void) vrdp_InterceptUSB (void *pvUser, uint32_t u32ClientId, PFNVRDPUSBCALLBACK *ppfn, void **ppv);
397#else
398 static DECLCALLBACK(int) vrdp_ClientLogon (void *pvUser, const char *pszUser, const char *pszPassword, const char *pszDomain);
399 static DECLCALLBACK(void) vrdp_ClientConnect (void *pvUser, uint32_t fu32SupportedOrders);
400 static DECLCALLBACK(void) vrdp_ClientDisconnect (void *pvUser);
401 static DECLCALLBACK(void) vrdp_InterceptAudio (void *pvUser, bool keepHostAudio);
402 static DECLCALLBACK(void) vrdp_InterceptUSB (void *pvUser, PFNVRDPUSBCALLBACK *ppfn, void **ppv);
403#endif /* VRDP_MC */
404
405 static VRDPSERVERCALLBACK sVrdpServerCallback;
406
407 static char *sSSMConsoleUnit;
408 static uint32_t sSSMConsoleVer;
409
410 HRESULT loadDataFromSavedState();
411
412 static DECLCALLBACK(void) saveStateFileExec (PSSMHANDLE pSSM, void *pvUser);
413 static DECLCALLBACK(int) loadStateFileExec (PSSMHANDLE pSSM, void *pvUser, uint32_t u32Version);
414
415 bool mSavedStateDataLoaded : 1;
416
417 const ComPtr <IMachine> mMachine;
418 const ComPtr <IInternalMachineControl> mControl;
419
420 const ComPtr <IVRDPServer> mVRDPServer;
421 const ComPtr <IDVDDrive> mDVDDrive;
422 const ComPtr <IFloppyDrive> mFloppyDrive;
423
424 ConsoleVRDPServer * const mConsoleVRDPServer;
425
426 const ComObjPtr <Guest> mGuest;
427 const ComObjPtr <Keyboard> mKeyboard;
428 const ComObjPtr <Mouse> mMouse;
429 const ComObjPtr <Display> mDisplay;
430 const ComObjPtr <MachineDebugger> mDebugger;
431 const ComObjPtr <RemoteDisplayInfo> mRemoteDisplayInfo;
432
433 USBDeviceList mUSBDevices;
434 RemoteUSBDeviceList mRemoteUSBDevices;
435 SharedFolderList mSharedFolders;
436
437 /** The VM instance handle. */
438 PVM mpVM;
439 /** Holds the number of "readonly" mpVM callers (users) */
440 uint32_t mVMCallers;
441 /** Semaphore posted when the number of mpVM callers drops to zero */
442 RTSEMEVENT mVMZeroCallersSem;
443 /** true when Console has entered the mpVM destruction phase */
444 bool mVMDestroying : 1;
445
446 /** The current DVD drive state in the VM.
447 * This does not have to match the state maintained in the DVD. */
448 DriveState_T meDVDState;
449 /** The current Floppy drive state in the VM.
450 * This does not have to match the state maintained in the Floppy. */
451 DriveState_T meFloppyState;
452
453 VMMDev * const mVMMDev;
454 AudioSniffer * const mAudioSniffer;
455
456 PPDMLED mapFDLeds[2];
457 PPDMLED mapIDELeds[4];
458 PPDMLED mapNetworkLeds[8];
459#ifdef __LINUX__
460 Utf8Str maTAPDeviceName[8];
461 RTFILE maTapFD[8];
462#endif
463
464 bool mVMStateChangeCallbackDisabled;
465
466 // local state value
467 MachineState_T mMachineState;
468
469 typedef std::list <ComPtr <IConsoleCallback> > CallbackList;
470 CallbackList mCallbacks;
471
472 friend struct VMTask;
473};
474
475#endif // ____H_CONSOLEIMPL
Note: See TracBrowser for help on using the repository browser.

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