2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2003-05-15 17:10:26 +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
|
2003-05-15 17:10:26 +00:00
|
|
|
|
2004-03-05 04:37:53 +00:00
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2005-11-21 18:34:44 +00:00
|
|
|
#else
|
|
|
|
#include "config.h"
|
2004-03-05 04:37:53 +00:00
|
|
|
#endif
|
2003-05-08 18:11:05 +00:00
|
|
|
|
2004-03-05 04:37:53 +00:00
|
|
|
#include "client_state.h"
|
2004-07-18 04:41:27 +00:00
|
|
|
#include "client_msgs.h"
|
2003-05-08 18:11:05 +00:00
|
|
|
#include "ss_logic.h"
|
2005-05-18 22:50:32 +00:00
|
|
|
#include "util.h"
|
2003-05-08 18:11:05 +00:00
|
|
|
|
2005-05-22 23:12:09 +00:00
|
|
|
#define SS_CHANGE_PERIOD 600
|
|
|
|
// if > 1 CPUs, change screensaver every 600 secs
|
|
|
|
|
2003-05-08 18:11:05 +00:00
|
|
|
SS_LOGIC::SS_LOGIC() {
|
|
|
|
do_ss = false;
|
|
|
|
blank_time = 0;
|
|
|
|
ack_deadline = 0;
|
2004-11-17 10:25:39 +00:00
|
|
|
ss_status = 0;
|
2003-05-08 18:11:05 +00:00
|
|
|
}
|
|
|
|
|
2005-04-05 00:32:24 +00:00
|
|
|
void SS_LOGIC::ask_app(ACTIVE_TASK* atp, GRAPHICS_MSG& m) {
|
|
|
|
atp->request_graphics_mode(m);
|
|
|
|
atp->is_ss_app = true;
|
2006-04-12 02:28:50 +00:00
|
|
|
ack_deadline = gstate.now + 30.0;
|
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] SS_LOGIC::ask_app(): starting %s current time %f deadline %f",
|
2006-06-22 19:40:30 +00:00
|
|
|
atp->result->name, gstate.now, ack_deadline
|
|
|
|
);
|
|
|
|
}
|
2005-04-05 00:32:24 +00:00
|
|
|
}
|
|
|
|
|
2005-04-04 21:14:49 +00:00
|
|
|
// called in response to a set_screensaver_mode RPC with <enabled>.
|
|
|
|
// Start providing screensaver graphics
|
2003-05-08 18:11:05 +00:00
|
|
|
//
|
2004-11-17 19:19:26 +00:00
|
|
|
void SS_LOGIC::start_ss(GRAPHICS_MSG& m, double new_blank_time) {
|
2003-05-08 18:11:05 +00:00
|
|
|
if (do_ss) return;
|
|
|
|
do_ss = true;
|
2004-11-18 01:52:07 +00:00
|
|
|
ss_status = SS_STATUS_ENABLED;
|
2004-11-16 08:04:57 +00:00
|
|
|
|
2003-05-08 18:11:05 +00:00
|
|
|
blank_time = new_blank_time;
|
|
|
|
gstate.active_tasks.save_app_modes();
|
|
|
|
gstate.active_tasks.hide_apps();
|
2004-11-16 08:04:57 +00:00
|
|
|
|
2004-11-17 19:19:26 +00:00
|
|
|
m.mode = MODE_FULLSCREEN;
|
2005-04-05 00:32:24 +00:00
|
|
|
saved_graphics_msg = m;
|
2003-05-08 18:11:05 +00:00
|
|
|
}
|
|
|
|
|
2005-04-04 21:14:49 +00:00
|
|
|
// Stop providing screensaver graphics
|
2006-12-06 20:59:29 +00:00
|
|
|
// called:
|
|
|
|
// 1) in response to a set_screensaver_mode RPC without <enabled>
|
|
|
|
// 2) from ACTIVE_TASK::check_graphics_mode_ack() when mode == MODE_QUIT
|
2005-04-04 21:14:49 +00:00
|
|
|
//
|
2003-05-08 18:11:05 +00:00
|
|
|
void SS_LOGIC::stop_ss() {
|
2003-05-09 20:33:57 +00:00
|
|
|
if (!do_ss) return;
|
2004-09-13 05:27:28 +00:00
|
|
|
reset();
|
2004-11-16 08:04:57 +00:00
|
|
|
do_ss = false;
|
2004-11-18 01:52:07 +00:00
|
|
|
ss_status = SS_STATUS_QUIT;
|
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] SS_LOGIC::stop_ss(): stopping screen saver"
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
2003-05-08 18:11:05 +00:00
|
|
|
gstate.active_tasks.restore_apps();
|
|
|
|
}
|
|
|
|
|
2004-09-13 23:17:16 +00:00
|
|
|
// If an app is acting as screensaver, tell it to stop.
|
2005-04-04 21:14:49 +00:00
|
|
|
// Called from CLIENT_STATE::schedule_cpus()
|
2004-07-19 20:37:45 +00:00
|
|
|
//
|
|
|
|
void SS_LOGIC::reset() {
|
2004-11-17 19:19:26 +00:00
|
|
|
GRAPHICS_MSG m;
|
|
|
|
|
|
|
|
m.mode = MODE_HIDE_GRAPHICS;
|
2004-09-13 23:17:16 +00:00
|
|
|
ACTIVE_TASK* atp = gstate.active_tasks.get_ss_app();
|
|
|
|
if (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] SS_LOGIC::reset(): resetting %s", atp->result->name
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
2004-11-17 19:19:26 +00:00
|
|
|
atp->request_graphics_mode(m);
|
2004-09-13 23:17:16 +00:00
|
|
|
atp->is_ss_app = false;
|
2006-12-06 20:59:29 +00:00
|
|
|
atp->graphics_mode_ack_timeout = gstate.now;
|
2004-07-19 20:37:45 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-09 00:00:39 +00:00
|
|
|
|
2006-08-18 02:51:27 +00:00
|
|
|
// called 1X per second
|
2003-05-08 18:11:05 +00:00
|
|
|
//
|
2005-06-07 19:22:50 +00:00
|
|
|
void SS_LOGIC::poll() {
|
2005-05-24 08:18:42 +00:00
|
|
|
ACTIVE_TASK* atp, *new_atp=0;
|
2004-11-17 19:19:26 +00:00
|
|
|
GRAPHICS_MSG m;
|
2005-04-05 00:32:24 +00:00
|
|
|
static double last_time=0;
|
2005-05-22 23:12:09 +00:00
|
|
|
static double ss_change_time = 0;
|
2004-11-17 19:19:26 +00:00
|
|
|
|
2005-06-07 19:22:50 +00:00
|
|
|
double dt = gstate.now - last_time;
|
2005-04-05 00:32:24 +00:00
|
|
|
if (dt < 1) return;
|
2005-06-07 19:22:50 +00:00
|
|
|
last_time = gstate.now;
|
2003-05-08 18:11:05 +00:00
|
|
|
|
2004-07-18 05:30:26 +00:00
|
|
|
#if 0
|
2004-08-21 23:57:25 +00:00
|
|
|
// if you want to debug screensaver functionality...
|
2006-08-18 02:51:27 +00:00
|
|
|
#define BLANK_DELAY 15 /* seconds */
|
|
|
|
#define SAVER_PERIOD 7 /* seconds */
|
|
|
|
GRAPHICS_MSG gm;
|
2004-07-18 05:30:26 +00:00
|
|
|
static int foo=0;
|
|
|
|
foo++;
|
2006-08-18 02:51:27 +00:00
|
|
|
if (foo == (SAVER_PERIOD)) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"starting screensaver"
|
|
|
|
);
|
|
|
|
start_ss(gm, time(0)+BLANK_DELAY);
|
|
|
|
}
|
|
|
|
if (foo >= ((2*SAVER_PERIOD)+BLANK_DELAY)) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"resetting screensaver counter"
|
|
|
|
);
|
|
|
|
stop_ss();
|
|
|
|
foo = 0;
|
|
|
|
}
|
2004-07-18 05:30:26 +00:00
|
|
|
#endif
|
|
|
|
|
2004-08-21 23:57:25 +00:00
|
|
|
if (!do_ss) return;
|
|
|
|
|
2007-02-08 16:38:02 +00:00
|
|
|
if (gstate.suspend_reason & (~SUSPEND_REASON_CPU_USAGE_LIMIT)) {
|
2004-09-13 23:17:16 +00:00
|
|
|
reset();
|
2004-11-16 08:04:57 +00:00
|
|
|
ss_status = SS_STATUS_BOINCSUSPENDED;
|
2004-08-21 23:57:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-03-18 23:14:42 +00:00
|
|
|
if (gstate.disable_graphics) {
|
|
|
|
reset();
|
2006-07-18 03:24:49 +00:00
|
|
|
ss_status = SS_STATUS_DAEMONALLOWSNOGRAPHICS;
|
2006-03-18 23:14:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-08-21 23:57:25 +00:00
|
|
|
|
|
|
|
// check if it's time to go to black screen
|
|
|
|
//
|
2005-06-07 19:22:50 +00:00
|
|
|
if (blank_time && (gstate.now > blank_time)) {
|
2004-11-16 08:04:57 +00:00
|
|
|
if (SS_STATUS_BLANKED != ss_status) {
|
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] SS_LOGIC::poll(): going to black"
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
2004-09-13 23:17:16 +00:00
|
|
|
reset();
|
2004-11-16 08:04:57 +00:00
|
|
|
ss_status = SS_STATUS_BLANKED;
|
2004-08-21 23:57:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-09-13 05:27:28 +00:00
|
|
|
atp = gstate.active_tasks.get_ss_app();
|
2004-08-21 23:57:25 +00:00
|
|
|
if (atp) {
|
2005-04-05 00:32:24 +00:00
|
|
|
bool stop_app_ss = false;
|
|
|
|
if (atp->graphics_mode_acked == MODE_FULLSCREEN) {
|
|
|
|
if (atp->scheduler_state != CPU_SCHED_SCHEDULED) {
|
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] SS_LOGIC::poll(): app %s not scheduled\n",
|
2006-06-22 19:40:30 +00:00
|
|
|
atp->result->name
|
|
|
|
);
|
|
|
|
}
|
2005-04-05 00:32:24 +00:00
|
|
|
stop_app_ss = true;
|
2005-06-07 19:22:50 +00:00
|
|
|
} else if (gstate.now - ss_change_time > SS_CHANGE_PERIOD) {
|
2005-05-22 23:12:09 +00:00
|
|
|
new_atp = gstate.get_next_graphics_capable_app();
|
|
|
|
if (new_atp && (new_atp != atp)) {
|
|
|
|
stop_app_ss = true;
|
|
|
|
}
|
2005-04-05 00:32:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
2005-06-07 19:22:50 +00:00
|
|
|
if (gstate.now > ack_deadline) {
|
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] SS_LOGIC::poll(): app %s is no longer fullscreen and passed ack deadline, current time %f deadline %f",
|
2006-06-22 19:40:30 +00:00
|
|
|
atp->result->name, gstate.now, ack_deadline
|
|
|
|
);
|
|
|
|
}
|
2005-04-05 00:32:24 +00:00
|
|
|
stop_app_ss = true;
|
2004-08-21 23:57:25 +00:00
|
|
|
}
|
|
|
|
}
|
2005-04-05 00:32:24 +00:00
|
|
|
if (!stop_app_ss) return;
|
|
|
|
|
2005-05-22 23:12:09 +00:00
|
|
|
// tell app not to do SSG any more
|
2005-04-05 00:32:24 +00:00
|
|
|
//
|
|
|
|
m.mode = MODE_HIDE_GRAPHICS;
|
|
|
|
atp->request_graphics_mode(m);
|
|
|
|
atp->is_ss_app = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// here if no app currently doing SSG
|
|
|
|
// try to find one.
|
|
|
|
//
|
2005-05-22 23:12:09 +00:00
|
|
|
if (new_atp) {
|
|
|
|
atp = new_atp;
|
|
|
|
} else {
|
|
|
|
atp = gstate.get_next_graphics_capable_app();
|
|
|
|
}
|
|
|
|
|
2005-04-05 00:32:24 +00:00
|
|
|
if (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] SS_LOGIC::poll(): picked %s, request restart\n",
|
2006-06-22 19:40:30 +00:00
|
|
|
atp->result->name
|
|
|
|
);
|
|
|
|
}
|
2005-04-05 00:32:24 +00:00
|
|
|
ask_app(atp, saved_graphics_msg);
|
2006-04-04 04:39:40 +00:00
|
|
|
ss_status = SS_STATUS_ENABLED;
|
2005-06-07 19:22:50 +00:00
|
|
|
ss_change_time = gstate.now;
|
2004-08-21 23:57:25 +00:00
|
|
|
} else {
|
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] SS_LOGIC::poll(): no app found"
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
2005-04-05 00:32:24 +00:00
|
|
|
if (gstate.active_tasks.active_tasks.size()==0) {
|
|
|
|
if (gstate.projects.size()>0) {
|
|
|
|
ss_status = SS_STATUS_NOAPPSEXECUTING;
|
2003-05-08 18:11:05 +00:00
|
|
|
} else {
|
2005-04-05 00:32:24 +00:00
|
|
|
ss_status = SS_STATUS_NOPROJECTSDETECTED;
|
2003-05-08 18:11:05 +00:00
|
|
|
}
|
2005-04-05 00:32:24 +00:00
|
|
|
} else {
|
|
|
|
ss_status = SS_STATUS_NOGRAPHICSAPPSEXECUTING;
|
2003-05-08 18:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
2004-05-03 23:35:45 +00:00
|
|
|
}
|
2003-05-08 18:11:05 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_dd5060e766 = "$Id$";
|