VirtualBox

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

Last change on this file since 52586 was 52586, checked in by vboxsync, 11 years ago

Additions/x11/VBoxClient: re-do virtual terminal switch monitoring to work with the kernel driver on X.Org Server 1.16 and later.

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