VirtualBox

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

Last change on this file since 64670 was 62530, checked in by vboxsync, 8 years ago

(C) 2016

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