seamless.cpp revision 1e8749f718360f779a7a345fd29ac8f758f6527d
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * X11 Guest client - seamless mode: main logic, communication with the host and
3184fc1a3e65025cd55704cdb1629f4ab1f3ccd2vboxsync * wrapper interface for the main code of the VBoxClient deamon. The
3184fc1a3e65025cd55704cdb1629f4ab1f3ccd2vboxsync * X11-specific parts are split out into their own file for ease of testing.
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * Copyright (C) 2006-2014 Oracle Corporation
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * available from http://www.virtualbox.org. This file is free software;
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * you can redistribute it and/or modify it under the terms of the GNU
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * General Public License (GPL) as published by the Free Software
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
be6a7ee8f237a71cf075c128e8e391e6c3654687vboxsync/*****************************************************************************
2fa05a4e777b070ba9bf01e3dd46434c99cd06a3vboxsync* Header files *
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync*****************************************************************************/
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * initialise the service.
d97357e2036109245c83ba553d0290212e28ea40vboxsync rc = VbglR3CtlFilterMask(VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST, 0);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync pcszStage = "Reporting support for seamless capability";
d97357e2036109245c83ba553d0290212e28ea40vboxsync } while(0);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogRel(("VBoxClient (seamless): failed to start. Stage: \"%s\" Error: %Rrc\n",
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * Run the main service thread which listens for host state change
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * notifications.
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * @returns iprt status value. Service will be set to the stopped state on
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* This will only exit if something goes wrong. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* If we are not stopping, sleep for a bit to avoid using up too
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync much CPU while retrying. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogRel(("VBoxClient (seamless): event loop failed with error: %Rrc\n",
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync/** Stops the service. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync VbglR3CtlFilterMask(0, VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * Waits for a seamless state change events from the host and dispatch it.
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * @returns IRPT return code.
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync VMMDevSeamlessMode newMode = VMMDev_Seamless_Disabled;
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync /* A simplified seamless mode, obtained by making the host VM window
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync * borderless and making the guest desktop transparent. */
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync LogRelFlowFunc(("\"Visible region\" mode requested (VBoxClient).\n"));
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync LogRelFlowFunc(("\"Disabled\" mode requested (VBoxClient).\n"));
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync /* One host window represents one guest window. Not yet implemented. */
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync LogRelFunc(("Unsupported \"host window\" mode requested (VBoxClient).\n"));
d97357e2036109245c83ba553d0290212e28ea40vboxsync LogRelFunc(("Unsupported mode %d requested (VBoxClient).\n",
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync if (mMode == VMMDev_Seamless_Visible_Region && !mfPaused)
d97357e2036109245c83ba553d0290212e28ea40vboxsync /* This does it's own logging on failure. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* This does it's own logging on failure. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogRelFunc(("VbglR3SeamlessWaitEvent returned %Rrc (VBoxClient)\n", rc));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * Update the set of visible rectangles in the host.
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncvoid SeamlessMain::sendRegionUpdate(RTRECT *pRects, size_t cRects)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogRelThisFunc(("ERROR: called with null pointer!\n"));
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * The actual X11 window configuration change monitor thread function.
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsyncint SeamlessMain::x11MonitorThread(RTTHREAD self, void *pvUser)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * Start the X11 window configuration change monitor thread.
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync rc = RTThreadCreate(&mX11MonitorThread, x11MonitorThread, this, 0,
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync "X11 events");
1041613dd6ee5da259fa80b5555bb556f4dd8aafvboxsync LogRelFunc(("Warning: failed to start X11 monitor thread (VBoxClient).\n"));
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync * Send a signal to the thread function that it should exit
d97357e2036109245c83ba553d0290212e28ea40vboxsync rc = RTThreadWait(mX11MonitorThread, RT_INDEFINITE_WAIT, NULL);
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync LogRelThisFunc(("Failed to stop X11 monitor thread, rc=%Rrc!\n",
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync/** Pause the service loop. */
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync pcszStage = "Reporting end of support for seamless capability";
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync } while (0);
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync LogRelFunc(("Failure. Stage: \"%s\" Error: %Rrc (VBoxClient)\n",
254e593d079dbddd48135ebe2893334eb36dcbafvboxsync/** Resume after pausing. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync pcszStage = "Reporting support for seamless capability";
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync } while (0);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogRelFunc(("Failure. Stage: \"%s\" Error: %Rrc (VBoxClient)\n",
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync/** @todo Expand this? */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if (RT_FAILURE(VbglR3WaitEvent(VMMDEV_EVENT_VALID_EVENT_MASK, 0, NULL)))
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync if ( VbglR3WaitEvent(VMMDEV_EVENT_VALID_EVENT_MASK, 0, NULL)
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync } while(0);
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync LogRel(("VBoxClient (seamless): self test failed. Stage: \"%s\"\n",
d97357e2036109245c83ba553d0290212e28ea40vboxsync/** VBoxClient service class wrapping the logic for the seamless service while
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync * the main VBoxClient code provides the daemon logic needed by all services.
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync virtual const char *getPidFilePath()
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync return ".vboxclient-seamless.pid";
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync virtual int init()
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync /* This only exits on error. */
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync virtual int resume() { return mSeamless.resume(); }
18470279db8a9fdd714617adbe1aa8b63cc80aeevboxsync virtual void cleanup()