1 | /* $Id: UISession.cpp 98422 2023-02-02 09:45:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UISession class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | /* Qt includes: */
|
---|
29 | #include <QApplication>
|
---|
30 | #include <QWidget>
|
---|
31 | #ifdef VBOX_WS_WIN
|
---|
32 | # include <iprt/win/windows.h> /* Workaround for compile errors if included directly by QtWin. */
|
---|
33 | # include <QtWin>
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | /* GUI includes: */
|
---|
37 | #include "UICommon.h"
|
---|
38 | #include "UIExtraDataManager.h"
|
---|
39 | #include "UISession.h"
|
---|
40 | #include "UIMachine.h"
|
---|
41 | #include "UIMedium.h"
|
---|
42 | #include "UIActionPoolRuntime.h"
|
---|
43 | #include "UIMachineLogic.h"
|
---|
44 | #include "UIMachineView.h"
|
---|
45 | #include "UIMachineWindow.h"
|
---|
46 | #include "UIMessageCenter.h"
|
---|
47 | #include "UIMousePointerShapeData.h"
|
---|
48 | #include "UINotificationCenter.h"
|
---|
49 | #include "UIConsoleEventHandler.h"
|
---|
50 | #include "UIFrameBuffer.h"
|
---|
51 | #include "UISettingsDialogSpecific.h"
|
---|
52 | #ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
|
---|
53 | # include "UIKeyboardHandler.h"
|
---|
54 | # include <signal.h>
|
---|
55 | #endif
|
---|
56 |
|
---|
57 | /* COM includes: */
|
---|
58 | #include "CGraphicsAdapter.h"
|
---|
59 | #include "CHostNetworkInterface.h"
|
---|
60 | #include "CHostUSBDevice.h"
|
---|
61 | #include "CMedium.h"
|
---|
62 | #include "CMediumAttachment.h"
|
---|
63 | #include "CSnapshot.h"
|
---|
64 | #include "CStorageController.h"
|
---|
65 | #include "CSystemProperties.h"
|
---|
66 | #include "CUSBController.h"
|
---|
67 | #include "CUSBDeviceFilter.h"
|
---|
68 | #include "CUSBDeviceFilters.h"
|
---|
69 | #ifdef VBOX_WITH_NETFLT
|
---|
70 | # include "CNetworkAdapter.h"
|
---|
71 | #endif
|
---|
72 |
|
---|
73 | /* External includes: */
|
---|
74 | #ifdef VBOX_WS_X11
|
---|
75 | # include <X11/Xlib.h>
|
---|
76 | # include <X11/Xutil.h>
|
---|
77 | #endif
|
---|
78 |
|
---|
79 |
|
---|
80 | #ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
|
---|
81 | static void signalHandlerSIGUSR1(int sig, siginfo_t *, void *);
|
---|
82 | #endif
|
---|
83 |
|
---|
84 | /* static */
|
---|
85 | bool UISession::create(UISession *&pSession, UIMachine *pMachine)
|
---|
86 | {
|
---|
87 | /* Make sure NULL pointer passed: */
|
---|
88 | AssertReturn(!pSession, false);
|
---|
89 |
|
---|
90 | /* Create session UI: */
|
---|
91 | pSession = new UISession(pMachine);
|
---|
92 | AssertPtrReturn(pSession, false);
|
---|
93 |
|
---|
94 | /* Make sure it's prepared: */
|
---|
95 | if (!pSession->prepare())
|
---|
96 | {
|
---|
97 | /* Destroy session UI otherwise: */
|
---|
98 | destroy(pSession);
|
---|
99 | /* False in that case: */
|
---|
100 | return false;
|
---|
101 | }
|
---|
102 |
|
---|
103 | /* True by default: */
|
---|
104 | return true;
|
---|
105 | }
|
---|
106 |
|
---|
107 | /* static */
|
---|
108 | void UISession::destroy(UISession *&pSession)
|
---|
109 | {
|
---|
110 | /* Make sure valid pointer passed: */
|
---|
111 | AssertPtrReturnVoid(pSession);
|
---|
112 |
|
---|
113 | /* Delete session: */
|
---|
114 | delete pSession;
|
---|
115 | pSession = 0;
|
---|
116 | }
|
---|
117 |
|
---|
118 | bool UISession::initialize()
|
---|
119 | {
|
---|
120 | /* Preprocess initialization: */
|
---|
121 | if (!preprocessInitialization())
|
---|
122 | return false;
|
---|
123 |
|
---|
124 | /* Notify user about mouse&keyboard auto-capturing: */
|
---|
125 | if (gEDataManager->autoCaptureEnabled())
|
---|
126 | UINotificationMessage::remindAboutAutoCapture();
|
---|
127 |
|
---|
128 | m_machineState = machine().GetState();
|
---|
129 |
|
---|
130 | /* Apply debug settings from the command line. */
|
---|
131 | if (!debugger().isNull() && debugger().isOk())
|
---|
132 | {
|
---|
133 | if (uiCommon().areWeToExecuteAllInIem())
|
---|
134 | debugger().SetExecuteAllInIEM(true);
|
---|
135 | if (!uiCommon().isDefaultWarpPct())
|
---|
136 | debugger().SetVirtualTimeRate(uiCommon().getWarpPct());
|
---|
137 | }
|
---|
138 |
|
---|
139 | /* Apply ad-hoc reconfigurations from the command line: */
|
---|
140 | if (uiCommon().hasFloppyImageToMount())
|
---|
141 | mountAdHocImage(KDeviceType_Floppy, UIMediumDeviceType_Floppy, uiCommon().getFloppyImage().toString());
|
---|
142 | if (uiCommon().hasDvdImageToMount())
|
---|
143 | mountAdHocImage(KDeviceType_DVD, UIMediumDeviceType_DVD, uiCommon().getDvdImage().toString());
|
---|
144 |
|
---|
145 | /* Power UP if this is NOT separate process: */
|
---|
146 | if (!uiCommon().isSeparateProcess())
|
---|
147 | if (!powerUp())
|
---|
148 | return false;
|
---|
149 |
|
---|
150 | /* Make sure all the pending Console events converted to signals
|
---|
151 | * during the powerUp() progress above reached their destinations.
|
---|
152 | * That is necessary to make sure all the pending machine state change events processed.
|
---|
153 | * We can't just use the machine state directly acquired from IMachine because there
|
---|
154 | * will be few places which are using stale machine state, not just this one. */
|
---|
155 | QApplication::sendPostedEvents(0, QEvent::MetaCall);
|
---|
156 |
|
---|
157 | /* Check if we missed a really quick termination after successful startup: */
|
---|
158 | if (isTurnedOff())
|
---|
159 | {
|
---|
160 | LogRel(("GUI: Aborting startup due to invalid machine state detected: %d\n", machineState()));
|
---|
161 | return false;
|
---|
162 | }
|
---|
163 |
|
---|
164 | /* Fetch corresponding states: */
|
---|
165 | if (uiCommon().isSeparateProcess())
|
---|
166 | {
|
---|
167 | sltAdditionsChange();
|
---|
168 | }
|
---|
169 | machineLogic()->initializePostPowerUp();
|
---|
170 |
|
---|
171 | /* Load VM settings: */
|
---|
172 | loadVMSettings();
|
---|
173 |
|
---|
174 | #ifdef VBOX_GUI_WITH_PIDFILE
|
---|
175 | uiCommon().createPidfile();
|
---|
176 | #endif /* VBOX_GUI_WITH_PIDFILE */
|
---|
177 |
|
---|
178 | /* Warn listeners about we are initialized: */
|
---|
179 | m_fInitialized = true;
|
---|
180 | emit sigInitialized();
|
---|
181 |
|
---|
182 | /* True by default: */
|
---|
183 | return true;
|
---|
184 | }
|
---|
185 |
|
---|
186 | bool UISession::powerUp()
|
---|
187 | {
|
---|
188 | /* Power UP machine: */
|
---|
189 | CProgress comProgress = uiCommon().shouldStartPaused() ? console().PowerUpPaused() : console().PowerUp();
|
---|
190 |
|
---|
191 | /* Check for immediate failure: */
|
---|
192 | if (!console().isOk() || comProgress.isNull())
|
---|
193 | {
|
---|
194 | if (uiCommon().showStartVMErrors())
|
---|
195 | msgCenter().cannotStartMachine(console(), machineName());
|
---|
196 | LogRel(("GUI: Aborting startup due to power up issue detected...\n"));
|
---|
197 | return false;
|
---|
198 | }
|
---|
199 |
|
---|
200 | /* Some logging right after we powered up: */
|
---|
201 | LogRel(("GUI: Qt version: %s\n", UICommon::qtRTVersionString().toUtf8().constData()));
|
---|
202 | #ifdef VBOX_WS_X11
|
---|
203 | LogRel(("GUI: X11 Window Manager code: %d\n", (int)uiCommon().typeOfWindowManager()));
|
---|
204 | #endif
|
---|
205 | #if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
|
---|
206 | LogRel(("GUI: HID LEDs sync is %s\n", uimachine()->isHidLedsSyncEnabled() ? "enabled" : "disabled"));
|
---|
207 | #else
|
---|
208 | LogRel(("GUI: HID LEDs sync is not supported on this platform\n"));
|
---|
209 | #endif
|
---|
210 |
|
---|
211 | /* Enable 'manual-override',
|
---|
212 | * preventing automatic Runtime UI closing
|
---|
213 | * and visual representation mode changes: */
|
---|
214 | uimachine()->setManualOverrideMode(true);
|
---|
215 |
|
---|
216 | /* Show "Starting/Restoring" progress dialog: */
|
---|
217 | if (isSaved())
|
---|
218 | {
|
---|
219 | msgCenter().showModalProgressDialog(comProgress, machineName(), ":/progress_state_restore_90px.png", 0, 0);
|
---|
220 | /* After restoring from 'saved' state, machine-window(s) geometry should be adjusted: */
|
---|
221 | machineLogic()->adjustMachineWindowsGeometry();
|
---|
222 | }
|
---|
223 | else
|
---|
224 | {
|
---|
225 | #ifdef VBOX_IS_QT6_OR_LATER /** @todo why is this any problem on qt6? */
|
---|
226 | msgCenter().showModalProgressDialog(comProgress, machineName(), ":/progress_start_90px.png", 0, 0);
|
---|
227 | #else
|
---|
228 | msgCenter().showModalProgressDialog(comProgress, machineName(), ":/progress_start_90px.png");
|
---|
229 | #endif
|
---|
230 | /* After VM start, machine-window(s) size-hint(s) should be sent: */
|
---|
231 | machineLogic()->sendMachineWindowsSizeHints();
|
---|
232 | }
|
---|
233 |
|
---|
234 | /* Check for progress failure: */
|
---|
235 | if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
|
---|
236 | {
|
---|
237 | if (uiCommon().showStartVMErrors())
|
---|
238 | msgCenter().cannotStartMachine(comProgress, machineName());
|
---|
239 | LogRel(("GUI: Aborting startup due to power up progress issue detected...\n"));
|
---|
240 | return false;
|
---|
241 | }
|
---|
242 |
|
---|
243 | /* Disable 'manual-override' finally: */
|
---|
244 | uimachine()->setManualOverrideMode(false);
|
---|
245 |
|
---|
246 | /* True by default: */
|
---|
247 | return true;
|
---|
248 | }
|
---|
249 |
|
---|
250 | WId UISession::mainMachineWindowId() const
|
---|
251 | {
|
---|
252 | return mainMachineWindow() ? mainMachineWindow()->winId() : 0;
|
---|
253 | }
|
---|
254 |
|
---|
255 | bool UISession::guestAdditionsUpgradable()
|
---|
256 | {
|
---|
257 | if (!machine().isOk())
|
---|
258 | return false;
|
---|
259 |
|
---|
260 | /* Auto GA update is currently for Windows and Linux guests only */
|
---|
261 | const CGuestOSType osType = uiCommon().vmGuestOSType(machine().GetOSTypeId());
|
---|
262 | if (!osType.isOk())
|
---|
263 | return false;
|
---|
264 |
|
---|
265 | const QString strGuestFamily = osType.GetFamilyId();
|
---|
266 | bool fIsWindowOrLinux = strGuestFamily.contains("windows", Qt::CaseInsensitive) || strGuestFamily.contains("linux", Qt::CaseInsensitive);
|
---|
267 |
|
---|
268 | if (!fIsWindowOrLinux)
|
---|
269 | return false;
|
---|
270 |
|
---|
271 | /* Also check whether we have something to update automatically: */
|
---|
272 | if (m_ulGuestAdditionsRunLevel < (ULONG)KAdditionsRunLevelType_Userland)
|
---|
273 | return false;
|
---|
274 |
|
---|
275 | return true;
|
---|
276 | }
|
---|
277 |
|
---|
278 | bool UISession::setPause(bool fOn)
|
---|
279 | {
|
---|
280 | if (fOn)
|
---|
281 | console().Pause();
|
---|
282 | else
|
---|
283 | console().Resume();
|
---|
284 |
|
---|
285 | bool ok = console().isOk();
|
---|
286 | if (!ok)
|
---|
287 | {
|
---|
288 | if (fOn)
|
---|
289 | UINotificationMessage::cannotPauseMachine(console());
|
---|
290 | else
|
---|
291 | UINotificationMessage::cannotResumeMachine(console());
|
---|
292 | }
|
---|
293 |
|
---|
294 | return ok;
|
---|
295 | }
|
---|
296 |
|
---|
297 | void UISession::sltInstallGuestAdditionsFrom(const QString &strSource)
|
---|
298 | {
|
---|
299 | if (!guestAdditionsUpgradable())
|
---|
300 | return sltMountDVDAdHoc(strSource);
|
---|
301 |
|
---|
302 | /* Update guest additions automatically: */
|
---|
303 | UINotificationProgressGuestAdditionsInstall *pNotification =
|
---|
304 | new UINotificationProgressGuestAdditionsInstall(guest(), strSource);
|
---|
305 | connect(pNotification, &UINotificationProgressGuestAdditionsInstall::sigGuestAdditionsInstallationFailed,
|
---|
306 | this, &UISession::sltMountDVDAdHoc);
|
---|
307 | gpNotificationCenter->append(pNotification);
|
---|
308 | }
|
---|
309 |
|
---|
310 | void UISession::sltMountDVDAdHoc(const QString &strSource)
|
---|
311 | {
|
---|
312 | mountAdHocImage(KDeviceType_DVD, UIMediumDeviceType_DVD, strSource);
|
---|
313 | }
|
---|
314 |
|
---|
315 | void UISession::sltDetachCOM()
|
---|
316 | {
|
---|
317 | /* Cleanup everything COM related: */
|
---|
318 | cleanupFramebuffers();
|
---|
319 | cleanupConsoleEventHandlers();
|
---|
320 | cleanupNotificationCenter();
|
---|
321 | cleanupSession();
|
---|
322 | }
|
---|
323 |
|
---|
324 | void UISession::sltStateChange(KMachineState state)
|
---|
325 | {
|
---|
326 | /* Check if something had changed: */
|
---|
327 | if (m_machineState != state)
|
---|
328 | {
|
---|
329 | /* Store new data: */
|
---|
330 | m_machineStatePrevious = m_machineState;
|
---|
331 | m_machineState = state;
|
---|
332 |
|
---|
333 | /* Notify listeners about machine state changed: */
|
---|
334 | emit sigMachineStateChange();
|
---|
335 | }
|
---|
336 | }
|
---|
337 |
|
---|
338 | void UISession::sltAdditionsChange()
|
---|
339 | {
|
---|
340 | /* Acquire actual states: */
|
---|
341 | const ULONG ulGuestAdditionsRunLevel = guest().GetAdditionsRunLevel();
|
---|
342 | LONG64 lLastUpdatedIgnored;
|
---|
343 | const bool fIsGuestSupportsGraphics = guest().GetFacilityStatus(KAdditionsFacilityType_Graphics, lLastUpdatedIgnored)
|
---|
344 | == KAdditionsFacilityStatus_Active;
|
---|
345 | const bool fIsGuestSupportsSeamless = guest().GetFacilityStatus(KAdditionsFacilityType_Seamless, lLastUpdatedIgnored)
|
---|
346 | == KAdditionsFacilityStatus_Active;
|
---|
347 |
|
---|
348 | /* Check if something had changed: */
|
---|
349 | if ( m_ulGuestAdditionsRunLevel != ulGuestAdditionsRunLevel
|
---|
350 | || m_fIsGuestSupportsGraphics != fIsGuestSupportsGraphics
|
---|
351 | || m_fIsGuestSupportsSeamless != fIsGuestSupportsSeamless)
|
---|
352 | {
|
---|
353 | /* Store new data: */
|
---|
354 | m_ulGuestAdditionsRunLevel = ulGuestAdditionsRunLevel;
|
---|
355 | m_fIsGuestSupportsGraphics = fIsGuestSupportsGraphics;
|
---|
356 | m_fIsGuestSupportsSeamless = fIsGuestSupportsSeamless;
|
---|
357 |
|
---|
358 | /* Notify listeners about GA state really changed: */
|
---|
359 | LogRel(("GUI: UISession::sltAdditionsChange: GA state really changed, notifying listeners.\n"));
|
---|
360 | emit sigAdditionsStateActualChange();
|
---|
361 | }
|
---|
362 | else
|
---|
363 | LogRel(("GUI: UISession::sltAdditionsChange: GA state doesn't really changed, still notifying listeners.\n"));
|
---|
364 |
|
---|
365 | /* Notify listeners about GA state change event came: */
|
---|
366 | emit sigAdditionsStateChange();
|
---|
367 | }
|
---|
368 |
|
---|
369 | UISession::UISession(UIMachine *pMachine)
|
---|
370 | : QObject(pMachine)
|
---|
371 | /* Base variables: */
|
---|
372 | , m_pMachine(pMachine)
|
---|
373 | , m_pConsoleEventhandler(0)
|
---|
374 | /* Common variables: */
|
---|
375 | , m_machineStatePrevious(KMachineState_Null)
|
---|
376 | , m_machineState(KMachineState_Null)
|
---|
377 | /* Common flags: */
|
---|
378 | , m_fInitialized(false)
|
---|
379 | , m_fIsGuestResizeIgnored(false)
|
---|
380 | , m_fIsAutoCaptureDisabled(false)
|
---|
381 | /* Guest additions flags: */
|
---|
382 | , m_ulGuestAdditionsRunLevel(0)
|
---|
383 | , m_fIsGuestSupportsGraphics(false)
|
---|
384 | , m_fIsGuestSupportsSeamless(false)
|
---|
385 | /* CPU hardware virtualization features for VM: */
|
---|
386 | , m_enmVMExecutionEngine(KVMExecutionEngine_NotSet)
|
---|
387 | , m_fIsHWVirtExNestedPagingEnabled(false)
|
---|
388 | , m_fIsHWVirtExUXEnabled(false)
|
---|
389 | /* VM's effective paravirtualization provider: */
|
---|
390 | , m_paraVirtProvider(KParavirtProvider_None)
|
---|
391 | {
|
---|
392 | }
|
---|
393 |
|
---|
394 | UISession::~UISession()
|
---|
395 | {
|
---|
396 | }
|
---|
397 |
|
---|
398 | UIMachineLogic *UISession::machineLogic() const
|
---|
399 | {
|
---|
400 | return uimachine() ? uimachine()->machineLogic() : 0;
|
---|
401 | }
|
---|
402 |
|
---|
403 | UIMachineWindow *UISession::activeMachineWindow() const
|
---|
404 | {
|
---|
405 | return machineLogic() ? machineLogic()->activeMachineWindow() : 0;
|
---|
406 | }
|
---|
407 |
|
---|
408 | QWidget *UISession::mainMachineWindow() const
|
---|
409 | {
|
---|
410 | return machineLogic() ? machineLogic()->mainMachineWindow() : 0;
|
---|
411 | }
|
---|
412 |
|
---|
413 | bool UISession::prepare()
|
---|
414 | {
|
---|
415 | /* Prepare COM stuff: */
|
---|
416 | if (!prepareSession())
|
---|
417 | return false;
|
---|
418 |
|
---|
419 | /* Prepare GUI stuff: */
|
---|
420 | prepareNotificationCenter();
|
---|
421 | prepareConsoleEventHandlers();
|
---|
422 | prepareFramebuffers();
|
---|
423 | prepareConnections();
|
---|
424 | prepareSignalHandling();
|
---|
425 |
|
---|
426 | /* True by default: */
|
---|
427 | return true;
|
---|
428 | }
|
---|
429 |
|
---|
430 | bool UISession::prepareSession()
|
---|
431 | {
|
---|
432 | /* Open session: */
|
---|
433 | m_session = uiCommon().openSession(uiCommon().managedVMUuid(),
|
---|
434 | uiCommon().isSeparateProcess()
|
---|
435 | ? KLockType_Shared
|
---|
436 | : KLockType_VM);
|
---|
437 | if (m_session.isNull())
|
---|
438 | return false;
|
---|
439 |
|
---|
440 | /* Get machine: */
|
---|
441 | m_machine = m_session.GetMachine();
|
---|
442 | if (m_machine.isNull())
|
---|
443 | return false;
|
---|
444 |
|
---|
445 | /* Get console: */
|
---|
446 | m_console = m_session.GetConsole();
|
---|
447 | if (m_console.isNull())
|
---|
448 | return false;
|
---|
449 |
|
---|
450 | /* Get display: */
|
---|
451 | m_display = m_console.GetDisplay();
|
---|
452 | if (m_display.isNull())
|
---|
453 | return false;
|
---|
454 |
|
---|
455 | /* Get guest: */
|
---|
456 | m_guest = m_console.GetGuest();
|
---|
457 | if (m_guest.isNull())
|
---|
458 | return false;
|
---|
459 |
|
---|
460 | /* Get mouse: */
|
---|
461 | m_mouse = m_console.GetMouse();
|
---|
462 | if (m_mouse.isNull())
|
---|
463 | return false;
|
---|
464 |
|
---|
465 | /* Get keyboard: */
|
---|
466 | m_keyboard = m_console.GetKeyboard();
|
---|
467 | if (m_keyboard.isNull())
|
---|
468 | return false;
|
---|
469 |
|
---|
470 | /* Get debugger: */
|
---|
471 | m_debugger = m_console.GetDebugger();
|
---|
472 | if (m_debugger.isNull())
|
---|
473 | return false;
|
---|
474 |
|
---|
475 | /* Update machine-name: */
|
---|
476 | m_strMachineName = machine().GetName();
|
---|
477 |
|
---|
478 | /* Update machine-state: */
|
---|
479 | m_machineState = machine().GetState();
|
---|
480 |
|
---|
481 | /* True by default: */
|
---|
482 | return true;
|
---|
483 | }
|
---|
484 |
|
---|
485 | void UISession::prepareNotificationCenter()
|
---|
486 | {
|
---|
487 | UINotificationCenter::create();
|
---|
488 | }
|
---|
489 |
|
---|
490 | void UISession::prepareConsoleEventHandlers()
|
---|
491 | {
|
---|
492 | /* Create console event-handler: */
|
---|
493 | m_pConsoleEventhandler = new UIConsoleEventHandler(this);
|
---|
494 |
|
---|
495 | /* Console event connections: */
|
---|
496 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigAdditionsChange,
|
---|
497 | this, &UISession::sltAdditionsChange);
|
---|
498 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigAudioAdapterChange,
|
---|
499 | this, &UISession::sigAudioAdapterChange);
|
---|
500 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigClipboardModeChange,
|
---|
501 | this, &UISession::sigClipboardModeChange);
|
---|
502 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigCPUExecutionCapChange,
|
---|
503 | this, &UISession::sigCPUExecutionCapChange);
|
---|
504 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigDnDModeChange,
|
---|
505 | this, &UISession::sigDnDModeChange);
|
---|
506 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigGuestMonitorChange,
|
---|
507 | this, &UISession::sigGuestMonitorChange);
|
---|
508 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigMediumChange,
|
---|
509 | this, &UISession::sigMediumChange);
|
---|
510 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigNetworkAdapterChange,
|
---|
511 | this, &UISession::sigNetworkAdapterChange);
|
---|
512 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigRecordingChange,
|
---|
513 | this, &UISession::sigRecordingChange);
|
---|
514 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigSharedFolderChange,
|
---|
515 | this, &UISession::sigSharedFolderChange);
|
---|
516 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigStateChange,
|
---|
517 | this, &UISession::sltStateChange);
|
---|
518 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigStorageDeviceChange,
|
---|
519 | this, &UISession::sigStorageDeviceChange);
|
---|
520 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigUSBControllerChange,
|
---|
521 | this, &UISession::sigUSBControllerChange);
|
---|
522 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigUSBDeviceStateChange,
|
---|
523 | this, &UISession::sigUSBDeviceStateChange);
|
---|
524 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigVRDEChange,
|
---|
525 | this, &UISession::sigVRDEChange);
|
---|
526 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigRuntimeError,
|
---|
527 | this, &UISession::sigRuntimeError);
|
---|
528 |
|
---|
529 | #ifdef VBOX_WS_MAC
|
---|
530 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigShowWindow,
|
---|
531 | this, &UISession::sigShowWindows, Qt::QueuedConnection);
|
---|
532 | #endif
|
---|
533 |
|
---|
534 | /* Console keyboard connections: */
|
---|
535 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigKeyboardLedsChange,
|
---|
536 | this, &UISession::sigKeyboardLedsChange);
|
---|
537 |
|
---|
538 | /* Console mouse connections: */
|
---|
539 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigMousePointerShapeChange,
|
---|
540 | this, &UISession::sigMousePointerShapeChange);
|
---|
541 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigMouseCapabilityChange,
|
---|
542 | this, &UISession::sigMouseCapabilityChange);
|
---|
543 | connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigCursorPositionChange,
|
---|
544 | this, &UISession::sigCursorPositionChange);
|
---|
545 | }
|
---|
546 |
|
---|
547 | void UISession::prepareFramebuffers()
|
---|
548 | {
|
---|
549 | /* Each framebuffer will be really prepared on first UIMachineView creation: */
|
---|
550 | m_frameBufferVector.resize(machine().GetGraphicsAdapter().GetMonitorCount());
|
---|
551 | }
|
---|
552 |
|
---|
553 | void UISession::prepareConnections()
|
---|
554 | {
|
---|
555 | /* UICommon connections: */
|
---|
556 | connect(&uiCommon(), &UICommon::sigAskToDetachCOM, this, &UISession::sltDetachCOM);
|
---|
557 | }
|
---|
558 |
|
---|
559 | void UISession::prepareSignalHandling()
|
---|
560 | {
|
---|
561 | #ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
|
---|
562 | struct sigaction sa;
|
---|
563 | sa.sa_sigaction = &signalHandlerSIGUSR1;
|
---|
564 | sigemptyset(&sa.sa_mask);
|
---|
565 | sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
---|
566 | sigaction(SIGUSR1, &sa, NULL);
|
---|
567 | #endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
|
---|
568 | }
|
---|
569 |
|
---|
570 | void UISession::cleanupFramebuffers()
|
---|
571 | {
|
---|
572 | /* Cleanup framebuffers finally: */
|
---|
573 | for (int i = m_frameBufferVector.size() - 1; i >= 0; --i)
|
---|
574 | {
|
---|
575 | UIFrameBuffer *pFrameBuffer = m_frameBufferVector[i];
|
---|
576 | if (pFrameBuffer)
|
---|
577 | {
|
---|
578 | /* Mark framebuffer as unused: */
|
---|
579 | pFrameBuffer->setMarkAsUnused(true);
|
---|
580 | /* Detach framebuffer from Display: */
|
---|
581 | pFrameBuffer->detach();
|
---|
582 | /* Delete framebuffer reference: */
|
---|
583 | delete pFrameBuffer;
|
---|
584 | }
|
---|
585 | }
|
---|
586 | m_frameBufferVector.clear();
|
---|
587 | }
|
---|
588 |
|
---|
589 | void UISession::cleanupConsoleEventHandlers()
|
---|
590 | {
|
---|
591 | /* Destroy console event-handler: */
|
---|
592 | delete m_pConsoleEventhandler;
|
---|
593 | m_pConsoleEventhandler = 0;
|
---|
594 | }
|
---|
595 |
|
---|
596 | void UISession::cleanupNotificationCenter()
|
---|
597 | {
|
---|
598 | UINotificationCenter::destroy();
|
---|
599 | }
|
---|
600 |
|
---|
601 | void UISession::cleanupSession()
|
---|
602 | {
|
---|
603 | /* Detach debugger: */
|
---|
604 | if (!m_debugger.isNull())
|
---|
605 | m_debugger.detach();
|
---|
606 |
|
---|
607 | /* Detach keyboard: */
|
---|
608 | if (!m_keyboard.isNull())
|
---|
609 | m_keyboard.detach();
|
---|
610 |
|
---|
611 | /* Detach mouse: */
|
---|
612 | if (!m_mouse.isNull())
|
---|
613 | m_mouse.detach();
|
---|
614 |
|
---|
615 | /* Detach guest: */
|
---|
616 | if (!m_guest.isNull())
|
---|
617 | m_guest.detach();
|
---|
618 |
|
---|
619 | /* Detach display: */
|
---|
620 | if (!m_display.isNull())
|
---|
621 | m_display.detach();
|
---|
622 |
|
---|
623 | /* Detach console: */
|
---|
624 | if (!m_console.isNull())
|
---|
625 | m_console.detach();
|
---|
626 |
|
---|
627 | /* Detach machine: */
|
---|
628 | if (!m_machine.isNull())
|
---|
629 | m_machine.detach();
|
---|
630 |
|
---|
631 | /* Close session: */
|
---|
632 | if (!m_session.isNull() && uiCommon().isVBoxSVCAvailable())
|
---|
633 | {
|
---|
634 | m_session.UnlockMachine();
|
---|
635 | m_session.detach();
|
---|
636 | }
|
---|
637 | }
|
---|
638 |
|
---|
639 | bool UISession::preprocessInitialization()
|
---|
640 | {
|
---|
641 | #ifdef VBOX_WITH_NETFLT
|
---|
642 | /* Skip network interface name checks if VM in saved state: */
|
---|
643 | if (!isSaved())
|
---|
644 | {
|
---|
645 | /* Make sure all the attached and enabled network
|
---|
646 | * adapters are present on the host. This check makes sense
|
---|
647 | * in two cases only - when attachement type is Bridged Network
|
---|
648 | * or Host-only Interface. NOTE: Only currently enabled
|
---|
649 | * attachement type is checked (incorrect parameters check for
|
---|
650 | * currently disabled attachement types is skipped). */
|
---|
651 | QStringList failedInterfaceNames;
|
---|
652 | QStringList availableInterfaceNames;
|
---|
653 |
|
---|
654 | /* Create host network interface names list: */
|
---|
655 | foreach (const CHostNetworkInterface &comNetIface, uiCommon().host().GetNetworkInterfaces())
|
---|
656 | {
|
---|
657 | availableInterfaceNames << comNetIface.GetName();
|
---|
658 | availableInterfaceNames << comNetIface.GetShortName();
|
---|
659 | }
|
---|
660 |
|
---|
661 | /* Enumerate all the virtual network adapters: */
|
---|
662 | const ulong cCount = uiCommon().virtualBox().GetSystemProperties().GetMaxNetworkAdapters(machine().GetChipsetType());
|
---|
663 | for (ulong uAdapterIndex = 0; uAdapterIndex < cCount; ++uAdapterIndex)
|
---|
664 | {
|
---|
665 | CNetworkAdapter comNetworkAdapter = machine().GetNetworkAdapter(uAdapterIndex);
|
---|
666 | if (comNetworkAdapter.GetEnabled())
|
---|
667 | {
|
---|
668 | /* Get physical network interface name for
|
---|
669 | * currently enabled network attachement type: */
|
---|
670 | QString strInterfaceName;
|
---|
671 | switch (comNetworkAdapter.GetAttachmentType())
|
---|
672 | {
|
---|
673 | case KNetworkAttachmentType_Bridged:
|
---|
674 | strInterfaceName = comNetworkAdapter.GetBridgedInterface();
|
---|
675 | break;
|
---|
676 | #ifndef VBOX_WITH_VMNET
|
---|
677 | case KNetworkAttachmentType_HostOnly:
|
---|
678 | strInterfaceName = comNetworkAdapter.GetHostOnlyInterface();
|
---|
679 | break;
|
---|
680 | #endif /* !VBOX_WITH_VMNET */
|
---|
681 | default:
|
---|
682 | break;
|
---|
683 | }
|
---|
684 |
|
---|
685 | if ( !strInterfaceName.isEmpty()
|
---|
686 | && !availableInterfaceNames.contains(strInterfaceName))
|
---|
687 | {
|
---|
688 | LogRel(("GUI: Invalid network interface found: %s\n", strInterfaceName.toUtf8().constData()));
|
---|
689 | failedInterfaceNames << QString("%1 (adapter %2)").arg(strInterfaceName).arg(uAdapterIndex + 1);
|
---|
690 | }
|
---|
691 | }
|
---|
692 | }
|
---|
693 |
|
---|
694 | /* Check if non-existent interfaces found: */
|
---|
695 | if (!failedInterfaceNames.isEmpty())
|
---|
696 | {
|
---|
697 | if (msgCenter().warnAboutNetworkInterfaceNotFound(machineName(), failedInterfaceNames.join(", ")))
|
---|
698 | machineLogic()->openNetworkSettingsDialog();
|
---|
699 | else
|
---|
700 | {
|
---|
701 | LogRel(("GUI: Aborting startup due to preprocess initialization issue detected...\n"));
|
---|
702 | return false;
|
---|
703 | }
|
---|
704 | }
|
---|
705 | }
|
---|
706 | #endif /* VBOX_WITH_NETFLT */
|
---|
707 |
|
---|
708 | /* Check for USB enumeration warning. Don't return false even if we have a warning: */
|
---|
709 | CHost comHost = uiCommon().host();
|
---|
710 | if (comHost.GetUSBDevices().isEmpty() && comHost.isWarning())
|
---|
711 | {
|
---|
712 | /* Do not bitch if USB disabled: */
|
---|
713 | if (!machine().GetUSBControllers().isEmpty())
|
---|
714 | {
|
---|
715 | /* Do not bitch if there are no filters (check if enabled too?): */
|
---|
716 | if (!machine().GetUSBDeviceFilters().GetDeviceFilters().isEmpty())
|
---|
717 | UINotificationMessage::cannotEnumerateHostUSBDevices(comHost);
|
---|
718 | }
|
---|
719 | }
|
---|
720 |
|
---|
721 | /* True by default: */
|
---|
722 | return true;
|
---|
723 | }
|
---|
724 |
|
---|
725 | bool UISession::mountAdHocImage(KDeviceType enmDeviceType, UIMediumDeviceType enmMediumType, const QString &strMediumName)
|
---|
726 | {
|
---|
727 | /* Get VBox: */
|
---|
728 | CVirtualBox comVBox = uiCommon().virtualBox();
|
---|
729 |
|
---|
730 | /* Prepare medium to mount: */
|
---|
731 | UIMedium guiMedium;
|
---|
732 |
|
---|
733 | /* The 'none' medium name means ejecting what ever is in the drive,
|
---|
734 | * in that case => leave the guiMedium variable null. */
|
---|
735 | if (strMediumName != "none")
|
---|
736 | {
|
---|
737 | /* Open the medium: */
|
---|
738 | const CMedium comMedium = comVBox.OpenMedium(strMediumName, enmDeviceType, KAccessMode_ReadWrite, false /* fForceNewUuid */);
|
---|
739 | if (!comVBox.isOk() || comMedium.isNull())
|
---|
740 | {
|
---|
741 | UINotificationMessage::cannotOpenMedium(comVBox, strMediumName);
|
---|
742 | return false;
|
---|
743 | }
|
---|
744 |
|
---|
745 | /* Make sure medium ID is valid: */
|
---|
746 | const QUuid uMediumId = comMedium.GetId();
|
---|
747 | AssertReturn(!uMediumId.isNull(), false);
|
---|
748 |
|
---|
749 | /* Try to find UIMedium among cached: */
|
---|
750 | guiMedium = uiCommon().medium(uMediumId);
|
---|
751 | if (guiMedium.isNull())
|
---|
752 | {
|
---|
753 | /* Cache new one if necessary: */
|
---|
754 | guiMedium = UIMedium(comMedium, enmMediumType, KMediumState_Created);
|
---|
755 | uiCommon().createMedium(guiMedium);
|
---|
756 | }
|
---|
757 | }
|
---|
758 |
|
---|
759 | /* Search for a suitable storage slots: */
|
---|
760 | QList<ExactStorageSlot> aFreeStorageSlots;
|
---|
761 | QList<ExactStorageSlot> aBusyStorageSlots;
|
---|
762 | foreach (const CStorageController &comController, machine().GetStorageControllers())
|
---|
763 | {
|
---|
764 | foreach (const CMediumAttachment &comAttachment, machine().GetMediumAttachmentsOfController(comController.GetName()))
|
---|
765 | {
|
---|
766 | /* Look for an optical devices only: */
|
---|
767 | if (comAttachment.GetType() == enmDeviceType)
|
---|
768 | {
|
---|
769 | /* Append storage slot to corresponding list: */
|
---|
770 | if (comAttachment.GetMedium().isNull())
|
---|
771 | aFreeStorageSlots << ExactStorageSlot(comController.GetName(), comController.GetBus(),
|
---|
772 | comAttachment.GetPort(), comAttachment.GetDevice());
|
---|
773 | else
|
---|
774 | aBusyStorageSlots << ExactStorageSlot(comController.GetName(), comController.GetBus(),
|
---|
775 | comAttachment.GetPort(), comAttachment.GetDevice());
|
---|
776 | }
|
---|
777 | }
|
---|
778 | }
|
---|
779 |
|
---|
780 | /* Make sure at least one storage slot found: */
|
---|
781 | QList<ExactStorageSlot> sStorageSlots = aFreeStorageSlots + aBusyStorageSlots;
|
---|
782 | if (sStorageSlots.isEmpty())
|
---|
783 | {
|
---|
784 | UINotificationMessage::cannotMountImage(machineName(), strMediumName);
|
---|
785 | return false;
|
---|
786 | }
|
---|
787 |
|
---|
788 | /* Try to mount medium into first available storage slot: */
|
---|
789 | while (!sStorageSlots.isEmpty())
|
---|
790 | {
|
---|
791 | const ExactStorageSlot storageSlot = sStorageSlots.takeFirst();
|
---|
792 | machine().MountMedium(storageSlot.controller, storageSlot.port, storageSlot.device, guiMedium.medium(), false /* force */);
|
---|
793 | if (machine().isOk())
|
---|
794 | break;
|
---|
795 | }
|
---|
796 |
|
---|
797 | /* Show error message if necessary: */
|
---|
798 | if (!machine().isOk())
|
---|
799 | {
|
---|
800 | msgCenter().cannotRemountMedium(machine(), guiMedium, true /* mount? */, false /* retry? */, activeMachineWindow());
|
---|
801 | return false;
|
---|
802 | }
|
---|
803 |
|
---|
804 | /* Save machine settings: */
|
---|
805 | machine().SaveSettings();
|
---|
806 |
|
---|
807 | /* Show error message if necessary: */
|
---|
808 | if (!machine().isOk())
|
---|
809 | {
|
---|
810 | UINotificationMessage::cannotSaveMachineSettings(machine());
|
---|
811 | return false;
|
---|
812 | }
|
---|
813 |
|
---|
814 | /* True by default: */
|
---|
815 | return true;
|
---|
816 | }
|
---|
817 |
|
---|
818 | CMediumVector UISession::machineMedia() const
|
---|
819 | {
|
---|
820 | CMediumVector comMedia;
|
---|
821 | /* Enumerate all the controllers: */
|
---|
822 | foreach (const CStorageController &comController, m_machine.GetStorageControllers())
|
---|
823 | {
|
---|
824 | /* Enumerate all the attachments: */
|
---|
825 | foreach (const CMediumAttachment &comAttachment, m_machine.GetMediumAttachmentsOfController(comController.GetName()))
|
---|
826 | {
|
---|
827 | /* Skip unrelated device types: */
|
---|
828 | const KDeviceType enmDeviceType = comAttachment.GetType();
|
---|
829 | if ( enmDeviceType != KDeviceType_HardDisk
|
---|
830 | && enmDeviceType != KDeviceType_Floppy
|
---|
831 | && enmDeviceType != KDeviceType_DVD)
|
---|
832 | continue;
|
---|
833 | if ( comAttachment.GetIsEjected()
|
---|
834 | || comAttachment.GetMedium().isNull())
|
---|
835 | continue;
|
---|
836 | comMedia.append(comAttachment.GetMedium());
|
---|
837 | }
|
---|
838 | }
|
---|
839 | return comMedia;
|
---|
840 | }
|
---|
841 |
|
---|
842 | bool UISession::prepareToBeSaved()
|
---|
843 | {
|
---|
844 | return isPaused()
|
---|
845 | || (isRunning() && pause());
|
---|
846 | }
|
---|
847 |
|
---|
848 | bool UISession::prepareToBeShutdowned()
|
---|
849 | {
|
---|
850 | const bool fValidMode = console().GetGuestEnteredACPIMode();
|
---|
851 | if (!fValidMode)
|
---|
852 | UINotificationMessage::cannotSendACPIToMachine();
|
---|
853 | return fValidMode;
|
---|
854 | }
|
---|
855 |
|
---|
856 | void UISession::loadVMSettings()
|
---|
857 | {
|
---|
858 | /* Cache IMachine::ExecutionEngine value. */
|
---|
859 | m_enmVMExecutionEngine = m_debugger.GetExecutionEngine();
|
---|
860 | /* Load nested-paging CPU hardware virtualization extension: */
|
---|
861 | m_fIsHWVirtExNestedPagingEnabled = m_debugger.GetHWVirtExNestedPagingEnabled();
|
---|
862 | /* Load whether the VM is currently making use of the unrestricted execution feature of VT-x: */
|
---|
863 | m_fIsHWVirtExUXEnabled = m_debugger.GetHWVirtExUXEnabled();
|
---|
864 | /* Load VM's effective paravirtualization provider: */
|
---|
865 | m_paraVirtProvider = m_machine.GetEffectiveParavirtProvider();
|
---|
866 | }
|
---|
867 |
|
---|
868 | UIFrameBuffer* UISession::frameBuffer(ulong uScreenId) const
|
---|
869 | {
|
---|
870 | Assert(uScreenId < (ulong)m_frameBufferVector.size());
|
---|
871 | return m_frameBufferVector.value((int)uScreenId, 0);
|
---|
872 | }
|
---|
873 |
|
---|
874 | void UISession::setFrameBuffer(ulong uScreenId, UIFrameBuffer* pFrameBuffer)
|
---|
875 | {
|
---|
876 | Assert(uScreenId < (ulong)m_frameBufferVector.size());
|
---|
877 | if (uScreenId < (ulong)m_frameBufferVector.size())
|
---|
878 | m_frameBufferVector[(int)uScreenId] = pFrameBuffer;
|
---|
879 | }
|
---|
880 |
|
---|
881 | #ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
|
---|
882 | /**
|
---|
883 | * Custom signal handler. When switching VTs, we might not get release events
|
---|
884 | * for Ctrl-Alt and in case a savestate is performed on the new VT, the VM will
|
---|
885 | * be saved with modifier keys stuck. This is annoying enough for introducing
|
---|
886 | * this hack.
|
---|
887 | */
|
---|
888 | /* static */
|
---|
889 | static void signalHandlerSIGUSR1(int sig, siginfo_t * /* pInfo */, void * /*pSecret */)
|
---|
890 | {
|
---|
891 | /* Only SIGUSR1 is interesting: */
|
---|
892 | if (sig == SIGUSR1)
|
---|
893 | if (gpMachine)
|
---|
894 | gpMachine->uisession()->machineLogic()->keyboardHandler()->releaseAllPressedKeys();
|
---|
895 | }
|
---|
896 | #endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
|
---|