seamless-host.h revision 7a2b83aaec5876fadd7aec6dd835388a213d9a73
/** @file
* X11 Guest client - seamless mode, missing proper description while using the
* potentially confusing word 'host'.
*/
/*
* Copyright (C) 2006-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* 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.
*/
#ifndef __Additions_client_seamless_host_h
# define __Additions_client_seamless_host_h
#include <VBox/log.h>
#include <VBox/VBoxGuestLib.h> /* for the R3 guest library functions */
#include "thread.h" /* for VBoxGuestThread */
class VBoxGuestSeamlessHost;
/**
* Host event (i.e. enter or leave seamless mode) thread function for the main
* seamless class
*/
class VBoxGuestSeamlessHostThread : public VBoxGuestThreadFunction
{
private:
// Copying or assigning a thread object is not sensible
VBoxGuestSeamlessHostThread(const VBoxGuestSeamlessHostThread&);
VBoxGuestSeamlessHostThread& operator=(const VBoxGuestSeamlessHostThread&);
// Private member variables
/** The host proxy object */
VBoxGuestSeamlessHost *mHost;
/** The thread object running us. */
VBoxGuestThread *mThread;
public:
VBoxGuestSeamlessHostThread(VBoxGuestSeamlessHost *pHost)
{
mHost = pHost;
}
virtual ~VBoxGuestSeamlessHostThread(void) {}
/**
* The actual thread function.
*
* @returns iprt status code as thread return value
* @param pParent the VBoxGuestThread running this thread function
*/
virtual int threadFunction(VBoxGuestThread *pThread);
/**
* Send a signal to the thread function that it should exit
*/
virtual void stop(void);
};
/**
* Small virtual class which provides the interface for notifying the host of
* changes to the X11 window configuration, mainly split out from
* @a VBoxGuestSeamlessHost to simplify the unit test.
*/
class VBoxGuestSeamlessHostInt
{
public:
virtual void notify(RTRECT *pRects, size_t cRects) = 0;
};
/**
* Interface to the host
*/
class VBoxGuestSeamlessHost : public VBoxGuestSeamlessHostInt
{
friend class VBoxGuestSeamlessHostThread;
public:
/** Events which can be reported by this class */
enum meEvent
{
/** Empty event */
NONE,
/** Request to enable seamless mode */
ENABLE,
/** Request to disable seamless mode */
DISABLE
};
private:
// We don't want a copy constructor or assignment operator
VBoxGuestSeamlessHost(const VBoxGuestSeamlessHost&);
VBoxGuestSeamlessHost& operator=(const VBoxGuestSeamlessHost&);
/** Thread to start and stop when we enter and leave seamless mode which
* monitors X11 windows in the guest. */
VBoxGuestThread *mX11MonitorThread;
/** Host seamless event (i.e. enter and leave) thread function. */
VBoxGuestSeamlessHostThread mThreadFunction;
/** Host seamless event thread. */
VBoxGuestThread mThread;
/** Is the service running? */
bool mRunning;
/** Last request issued by the host. */
meEvent mState;
/**
* Waits for a seamless state change events from the host and dispatch it. This is
* meant to be called by the host event monitor thread exclusively.
*
* @returns IRPT return code.
*/
int nextEvent(void);
/**
* Interrupt an event wait and cause nextEvent() to return immediately.
*/
void cancelEvent(void) { VbglR3InterruptEventWaits(); }
public:
/**
* Initialise the guest and ensure that it is capable of handling seamless mode
* @param pX11MonitorThread Thread class to monitor guest windows.
*
* @returns iprt status code
*/
int init(VBoxGuestThread *pX11MonitorThread)
{
LogRelFlowFunc(("\n"));
if (mX11MonitorThread != 0) /* Assertion */
{
LogRel(("VBoxClient: ERROR: attempt to initialise seamless host object twice!\n"));
return VERR_INTERNAL_ERROR;
}
mX11MonitorThread = pX11MonitorThread;
LogRelFlowFunc(("returning VINF_SUCCESS\n"));
return VINF_SUCCESS;
}
/**
* Start the service.
* @returns iprt status value
*/
int start(void);
/**
* Stops the service.
* @param cMillies how long to wait for the thread to exit
*/
void stop(RTMSINTERVAL cMillies = RT_INDEFINITE_WAIT);
/** Returns the current state of the host - i.e. requesting seamless or not. */
meEvent getState(void) { return mState; }
/**
* Update the set of visible rectangles in the host.
*/
virtual void notify(RTRECT *pRects, size_t cRects);
VBoxGuestSeamlessHost(void) : mThreadFunction(this),
mThread(&mThreadFunction, 0, RTTHREADTYPE_MSG_PUMP,
RTTHREADFLAGS_WAITABLE, "Host events")
{
mX11MonitorThread = 0;
mRunning = false;
mState = NONE;
}
~VBoxGuestSeamlessHost()
{
LogRelFlowFunc(("\n"));
if (mRunning) /* Assertion */
{
LogRel(("VBoxClient: seamless host object still running! Stopping...\n"));
stop(2000);
}
LogRelFlowFunc(("returning\n"));
}
};
#endif /* __Additions_xclient_seamless_h not defined */