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