1 | /** @file
|
---|
2 | * X11 Guest client - seamless mode, missing proper description while using the
|
---|
3 | * potentially confusing word 'host'.
|
---|
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_client_seamless_host_h
|
---|
19 | # define __Additions_client_seamless_host_h
|
---|
20 |
|
---|
21 | #include <memory> /* for auto_ptr */
|
---|
22 | #include <vector> /* for vector */
|
---|
23 |
|
---|
24 | #include <VBox/log.h>
|
---|
25 | #include <VBox/VBoxGuestLib.h> /* for the R3 guest library functions */
|
---|
26 |
|
---|
27 | #include "seamless-glue.h" /* for VBoxGuestSeamlessObserver */
|
---|
28 | #include "thread.h" /* for VBoxGuestThread */
|
---|
29 |
|
---|
30 | class VBoxGuestSeamlessHost;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Host event (i.e. enter or leave seamless mode) thread function for the main
|
---|
34 | * seamless class
|
---|
35 | */
|
---|
36 | class VBoxGuestSeamlessHostThread : public VBoxGuestThreadFunction
|
---|
37 | {
|
---|
38 | private:
|
---|
39 | // Copying or assigning a thread object is not sensible
|
---|
40 | VBoxGuestSeamlessHostThread(const VBoxGuestSeamlessHostThread&);
|
---|
41 | VBoxGuestSeamlessHostThread& operator=(const VBoxGuestSeamlessHostThread&);
|
---|
42 |
|
---|
43 | // Private member variables
|
---|
44 | /** The host proxy object */
|
---|
45 | VBoxGuestSeamlessHost *mHost;
|
---|
46 |
|
---|
47 | /** The thread object running us. */
|
---|
48 | VBoxGuestThread *mThread;
|
---|
49 | public:
|
---|
50 | VBoxGuestSeamlessHostThread(VBoxGuestSeamlessHost *pHost)
|
---|
51 | {
|
---|
52 | mHost = pHost;
|
---|
53 | }
|
---|
54 | virtual ~VBoxGuestSeamlessHostThread(void) {}
|
---|
55 | /**
|
---|
56 | * The actual thread function.
|
---|
57 | *
|
---|
58 | * @returns iprt status code as thread return value
|
---|
59 | * @param pParent the VBoxGuestThread running this thread function
|
---|
60 | */
|
---|
61 | virtual int threadFunction(VBoxGuestThread *pThread);
|
---|
62 | /**
|
---|
63 | * Send a signal to the thread function that it should exit
|
---|
64 | */
|
---|
65 | virtual void stop(void);
|
---|
66 | };
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Interface to the host
|
---|
70 | */
|
---|
71 | class VBoxGuestSeamlessHost
|
---|
72 | {
|
---|
73 | friend class VBoxGuestSeamlessHostThread;
|
---|
74 | public:
|
---|
75 | /** Events which can be reported by this class */
|
---|
76 | enum meEvent
|
---|
77 | {
|
---|
78 | /** Empty event */
|
---|
79 | NONE,
|
---|
80 | /** Request to enable seamless mode */
|
---|
81 | ENABLE,
|
---|
82 | /** Request to disable seamless mode */
|
---|
83 | DISABLE
|
---|
84 | };
|
---|
85 |
|
---|
86 | private:
|
---|
87 | // We don't want a copy constructor or assignment operator
|
---|
88 | VBoxGuestSeamlessHost(const VBoxGuestSeamlessHost&);
|
---|
89 | VBoxGuestSeamlessHost& operator=(const VBoxGuestSeamlessHost&);
|
---|
90 |
|
---|
91 | /** Observer to connect guest and host and ferry events back and forth. */
|
---|
92 | VBoxGuestSeamlessObserver *mObserver;
|
---|
93 | /** Host seamless event (i.e. enter and leave) thread function. */
|
---|
94 | VBoxGuestSeamlessHostThread mThreadFunction;
|
---|
95 | /** Host seamless event thread. */
|
---|
96 | VBoxGuestThread mThread;
|
---|
97 | /** Is the service running? */
|
---|
98 | bool mRunning;
|
---|
99 | /** Last request issued by the host. */
|
---|
100 | meEvent mState;
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Waits for a seamless state change events from the host and dispatch it. This is
|
---|
104 | * meant to be called by the host event monitor thread exclusively.
|
---|
105 | *
|
---|
106 | * @returns IRPT return code.
|
---|
107 | */
|
---|
108 | int nextEvent(void);
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Interrupt an event wait and cause nextEvent() to return immediately.
|
---|
112 | */
|
---|
113 | void cancelEvent(void) { VbglR3InterruptEventWaits(); }
|
---|
114 |
|
---|
115 | public:
|
---|
116 | /**
|
---|
117 | * Initialise the guest and ensure that it is capable of handling seamless mode
|
---|
118 | * @param pObserver Observer class to connect host and guest interfaces
|
---|
119 | *
|
---|
120 | * @returns iprt status code
|
---|
121 | */
|
---|
122 | int init(VBoxGuestSeamlessObserver *pObserver)
|
---|
123 | {
|
---|
124 | LogRelFlowFunc(("\n"));
|
---|
125 | if (mObserver != 0) /* Assertion */
|
---|
126 | {
|
---|
127 | LogRel(("VBoxClient: ERROR: attempt to initialise seamless host object twice!\n"));
|
---|
128 | return VERR_INTERNAL_ERROR;
|
---|
129 | }
|
---|
130 | mObserver = pObserver;
|
---|
131 | LogRelFlowFunc(("returning VINF_SUCCESS\n"));
|
---|
132 | return VINF_SUCCESS;
|
---|
133 | }
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * Start the service.
|
---|
137 | * @returns iprt status value
|
---|
138 | */
|
---|
139 | int start(void);
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Stops the service.
|
---|
143 | * @param cMillies how long to wait for the thread to exit
|
---|
144 | */
|
---|
145 | void stop(RTMSINTERVAL cMillies = RT_INDEFINITE_WAIT);
|
---|
146 |
|
---|
147 | /** Returns the current state of the host - i.e. requesting seamless or not. */
|
---|
148 | meEvent getState(void) { return mState; }
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Update the set of visible rectangles in the host.
|
---|
152 | */
|
---|
153 | void updateRects(std::auto_ptr<std::vector<RTRECT> > pRects);
|
---|
154 |
|
---|
155 | VBoxGuestSeamlessHost(void) : mThreadFunction(this),
|
---|
156 | mThread(&mThreadFunction, 0, RTTHREADTYPE_MSG_PUMP,
|
---|
157 | RTTHREADFLAGS_WAITABLE, "Host events")
|
---|
158 | {
|
---|
159 | mObserver = 0;
|
---|
160 | mRunning = false;
|
---|
161 | mState = NONE;
|
---|
162 | }
|
---|
163 |
|
---|
164 | ~VBoxGuestSeamlessHost()
|
---|
165 | {
|
---|
166 | LogRelFlowFunc(("\n"));
|
---|
167 | if (mRunning) /* Assertion */
|
---|
168 | {
|
---|
169 | LogRel(("VBoxClient: seamless host object still running! Stopping...\n"));
|
---|
170 | try
|
---|
171 | {
|
---|
172 | stop(2000);
|
---|
173 | }
|
---|
174 | catch(...) {}
|
---|
175 | }
|
---|
176 | LogRelFlowFunc(("returning\n"));
|
---|
177 | }
|
---|
178 | };
|
---|
179 |
|
---|
180 | #endif /* __Additions_xclient_seamless_h not defined */
|
---|