VirtualBox

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

Last change on this file since 6124 was 6000, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change, fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 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 innotek GmbH
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 PVMREQ pReq;
61 int rcVBox = VMR3ReqCall(pVM, &pReq, RT_INDEFINITE_WAIT,
62 (PFNRT)VMR3Suspend, 1, pVM);
63 AssertRC(rcVBox);
64 if (VBOX_SUCCESS(rcVBox))
65 {
66 rcVBox = pReq->iStatus;
67 VMR3ReqFree(pReq);
68 }
69 return VINF_SUCCESS;
70}
71
72/**
73 * Resume the VM.
74 */
75int
76VMCtrlResume(void)
77{
78 if (machineState != VMSTATE_SUSPENDED)
79 return VERR_VM_INVALID_VM_STATE;
80
81 PVMREQ pReq;
82 int rcVBox = VMR3ReqCall(pVM, &pReq, RT_INDEFINITE_WAIT,
83 (PFNRT)VMR3Resume, 1, pVM);
84 AssertRC(rcVBox);
85 if (VBOX_SUCCESS(rcVBox))
86 {
87 rcVBox = pReq->iStatus;
88 VMR3ReqFree(pReq);
89 }
90 return VINF_SUCCESS;
91}
92
93/**
94 * Reset the VM
95 */
96int
97VMCtrlReset(void)
98{
99 PVMREQ pReq;
100 int rcVBox = VMR3ReqCall(pVM, &pReq, RT_INDEFINITE_WAIT,
101 (PFNRT)VMR3Reset, 1, pVM);
102 AssertRC(rcVBox);
103 if (VBOX_SUCCESS(rcVBox))
104 {
105 rcVBox = pReq->iStatus;
106 VMR3ReqFree(pReq);
107 }
108
109 return VINF_SUCCESS;
110}
111
112/**
113 * Send ACPI power button press event
114 */
115int
116VMCtrlACPIButton(void)
117{
118 PPDMIBASE pBase;
119 int vrc = PDMR3QueryDeviceLun (pVM, "acpi", 0, 0, &pBase);
120 if (VBOX_SUCCESS (vrc))
121 {
122 Assert (pBase);
123 PPDMIACPIPORT pPort =
124 (PPDMIACPIPORT) pBase->pfnQueryInterface(pBase, PDMINTERFACE_ACPI_PORT);
125 vrc = pPort ? pPort->pfnPowerButtonPress(pPort) : VERR_INVALID_POINTER;
126 }
127 return VINF_SUCCESS;
128}
129
130/**
131 * Worker thread while saving the VM
132 */
133DECLCALLBACK(int) VMSaveThread(RTTHREAD Thread, void *pvUser)
134{
135 PVMREQ pReq;
136 void (*pfnQuit)(void) = (void(*)(void))pvUser;
137 int rc;
138
139 startProgressInfo("Saving");
140 rc = VMR3ReqCall(pVM, &pReq, RT_INDEFINITE_WAIT,
141 (PFNRT)VMR3Save, 4, pVM, g_pszStateFile, &callProgressInfo, NULL);
142 endProgressInfo();
143 if (VBOX_SUCCESS(rc))
144 {
145 rc = pReq->iStatus;
146 VMR3ReqFree(pReq);
147 }
148 pfnQuit();
149
150 return 0;
151}
152
153/*
154 * Save the machine's state
155 */
156int
157VMCtrlSave(void (*pfnQuit)(void))
158{
159 int rc;
160
161 if (!g_pszStateFile || !*g_pszStateFile)
162 return VERR_INVALID_PARAMETER;
163
164 gConsole->resetKeys();
165 RTThreadYield();
166 if (gConsole->inputGrabbed())
167 gConsole->inputGrabEnd();
168 RTThreadYield();
169
170 if (machineState == VMSTATE_RUNNING)
171 {
172 PVMREQ pReq;
173 rc = VMR3ReqCall(pVM, &pReq, RT_INDEFINITE_WAIT,
174 (PFNRT)VMR3Suspend, 1, pVM);
175 AssertRC(rc);
176 if (VBOX_SUCCESS(rc))
177 {
178 rc = pReq->iStatus;
179 VMR3ReqFree(pReq);
180 }
181 }
182
183 RTTHREAD thread;
184 rc = RTThreadCreate(&thread, VMSaveThread, (void*)pfnQuit, 0,
185 RTTHREADTYPE_MAIN_WORKER, 0, "Save");
186 if (VBOX_FAILURE(rc))
187 {
188 RTPrintf("Error: Thread creation failed with %d\n", rc);
189 return rc;
190 }
191
192 return VINF_SUCCESS;
193}
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