VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/VBoxClient/seamless-host.h@ 19015

Last change on this file since 19015 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

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