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