VirtualBox

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

Last change on this file since 23794 was 21227, checked in by vboxsync, 15 years ago

VBoxGuest.h/VMMDev.h/VBoxGuestLib.h usage cleanup.

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