Changeset 50337 in vbox for trunk/src/VBox/Additions/x11/VBoxClient
- Timestamp:
- Feb 6, 2014 8:50:10 AM (11 years ago)
- 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 59 59 VBoxClient_DEFS += SEAMLESS_GUEST DYNAMIC_RESIZE 60 60 VBoxClient_SOURCES += \ 61 seamless.cpp \62 61 seamless-host.cpp \ 63 62 seamless-x11.cpp \ -
trunk/src/VBox/Additions/x11/VBoxClient/seamless-host.cpp
r50336 r50337 1 1 /** @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. 4 5 */ 5 6 6 7 /* 7 * Copyright (C) 2006-201 1Oracle Corporation8 * Copyright (C) 2006-2014 Oracle Corporation 8 9 * 9 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 19 20 * Header files * 20 21 *****************************************************************************/ 22 23 #include <X11/Xlib.h> 24 21 25 #include <VBox/log.h> 22 26 #include <VBox/VMMDev.h> … … 24 28 #include <iprt/err.h> 25 29 30 #include "VBoxClient.h" 26 31 #include "seamless-host.h" 27 32 #include "seamless-x11.h" … … 50 55 { 51 56 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. */ 52 62 rc = RTThreadCreate(&mThread, threadFunction, this, 0, 53 63 RTTHREADTYPE_MSG_PUMP, RTTHREADFLAGS_WAITABLE, … … 68 78 69 79 /** Stops the service. */ 70 void VBoxGuestSeamlessHost::stop( RTMSINTERVAL cMillies /* = RT_INDEFINITE_WAIT */)80 void VBoxGuestSeamlessHost::stop() 71 81 { 72 82 LogRelFlowFunc(("\n")); … … 74 84 LogRel(("VBoxClient: tried to stop seamless service which is not running!\n")); 75 85 else 76 stopThread( cMillies);86 stopThread(); 77 87 if (mX11MonitorRTThread) 78 88 stopX11Thread(); … … 103 113 LogRelFunc(("VMMDev_Seamless_Visible_Region request received (VBoxClient).\n")); 104 114 #endif 105 mState = ENABLE;106 115 mX11ThreadStopping = false; 107 116 /** @todo Do something on failure, like bail out. */ … … 122 131 LogRelFunc(("VMMDev_Seamless_Disabled set (VBoxClient).\n")); 123 132 #endif 124 mState = DISABLE;125 133 if (mX11MonitorRTThread) 126 134 stopX11Thread(); … … 182 190 * Send a signal to the thread that it should exit 183 191 */ 184 void VBoxGuestSeamlessHost::stopThread( RTMSINTERVAL cMillies)192 void VBoxGuestSeamlessHost::stopThread() 185 193 { 186 194 int rc; … … 217 225 218 226 LogRelFlowFunc(("\n")); 219 rc = pHost->mX11Monitor ->start();227 rc = pHost->mX11Monitor.start(); 220 228 if (RT_SUCCESS(rc)) 221 229 { 222 230 while (!pHost->mX11ThreadStopping) 223 231 { 224 pHost->mX11Monitor ->nextEvent();225 } 226 pHost->mX11Monitor ->stop();232 pHost->mX11Monitor.nextEvent(); 233 } 234 pHost->mX11Monitor.stop(); 227 235 } 228 236 LogRelFlowFunc(("returning %Rrc\n", rc)); … … 238 246 239 247 mX11ThreadStopping = true; 240 mX11Monitor ->interruptEvent();248 mX11Monitor.interruptEvent(); 241 249 rc = RTThreadWait(mX11MonitorRTThread, RT_INDEFINITE_WAIT, NULL); 242 250 if (RT_SUCCESS(rc)) … … 246 254 rc)); 247 255 } 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 */ 260 class SeamlessService : public VBoxClient::Service 261 { 262 private: 263 VBoxGuestSeamlessHost mSeamless; 264 bool mIsInitialised; 265 public: 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 303 VBoxClient::Service *VBoxClient::GetSeamlessService() 304 { 305 return new SeamlessService; 306 } -
trunk/src/VBox/Additions/x11/VBoxClient/seamless-host.h
r50336 r50337 24 24 #include <VBox/VBoxGuestLib.h> /* for the R3 guest library functions */ 25 25 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" 38 27 39 28 /** 40 29 * Interface to the host 41 30 */ 42 class VBoxGuestSeamlessHost : public VBoxGuestSeamlessHostInt31 class VBoxGuestSeamlessHost : public SeamlessHostProxy 43 32 { 44 33 public: … … 59 48 VBoxGuestSeamlessHost& operator=(const VBoxGuestSeamlessHost&); 60 49 50 /** Have we been initialised yet? */ 51 bool mIsInitialised; 52 /** X11 event monitor object */ 53 VBoxGuestSeamlessX11 mX11Monitor; 54 61 55 /** Thread to start and stop when we enter and leave seamless mode which 62 56 * monitors X11 windows in the guest. */ 63 57 RTTHREAD mX11MonitorRTThread; 64 /** X11 event monitor class */65 VBoxGuestSeamlessX11 *mX11Monitor;66 58 /** Should the X11 monitor thread be stopping? */ 67 59 volatile bool mX11ThreadStopping; … … 72 64 /** Should the thread be stopping? */ 73 65 volatile bool mThreadStopping; 74 /** Last request issued by the host. */75 meEvent mState;76 66 77 67 /** … … 93 83 94 84 /** Helper to stop the event query thread again. */ 95 void stopThread( RTMSINTERVAL cMillies);85 void stopThread(); 96 86 97 87 /** Thread function to monitor X11 window configuration changes. */ … … 108 98 * @returns iprt status code 109 99 */ 110 int init( VBoxGuestSeamlessX11 *pX11Monitor)100 int init(void) 111 101 { 102 int rc; 103 112 104 LogRelFlowFunc(("\n")); 113 if (mX11Monitor != NULL) /* Assertion */ 114 { 115 LogRel(("VBoxClient: ERROR: attempt to initialise seamless host object twice!\n")); 105 if (mIsInitialised) 116 106 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; 121 111 } 122 112 … … 131 121 * @param cMillies how long to wait for the thread to exit 132 122 */ 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(); 137 124 138 125 /** … … 143 130 VBoxGuestSeamlessHost(void) 144 131 { 132 mIsInitialised = false; 145 133 mX11MonitorRTThread = NIL_RTTHREAD; 146 mX11Monitor = NULL;147 134 mX11ThreadStopping = false; 148 135 mThread = NIL_RTTHREAD; 149 136 mThreadRunning = false; 150 137 mThreadStopping = false; 151 mState = NONE;152 138 } 153 139 … … 155 141 { 156 142 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(); 162 145 LogRelFlowFunc(("returning\n")); 163 146 } -
trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.cpp
r50324 r50337 71 71 * @returns true if it can handle seamless, false otherwise 72 72 */ 73 int VBoxGuestSeamlessX11::init( VBoxGuestSeamlessHostInt*pHost)73 int VBoxGuestSeamlessX11::init(SeamlessHostProxy *pHost) 74 74 { 75 75 int rc = VINF_SUCCESS; -
trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.h
r50336 r50337 23 23 #include <iprt/avl.h> 24 24 25 #include "seamless-x11.h"26 #include "seamless-host.h"27 28 25 #include <X11/Xlib.h> 29 26 #include <X11/Xutil.h> … … 35 32 /* This is defined wrong in my X11 header files! */ 36 33 #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 */ 40 class SeamlessHostProxy 41 { 42 public: 43 virtual void notify(RTRECT *pRects, size_t cRects) = 0; 44 }; 37 45 38 46 /** Structure containing information about a guest window's position and visible area. … … 156 164 // Private member variables 157 165 /** Pointer to the host class. */ 158 VBoxGuestSeamlessHostInt*mHost;166 SeamlessHostProxy *mHost; 159 167 /** Our connection to the X11 display we are running on. */ 160 168 Display *mDisplay; … … 201 209 * @returns iprt status code 202 210 */ 203 int init( VBoxGuestSeamlessHostInt*pHost);211 int init(SeamlessHostProxy *pHost); 204 212 205 213 /** -
trunk/src/VBox/Additions/x11/VBoxClient/seamless.h
r50336 r50337 28 28 private: 29 29 VBoxGuestSeamlessHost mHost; 30 VBoxGuestSeamlessX11 mGuest;31 30 32 31 bool isInitialised; … … 44 43 if (RT_SUCCESS(rc)) 45 44 { 46 rc = mHost.init(&mGuest); 47 } 48 if (RT_SUCCESS(rc)) 49 { 50 rc = mGuest.init(&mHost); 45 rc = mHost.init(); 51 46 } 52 47 if (RT_SUCCESS(rc)) … … 66 61 } 67 62 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 80 63 VBoxGuestSeamless() { isInitialised = false; } 81 ~VBoxGuestSeamless() { uninit();}64 ~VBoxGuestSeamless() { } 82 65 }; 83 66 -
trunk/src/VBox/Additions/x11/VBoxClient/testcase/tstSeamlessX11-auto.cpp
r50324 r50337 29 29 30 30 #include "../seamless.h" 31 #include "../seamless-host.h"32 31 33 32 #undef DefaultRootWindow … … 299 298 300 299 /** Dummy host class */ 301 class testHost: public VBoxGuestSeamlessHostInt300 class testHost: public SeamlessHostProxy 302 301 { 303 302 bool mfNotified; -
trunk/src/VBox/Additions/x11/VBoxClient/testcase/tstSeamlessX11.cpp
r44529 r50337 127 127 } 128 128 RTStrmGetLine(g_pStdIn, ach, sizeof(ach)); 129 seamless.uninit();130 129 return rc; 131 130 }
Note:
See TracChangeset
for help on using the changeset viewer.