seamless-host.h revision b72771e8c6ba3b3d9ebdd7977730325131ae0f98
1N/A/** @file
1N/A *
1N/A * Guest client: seamless mode.
1N/A */
1N/A
1N/A/*
1N/A * Copyright (C) 2006-2007 Sun Microsystems, Inc.
1N/A *
1N/A * This file is part of VirtualBox Open Source Edition (OSE), as
1N/A * available from http://www.virtualbox.org. This file is free software;
1N/A * you can redistribute it and/or modify it under the terms of the GNU
1N/A * General Public License (GPL) as published by the Free Software
1N/A * Foundation, in version 2 as it comes in the "COPYING" file of the
1N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1N/A *
1N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1N/A * Clara, CA 95054 USA or visit http://www.sun.com if you need
1N/A * additional information or have any questions.
1N/A */
1N/A
1N/A#ifndef __Additions_client_seamless_host_h
1N/A# define __Additions_client_seamless_host_h
1N/A
1N/A#include <memory> /* for auto_ptr */
1N/A#include <vector> /* for vector */
1N/A
1N/A#include <VBox/log.h>
1N/A#include <VBox/VBoxGuest.h> /* for the R3 guest library functions */
1N/A
1N/A#include "seamless-glue.h" /* for VBoxGuestSeamlessObserver */
1N/A#include "thread.h" /* for VBoxGuestThread */
1N/A
1N/Aclass VBoxGuestSeamlessHost;
1N/A
1N/A/**
1N/A * Host event (i.e. enter or leave seamless mode) thread function for the main
1N/A * seamless class
1N/A */
1N/Aclass VBoxGuestSeamlessHostThread : public VBoxGuestThreadFunction
1N/A{
1N/Aprivate:
1N/A // Copying or assigning a thread object is not sensible
1N/A VBoxGuestSeamlessHostThread(const VBoxGuestSeamlessHostThread&);
1N/A VBoxGuestSeamlessHostThread& operator=(const VBoxGuestSeamlessHostThread&);
1N/A
1N/A // Private member variables
1N/A /** The host proxy object */
1N/A VBoxGuestSeamlessHost *mHost;
1N/A
1N/A /** The thread object running us. */
1N/A VBoxGuestThread *mThread;
1N/Apublic:
1N/A VBoxGuestSeamlessHostThread(VBoxGuestSeamlessHost *pHost)
1N/A {
1N/A mHost = pHost;
1N/A }
1N/A virtual ~VBoxGuestSeamlessHostThread(void) {}
1N/A /**
1N/A * The actual thread function.
1N/A *
1N/A * @returns iprt status code as thread return value
1N/A * @param pParent the VBoxGuestThread running this thread function
1N/A */
1N/A virtual int threadFunction(VBoxGuestThread *pThread);
1N/A /**
1N/A * Send a signal to the thread function that it should exit
1N/A */
1N/A virtual void stop(void);
1N/A};
1N/A
1N/A/**
1N/A * Interface to the host
1N/A */
1N/Aclass VBoxGuestSeamlessHost
1N/A{
1N/A friend class VBoxGuestSeamlessHostThread;
1N/Apublic:
1N/A /** Events which can be reported by this class */
1N/A enum meEvent
1N/A {
1N/A /** Empty event */
1N/A NONE,
1N/A /** Request to enable seamless mode */
1N/A ENABLE,
1N/A /** Request to disable seamless mode */
1N/A DISABLE
1N/A };
1N/A
1N/Aprivate:
1N/A // We don't want a copy constructor or assignment operator
1N/A VBoxGuestSeamlessHost(const VBoxGuestSeamlessHost&);
1N/A VBoxGuestSeamlessHost& operator=(const VBoxGuestSeamlessHost&);
1N/A
1N/A /** Observer to connect guest and host and ferry events back and forth. */
1N/A VBoxGuestSeamlessObserver *mObserver;
1N/A /** Host seamless event (i.e. enter and leave) thread function. */
1N/A VBoxGuestSeamlessHostThread mThreadFunction;
1N/A /** Host seamless event thread. */
1N/A VBoxGuestThread mThread;
1N/A /** Is the service running? */
1N/A bool mRunning;
1N/A /** Last request issued by the host. */
1N/A meEvent mState;
1N/A
1N/A /**
1N/A * Waits for a seamless state change events from the host and dispatch it. This is
1N/A * meant to be called by the host event monitor thread exclusively.
1N/A *
1N/A * @returns IRPT return code.
1N/A */
1N/A int nextEvent(void);
1N/A
1N/A /**
1N/A * Interrupt an event wait and cause nextEvent() to return immediately.
1N/A */
1N/A void cancelEvent(void) { VbglR3InterruptEventWaits(); }
1N/A
1N/Apublic:
1N/A /**
1N/A * Initialise the guest and ensure that it is capable of handling seamless mode
1N/A * @param pObserver Observer class to connect host and guest interfaces
1N/A *
1N/A * @returns iprt status code
1N/A */
1N/A int init(VBoxGuestSeamlessObserver *pObserver)
1N/A {
1N/A LogFlowThisFunc(("\n"));
1N/A if (mObserver != 0) /* Assertion */
1N/A {
1N/A LogRel(("VBoxClient: ERROR: attempt to initialise seamless host object twice!\n"));
1N/A return VERR_INTERNAL_ERROR;
1N/A }
1N/A mObserver = pObserver;
1N/A LogFlowThisFunc(("returning VINF_SUCCESS\n"));
1N/A return VINF_SUCCESS;
1N/A }
1N/A
1N/A /**
1N/A * Start the service.
1N/A * @returns iprt status value
1N/A */
1N/A int start(void);
1N/A
1N/A /**
1N/A * Stops the service.
1N/A * @param cMillies how long to wait for the thread to exit
1N/A */
1N/A void stop(unsigned cMillies = RT_INDEFINITE_WAIT);
1N/A
1N/A /** Returns the current state of the host - i.e. requesting seamless or not. */
1N/A meEvent getState(void) { return mState; }
1N/A
1N/A /**
1N/A * Update the set of visible rectangles in the host.
1N/A */
1N/A void updateRects(std::auto_ptr<std::vector<RTRECT> > pRects);
1N/A
1N/A VBoxGuestSeamlessHost(void) : mThreadFunction(this),
1N/A mThread(&mThreadFunction, 0, RTTHREADTYPE_MSG_PUMP,
1N/A RTTHREADFLAGS_WAITABLE, "Host events")
1N/A {
1N/A mObserver = 0;
1N/A mRunning = false;
1N/A mState = NONE;
1N/A }
1N/A
1N/A ~VBoxGuestSeamlessHost()
1N/A {
1N/A LogFlowThisFunc(("\n"));
1N/A if (mRunning) /* Assertion */
1N/A {
1N/A LogRel(("VBoxClient: seamless host object still running! Stopping...\n"));
1N/A try
1N/A {
1N/A stop(2000);
1N/A }
1N/A catch(...) {}
1N/A }
1N/A LogFlowThisFunc(("returning\n"));
1N/A }
1N/A};
1N/A
1N/A#endif /* __Additions_xclient_seamless_h not defined */
1N/A