VirtualBox

source: vbox/trunk/src/VBox/Main/testcase/VBox.cpp@ 28800

Last change on this file since 28800 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: 4.2 KB
Line 
1/** @file
2 *
3 * VBox - Main Program.
4 *
5 */
6
7/*
8 * Copyright (C) 2006-2007 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include <iprt/initterm.h>
23#include <VBox/vm.h>
24#include <VBox/err.h>
25#include <signal.h>
26#include <stdio.h>
27#ifdef _MSC_VER
28# include <stdlib.h>
29#else
30# include <unistd.h>
31#endif
32
33
34/*******************************************************************************
35* Internal Functions *
36*******************************************************************************/
37static void SignalInterrupt(int iSignalNo);
38
39
40int main(int argc, char **argv)
41{
42 int rc = -1;
43
44 /* todo: decide whether or not we're gonna have one executable
45 * which contains both GUI and VM backend or separate executables.
46 *
47 * In any case we're expecting this code to be rewritten as this is mostly
48 * a sketch of what we currently think is going to happen when a VM is started.
49 */
50
51 /*
52 * Init runtime.
53 */
54 rc = RTR3Init();
55 if (!RT_SUCCESS(rc))
56 {
57 printf("fatal error: failed to initialize runtime. (rc=%d)\n", rc);
58 return 1;
59 }
60
61 /*
62 * Parse arguments.
63 */
64 char *pszVMConfig = NULL;
65 for (int argi = 1; argi < argc; argi++)
66 {
67 if (argv[argi][0] == '-')
68 {
69 switch (argv[argi][1])
70 {
71 case '?':
72 case 'h':
73 case 'H':
74 printf("syntax: %s <VMConfig>\n", argv[0]);
75 return 1;
76
77 default:
78 printf("syntax error: Unknown option %s\n", argv[argi]);
79 return 1;
80 }
81 }
82 else
83 {
84 if (pszVMConfig)
85 {
86 printf("syntax error: Multiple VM configuration files specified!\n");
87 return 1;
88 }
89 pszVMConfig = argv[argi];
90 }
91 }
92
93 /*
94 * Create the VM from the given config file.
95 */
96 PVM pVM = NULL;
97 rc = VMR3Create(pszVMConfig, &pVM);
98 if (RT_SUCCESS(rc))
99 {
100 /*
101 * Run the VM.
102 */
103 rc = VMR3PowerOn(pVM);
104 if (RT_SUCCESS(rc))
105 {
106 /*
107 * Wait for user to press Control-C,
108 * (or Control-Break if signal is available).
109 */
110 signal(SIGINT, SignalInterrupt);
111 #ifdef SIGBREAK
112 signal(SIGBREAK, SignalInterrupt);
113 #endif
114 #ifdef _MSC_VER
115 _sleep(~0);
116 #else
117 pause();
118 #endif
119 rc = 0;
120 }
121 else
122 {
123 printf("fatal error: Failed to power on the VM! rc=%d\n", rc);
124 rc = 1;
125 }
126
127 /*
128 * Destroy the VM.
129 */
130 int rc2 = VMR3Destroy(pVM);
131 if (!RT_SUCCESS(rc2))
132 {
133 printf("warning: VMR3Destroy() failed with rc=%d\n", rc);
134 rc = 1;
135 }
136 }
137 else
138 {
139 printf("fatal error: failed to create VM from %s, rc=%d\n", pszVMConfig, rc);
140 rc = 1;
141 }
142 return rc;
143}
144
145
146/**
147 * Signal handler.
148 * @param iSignalNo Signal number.
149 */
150void SignalInterrupt(int iSignalNo)
151{
152 #ifdef SIGBREAK
153 if (iSignalNo == SIGBREAK)
154 printf("SIGBREAK!\n");
155 else
156 printf("SIGINT!\n");
157 #else
158 printf("SIGINT!\n");
159 #endif
160
161 /*
162 * assuming BSD style signals here, meaning that execution
163 * continues upon return....
164 * I've no clue how that works on Win32 and linux though.
165 */
166 #ifdef SIG_ACK
167 signal(iSignalNo, SIG_ACK);
168 #endif
169}
170
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