VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/VBoxClient/testcase/tstSeamlessX11.cpp@ 97956

最後變更 在這個檔案從97956是 96407,由 vboxsync 提交於 3 年 前

scm copyright and license note update

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 4.8 KB
 
1/* $Id: tstSeamlessX11.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * Linux seamless guest additions simulator in host.
4 */
5
6/*
7 * Copyright (C) 2007-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.alldomusa.eu.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#include <stdlib.h> /* exit() */
29
30#include <iprt/errcore.h>
31#include <iprt/initterm.h>
32#include <iprt/semaphore.h>
33#include <iprt/string.h>
34#include <iprt/stream.h>
35#include <VBox/VBoxGuestLib.h>
36
37#include "../seamless.h"
38
39static RTSEMEVENT eventSem;
40
41void VBClLogError(const char *pszFormat, ...)
42{
43 va_list args;
44 va_start(args, pszFormat);
45 char *psz = NULL;
46 RTStrAPrintfV(&psz, pszFormat, args);
47 va_end(args);
48
49 AssertPtr(psz);
50 RTPrintf("Error: %s", psz);
51
52 RTStrFree(psz);
53}
54
55/** Exit with a fatal error. */
56void VBClLogFatalError(const char *pszFormat, ...)
57{
58 va_list args;
59 va_start(args, pszFormat);
60 char *psz = NULL;
61 RTStrAPrintfV(&psz, pszFormat, args);
62 va_end(args);
63
64 AssertPtr(psz);
65 RTPrintf("Fatal error: %s", psz);
66
67 RTStrFree(psz);
68
69 exit(1);
70}
71
72void VBClLogVerbose(unsigned iLevel, const char *pszFormat, ...)
73{
74 RT_NOREF(iLevel);
75
76 va_list va;
77 va_start(va, pszFormat);
78 RTPrintf("%s", pszFormat);
79 va_end(va);
80}
81
82int VBClStartVTMonitor()
83{
84 return VINF_SUCCESS;
85}
86
87int VbglR3SeamlessSendRects(uint32_t cRects, PRTRECT pRects)
88{
89 RTPrintf("Received rectangle update (%u rectangles):\n", cRects);
90 for (unsigned i = 0; i < cRects; ++i)
91 {
92 RTPrintf(" xLeft: %d yTop: %d xRight: %d yBottom: %d\n",
93 pRects[i].xLeft, pRects[i].yTop, pRects[i].xRight,
94 pRects[i].yBottom);
95 }
96 return VINF_SUCCESS;
97}
98
99int VbglR3SeamlessSetCap(bool bState)
100{
101 RTPrintf("%s\n", bState ? "Seamless capability set"
102 : "Seamless capability unset");
103 return VINF_SUCCESS;
104}
105
106int VbglR3CtlFilterMask(uint32_t u32OrMask, uint32_t u32NotMask)
107{
108 RTPrintf("IRQ filter mask changed. Or mask: 0x%x. Not mask: 0x%x\n",
109 u32OrMask, u32NotMask);
110 return VINF_SUCCESS;
111}
112
113int VbglR3SeamlessWaitEvent(VMMDevSeamlessMode *pMode)
114{
115 static bool active = false;
116
117 int rc = VINF_SUCCESS;
118 if (!active)
119 {
120 active = true;
121 *pMode = VMMDev_Seamless_Visible_Region;
122 }
123 else
124 rc = RTSemEventWait(eventSem, RT_INDEFINITE_WAIT);
125 return rc;
126}
127
128VBGLR3DECL(int) VbglR3InitUser(void) { return VINF_SUCCESS; }
129VBGLR3DECL(void) VbglR3Term(void) {}
130
131/**
132 * Xlib error handler for certain errors that we can't avoid.
133 */
134int vboxClientXLibErrorHandler(Display *pDisplay, XErrorEvent *pError)
135{
136 char errorText[1024];
137
138 if (pError->error_code == BadWindow)
139 {
140 /* This can be triggered if a guest application destroys a window before we notice. */
141 RTPrintf("ignoring BadAtom error and returning\n");
142 return 0;
143 }
144 XGetErrorText(pDisplay, pError->error_code, errorText, sizeof(errorText));
145 RTPrintf("An X Window protocol error occurred: %s\n"
146 " Request code: %d\n"
147 " Minor code: %d\n"
148 " Serial number of the failed request: %d\n\n"
149 "exiting.\n",
150 errorText, (int)pError->request_code, (int)pError->minor_code,
151 (int)pError->serial);
152 exit(1);
153}
154
155int main( int argc, char **argv)
156{
157 int rc = VINF_SUCCESS;
158
159 RTR3InitExe(argc, &argv, 0);
160 RTPrintf("VirtualBox guest additions X11 seamless mode testcase\n");
161 if (0 == XInitThreads())
162 {
163 RTPrintf("Failed to initialise X11 threading, exiting.\n");
164 exit(1);
165 }
166 /* Set an X11 error handler, so that we don't die when we get unavoidable errors. */
167 XSetErrorHandler(vboxClientXLibErrorHandler);
168 RTPrintf("\nType Ctrl-C to exit...\n");
169 RTSemEventCreate(&eventSem);
170 /** Our instance of the seamless class. */
171 SeamlessMain seamless;
172 LogRel(("Starting seamless Guest Additions...\n"));
173 rc = seamless.init();
174 if (rc != VINF_SUCCESS)
175 {
176 RTPrintf("Failed to initialise seamless Additions, rc = %Rrc\n", rc);
177 }
178 bool fShutdown = false;
179 rc = seamless.worker(&fShutdown);
180 if (rc != VINF_SUCCESS)
181 {
182 RTPrintf("Failed to run seamless Additions, rc = %Rrc\n", rc);
183 }
184 return rc;
185}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette