VirtualBox

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

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

pdmifs.h: the penultimate batch of refactored interface ID code.

  • 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 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 int rcVBox = VMR3ReqCallWait(gpVM, VMCPUID_ANY, (PFNRT)VMR3Suspend, 1, gpVM);
65 AssertRC(rcVBox);
66 return VINF_SUCCESS;
67}
68
69/**
70 * Resume the VM.
71 */
72int
73VMCtrlResume(void)
74{
75 if (machineState != VMSTATE_SUSPENDED)
76 return VERR_VM_INVALID_VM_STATE;
77
78 int rcVBox = VMR3ReqCallWait(gpVM, VMCPUID_ANY, (PFNRT)VMR3Resume, 1, gpVM);
79 AssertRC(rcVBox);
80 return VINF_SUCCESS;
81}
82
83/**
84 * Reset the VM
85 */
86int
87VMCtrlReset(void)
88{
89 int rcVBox = VMR3ReqCallWait(gpVM, VMCPUID_ANY, (PFNRT)VMR3Reset, 1, gpVM);
90 AssertRC(rcVBox);
91 return VINF_SUCCESS;
92}
93
94/**
95 * Send ACPI power button press event
96 */
97int
98VMCtrlACPIPowerButton(void)
99{
100 PPDMIBASE pBase;
101 int vrc = PDMR3QueryDeviceLun (gpVM, "acpi", 0, 0, &pBase);
102 if (RT_SUCCESS (vrc))
103 {
104 Assert (pBase);
105 PPDMIACPIPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIACPIPORT);
106 vrc = pPort ? pPort->pfnPowerButtonPress(pPort) : VERR_INVALID_POINTER;
107 }
108 return VINF_SUCCESS;
109}
110
111/**
112 * Send ACPI sleep button press event
113 */
114int
115VMCtrlACPISleepButton(void)
116{
117 PPDMIBASE pBase;
118 int vrc = PDMR3QueryDeviceLun (gpVM, "acpi", 0, 0, &pBase);
119 if (RT_SUCCESS (vrc))
120 {
121 Assert (pBase);
122 PPDMIACPIPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIACPIPORT);
123 vrc = pPort ? pPort->pfnSleepButtonPress(pPort) : VERR_INVALID_POINTER;
124 }
125 return VINF_SUCCESS;
126}
127
128/**
129 * Worker thread while saving the VM
130 */
131DECLCALLBACK(int) VMSaveThread(RTTHREAD Thread, void *pvUser)
132{
133 void (*pfnQuit)(void) = (void(*)(void))pvUser;
134 int rc;
135
136 startProgressInfo("Saving");
137 rc = VMR3ReqCallWait(gpVM, VMCPUID_ANY,
138 (PFNRT)VMR3Save, 5, gpVM, g_pszStateFile, false /*fContinueAftewards*/, &callProgressInfo, (uintptr_t)NULL);
139 AssertRC(rc);
140 endProgressInfo();
141 pfnQuit();
142
143 return VINF_SUCCESS;
144}
145
146/*
147 * Save the machine's state
148 */
149int
150VMCtrlSave(void (*pfnQuit)(void))
151{
152 int rc;
153
154 if (!g_pszStateFile || !*g_pszStateFile)
155 return VERR_INVALID_PARAMETER;
156
157 gConsole->resetKeys();
158 RTThreadYield();
159 if (gConsole->inputGrabbed())
160 gConsole->inputGrabEnd();
161 RTThreadYield();
162
163 if (machineState == VMSTATE_RUNNING)
164 {
165 rc = VMR3ReqCallWait(gpVM, VMCPUID_ANY, (PFNRT)VMR3Suspend, 1, gpVM);
166 AssertRC(rc);
167 }
168
169 RTTHREAD thread;
170 rc = RTThreadCreate(&thread, VMSaveThread, (void*)pfnQuit, 0,
171 RTTHREADTYPE_MAIN_WORKER, 0, "Save");
172 if (RT_FAILURE(rc))
173 {
174 RTPrintf("Error: Thread creation failed with %d\n", rc);
175 return rc;
176 }
177
178 return VINF_SUCCESS;
179}
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