VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBFE/VMControl.cpp@ 31976

Last change on this file since 31976 was 31895, checked in by vboxsync, 15 years ago

FT updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/** @file
2 *
3 * VBox frontends: Basic Frontend (BFE):
4 * VBoxBFE VM control routines
5 *
6 */
7
8/*
9 * Copyright (C) 2006-2007 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#include <iprt/stream.h>
21#include <VBox/err.h>
22#include "DisplayImpl.h"
23#include "ConsoleImpl.h"
24#include "VBoxBFE.h"
25#include "VMControl.h"
26
27/**
28 * Fullscreen / Windowed toggle.
29 */
30int
31VMCtrlToggleFullscreen(void)
32{
33 /* not allowed */
34 if (!gfAllowFullscreenToggle)
35 return VERR_ACCESS_DENIED;
36
37 gFramebuffer->setFullscreen(!gFramebuffer->getFullscreen());
38
39 /*
40 * We have switched from/to fullscreen, so request a full
41 * screen repaint, just to be sure.
42 */
43 gDisplay->InvalidateAndUpdate();
44
45 return VINF_SUCCESS;
46}
47
48/**
49 * Pause the VM.
50 */
51int
52VMCtrlPause(void)
53{
54 if (machineState != VMSTATE_RUNNING)
55 return VERR_VM_INVALID_VM_STATE;
56
57 if (gConsole->inputGrabbed())
58 gConsole->inputGrabEnd();
59
60 int rcVBox = VMR3ReqCallWait(gpVM, VMCPUID_ANY, (PFNRT)VMR3Suspend, 1, gpVM);
61 AssertRC(rcVBox);
62 return VINF_SUCCESS;
63}
64
65/**
66 * Resume the VM.
67 */
68int
69VMCtrlResume(void)
70{
71 if (machineState != VMSTATE_SUSPENDED)
72 return VERR_VM_INVALID_VM_STATE;
73
74 int rcVBox = VMR3ReqCallWait(gpVM, VMCPUID_ANY, (PFNRT)VMR3Resume, 1, gpVM);
75 AssertRC(rcVBox);
76 return VINF_SUCCESS;
77}
78
79/**
80 * Reset the VM
81 */
82int
83VMCtrlReset(void)
84{
85 int rcVBox = VMR3ReqCallWait(gpVM, VMCPUID_ANY, (PFNRT)VMR3Reset, 1, gpVM);
86 AssertRC(rcVBox);
87 return VINF_SUCCESS;
88}
89
90/**
91 * Send ACPI power button press event
92 */
93int
94VMCtrlACPIPowerButton(void)
95{
96 PPDMIBASE pBase;
97 int vrc = PDMR3QueryDeviceLun (gpVM, "acpi", 0, 0, &pBase);
98 if (RT_SUCCESS (vrc))
99 {
100 Assert (pBase);
101 PPDMIACPIPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIACPIPORT);
102 vrc = pPort ? pPort->pfnPowerButtonPress(pPort) : VERR_INVALID_POINTER;
103 }
104 return VINF_SUCCESS;
105}
106
107/**
108 * Send ACPI sleep button press event
109 */
110int
111VMCtrlACPISleepButton(void)
112{
113 PPDMIBASE pBase;
114 int vrc = PDMR3QueryDeviceLun (gpVM, "acpi", 0, 0, &pBase);
115 if (RT_SUCCESS (vrc))
116 {
117 Assert (pBase);
118 PPDMIACPIPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIACPIPORT);
119 vrc = pPort ? pPort->pfnSleepButtonPress(pPort) : VERR_INVALID_POINTER;
120 }
121 return VINF_SUCCESS;
122}
123
124/**
125 * Worker thread while saving the VM
126 */
127DECLCALLBACK(int) VMSaveThread(RTTHREAD Thread, void *pvUser)
128{
129 void (*pfnQuit)(void) = (void(*)(void))pvUser;
130 int rc;
131
132 startProgressInfo("Saving");
133 rc = VMR3ReqCallWait(gpVM, VMCPUID_ANY,
134 (PFNRT)VMR3Save, 7, gpVM, g_pszStateFile,
135 NULL /* pStreamOps */,
136 NULL /* pvStreamOpsUser */,
137 false /*fContinueAftewards*/, &callProgressInfo, (uintptr_t)NULL);
138 AssertRC(rc);
139 endProgressInfo();
140 pfnQuit();
141
142 return VINF_SUCCESS;
143}
144
145/*
146 * Save the machine's state
147 */
148int
149VMCtrlSave(void (*pfnQuit)(void))
150{
151 int rc;
152
153 if (!g_pszStateFile || !*g_pszStateFile)
154 return VERR_INVALID_PARAMETER;
155
156 gConsole->resetKeys();
157 RTThreadYield();
158 if (gConsole->inputGrabbed())
159 gConsole->inputGrabEnd();
160 RTThreadYield();
161
162 if (machineState == VMSTATE_RUNNING)
163 {
164 rc = VMR3ReqCallWait(gpVM, VMCPUID_ANY, (PFNRT)VMR3Suspend, 1, gpVM);
165 AssertRC(rc);
166 }
167
168 RTTHREAD thread;
169 rc = RTThreadCreate(&thread, VMSaveThread, (void*)pfnQuit, 0,
170 RTTHREADTYPE_MAIN_WORKER, 0, "Save");
171 if (RT_FAILURE(rc))
172 {
173 RTPrintf("Error: Thread creation failed with %d\n", rc);
174 return rc;
175 }
176
177 return VINF_SUCCESS;
178}
Note: See TracBrowser for help on using the repository browser.

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