VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/xclient/seamless.h@ 6359

Last change on this file since 6359 was 6290, checked in by vboxsync, 17 years ago

Guest Additions: update for the Linux seamless additions

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.2 KB
Line 
1/** @file
2 *
3 * Guest client: seamless mode.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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
18#ifndef __Additions_xclient_seamless_h
19# define __Additions_xclient_seamless_h
20
21#include "seamless-host.h"
22#include "seamless-guest.h"
23#include "seamless-glue.h"
24
25/** Thread function class for VBoxGuestSeamlessX11. */
26class VBoxGuestSeamlessGuestThread: public VBoxGuestThreadFunction
27{
28private:
29 /** The guest class "owning" us. */
30 VBoxGuestSeamlessGuestImpl *mGuest;
31 /** The guest observer monitoring the guest. */
32 VBoxGuestSeamlessObserver *mObserver;
33 /** Should we exit the thread? */
34 bool mExit;
35
36 // Copying or assigning a thread object is not sensible
37 VBoxGuestSeamlessGuestThread(const VBoxGuestSeamlessGuestThread&);
38 VBoxGuestSeamlessGuestThread& operator=(const VBoxGuestSeamlessGuestThread&);
39
40public:
41 VBoxGuestSeamlessGuestThread(VBoxGuestSeamlessGuestImpl *pGuest,
42 VBoxGuestSeamlessObserver *pObserver)
43 { mGuest = pGuest; mObserver = pObserver; mExit = false; }
44 virtual ~VBoxGuestSeamlessGuestThread(void) {}
45 /**
46 * The actual thread function.
47 *
48 * @returns iprt status code as thread return value
49 * @param pParent the VBoxGuestThread running this thread function
50 */
51 virtual int threadFunction(VBoxGuestThread *pThread)
52 {
53 int rc = VINF_SUCCESS;
54
55 rc = mGuest->start();
56 if (RT_SUCCESS(rc))
57 {
58 while (!pThread->isStopping())
59 {
60 mGuest->nextEvent();
61 }
62 mGuest->stop();
63 }
64 return rc;
65 }
66 /**
67 * Send a signal to the thread function that it should exit
68 */
69 virtual void stop(void) { mGuest->interruptEvent(); }
70};
71
72/** Observer for the host class - start and stop seamless reporting in the guest when the
73 host requests. */
74class VBoxGuestSeamlessHostObserver : public VBoxGuestSeamlessObserver
75{
76private:
77 VBoxGuestSeamlessHost *mHost;
78 VBoxGuestThread *mGuestThread;
79
80public:
81 VBoxGuestSeamlessHostObserver(VBoxGuestSeamlessHost *pHost,
82 VBoxGuestThread *pGuestThread)
83 {
84 mHost = pHost;
85 mGuestThread = pGuestThread;
86 }
87
88 virtual void notify(void)
89 {
90 switch (mHost->getState())
91 {
92 case VBoxGuestSeamlessHost::ENABLE:
93 mGuestThread->start();
94 break;
95 case VBoxGuestSeamlessHost::DISABLE:
96 mGuestThread->stop(RT_INDEFINITE_WAIT, 0);
97 break;
98 default:
99 break;
100 }
101 }
102};
103
104/** Observer for the guest class - send the host updated seamless rectangle information when
105 it becomes available. */
106class VBoxGuestSeamlessGuestObserver : public VBoxGuestSeamlessObserver
107{
108private:
109 VBoxGuestSeamlessHost *mHost;
110 VBoxGuestSeamlessGuestImpl *mGuest;
111
112public:
113 VBoxGuestSeamlessGuestObserver(VBoxGuestSeamlessHost *pHost,
114 VBoxGuestSeamlessGuestImpl *pGuest)
115 {
116 mHost = pHost;
117 mGuest = pGuest;
118 }
119
120 virtual void notify(void)
121 {
122 mHost->updateRects(mGuest->getRects());
123 }
124};
125
126class VBoxGuestSeamless
127{
128private:
129 VBoxGuestSeamlessHost mHost;
130 VBoxGuestSeamlessGuestImpl mGuest;
131 VBoxGuestSeamlessGuestThread mGuestFunction;
132 VBoxGuestThread mGuestThread;
133 VBoxGuestSeamlessHostObserver mHostObs;
134 VBoxGuestSeamlessGuestObserver mGuestObs;
135
136 bool isInitialised;
137public:
138 int init(void)
139 {
140 int rc = VINF_SUCCESS;
141
142 if (isInitialised) /* Assertion */
143 {
144 LogRelFunc(("error: called a second time! (VBoxService)\n"));
145 rc = VERR_INTERNAL_ERROR;
146 }
147 if (RT_SUCCESS(rc))
148 {
149 rc = mHost.init(&mHostObs);
150 }
151 if (RT_SUCCESS(rc))
152 {
153 rc = mGuest.init(&mGuestObs);
154 }
155 if (RT_SUCCESS(rc))
156 {
157 rc = mHost.start();
158 }
159 if (RT_SUCCESS(rc))
160 {
161 isInitialised = true;
162 }
163 if (RT_FAILURE(rc))
164 {
165 LogFunc(("returning %Rrc (VBoxService)\n", rc));
166 }
167 return rc;
168 }
169
170 void uninit(void)
171 {
172 if (isInitialised)
173 {
174 mHost.stop();
175 mGuestThread.stop(RT_INDEFINITE_WAIT, 0);
176 mGuest.uninit();
177 isInitialised = false;
178 }
179 }
180
181 VBoxGuestSeamless() : mGuestFunction(&mGuest, &mGuestObs),
182 mGuestThread(&mGuestFunction, 0, RTTHREADTYPE_MSG_PUMP,
183 RTTHREADFLAGS_WAITABLE, "Guest events"),
184 mHostObs(&mHost, &mGuestThread), mGuestObs(&mHost, &mGuest)
185 {
186 isInitialised = false;
187 }
188 ~VBoxGuestSeamless() { uninit(); }
189};
190
191#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