seamless.cpp revision cf59f0d26d20b28df49bd34b4c33401e009c4fe6
/** @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"
/**
* Start the service.
* @returns iprt status value
*/
int SeamlessMain::start(void)
{
int rc = VERR_NOT_SUPPORTED;
LogRelFlowFunc(("\n"));
if (mThread) /* Assertion */
{
LogRel(("VBoxClient: seamless service started twice!\n"));
return VERR_INTERNAL_ERROR;
}
if (RT_FAILURE(rc))
{
}
rc = VbglR3SeamlessSetCap(true);
if (RT_SUCCESS(rc))
{
LogRel(("VBoxClient: enabled seamless capability on host.\n"));
/* 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. */
"Host events");
if (RT_FAILURE(rc))
{
LogRel(("VBoxClient: failed to start seamless event thread, rc=%Rrc. Disabled seamless capability on host again.\n", rc));
VbglR3SeamlessSetCap(false);
}
}
if (RT_FAILURE(rc))
{
}
return rc;
}
/** Stops the service. */
void SeamlessMain::stop()
{
LogRelFlowFunc(("\n"));
if (!mThread) /* Assertion */
LogRel(("VBoxClient: tried to stop seamless service which is not running!\n"));
else
stopThread();
if (mX11MonitorRTThread)
VbglR3SeamlessSetCap(false);
LogRelFlowFunc(("returning\n"));
}
/**
* Waits for a seamless state change events from the host and dispatch it.
*
* @returns IRPT return code.
*/
int SeamlessMain::nextEvent(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. */
#ifdef DEBUG
LogRelFunc(("VMMDev_Seamless_Visible_Region request received (VBoxClient).\n"));
#endif
mX11ThreadStopping = false;
/** @todo Do something on failure, like bail out. */
x11ThreadFunction, this, 0, RTTHREADTYPE_MSG_PUMP,
RTTHREADFLAGS_WAITABLE, "X11 events")))
LogRelFunc(("Warning: failed to start X11 monitor thread (VBoxClient).\n"));
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:
#ifdef DEBUG
LogRelFunc(("VMMDev_Seamless_Disabled set (VBoxClient).\n"));
#endif
if (mX11MonitorRTThread)
else
LogRelThisFunc(("Attempted to stop X11 monitor thread which is not running (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"));
}
/**
* The actual event thread function.
*/
{
LogRelFlowFunc(("\n"));
pHost->mThreadRunning = true;
if (0 != pHost)
{
while (!pHost->mThreadStopping)
{
{
/* If we are not stopping, sleep for a bit to avoid using up too
much CPU while retrying. */
}
}
}
pHost->mThreadRunning = false;
LogRelFlowFunc(("returning VINF_SUCCESS\n"));
return VINF_SUCCESS;
}
/**
* Send a signal to the thread that it should exit
*/
void SeamlessMain::stopThread()
{
int rc;
LogRelFlowFunc(("\n"));
/**
* @todo is this reasonable? If the thread is in the event loop then the cancelEvent()
* will cause it to exit. If it enters or exits the event loop it will also
* notice that we wish it to exit. And if it is somewhere in-between, the
* yield() should give it time to get to one of places mentioned above.
*/
mThreadStopping = true;
for (int i = 0; (i < 5) && mThreadRunning; ++i)
{
cancelEvent();
}
if (RT_SUCCESS(rc))
else
LogRelThisFunc(("Failed to stop seamless event thread, rc=%Rrc!\n",
rc));
LogRelFlowFunc(("returning\n"));
}
/**
* The actual X11 event thread function.
*/
{
int rc = VINF_SUCCESS;
LogRelFlowFunc(("\n"));
if (RT_SUCCESS(rc))
{
while (!pHost->mX11ThreadStopping)
{
}
}
return rc;
}
/**
* Send a signal to the thread function that it should exit
*/
void SeamlessMain::stopX11Thread(void)
{
int rc;
mX11ThreadStopping = true;
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";
}
{
int rc;
if (mIsInitialised) /* Assertion */
{
LogRelFunc(("error: called a second time! (VBoxClient)\n"));
}
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
mIsInitialised = true;
if (RT_FAILURE(rc))
{
return rc;
}
/* Stay running as long as X does... */
while (true)
return VERR_INTERRUPTED;
}
virtual void cleanup()
{
VbglR3SeamlessSetCap(false);
}
};
{
return new SeamlessService;
}