2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// 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
|
2004-08-11 11:30:25 +00:00
|
|
|
|
|
|
|
// graphics-related interaction with running apps
|
|
|
|
|
|
|
|
#include "cpp.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
2005-11-21 18:34:44 +00:00
|
|
|
#else
|
|
|
|
#include "config.h"
|
2004-08-11 11:30:25 +00:00
|
|
|
#endif
|
|
|
|
|
2004-11-18 04:09:10 +00:00
|
|
|
#include "diagnostics.h"
|
2004-08-11 11:30:25 +00:00
|
|
|
#include "client_state.h"
|
2004-09-13 05:27:28 +00:00
|
|
|
#include "client_msgs.h"
|
2004-08-11 11:30:25 +00:00
|
|
|
|
|
|
|
#include "app.h"
|
2004-11-17 09:27:06 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2005-04-08 21:40:32 +00:00
|
|
|
|
2004-11-17 19:19:26 +00:00
|
|
|
void ACTIVE_TASK::request_graphics_mode(GRAPHICS_MSG& m) {
|
|
|
|
char buf[MSG_CHANNEL_SIZE], buf2[256];
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2004-09-13 05:27:28 +00:00
|
|
|
if (!app_client_shm.shm) return;
|
2004-11-17 09:27:06 +00:00
|
|
|
|
2005-02-15 07:30:44 +00:00
|
|
|
graphics_msg = m; // save graphics_station, desktop, display
|
2004-11-17 19:19:26 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2005-03-10 00:43:22 +00:00
|
|
|
if (strlen(m.display)) {
|
|
|
|
sprintf(buf2, "<display>%s</display>", m.display);
|
2005-02-15 07:30:44 +00:00
|
|
|
strcat(buf, buf2);
|
|
|
|
}
|
2004-11-17 09:27:06 +00:00
|
|
|
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.scrsave_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2006-09-07 20:39:25 +00:00
|
|
|
"[scrsave_debug] ACTIVE_TASK::request_graphics_mode(): requesting graphics mode %s for %s",
|
2006-06-22 19:40:30 +00:00
|
|
|
xml_graphics_modes[m.mode], result->name
|
|
|
|
);
|
|
|
|
}
|
2004-09-13 05:27:28 +00:00
|
|
|
graphics_request_queue.msg_queue_send(
|
2004-11-17 09:27:06 +00:00
|
|
|
buf,
|
2004-09-13 05:27:28 +00:00
|
|
|
app_client_shm.shm->graphics_request
|
2004-08-11 11:30:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2004-09-13 05:27:28 +00:00
|
|
|
|
2006-12-06 20:59:29 +00:00
|
|
|
// handle messages on the "graphics_reply" channel
|
|
|
|
//
|
2004-08-11 11:30:25 +00:00
|
|
|
void ACTIVE_TASK::check_graphics_mode_ack() {
|
2004-11-17 19:19:26 +00:00
|
|
|
GRAPHICS_MSG gm;
|
2004-08-11 11:30:25 +00:00
|
|
|
char buf[MSG_CHANNEL_SIZE];
|
2006-02-06 23:44:05 +00:00
|
|
|
#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
|
2004-08-24 21:44:54 +00:00
|
|
|
|
|
|
|
if (!app_client_shm.shm) return;
|
2004-08-11 11:30:25 +00:00
|
|
|
if (app_client_shm.shm->graphics_reply.get_msg(buf)) {
|
2004-11-18 01:30:37 +00:00
|
|
|
app_client_shm.decode_graphics_msg(buf, gm);
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.scrsave_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2006-09-07 20:39:25 +00:00
|
|
|
"[scrsave_debug] ACTIVE_TASK::check_graphics_mode_ack(): got graphics ack %s for %s, previous mode %s",
|
2006-06-22 19:40:30 +00:00
|
|
|
buf, result->name, xml_graphics_modes[graphics_mode_acked]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2005-05-24 01:02:05 +00:00
|
|
|
// if we receive MODE_HIDE_GRAPHICS from an application acting as the
|
|
|
|
// screensaver it can be for one of two reasons:
|
2006-12-06 20:59:29 +00:00
|
|
|
// 1) application shut down because it was done processing.
|
|
|
|
// 2) user input was detected.
|
2005-05-24 01:02:05 +00:00
|
|
|
//
|
2006-12-06 20:59:29 +00:00
|
|
|
// in the first case we should choose another application to be
|
|
|
|
// screensaver in the SS_LOGIC::poll function.
|
|
|
|
// In the second condition
|
2005-05-24 01:02:05 +00:00
|
|
|
// we should inform the various screensaver components to shutdown.
|
2006-12-06 20:59:29 +00:00
|
|
|
//
|
2005-05-24 12:41:22 +00:00
|
|
|
if (is_ss_app && (graphics_mode_acked == MODE_FULLSCREEN) &&
|
2005-05-24 01:02:05 +00:00
|
|
|
(gm.mode != MODE_FULLSCREEN) && (gm.mode != MODE_REREAD_PREFS) &&
|
2006-12-06 20:59:29 +00:00
|
|
|
!gstate.host_info.users_idle(true, 0.5)
|
|
|
|
) {
|
2004-11-17 20:06:44 +00:00
|
|
|
gstate.ss_logic.stop_ss();
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.scrsave_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2006-09-07 20:39:25 +00:00
|
|
|
"[scrsave_debug] ACTIVE_TASK::check_graphics_mode_ack(): shutting down the screensaver"
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2005-05-18 06:46:29 +00:00
|
|
|
if (gm.mode != MODE_REREAD_PREFS) {
|
|
|
|
graphics_mode_acked = gm.mode;
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-13 23:17:16 +00:00
|
|
|
// return the active task that's currently acting as screensaver
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
2004-09-13 05:27:28 +00:00
|
|
|
ACTIVE_TASK* ACTIVE_TASK_SET::get_ss_app() {
|
2004-08-11 11:30:25 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
2004-09-13 23:17:16 +00:00
|
|
|
ACTIVE_TASK* atp = active_tasks[i];
|
2004-09-13 05:27:28 +00:00
|
|
|
if (atp->is_ss_app) {
|
2004-08-11 11:30:25 +00:00
|
|
|
return atp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-08-23 22:06:48 +00:00
|
|
|
// remember graphics state of apps.
|
|
|
|
// Called when entering screensaver mode,
|
|
|
|
// so that we can return to same state later
|
|
|
|
//
|
2004-08-11 11:30:25 +00:00
|
|
|
void ACTIVE_TASK_SET::save_app_modes() {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2004-09-13 05:27:28 +00:00
|
|
|
|
|
|
|
// nothing should be in fullscreen mode.
|
|
|
|
//
|
|
|
|
if (atp->graphics_mode_acked == MODE_FULLSCREEN) {
|
|
|
|
atp->graphics_mode_acked = MODE_HIDE_GRAPHICS;
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
atp->graphics_mode_before_ss = atp->graphics_mode_acked;
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.scrsave_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2006-09-07 20:39:25 +00:00
|
|
|
"[scrsave_debug] ACTIVE_TASK_SET::save_app_modes(): saved mode %d",
|
2006-06-22 19:40:30 +00:00
|
|
|
atp->graphics_mode_acked
|
|
|
|
);
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ACTIVE_TASK_SET::hide_apps() {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2004-11-17 19:19:26 +00:00
|
|
|
atp->graphics_msg.mode = MODE_HIDE_GRAPHICS;
|
|
|
|
atp->request_graphics_mode(atp->graphics_msg);
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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];
|
2004-09-13 05:27:28 +00:00
|
|
|
if (atp->graphics_mode_before_ss == MODE_WINDOW) {
|
2004-11-17 19:19:26 +00:00
|
|
|
atp->graphics_msg.mode = MODE_WINDOW;
|
|
|
|
atp->request_graphics_mode(atp->graphics_msg);
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ACTIVE_TASK_SET::graphics_poll() {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2004-08-23 22:44:53 +00:00
|
|
|
if (!atp->process_exists()) continue;
|
2004-09-13 05:27:28 +00:00
|
|
|
atp->graphics_request_queue.msg_queue_poll(
|
|
|
|
atp->app_client_shm.shm->graphics_request
|
|
|
|
);
|
2004-08-11 11:30:25 +00:00
|
|
|
atp->check_graphics_mode_ack();
|
2006-02-21 12:22:23 +00:00
|
|
|
|
2006-06-22 19:40:30 +00:00
|
|
|
// 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.
|
2006-12-06 20:59:29 +00:00
|
|
|
//
|
|
|
|
if (atp->graphics_mode_ack_timeout) {
|
2006-12-07 17:30:48 +00:00
|
|
|
if (log_flags.scrsave_debug) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "ack_timeout %f is_ss_app %d acked %d",
|
|
|
|
gstate.now-atp->graphics_mode_acked, atp->is_ss_app, atp->graphics_mode_acked
|
|
|
|
);
|
|
|
|
}
|
2006-12-06 20:59:29 +00:00
|
|
|
if (atp->is_ss_app || (atp->graphics_mode_acked != MODE_FULLSCREEN)) {
|
2006-02-21 12:22:23 +00:00
|
|
|
atp->exit_requested = false;
|
2006-12-06 20:59:29 +00:00
|
|
|
atp->graphics_mode_ack_timeout = 0.0;
|
2006-02-21 12:22:23 +00:00
|
|
|
}
|
2006-12-06 20:59:29 +00:00
|
|
|
}
|
2006-02-21 12:22:23 +00:00
|
|
|
if (atp->graphics_mode_ack_timeout) {
|
2006-12-07 17:30:48 +00:00
|
|
|
if (gstate.now > atp->graphics_mode_ack_timeout + 3.0) {
|
2006-12-06 20:59:29 +00:00
|
|
|
if (atp->has_task_exited()) {
|
2006-02-21 12:22:23 +00:00
|
|
|
atp->exit_requested = false;
|
2006-12-06 20:59:29 +00:00
|
|
|
atp->graphics_mode_ack_timeout = 0.0;
|
2006-02-21 12:22:23 +00:00
|
|
|
} else {
|
2006-12-06 20:59:29 +00:00
|
|
|
if (!atp->exit_requested) {
|
2006-02-21 12:22:23 +00:00
|
|
|
atp->exit_requested = true;
|
2006-12-06 20:59:29 +00:00
|
|
|
atp->request_exit();
|
|
|
|
|
|
|
|
// Wait 2 more seconds for app to exit
|
|
|
|
//
|
|
|
|
atp->graphics_mode_ack_timeout = gstate.now;
|
|
|
|
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(atp->wup->project, MSG_INTERNAL_ERROR,
|
2006-12-06 20:59:29 +00:00
|
|
|
"%s not responding to screensaver, requesting exit",
|
2006-06-22 19:40:30 +00:00
|
|
|
atp->app_version->app_name
|
|
|
|
);
|
2006-02-21 12:22:23 +00:00
|
|
|
} else {
|
|
|
|
atp->exit_requested = false;
|
2006-12-06 20:59:29 +00:00
|
|
|
atp->graphics_mode_ack_timeout = 0.0;
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(atp->wup->project, MSG_INTERNAL_ERROR,
|
2006-12-06 20:59:29 +00:00
|
|
|
"%s not responding to screensaver, killing it",
|
|
|
|
atp->app_version->app_name
|
|
|
|
);
|
2006-12-07 17:30:48 +00:00
|
|
|
atp->kill_task(true);
|
2006-02-21 12:22:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ACTIVE_TASK::supports_graphics() {
|
2006-02-06 23:44:05 +00:00
|
|
|
#if (defined(__APPLE__) && defined(__i386__))
|
|
|
|
// PowerPC apps emulated on i386 Macs crash if running graphics
|
|
|
|
if (powerpc_emulated_on_i386)
|
|
|
|
return false;
|
|
|
|
#endif
|
2006-06-30 23:32:26 +00:00
|
|
|
if (graphics_mode_acked == MODE_UNSUPPORTED) return false;
|
2006-08-07 00:58:12 +00:00
|
|
|
if (scheduler_state != CPU_SCHED_SCHEDULED) return false;
|
2006-06-30 23:32:26 +00:00
|
|
|
return true;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
|
2004-08-23 22:06:48 +00:00
|
|
|
// Return the next graphics-capable running app.
|
2004-08-11 11:30:25 +00:00
|
|
|
// 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;
|
2004-09-13 05:27:28 +00:00
|
|
|
ACTIVE_TASK *atp, *best_atp;
|
2004-08-11 11:30:25 +00:00
|
|
|
PROJECT *p;
|
|
|
|
|
2005-05-22 23:12:09 +00:00
|
|
|
// check to see if the applications have changed the graphics mode;
|
|
|
|
// this can happen if they fail to find the target desktop
|
2005-04-05 20:02:59 +00:00
|
|
|
//
|
|
|
|
for (i=0; i<active_tasks.active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks.active_tasks[i];
|
|
|
|
atp->check_graphics_mode_ack();
|
|
|
|
}
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
// 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++];
|
|
|
|
|
2004-09-13 05:27:28 +00:00
|
|
|
best_atp = NULL;
|
|
|
|
for (j=0; j<active_tasks.active_tasks.size(); j++) {
|
2004-08-11 11:30:25 +00:00
|
|
|
atp = active_tasks.active_tasks[j];
|
2004-08-23 22:06:48 +00:00
|
|
|
if (atp->scheduler_state != CPU_SCHED_SCHEDULED) continue;
|
2005-05-20 20:28:00 +00:00
|
|
|
// 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;
|
2004-08-11 11:30:25 +00:00
|
|
|
if (atp->result->project != p) continue;
|
2005-05-20 20:28:00 +00:00
|
|
|
|
|
|
|
if (!best_atp && atp->graphics_mode_before_ss == MODE_WINDOW) {
|
2004-09-13 05:27:28 +00:00
|
|
|
best_atp = atp;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2005-05-20 20:28:00 +00:00
|
|
|
if (!best_atp && atp->graphics_mode_before_ss == MODE_HIDE_GRAPHICS) {
|
2004-09-13 05:27:28 +00:00
|
|
|
best_atp = atp;
|
|
|
|
}
|
2005-05-20 20:28:00 +00:00
|
|
|
if (!best_atp) {
|
2004-09-13 05:27:28 +00:00
|
|
|
best_atp = atp;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2004-09-13 05:27:28 +00:00
|
|
|
if (best_atp) {
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.scrsave_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2006-09-07 20:39:25 +00:00
|
|
|
"[scrsave_debug] CLIENT_STATE::get_next_graphics_capable_app(): get_next_app: %s",
|
2006-06-22 19:40:30 +00:00
|
|
|
best_atp->result->name
|
|
|
|
);
|
|
|
|
}
|
2004-11-18 22:18:00 +00:00
|
|
|
return atp;
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.scrsave_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2006-09-07 20:39:25 +00:00
|
|
|
"[scrsave_debug] CLIENT_STATE::get_next_graphics_capable_app(): get_next_app: none"
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_71e9cd9f4d = "$Id$";
|