VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/xclient/testcase/tstSeamlessX11.cpp@ 7278

Last change on this file since 7278 was 7278, checked in by vboxsync, 17 years ago

Additions/x11: export tstSeamlessX11.cpp

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 4.7 KB
Line 
1/** @file
2 * Linux seamless guest additions simulator in host.
3 */
4
5/*
6 * Copyright (C) 2007 innotek GmbH
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 as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#include <iostream>
18
19#include <iprt/semaphore.h>
20#include <iprt/runtime.h>
21#include <VBox/VBoxGuest.h>
22
23#include "../seamless.h"
24
25static RTSEMEVENT eventSem;
26
27int VbglR3SeamlessSendRects(uint32_t cRects, PRTRECT pRects)
28{
29 std::cout << "Received rectangle update (" << cRects << " rectangles):" << std::endl;
30 for (unsigned i = 0; i < cRects; ++i)
31 {
32 std::cout << " xLeft: " << pRects[i].xLeft << " yTop: " << pRects[i].yTop
33 << " xRight: " << pRects[i].xRight << " yBottom: " << pRects[i].yBottom
34 << std::endl;
35 }
36 return true;
37}
38
39int VbglR3SeamlessSetCap(bool bState)
40{
41 std::cout << (bState ? "Seamless capability set" : "Seamless capability unset")
42 << std::endl;
43 return true;
44}
45
46int VbglR3CtlFilterMask(uint32_t u32OrMask, uint32_t u32NotMask)
47{
48 std::cout << "IRQ filter mask changed. Or mask: 0x" << std::hex << u32OrMask
49 << ". Not mask: 0x" << u32NotMask << std::dec
50 << std::endl;
51 return true;
52}
53
54int VbglR3SeamlessWaitEvent(VMMDevSeamlessMode *pMode)
55{
56 static bool active = false;
57
58 int rc = VINF_SUCCESS;
59 if (!active)
60 {
61 active = true;
62 *pMode = VMMDev_Seamless_Visible_Region;
63 }
64 else
65 {
66 rc = RTSemEventWait(eventSem, RT_INDEFINITE_WAIT);
67 if (RT_SUCCESS(rc))
68 {
69 rc = VERR_INTERRUPTED;
70 }
71 }
72 return true;
73}
74
75int VbglR3InterruptEventWaits(void)
76{
77 return RTSemEventSignal(eventSem);
78}
79
80/**
81 * Xlib error handler for certain errors that we can't avoid.
82 */
83int vboxClientXLibErrorHandler(Display *pDisplay, XErrorEvent *pError)
84{
85 char errorText[1024];
86
87 if (pError->error_code == BadWindow)
88 {
89 /* This can be triggered if a guest application destroys a window before we notice. */
90 std::cout << "ignoring BadAtom error and returning" << std::endl;
91 return 0;
92 }
93 XGetErrorText(pDisplay, pError->error_code, errorText, sizeof(errorText));
94 std::cout << "An X Window protocol error occurred: " << errorText << std::endl
95 << " Request code: " << int(pError->request_code) << std::endl
96 << " Minor code: " << int(pError->minor_code) << std::endl
97 << " Serial number of the failed request: " << int(pError->serial)
98 << std::endl;
99 std::cout << std::endl << "exiting." << std::endl;
100 exit(1);
101}
102
103int main( int argc, char **argv)
104{
105 int rc = VINF_SUCCESS;
106 std::string sTmp;
107
108 RTR3Init(false);
109 std::cout << "VirtualBox guest additions X11 seamless mode testcase" << std::endl;
110 if (0 == XInitThreads())
111 {
112 std::cout << "Failed to initialise X11 threading, exiting." << std::endl;
113 exit(1);
114 }
115 /* Set an X11 error handler, so that we don't die when we get unavoidable errors. */
116 XSetErrorHandler(vboxClientXLibErrorHandler);
117 std::cout << std::endl << "Press <Enter> to exit..." << std::endl;
118 RTSemEventCreate(&eventSem);
119 /** Our instance of the seamless class. */
120 VBoxGuestSeamless seamless;
121 try
122 {
123 LogRel(("Starting seamless Guest Additions...\n"));
124 rc = seamless.init();
125 if (rc != VINF_SUCCESS)
126 {
127 std::cout << "Failed to initialise seamless Additions, rc = " << rc << std::endl;
128 }
129 }
130 catch (std::exception e)
131 {
132 std::cout << "Failed to initialise seamless Additions - caught exception: " << e.what()
133 << std::endl;
134 rc = VERR_UNRESOLVED_ERROR;
135 }
136 catch (...)
137 {
138 std::cout << "Failed to initialise seamless Additions - caught unknown exception.\n"
139 << std::endl;
140 rc = VERR_UNRESOLVED_ERROR;
141 }
142 std::getline(std::cin, sTmp);
143 try
144 {
145 seamless.uninit();
146 }
147 catch (std::exception e)
148 {
149 std::cout << "Error shutting down seamless Additions - caught exception: " << e.what()
150 << std::endl;
151 rc = VERR_UNRESOLVED_ERROR;
152 }
153 catch (...)
154 {
155 std::cout << "Error shutting down seamless Additions - caught unknown exception.\n"
156 << std::endl;
157 rc = VERR_UNRESOLVED_ERROR;
158 }
159 return rc;
160}
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