1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
// Berkeley Open Infrastructure for Network Computing
// http://boinc.berkeley.edu
// Copyright (C) 2005 University of California
//
// This is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation;
// either version 2.1 of the License, or (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// To view the GNU Lesser General Public License visit
// http://www.gnu.org/copyleft/lesser.html
// or write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// graphics-related interaction with running apps
#include "cpp.h"
#ifdef _WIN32
#include "boinc_win.h"
#else
#include "config.h"
#endif
#include "exception.h"
#include "diagnostics.h"
#include "client_state.h"
#include "client_msgs.h"
#include "app.h"
#include "util.h"
//#define SS_DEBUG 1
void ACTIVE_TASK::request_graphics_mode(GRAPHICS_MSG& m) {
char buf[MSG_CHANNEL_SIZE], buf2[256];
SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_SCRSAVE);
if (!app_client_shm.shm) return;
graphics_msg = m; // save graphics_station, desktop, display
strcpy(buf, xml_graphics_modes[m.mode]);
if (strlen(m.window_station)) {
sprintf(buf2, "<window_station>%s</window_station>", m.window_station);
strcat(buf, buf2);
}
if (strlen(m.desktop)) {
sprintf(buf2, "<desktop>%s</desktop>", m.desktop);
strcat(buf, buf2);
}
if (strlen(m.display)) {
sprintf(buf2, "<display>%s</display>", m.display);
strcat(buf, buf2);
}
scope_messages.printf(
"ACTIVE_TASK::request_graphics_mode(): requesting graphics mode %s for %s\n",
xml_graphics_modes[m.mode], result->name
);
graphics_request_queue.msg_queue_send(
buf,
app_client_shm.shm->graphics_request
);
}
void ACTIVE_TASK::check_graphics_mode_ack() {
GRAPHICS_MSG gm;
char buf[MSG_CHANNEL_SIZE];
SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_SCRSAVE);
#if (defined(__APPLE__) && defined(__i386__))
// PowerPC apps emulated on i386 Macs crash if running graphics
if (powerpc_emulated_on_i386) {
graphics_mode_acked = MODE_UNSUPPORTED;
return;
}
#endif
if (!app_client_shm.shm) return;
if (app_client_shm.shm->graphics_reply.get_msg(buf)) {
app_client_shm.decode_graphics_msg(buf, gm);
scope_messages.printf(
"ACTIVE_TASK::check_graphics_mode_ack(): got graphics ack %s for %s, previous mode %s\n",
buf, result->name, xml_graphics_modes[graphics_mode_acked]
);
// if we receive MODE_HIDE_GRAPHICS from an application acting as the
// screensaver it can be for one of two reasons:
// 1) application shut down because it was done processing.
// 2) user input was detected.
//
// in the first condition we should promote another application to be
// screensaver in the SS_LOGIC::poll function. In the second condition
// we should inform the various screensaver components to shutdown.
if (is_ss_app && (graphics_mode_acked == MODE_FULLSCREEN) &&
(gm.mode != MODE_FULLSCREEN) && (gm.mode != MODE_REREAD_PREFS) &&
!gstate.host_info.users_idle(true, 0.5)) {
gstate.ss_logic.stop_ss();
scope_messages.printf(
"ACTIVE_TASK::check_graphics_mode_ack(): shutting down the screensaver\n"
);
}
if (gm.mode != MODE_REREAD_PREFS) {
graphics_mode_acked = gm.mode;
}
}
}
// return the active task that's currently acting as screensaver
//
ACTIVE_TASK* ACTIVE_TASK_SET::get_ss_app() {
unsigned int i;
for (i=0; i<active_tasks.size(); i++) {
ACTIVE_TASK* atp = active_tasks[i];
if (atp->is_ss_app) {
return atp;
}
}
return NULL;
}
// remember graphics state of apps.
// Called when entering screensaver mode,
// so that we can return to same state later
//
void ACTIVE_TASK_SET::save_app_modes() {
unsigned int i;
ACTIVE_TASK* atp;
SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_SCRSAVE);
for (i=0; i<active_tasks.size(); i++) {
atp = active_tasks[i];
// nothing should be in fullscreen mode.
//
if (atp->graphics_mode_acked == MODE_FULLSCREEN) {
atp->graphics_mode_acked = MODE_HIDE_GRAPHICS;
}
atp->graphics_mode_before_ss = atp->graphics_mode_acked;
scope_messages.printf(
"ACTIVE_TASK_SET::save_app_modes(): saved mode %d\n", atp->graphics_mode_acked
);
}
}
void ACTIVE_TASK_SET::hide_apps() {
unsigned int i;
ACTIVE_TASK* atp;
for (i=0; i<active_tasks.size(); i++) {
atp = active_tasks[i];
atp->graphics_msg.mode = MODE_HIDE_GRAPHICS;
atp->request_graphics_mode(atp->graphics_msg);
}
}
// return apps to the mode they were in before screensaving started
//
void ACTIVE_TASK_SET::restore_apps() {
unsigned int i;
ACTIVE_TASK* atp;
for (i=0; i<active_tasks.size(); i++) {
atp = active_tasks[i];
if (atp->graphics_mode_before_ss == MODE_WINDOW) {
atp->graphics_msg.mode = MODE_WINDOW;
atp->request_graphics_mode(atp->graphics_msg);
}
}
}
void ACTIVE_TASK_SET::graphics_poll() {
unsigned int i;
ACTIVE_TASK* atp;
for (i=0; i<active_tasks.size(); i++) {
atp = active_tasks[i];
if (!atp->process_exists()) continue;
atp->graphics_request_queue.msg_queue_poll(
atp->app_client_shm.shm->graphics_request
);
atp->check_graphics_mode_ack();
// If screensaver application has not responded to our request to exit MODE_FULLSCREEN after
// 2 seconds, then assume it has hung and kill it, so it doesn't block access to the computer.
// First try an exit request. If it has not exit after 2 more seconds, kill it.
if (atp->graphics_mode_ack_timeout) // If we are waiting for app to stop screensaver mode
if ( atp->is_ss_app || (atp->graphics_mode_acked != MODE_FULLSCREEN) ) {
atp->exit_requested = false;
atp->graphics_mode_ack_timeout = 0.0; // Reset Mac screensaver safety timer
}
if (atp->graphics_mode_ack_timeout) {
if (gstate.now > atp->graphics_mode_ack_timeout + 2.0) {
if (atp->has_task_exited()) { // Successfully exited
atp->exit_requested = false;
atp->graphics_mode_ack_timeout = 0.0; // Reset safety timer
} else {
if (! atp->exit_requested) {
atp->exit_requested = true;
atp->request_exit(); // Request exit after 2 seconds
atp->graphics_mode_ack_timeout = gstate.now; // Wait 2 more seconds for app to exit
msg_printf(atp->wup->project, MSG_ERROR, "%s not responding to screensaver, exiting", atp->app_version->app_name);
} else {
atp->exit_requested = false;
atp->graphics_mode_ack_timeout = 0.0; // Reset safety timer
atp->kill_task(); // Kill app if exit request failed after 2 seconds
}
}
}
}
}
}
bool ACTIVE_TASK::supports_graphics() {
#if (defined(__APPLE__) && defined(__i386__))
// PowerPC apps emulated on i386 Macs crash if running graphics
if (powerpc_emulated_on_i386)
return false;
#endif
return (graphics_mode_acked != MODE_UNSUPPORTED);
}
// Return the next graphics-capable running app.
// Always try to choose a new project.
// Preferences goes to apps with pre-ss mode WINDOW,
// then apps with pre-ss mode HIDE
//
ACTIVE_TASK* CLIENT_STATE::get_next_graphics_capable_app() {
static int project_index=0;
unsigned int i, j;
ACTIVE_TASK *atp, *best_atp;
PROJECT *p;
SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_SCRSAVE);
// check to see if the applications have changed the graphics mode;
// this can happen if they fail to find the target desktop
//
for (i=0; i<active_tasks.active_tasks.size(); i++) {
atp = active_tasks.active_tasks[i];
atp->check_graphics_mode_ack();
}
// loop through all projects starting with the one at project_index
//
for (i=0; i<projects.size(); ++i) {
project_index %= projects.size();
p = projects[project_index++];
best_atp = NULL;
for (j=0; j<active_tasks.active_tasks.size(); j++) {
atp = active_tasks.active_tasks[j];
if (atp->scheduler_state != CPU_SCHED_SCHEDULED) continue;
// don't choose an application that doesn't support graphics
if (atp->graphics_mode_acked == MODE_UNSUPPORTED) continue;
// don't choose an application that hasn't ack'ed the
// hide graphics request
if (atp->graphics_mode_acked != MODE_HIDE_GRAPHICS) continue;
if (atp->result->project != p) continue;
if (!best_atp && atp->graphics_mode_before_ss == MODE_WINDOW) {
best_atp = atp;
}
if (!best_atp && atp->graphics_mode_before_ss == MODE_HIDE_GRAPHICS) {
best_atp = atp;
}
if (!best_atp) {
best_atp = atp;
}
if (best_atp) {
scope_messages.printf(
"CLIENT_STATE::get_next_graphics_capable_app(): get_next_app: %s\n", best_atp->result->name
);
return atp;
}
}
}
scope_messages.printf(
"CLIENT_STATE::get_next_graphics_capable_app(): get_next_app: none\n"
);
return NULL;
}
const char *BOINC_RCSID_71e9cd9f4d = "$Id: app_graphics.C,v 1.37.2.1 2006/04/10 23:58:30 charlief Exp $";
|