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