seamless.cpp revision 8c02584ef33c18111419a0c2c26ee085ee90bbc4
/** @file
* X11 Guest client - seamless mode: main logic, communication with the host and
* wrapper interface for the main code of the VBoxClient deamon. The
* X11-specific parts are split out into their own file for ease of testing.
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*****************************************************************************
* Header files *
*****************************************************************************/
#include <VBox/VBoxGuestLib.h>
#include "VBoxClient.h"
#include "seamless.h"
SeamlessMain::SeamlessMain(void)
{
LogRelFlowFunc(("\n"));
mX11MonitorThreadStopping = false;
mHostEventThreadRunning = false;
mHostEventThreadStopping = false;
}
{
LogRelFlowFunc(("\n"));
stop();
}
/**
* Start the main service thread which listens for host state change
* notifications.
* @returns iprt status value. Service will be set to the stopped state on
* failure.
*/
int SeamlessMain::start(void)
{
int rc;
const char *pszStage;
LogRelFlowFunc(("\n"));
do {
pszStage = "Checking that we are not already running";
if (mHostEventThread) /* Assertion */
break;
pszStage = "Testing event loop cancellation";
break;
!= VERR_TIMEOUT)
break;
pszStage = "Connecting to the X server";
if (RT_FAILURE(rc))
break;
/* Create a thread to wait for requests from the host. This is currently
* done on a separate thread as the main thread monitors the X11 server
* for disconnections. */
/** @todo Move the disconnection monitoring to its own thread (better, the
* VT monitor thread) and run this logic on the main service thread. */
pszStage = "Starting host event thread";
rc = startHostEventThread();
if (RT_FAILURE(rc))
break;
pszStage = "Setting guest IRQ filter mask";
if (RT_FAILURE(rc))
break;
pszStage = "Reporting support for seamless capability";
rc = VbglR3SeamlessSetCap(true);
if (RT_FAILURE(rc))
break;
} while(0);
if (RT_FAILURE(rc))
{
LogRel(("VBoxClient (seamless): failed to start. Stage: \"%s\" Error: %Rrc\n",
stop();
}
return rc;
}
/** Stops the service. */
void SeamlessMain::stop()
{
LogRelFlowFunc(("\n"));
VbglR3SeamlessSetCap(false);
if (mHostEventThread)
LogRelFlowFunc(("returning\n"));
}
/**
* Waits for a seamless state change events from the host and dispatch it.
*
* @returns IRPT return code.
*/
int SeamlessMain::nextStateChangeEvent(void)
{
LogRelFlowFunc(("\n"));
if (RT_SUCCESS(rc))
{
switch(newMode)
{
/* A simplified seamless mode, obtained by making the host VM window borderless and
making the guest desktop transparent. */
LogRelFlowFunc(("VMMDev_Seamless_Visible_Region request received (VBoxClient).\n"));
/** @todo Do something on failure, like bail out. */
break;
/* One host window represents one guest window. Not yet implemented. */
LogRelFunc(("Warning: VMMDev_Seamless_Host_Window request received (VBoxClient).\n"));
/* fall through to default */
default:
/* fall through to case VMMDev_Seamless_Disabled */
case VMMDev_Seamless_Disabled:
LogRelFlowFunc(("VMMDev_Seamless_Disabled set (VBoxClient).\n"));
}
}
else
{
}
return rc;
}
/**
* Update the set of visible rectangles in the host.
*/
{
LogRelFlowFunc(("\n"));
{
LogRelThisFunc(("ERROR: called with null pointer!\n"));
return;
}
LogRelFlowFunc(("returning\n"));
}
/**
* Thread to listen for seamless state change notifications from the host.
*/
{
LogRelFlowFunc(("\n"));
pHost->mHostEventThreadRunning = true;
if (0 != pHost)
{
while (!pHost->mHostEventThreadStopping)
{
/* This thread is stopped by setting @a mHostEventThreadStopping
* and sending a cancel to the state change event wait, see below.
*/
{
/* If we are not stopping, sleep for a bit to avoid using up too
much CPU while retrying. */
}
}
}
pHost->mHostEventThreadRunning = false;
return VINF_SUCCESS;
}
/**
* Start the seamless state change notification listener thread.
*/
int SeamlessMain::startHostEventThread()
{
int rc;
mHostEventThreadStopping = false;
"Host events");
if (RT_FAILURE(rc))
LogRel(("VBoxClient: failed to start seamless event thread, rc=%Rrc.\n",
rc));
return rc;
}
/**
* Send a signal to the host event thread that it should exit and poke it.
*/
void SeamlessMain::stopHostEventThread()
{
int rc;
LogRelFlowFunc(("\n"));
mHostEventThreadStopping = true;
cancelEvent();
if (RT_SUCCESS(rc))
else
LogRelThisFunc(("Failed to stop seamless event thread, rc=%Rrc!\n",
rc));
LogRelFlowFunc(("returning\n"));
}
/**
* The actual X11 window configuration change monitor thread function.
*/
{
int rc = VINF_SUCCESS;
LogRelFlowFunc(("\n"));
if (RT_SUCCESS(rc))
{
while (!pHost->mX11MonitorThreadStopping)
}
return rc;
}
/**
* Start the X11 window configuration change monitor thread.
*/
int SeamlessMain::startX11MonitorThread(void)
{
int rc;
mX11MonitorThreadStopping = false;
"X11 events");
if (RT_FAILURE(rc))
LogRelFunc(("Warning: failed to start X11 monitor thread (VBoxClient).\n"));
return rc;
}
/**
* Send a signal to the thread function that it should exit
*/
void SeamlessMain::stopX11MonitorThread(void)
{
int rc;
mX11MonitorThreadStopping = true;
if (!mX11MonitorThread)
return;
if (RT_SUCCESS(rc))
else
LogRelThisFunc(("Failed to stop X11 monitor thread, rc=%Rrc!\n",
rc));
}
/** VBoxClient service class wrapping the logic for the seamless service while
* the main VBoxClient code provides the daemon logic needed by all services.
*/
{
private:
bool mIsInitialised;
public:
virtual const char *getPidFilePath()
{
return ".vboxclient-seamless.pid";
}
{
const char *pszStage;
int rc;
do {
pszStage = "Checking that we are not already running";
if (mIsInitialised) /* Assertion */
break;
pszStage = "Connecting to the X server";
if (!pDisplay)
break;
pszStage = "Starting the service";
if (RT_FAILURE(rc))
break;
} while(0);
if (RT_FAILURE(rc))
{
LogRelFunc(("VBoxClient seamless service control: failed at stage: \"%s\". Error: %Rrc\n",
if (pDisplay)
return rc;
}
mIsInitialised = true;
/* Stay running as long as X does... */
while (true)
return VERR_INTERRUPTED;
}
virtual void cleanup()
{
VbglR3SeamlessSetCap(false);
}
};
{
return new SeamlessService;
}