VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/VBoxClient/seamless.h@ 25728

Last change on this file since 25728 was 25728, checked in by vboxsync, 15 years ago

*: Use RTMSINTERVAL for timeouts.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.7 KB
Line 
1/** @file
2 *
3 * Guest client: seamless mode.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef __Additions_xclient_seamless_h
23# define __Additions_xclient_seamless_h
24
25#include <VBox/log.h>
26
27#include "seamless-host.h"
28#include "seamless-guest.h"
29#include "seamless-glue.h"
30
31/** Thread function class for VBoxGuestSeamlessGuest. */
32class VBoxGuestSeamlessGuestThread: public VBoxGuestThreadFunction
33{
34private:
35 /** The guest class "owning" us. */
36 VBoxGuestSeamlessGuestImpl *mGuest;
37 /** The guest observer monitoring the guest. */
38 VBoxGuestSeamlessObserver *mObserver;
39 /** Should we exit the thread? */
40 bool mExit;
41
42 // Copying or assigning a thread object is not sensible
43 VBoxGuestSeamlessGuestThread(const VBoxGuestSeamlessGuestThread&);
44 VBoxGuestSeamlessGuestThread& operator=(const VBoxGuestSeamlessGuestThread&);
45
46public:
47 VBoxGuestSeamlessGuestThread(VBoxGuestSeamlessGuestImpl *pGuest,
48 VBoxGuestSeamlessObserver *pObserver)
49 { mGuest = pGuest; mObserver = pObserver; mExit = false; }
50 virtual ~VBoxGuestSeamlessGuestThread(void) {}
51 /**
52 * The actual thread function.
53 *
54 * @returns iprt status code as thread return value
55 * @param pParent the VBoxGuestThread running this thread function
56 */
57 virtual int threadFunction(VBoxGuestThread *pThread)
58 {
59 int rc = VINF_SUCCESS;
60
61 LogFlowThisFunc(("\n"));
62 rc = mGuest->start();
63 if (RT_SUCCESS(rc))
64 {
65 while (!pThread->isStopping())
66 {
67 mGuest->nextEvent();
68 }
69 mGuest->stop();
70 }
71 LogFlowThisFunc(("returning %Rrc\n", rc));
72 return rc;
73 }
74 /**
75 * Send a signal to the thread function that it should exit
76 */
77 virtual void stop(void) { mGuest->interruptEvent(); }
78};
79
80/** Observer for the host class - start and stop seamless reporting in the guest when the
81 host requests. */
82class VBoxGuestSeamlessHostObserver : public VBoxGuestSeamlessObserver
83{
84private:
85 VBoxGuestSeamlessHost *mHost;
86 VBoxGuestThread *mGuestThread;
87
88public:
89 VBoxGuestSeamlessHostObserver(VBoxGuestSeamlessHost *pHost,
90 VBoxGuestThread *pGuestThread)
91 {
92 mHost = pHost;
93 mGuestThread = pGuestThread;
94 }
95
96 virtual void notify(void)
97 {
98 switch (mHost->getState())
99 {
100 case VBoxGuestSeamlessHost::ENABLE:
101 mGuestThread->start();
102 break;
103 case VBoxGuestSeamlessHost::DISABLE:
104 mGuestThread->stop(RT_INDEFINITE_WAIT, 0);
105 break;
106 default:
107 break;
108 }
109 }
110};
111
112/** Observer for the guest class - send the host updated seamless rectangle information when
113 it becomes available. */
114class VBoxGuestSeamlessGuestObserver : public VBoxGuestSeamlessObserver
115{
116private:
117 VBoxGuestSeamlessHost *mHost;
118 VBoxGuestSeamlessGuestImpl *mGuest;
119
120public:
121 VBoxGuestSeamlessGuestObserver(VBoxGuestSeamlessHost *pHost,
122 VBoxGuestSeamlessGuestImpl *pGuest)
123 {
124 mHost = pHost;
125 mGuest = pGuest;
126 }
127
128 virtual void notify(void)
129 {
130 mHost->updateRects(mGuest->getRects());
131 }
132};
133
134class VBoxGuestSeamless
135{
136private:
137 VBoxGuestSeamlessHost mHost;
138 VBoxGuestSeamlessGuestImpl mGuest;
139 VBoxGuestSeamlessGuestThread mGuestFunction;
140 VBoxGuestThread mGuestThread;
141 VBoxGuestSeamlessHostObserver mHostObs;
142 VBoxGuestSeamlessGuestObserver mGuestObs;
143
144 bool isInitialised;
145public:
146 int init(void)
147 {
148 int rc = VINF_SUCCESS;
149
150 LogFlowThisFunc(("\n"));
151 if (isInitialised) /* Assertion */
152 {
153 LogRelFunc(("error: called a second time! (VBoxClient)\n"));
154 rc = VERR_INTERNAL_ERROR;
155 }
156 if (RT_SUCCESS(rc))
157 {
158 rc = mHost.init(&mHostObs);
159 }
160 if (RT_SUCCESS(rc))
161 {
162 rc = mGuest.init(&mGuestObs);
163 }
164 if (RT_SUCCESS(rc))
165 {
166 rc = mHost.start();
167 }
168 if (RT_SUCCESS(rc))
169 {
170 isInitialised = true;
171 }
172 if (RT_FAILURE(rc))
173 {
174 LogFunc(("returning %Rrc (VBoxClient)\n", rc));
175 }
176 LogFlowThisFunc(("returning %Rrc\n", rc));
177 return rc;
178 }
179
180 void uninit(RTMSINTERVAL cMillies = RT_INDEFINITE_WAIT)
181 {
182 LogFlowThisFunc(("\n"));
183 if (isInitialised)
184 {
185 mHost.stop(cMillies);
186 mGuestThread.stop(cMillies, 0);
187 mGuest.uninit();
188 isInitialised = false;
189 }
190 LogFlowThisFunc(("returning\n"));
191 }
192
193 VBoxGuestSeamless() : mGuestFunction(&mGuest, &mGuestObs),
194 mGuestThread(&mGuestFunction, 0, RTTHREADTYPE_MSG_PUMP,
195 RTTHREADFLAGS_WAITABLE, "Guest events"),
196 mHostObs(&mHost, &mGuestThread), mGuestObs(&mHost, &mGuest)
197 {
198 isInitialised = false;
199 }
200 ~VBoxGuestSeamless() { uninit(); }
201};
202
203#endif /* __Additions_xclient_seamless_h not defined */
Note: See TracBrowser for help on using the repository browser.

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