VirtualBox

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

最後變更 在這個檔案從82968是 82968,由 vboxsync 提交於 5 年 前

Copyright year updates by scm.

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

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