VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.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 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, 5, gpVM, g_pszStateFile, false /*fContinueAftewards*/, &callProgressInfo, (uintptr_t)NULL);
135 AssertRC(rc);
136 endProgressInfo();
137 pfnQuit();
138
139 return VINF_SUCCESS;
140}
141
142/*
143 * Save the machine's state
144 */
145int
146VMCtrlSave(void (*pfnQuit)(void))
147{
148 int rc;
149
150 if (!g_pszStateFile || !*g_pszStateFile)
151 return VERR_INVALID_PARAMETER;
152
153 gConsole->resetKeys();
154 RTThreadYield();
155 if (gConsole->inputGrabbed())
156 gConsole->inputGrabEnd();
157 RTThreadYield();
158
159 if (machineState == VMSTATE_RUNNING)
160 {
161 rc = VMR3ReqCallWait(gpVM, VMCPUID_ANY, (PFNRT)VMR3Suspend, 1, gpVM);
162 AssertRC(rc);
163 }
164
165 RTTHREAD thread;
166 rc = RTThreadCreate(&thread, VMSaveThread, (void*)pfnQuit, 0,
167 RTTHREADTYPE_MAIN_WORKER, 0, "Save");
168 if (RT_FAILURE(rc))
169 {
170 RTPrintf("Error: Thread creation failed with %d\n", rc);
171 return rc;
172 }
173
174 return VINF_SUCCESS;
175}
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