VirtualBox

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

Last change on this file since 55377 was 54008, checked in by vboxsync, 10 years ago

Additions/x11/VBoxClient: initialise the guest library from the services, as preparation for running the display service without using the VMM device.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 4.1 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
91VBGLR3DECL(int) VbglR3InitUser(void) { return VINF_SUCCESS; }
92VBGLR3DECL(void) VbglR3Term(void) {}
93
94/**
95 * Xlib error handler for certain errors that we can't avoid.
96 */
97int vboxClientXLibErrorHandler(Display *pDisplay, XErrorEvent *pError)
98{
99 char errorText[1024];
100
101 if (pError->error_code == BadWindow)
102 {
103 /* This can be triggered if a guest application destroys a window before we notice. */
104 RTPrintf("ignoring BadAtom error and returning\n");
105 return 0;
106 }
107 XGetErrorText(pDisplay, pError->error_code, errorText, sizeof(errorText));
108 RTPrintf("An X Window protocol error occurred: %s\n"
109 " Request code: %d\n"
110 " Minor code: %d\n"
111 " Serial number of the failed request: %d\n\n"
112 "exiting.\n",
113 errorText, (int)pError->request_code, (int)pError->minor_code,
114 (int)pError->serial);
115 exit(1);
116}
117
118int main( int argc, char **argv)
119{
120 int rc = VINF_SUCCESS;
121 char ach[2];
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