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