VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/xclient/displaychange-x11.cpp@ 8256

Last change on this file since 8256 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: 4.1 KB
Line 
1/** @file
2 *
3 * Guest client: display auto-resize.
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#include <VBox/log.h>
23#include <VBox/VBoxGuest.h>
24#include <iprt/assert.h>
25
26/** @todo this should probably be replaced by something IPRT */
27/* For system() and WEXITSTATUS() */
28#include <stdlib.h>
29#include <sys/types.h>
30#include <sys/wait.h>
31#include <errno.h>
32
33#include "displaychange.h"
34
35int VBoxGuestDisplayChangeThreadX11::init(void)
36{
37 int rc = VINF_SUCCESS, rcSystem, rcErrno;
38
39 LogFlowThisFunc(("\n"));
40 rcSystem = system("VBoxRandR --test");
41 if (-1 == rcSystem)
42 {
43 rcErrno = errno;
44 rc = RTErrConvertFromErrno(rcErrno);
45 }
46 if (RT_SUCCESS(rc))
47 {
48 if (0 != WEXITSTATUS(rcSystem))
49 rc = VERR_NOT_SUPPORTED;
50 }
51 if (RT_SUCCESS(rc))
52 rc = VbglR3CtlFilterMask(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, 0);
53 if (RT_SUCCESS(rc))
54 mInit = true;
55 LogFlowThisFunc(("returning %Rrc\n", rc));
56 return rc;
57}
58
59void VBoxGuestDisplayChangeThreadX11::uninit(void)
60{
61 LogFlowThisFunc(("\n"));
62 VbglR3CtlFilterMask(0, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
63 mInit = false;
64 LogFlowThisFunc(("returning\n"));
65}
66
67/**
68 * Display change request monitor thread function
69 */
70int VBoxGuestDisplayChangeThreadX11::threadFunction(VBoxGuestThread *pThread)
71{
72 mThread = pThread;
73 LogFlowThisFunc(("\n"));
74 while (!mThread->isStopping())
75 {
76 uint32_t cx, cy, cBits, iDisplay;
77 int rc = VbglR3DisplayChangeWaitEvent(&cx, &cy, &cBits, &iDisplay);
78 /* If we are not stopping, sleep for a bit to avoid using up too
79 much CPU while retrying. */
80 if (RT_FAILURE(rc) && !mThread->isStopping())
81 mThread->yield();
82 else
83 system("VBoxRandR");
84 }
85 LogFlowThisFunc(("returning VINF_SUCCESS\n"));
86 return VINF_SUCCESS;
87}
88
89/**
90 * Send a signal to the thread function that it should exit
91 */
92void VBoxGuestDisplayChangeThreadX11::stop(void)
93{
94 /**
95 * @todo is this reasonable? If the thread is in the event loop then the cancelEvent()
96 * will cause it to exit. If it enters or exits the event loop it will also
97 * notice that we wish it to exit. And if it is somewhere in-between, the
98 * yield() should give it time to get to one of places mentioned above.
99 */
100 LogFlowThisFunc(("\n"));
101 for (int i = 0; (i < 5) && mThread->isRunning(); ++i)
102 {
103 VbglR3InterruptEventWaits();;
104 mThread->yield();
105 }
106 LogFlowThisFunc(("returning\n"));
107}
108
109int VBoxGuestDisplayChangeMonitor::init(void)
110{
111 int rc = VINF_SUCCESS;
112
113 LogFlowThisFunc(("\n"));
114 if (mInit)
115 return VINF_SUCCESS;
116 rc = mThreadFunction.init();
117 if (RT_FAILURE(rc))
118 Log(("VBoxClient: failed to initialise the display change thread, rc=%Rrc (VBoxGuestDisplayChangeMonitor::init)\n", rc));
119 if (RT_SUCCESS(rc))
120 {
121 rc = mThread.start();
122 if (RT_FAILURE(rc))
123 Log(("VBoxClient: failed to start the display change thread, rc=%Rrc (VBoxGuestDisplayChangeMonitor::init)\n", rc));
124 }
125 if (RT_SUCCESS(rc))
126 mInit = true;
127 LogFlowThisFunc(("returning %Rrc\n, rc"));
128 return rc;
129}
130
131void VBoxGuestDisplayChangeMonitor::uninit(unsigned cMillies /* = RT_INDEFINITE_WAIT */)
132{
133 LogFlowThisFunc(("\n"));
134 if (mInit)
135 {
136 if (mThread.stop(cMillies, 0))
137 mThreadFunction.uninit();
138 }
139 LogFlowThisFunc(("returning\n"));
140}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette