VirtualBox

Ignore:
Timestamp:
Feb 6, 2014 8:50:10 AM (11 years ago)
Author:
vboxsync
Message:

Additions/x11/VBoxClient: more clean-up.

Location:
trunk/src/VBox/Additions/x11/VBoxClient
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/Makefile.kmk

    r50336 r50337  
    5959 VBoxClient_DEFS += SEAMLESS_GUEST DYNAMIC_RESIZE
    6060 VBoxClient_SOURCES += \
    61         seamless.cpp \
    6261        seamless-host.cpp \
    6362        seamless-x11.cpp \
  • trunk/src/VBox/Additions/x11/VBoxClient/seamless-host.cpp

    r50336 r50337  
    11/** @file
    2  * X11 Guest client - seamless mode, missing proper description while using the
    3  * potentially confusing word 'host'.
     2 * X11 Guest client - seamless mode: main logic, communication with the host and
     3 * wrapper interface for the main code of the VBoxClient deamon.  The
     4 * X11-specific parts are split out into their own file for ease of testing.
    45 */
    56
    67/*
    7  * Copyright (C) 2006-2011 Oracle Corporation
     8 * Copyright (C) 2006-2014 Oracle Corporation
    89 *
    910 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1920*   Header files                                                             *
    2021*****************************************************************************/
     22
     23#include <X11/Xlib.h>
     24
    2125#include <VBox/log.h>
    2226#include <VBox/VMMDev.h>
     
    2428#include <iprt/err.h>
    2529
     30#include "VBoxClient.h"
    2631#include "seamless-host.h"
    2732#include "seamless-x11.h"
     
    5055    {
    5156        LogRel(("VBoxClient: enabled seamless capability on host.\n"));
     57        /* Create a thread to wait for requests from the host.  This is currently
     58         * done on a separate thread as the main thread monitors the X11 server
     59         * for disconnections. */
     60        /** @todo Move the disconnection monitoring to its own thread (better, the
     61         *  VT monitor thread) and run this logic on the main service thread. */
    5262        rc = RTThreadCreate(&mThread, threadFunction, this, 0,
    5363                            RTTHREADTYPE_MSG_PUMP, RTTHREADFLAGS_WAITABLE,
     
    6878
    6979/** Stops the service. */
    70 void VBoxGuestSeamlessHost::stop(RTMSINTERVAL cMillies /* = RT_INDEFINITE_WAIT */)
     80void VBoxGuestSeamlessHost::stop()
    7181{
    7282    LogRelFlowFunc(("\n"));
     
    7484        LogRel(("VBoxClient: tried to stop seamless service which is not running!\n"));
    7585    else
    76         stopThread(cMillies);
     86        stopThread();
    7787    if (mX11MonitorRTThread)
    7888        stopX11Thread();
     
    103113                LogRelFunc(("VMMDev_Seamless_Visible_Region request received (VBoxClient).\n"));
    104114#endif
    105                 mState = ENABLE;
    106115                mX11ThreadStopping = false;
    107116                /** @todo Do something on failure, like bail out. */
     
    122131                LogRelFunc(("VMMDev_Seamless_Disabled set (VBoxClient).\n"));
    123132#endif
    124                 mState = DISABLE;
    125133                if (mX11MonitorRTThread)
    126134                    stopX11Thread();
     
    182190 * Send a signal to the thread that it should exit
    183191 */
    184 void VBoxGuestSeamlessHost::stopThread(RTMSINTERVAL cMillies)
     192void VBoxGuestSeamlessHost::stopThread()
    185193{
    186194    int rc;
     
    217225
    218226    LogRelFlowFunc(("\n"));
    219     rc = pHost->mX11Monitor->start();
     227    rc = pHost->mX11Monitor.start();
    220228    if (RT_SUCCESS(rc))
    221229    {
    222230        while (!pHost->mX11ThreadStopping)
    223231        {
    224             pHost->mX11Monitor->nextEvent();
    225         }
    226         pHost->mX11Monitor->stop();
     232            pHost->mX11Monitor.nextEvent();
     233        }
     234        pHost->mX11Monitor.stop();
    227235    }
    228236    LogRelFlowFunc(("returning %Rrc\n", rc));
     
    238246
    239247    mX11ThreadStopping = true;
    240     mX11Monitor->interruptEvent();
     248    mX11Monitor.interruptEvent();
    241249    rc = RTThreadWait(mX11MonitorRTThread, RT_INDEFINITE_WAIT, NULL);
    242250    if (RT_SUCCESS(rc))
     
    246254                        rc));
    247255}
     256
     257/** VBoxClient service class wrapping the logic for the seamless service while
     258 *  the main VBoxClient code provides the daemon logic needed by all services.
     259 */
     260class SeamlessService : public VBoxClient::Service
     261{
     262private:
     263    VBoxGuestSeamlessHost mSeamless;
     264    bool mIsInitialised;
     265public:
     266    virtual const char *getPidFilePath()
     267    {
     268        return ".vboxclient-seamless.pid";
     269    }
     270    virtual int run(bool fDaemonised /* = false */)
     271    {
     272        int rc;
     273
     274        if (mIsInitialised)  /* Assertion */
     275        {
     276            LogRelFunc(("error: called a second time! (VBoxClient)\n"));
     277            rc = VERR_INTERNAL_ERROR;
     278        }
     279        if (RT_SUCCESS(rc))
     280            rc = mSeamless.init();
     281        if (RT_SUCCESS(rc))
     282            rc = mSeamless.start();
     283        if (RT_SUCCESS(rc))
     284            mIsInitialised = true;
     285        if (RT_FAILURE(rc))
     286        {
     287            LogRelFunc(("returning %Rrc (VBoxClient)\n", rc));
     288            return rc;
     289        }
     290        /* Stay running as long as X does... */
     291        Display *pDisplay = XOpenDisplay(NULL);
     292        XEvent ev;
     293        while (true)
     294            XNextEvent(pDisplay, &ev);
     295        return VERR_INTERRUPTED;
     296    }
     297    virtual void cleanup()
     298    {
     299        VbglR3SeamlessSetCap(false);
     300    }
     301};
     302
     303VBoxClient::Service *VBoxClient::GetSeamlessService()
     304{
     305    return new SeamlessService;
     306}
  • trunk/src/VBox/Additions/x11/VBoxClient/seamless-host.h

    r50336 r50337  
    2424#include <VBox/VBoxGuestLib.h>      /* for the R3 guest library functions  */
    2525
    26 class VBoxGuestSeamlessX11;
    27 
    28 /**
    29  * Small virtual class which provides the interface for notifying the host of
    30  * changes to the X11 window configuration, mainly split out from
    31  * @a VBoxGuestSeamlessHost to simplify the unit test.
    32  */
    33 class VBoxGuestSeamlessHostInt
    34 {
    35 public:
    36     virtual void notify(RTRECT *pRects, size_t cRects) = 0;
    37 };
     26#include "seamless-x11.h"
    3827
    3928/**
    4029 * Interface to the host
    4130 */
    42 class VBoxGuestSeamlessHost : public VBoxGuestSeamlessHostInt
     31class VBoxGuestSeamlessHost : public SeamlessHostProxy
    4332{
    4433public:
     
    5948    VBoxGuestSeamlessHost& operator=(const VBoxGuestSeamlessHost&);
    6049
     50    /** Have we been initialised yet? */
     51    bool mIsInitialised;
     52    /** X11 event monitor object */
     53    VBoxGuestSeamlessX11 mX11Monitor;
     54
    6155    /** Thread to start and stop when we enter and leave seamless mode which
    6256     *  monitors X11 windows in the guest. */
    6357    RTTHREAD mX11MonitorRTThread;
    64     /** X11 event monitor class */
    65     VBoxGuestSeamlessX11 *mX11Monitor;
    6658    /** Should the X11 monitor thread be stopping? */
    6759    volatile bool mX11ThreadStopping;
     
    7264    /** Should the thread be stopping? */
    7365    volatile bool mThreadStopping;
    74     /** Last request issued by the host. */
    75     meEvent mState;
    7666
    7767    /**
     
    9383
    9484    /** Helper to stop the event query thread again. */
    95     void stopThread(RTMSINTERVAL cMillies);
     85    void stopThread();
    9686
    9787    /** Thread function to monitor X11 window configuration changes. */
     
    10898     * @returns iprt status code
    10999     */
    110     int init(VBoxGuestSeamlessX11 *pX11Monitor)
     100    int init(void)
    111101    {
     102        int rc;
     103
    112104        LogRelFlowFunc(("\n"));
    113         if (mX11Monitor != NULL)  /* Assertion */
    114         {
    115             LogRel(("VBoxClient: ERROR: attempt to initialise seamless host object twice!\n"));
     105        if (mIsInitialised)
    116106            return VERR_INTERNAL_ERROR;
    117         }
    118         mX11Monitor = pX11Monitor;
    119         LogRelFlowFunc(("returning VINF_SUCCESS\n"));
    120         return VINF_SUCCESS;
     107        rc = mX11Monitor.init(this);
     108        if (RT_SUCCESS(rc))
     109            mIsInitialised = true;
     110        return rc;
    121111    }
    122112
     
    131121     * @param cMillies how long to wait for the thread to exit
    132122     */
    133     void stop(RTMSINTERVAL cMillies = RT_INDEFINITE_WAIT);
    134 
    135     /** Returns the current state of the host - i.e. requesting seamless or not. */
    136     meEvent getState(void) { return mState; }
     123    void stop();
    137124
    138125    /**
     
    143130    VBoxGuestSeamlessHost(void)
    144131    {
     132        mIsInitialised = false;
    145133        mX11MonitorRTThread = NIL_RTTHREAD;
    146         mX11Monitor = NULL;
    147134        mX11ThreadStopping = false;
    148135        mThread = NIL_RTTHREAD;
    149136        mThreadRunning = false;
    150137        mThreadStopping = false;
    151         mState = NONE;
    152138    }
    153139
     
    155141    {
    156142        LogRelFlowFunc(("\n"));
    157         if (mThread)  /* Assertion */
    158         {
    159             LogRel(("VBoxClient: seamless host object still running!  Stopping...\n"));
    160             stop(2000);
    161         }
     143        if (mThread)
     144            stop();
    162145        LogRelFlowFunc(("returning\n"));
    163146    }
  • trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.cpp

    r50324 r50337  
    7171  * @returns true if it can handle seamless, false otherwise
    7272  */
    73 int VBoxGuestSeamlessX11::init(VBoxGuestSeamlessHostInt *pHost)
     73int VBoxGuestSeamlessX11::init(SeamlessHostProxy *pHost)
    7474{
    7575    int rc = VINF_SUCCESS;
  • trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.h

    r50336 r50337  
    2323#include <iprt/avl.h>
    2424
    25 #include "seamless-x11.h"
    26 #include "seamless-host.h"
    27 
    2825#include <X11/Xlib.h>
    2926#include <X11/Xutil.h>
     
    3532/* This is defined wrong in my X11 header files! */
    3633#define VBoxShapeNotify 64
     34
     35/**
     36 * Small virtual class which provides the interface for notifying the host of
     37 * changes to the X11 window configuration, mainly split out from
     38 * @a VBoxGuestSeamlessHost to simplify the unit test.
     39 */
     40class SeamlessHostProxy
     41{
     42public:
     43    virtual void notify(RTRECT *pRects, size_t cRects) = 0;
     44};
    3745
    3846/** Structure containing information about a guest window's position and visible area.
     
    156164    // Private member variables
    157165    /** Pointer to the host class. */
    158     VBoxGuestSeamlessHostInt *mHost;
     166    SeamlessHostProxy *mHost;
    159167    /** Our connection to the X11 display we are running on. */
    160168    Display *mDisplay;
     
    201209     * @returns iprt status code
    202210     */
    203     int init(VBoxGuestSeamlessHostInt *pHost);
     211    int init(SeamlessHostProxy *pHost);
    204212
    205213    /**
  • trunk/src/VBox/Additions/x11/VBoxClient/seamless.h

    r50336 r50337  
    2828private:
    2929    VBoxGuestSeamlessHost mHost;
    30     VBoxGuestSeamlessX11 mGuest;
    3130
    3231    bool isInitialised;
     
    4443        if (RT_SUCCESS(rc))
    4544        {
    46             rc = mHost.init(&mGuest);
    47         }
    48         if (RT_SUCCESS(rc))
    49         {
    50             rc = mGuest.init(&mHost);
     45            rc = mHost.init();
    5146        }
    5247        if (RT_SUCCESS(rc))
     
    6661    }
    6762
    68     void uninit(RTMSINTERVAL cMillies = RT_INDEFINITE_WAIT)
    69     {
    70         LogRelFlowFunc(("\n"));
    71         if (isInitialised)
    72         {
    73             mHost.stop(cMillies);
    74             mGuest.uninit();
    75             isInitialised = false;
    76         }
    77         LogRelFlowFunc(("returning\n"));
    78     }
    79 
    8063    VBoxGuestSeamless() { isInitialised = false; }
    81     ~VBoxGuestSeamless() { uninit(); }
     64    ~VBoxGuestSeamless() { }
    8265};
    8366
  • trunk/src/VBox/Additions/x11/VBoxClient/testcase/tstSeamlessX11-auto.cpp

    r50324 r50337  
    2929
    3030#include "../seamless.h"
    31 #include "../seamless-host.h"
    3231
    3332#undef DefaultRootWindow
     
    299298
    300299/** Dummy host class */
    301 class testHost: public VBoxGuestSeamlessHostInt
     300class testHost: public SeamlessHostProxy
    302301{
    303302    bool mfNotified;
  • trunk/src/VBox/Additions/x11/VBoxClient/testcase/tstSeamlessX11.cpp

    r44529 r50337  
    127127    }
    128128    RTStrmGetLine(g_pStdIn, ach, sizeof(ach));
    129     seamless.uninit();
    130129    return rc;
    131130}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette