VirtualBox

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

Last change on this file since 13782 was 13782, checked in by vboxsync, 16 years ago

More SMP groundwork.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 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 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#include <iprt/stream.h>
25#include <VBox/err.h>
26#include "DisplayImpl.h"
27#include "ConsoleImpl.h"
28#include "VBoxBFE.h"
29#include "VMControl.h"
30
31/**
32 * Fullscreen / Windowed toggle.
33 */
34int
35VMCtrlToggleFullscreen(void)
36{
37 /* not allowed */
38 if (!gfAllowFullscreenToggle)
39 return VERR_ACCESS_DENIED;
40
41 gFramebuffer->setFullscreen(!gFramebuffer->getFullscreen());
42
43 /*
44 * We have switched from/to fullscreen, so request a full
45 * screen repaint, just to be sure.
46 */
47 gDisplay->InvalidateAndUpdate();
48
49 return VINF_SUCCESS;
50}
51
52/**
53 * Pause the VM.
54 */
55int
56VMCtrlPause(void)
57{
58 if (machineState != VMSTATE_RUNNING)
59 return VERR_VM_INVALID_VM_STATE;
60
61 if (gConsole->inputGrabbed())
62 gConsole->inputGrabEnd();
63
64 PVMREQ pReq;
65 int rcVBox = VMR3ReqCall(pVM, VMREQDEST_ANY, &pReq, RT_INDEFINITE_WAIT,
66 (PFNRT)VMR3Suspend, 1, pVM);
67 AssertRC(rcVBox);
68 if (VBOX_SUCCESS(rcVBox))
69 {
70 rcVBox = pReq->iStatus;
71 VMR3ReqFree(pReq);
72 }
73 return VINF_SUCCESS;
74}
75
76/**
77 * Resume the VM.
78 */
79int
80VMCtrlResume(void)
81{
82 if (machineState != VMSTATE_SUSPENDED)
83 return VERR_VM_INVALID_VM_STATE;
84
85 PVMREQ pReq;
86 int rcVBox = VMR3ReqCall(pVM, VMREQDEST_ANY, &pReq, RT_INDEFINITE_WAIT,
87 (PFNRT)VMR3Resume, 1, pVM);
88 AssertRC(rcVBox);
89 if (VBOX_SUCCESS(rcVBox))
90 {
91 rcVBox = pReq->iStatus;
92 VMR3ReqFree(pReq);
93 }
94 return VINF_SUCCESS;
95}
96
97/**
98 * Reset the VM
99 */
100int
101VMCtrlReset(void)
102{
103 PVMREQ pReq;
104 int rcVBox = VMR3ReqCall(pVM, VMREQDEST_ANY, &pReq, RT_INDEFINITE_WAIT,
105 (PFNRT)VMR3Reset, 1, pVM);
106 AssertRC(rcVBox);
107 if (VBOX_SUCCESS(rcVBox))
108 {
109 rcVBox = pReq->iStatus;
110 VMR3ReqFree(pReq);
111 }
112
113 return VINF_SUCCESS;
114}
115
116/**
117 * Send ACPI power button press event
118 */
119int
120VMCtrlACPIPowerButton(void)
121{
122 PPDMIBASE pBase;
123 int vrc = PDMR3QueryDeviceLun (pVM, "acpi", 0, 0, &pBase);
124 if (VBOX_SUCCESS (vrc))
125 {
126 Assert (pBase);
127 PPDMIACPIPORT pPort =
128 (PPDMIACPIPORT) pBase->pfnQueryInterface(pBase, PDMINTERFACE_ACPI_PORT);
129 vrc = pPort ? pPort->pfnPowerButtonPress(pPort) : VERR_INVALID_POINTER;
130 }
131 return VINF_SUCCESS;
132}
133
134/**
135 * Send ACPI sleep button press event
136 */
137int
138VMCtrlACPISleepButton(void)
139{
140 PPDMIBASE pBase;
141 int vrc = PDMR3QueryDeviceLun (pVM, "acpi", 0, 0, &pBase);
142 if (VBOX_SUCCESS (vrc))
143 {
144 Assert (pBase);
145 PPDMIACPIPORT pPort =
146 (PPDMIACPIPORT) pBase->pfnQueryInterface(pBase, PDMINTERFACE_ACPI_PORT);
147 vrc = pPort ? pPort->pfnSleepButtonPress(pPort) : VERR_INVALID_POINTER;
148 }
149 return VINF_SUCCESS;
150}
151
152/**
153 * Worker thread while saving the VM
154 */
155DECLCALLBACK(int) VMSaveThread(RTTHREAD Thread, void *pvUser)
156{
157 PVMREQ pReq;
158 void (*pfnQuit)(void) = (void(*)(void))pvUser;
159 int rc;
160
161 startProgressInfo("Saving");
162 rc = VMR3ReqCall(pVM, VMREQDEST_ANY, &pReq, RT_INDEFINITE_WAIT,
163 (PFNRT)VMR3Save, 4, pVM, g_pszStateFile, &callProgressInfo, NULL);
164 endProgressInfo();
165 if (VBOX_SUCCESS(rc))
166 {
167 rc = pReq->iStatus;
168 VMR3ReqFree(pReq);
169 }
170 pfnQuit();
171
172 return 0;
173}
174
175/*
176 * Save the machine's state
177 */
178int
179VMCtrlSave(void (*pfnQuit)(void))
180{
181 int rc;
182
183 if (!g_pszStateFile || !*g_pszStateFile)
184 return VERR_INVALID_PARAMETER;
185
186 gConsole->resetKeys();
187 RTThreadYield();
188 if (gConsole->inputGrabbed())
189 gConsole->inputGrabEnd();
190 RTThreadYield();
191
192 if (machineState == VMSTATE_RUNNING)
193 {
194 PVMREQ pReq;
195 rc = VMR3ReqCall(pVM, VMREQDEST_ANY, &pReq, RT_INDEFINITE_WAIT,
196 (PFNRT)VMR3Suspend, 1, pVM);
197 AssertRC(rc);
198 if (VBOX_SUCCESS(rc))
199 {
200 rc = pReq->iStatus;
201 VMR3ReqFree(pReq);
202 }
203 }
204
205 RTTHREAD thread;
206 rc = RTThreadCreate(&thread, VMSaveThread, (void*)pfnQuit, 0,
207 RTTHREADTYPE_MAIN_WORKER, 0, "Save");
208 if (VBOX_FAILURE(rc))
209 {
210 RTPrintf("Error: Thread creation failed with %d\n", rc);
211 return rc;
212 }
213
214 return VINF_SUCCESS;
215}
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