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