2009-02-21 02:42:50 +00:00
|
|
|
// This file is part of BOINC.
|
2008-08-18 22:09:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2009-02-21 02:42:50 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2008-08-18 22:09:22 +00:00
|
|
|
//
|
2009-02-21 02:42:50 +00:00
|
|
|
// BOINC 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 3 of the License, or (at your option) any later version.
|
2008-08-18 22:09:22 +00:00
|
|
|
//
|
2009-02-21 02:42:50 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2008-08-18 22:09:22 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2009-02-21 02:42:50 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2008-08-18 22:09:22 +00:00
|
|
|
|
2009-09-25 17:39:50 +00:00
|
|
|
// Screensaver coordinator.
|
|
|
|
// Alternates between a "default screensaver"
|
|
|
|
// and application graphics for running jobs.
|
|
|
|
// Periods are configurable via config file "ss_config.xml".
|
|
|
|
// See http://boinc.berkeley.edu/trac/wiki/ScreensaverEnhancements
|
2009-02-25 14:56:48 +00:00
|
|
|
|
2008-08-18 22:09:22 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
2009-02-25 14:56:48 +00:00
|
|
|
#endif
|
2008-08-18 22:09:22 +00:00
|
|
|
|
2009-02-25 14:56:48 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#include <sys/wait.h>
|
2008-08-18 22:09:22 +00:00
|
|
|
#endif
|
|
|
|
|
2009-02-25 14:56:48 +00:00
|
|
|
// Common application includes
|
|
|
|
//
|
2008-08-18 22:09:22 +00:00
|
|
|
#include "diagnostics.h"
|
|
|
|
#include "common_defs.h"
|
|
|
|
#include "util.h"
|
2009-02-05 12:32:16 +00:00
|
|
|
#include "common_defs.h"
|
|
|
|
#include "filesys.h"
|
2009-02-20 11:49:49 +00:00
|
|
|
#include "error_numbers.h"
|
2009-09-25 17:39:50 +00:00
|
|
|
#include "gui_rpc_client.h"
|
2009-02-25 14:56:48 +00:00
|
|
|
#include "str_util.h"
|
2009-06-16 21:58:38 +00:00
|
|
|
#include "str_replace.h"
|
2009-02-25 14:56:48 +00:00
|
|
|
#include "screensaver.h"
|
|
|
|
|
|
|
|
// Platform specific application includes
|
|
|
|
//
|
|
|
|
#if defined(_WIN32)
|
|
|
|
#include "screensaver_win.h"
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
#include "Mac_Saver_Module.h"
|
|
|
|
#endif
|
2009-02-05 12:32:16 +00:00
|
|
|
|
2008-08-18 22:09:22 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2009-02-14 01:43:08 +00:00
|
|
|
// Allow for Unicode wide characters
|
|
|
|
#define PATH_SEPARATOR (_T("\\"))
|
|
|
|
#define THE_DEFAULT_SS_EXECUTABLE (_T(DEFAULT_SS_EXECUTABLE))
|
|
|
|
#define THE_SS_CONFIG_FILE (_T(SS_CONFIG_FILE))
|
2009-02-20 11:49:49 +00:00
|
|
|
#define DEFAULT_GFX_CANT_CONNECT ERR_CONNECT
|
2009-02-06 02:17:45 +00:00
|
|
|
#else
|
2009-02-14 01:43:08 +00:00
|
|
|
// Using (_T()) here causes compiler errors on Mac
|
2009-02-06 02:17:45 +00:00
|
|
|
#define PATH_SEPARATOR "/"
|
2009-02-14 01:43:08 +00:00
|
|
|
#define THE_DEFAULT_SS_EXECUTABLE DEFAULT_SS_EXECUTABLE
|
|
|
|
#define THE_SS_CONFIG_FILE SS_CONFIG_FILE
|
2009-02-20 11:49:49 +00:00
|
|
|
#define DEFAULT_GFX_CANT_CONNECT (ERR_CONNECT & 0xff)
|
2008-08-18 22:09:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Flags for testing & debugging
|
|
|
|
#define SIMULATE_NO_GRAPHICS 0
|
|
|
|
|
|
|
|
|
|
|
|
bool CScreensaver::is_same_task(RESULT* taska, RESULT* taskb) {
|
|
|
|
if ((taska == NULL) || (taskb == NULL)) return false;
|
2010-03-23 17:11:33 +00:00
|
|
|
if (strcmp(taska->name, taskb->name)) return false;
|
|
|
|
if (strcmp(taska->project_url, taskb->project_url)) return false;
|
2008-08-18 22:09:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CScreensaver::count_active_graphic_apps(RESULTS& results, RESULT* exclude) {
|
|
|
|
unsigned int i = 0;
|
|
|
|
unsigned int graphics_app_count = 0;
|
|
|
|
m_bV5_GFX_app_is_running = false;
|
|
|
|
|
|
|
|
// Count the number of active graphics-capable apps excluding the specified result.
|
|
|
|
// If exclude is NULL, don't exclude any results.
|
|
|
|
for (i = 0; i < results.results.size(); i++) {
|
|
|
|
BOINCTRACE(_T("get_random_graphics_app -- active task detected\n"));
|
|
|
|
BOINCTRACE(
|
|
|
|
_T("get_random_graphics_app -- name = '%s', path = '%s'\n"),
|
2010-03-13 04:25:07 +00:00
|
|
|
results.results[i]->name, results.results[i]->graphics_exec_path
|
2008-08-18 22:09:22 +00:00
|
|
|
);
|
|
|
|
if (results.results[i]->supports_graphics) m_bV5_GFX_app_is_running = true;
|
2010-03-13 04:25:07 +00:00
|
|
|
if (!strlen(results.results[i]->graphics_exec_path)
|
2010-03-23 17:11:33 +00:00
|
|
|
&& (state.executing_as_daemon || !(results.results[i]->supports_graphics))
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-08-18 22:09:22 +00:00
|
|
|
BOINCTRACE(_T("get_random_graphics_app -- active task detected w/graphics\n"));
|
2009-02-06 11:17:13 +00:00
|
|
|
|
2008-08-18 22:09:22 +00:00
|
|
|
if (is_same_task(results.results[i], exclude)) continue;
|
|
|
|
graphics_app_count++;
|
|
|
|
}
|
|
|
|
return graphics_app_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Choose a random graphics application out of the vector.
|
|
|
|
// Exclude the specified result unless it is the only candidate.
|
|
|
|
// If exclude is NULL or an empty string, don't exclude any results.
|
|
|
|
//
|
|
|
|
RESULT* CScreensaver::get_random_graphics_app(RESULTS& results, RESULT* exclude) {
|
|
|
|
RESULT* rp = NULL;
|
|
|
|
unsigned int i = 0;
|
|
|
|
unsigned int graphics_app_count = 0;
|
|
|
|
unsigned int random_selection = 0;
|
|
|
|
unsigned int current_counter = 0;
|
|
|
|
RESULT *avoid = exclude;
|
|
|
|
|
|
|
|
BOINCTRACE(_T("get_random_graphics_app -- Function Start\n"));
|
|
|
|
|
|
|
|
graphics_app_count = count_active_graphic_apps(results, avoid);
|
|
|
|
BOINCTRACE(_T("get_random_graphics_app -- graphics_app_count = '%d'\n"), graphics_app_count);
|
|
|
|
|
|
|
|
// If no graphics app found other than the one excluded, count again without excluding any
|
|
|
|
if ((0 == graphics_app_count) && (avoid != NULL)) {
|
|
|
|
avoid = NULL;
|
|
|
|
graphics_app_count = count_active_graphic_apps(results, avoid);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no graphics app was found, return NULL
|
|
|
|
if (0 == graphics_app_count) {
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Choose which application to display.
|
|
|
|
random_selection = (rand() % graphics_app_count) + 1;
|
|
|
|
BOINCTRACE(_T("get_random_graphics_app -- random_selection = '%d'\n"), random_selection);
|
|
|
|
|
|
|
|
// Lets find the chosen graphics application.
|
|
|
|
for (i = 0; i < results.results.size(); i++) {
|
2010-03-13 04:25:07 +00:00
|
|
|
if (!strlen(results.results[i]->graphics_exec_path)
|
2010-03-23 17:11:33 +00:00
|
|
|
&& (state.executing_as_daemon || !(results.results[i]->supports_graphics))
|
|
|
|
){
|
|
|
|
continue;
|
|
|
|
}
|
2008-08-18 22:09:22 +00:00
|
|
|
if (is_same_task(results.results[i], avoid)) continue;
|
|
|
|
|
|
|
|
current_counter++;
|
|
|
|
if (current_counter == random_selection) {
|
|
|
|
rp = results.results[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CLEANUP:
|
|
|
|
BOINCTRACE(_T("get_random_graphics_app -- Function End\n"));
|
|
|
|
|
|
|
|
return rp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-02 10:25:16 +00:00
|
|
|
// Launch a project (science) graphics application
|
2008-08-18 22:09:22 +00:00
|
|
|
//
|
|
|
|
#ifdef _WIN32
|
|
|
|
int CScreensaver::launch_screensaver(RESULT* rp, HANDLE& graphics_application)
|
|
|
|
#else
|
|
|
|
int CScreensaver::launch_screensaver(RESULT* rp, int& graphics_application)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
int retval = 0;
|
2010-03-13 04:25:07 +00:00
|
|
|
if (strlen(rp->graphics_exec_path)) {
|
2008-08-18 22:09:22 +00:00
|
|
|
// V6 Graphics
|
|
|
|
#ifdef __APPLE__
|
|
|
|
// For sandbox security, use gfx_switcher to launch gfx app
|
|
|
|
// as user boinc_project and group boinc_project.
|
|
|
|
//
|
|
|
|
// For unknown reasons, the graphics application exits with
|
|
|
|
// "RegisterProcess failed (error = -50)" unless we pass its
|
|
|
|
// full path twice in the argument list to execv.
|
|
|
|
char* argv[5];
|
|
|
|
argv[0] = "gfx_Switcher";
|
|
|
|
argv[1] = "-launch_gfx";
|
2010-03-23 09:52:05 +00:00
|
|
|
argv[2] = strrchr(rp->slot_path, '/');
|
2008-08-18 22:09:22 +00:00
|
|
|
if (*argv[2]) argv[2]++; // Point to the slot number in ascii
|
|
|
|
|
|
|
|
argv[3] = "--fullscreen";
|
|
|
|
argv[4] = 0;
|
|
|
|
|
|
|
|
retval = run_program(
|
2010-03-23 09:52:05 +00:00
|
|
|
rp->slot_path,
|
2008-08-18 22:09:22 +00:00
|
|
|
m_gfx_Switcher_Path,
|
|
|
|
4,
|
|
|
|
argv,
|
|
|
|
0,
|
|
|
|
graphics_application
|
|
|
|
);
|
|
|
|
#else
|
|
|
|
char* argv[3];
|
|
|
|
argv[0] = "app_graphics"; // not used
|
|
|
|
argv[1] = "--fullscreen";
|
|
|
|
argv[2] = 0;
|
|
|
|
retval = run_program(
|
2010-03-13 04:25:07 +00:00
|
|
|
rp->slot_path,
|
|
|
|
rp->graphics_exec_path,
|
2008-08-18 22:09:22 +00:00
|
|
|
2,
|
|
|
|
argv,
|
|
|
|
0,
|
|
|
|
graphics_application
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
// V5 and Older
|
|
|
|
DISPLAY_INFO di;
|
|
|
|
#ifdef _WIN32
|
|
|
|
graphics_application = NULL;
|
|
|
|
|
|
|
|
memset(di.window_station, 0, sizeof(di.window_station));
|
|
|
|
memset(di.desktop, 0, sizeof(di.desktop));
|
|
|
|
memset(di.display, 0, sizeof(di.display));
|
|
|
|
|
2009-07-25 03:53:25 +00:00
|
|
|
// Retrieve the current window station and desktop names
|
|
|
|
GetUserObjectInformation(
|
|
|
|
GetProcessWindowStation(),
|
|
|
|
UOI_NAME,
|
|
|
|
di.window_station,
|
|
|
|
(sizeof(di.window_station)),
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
GetUserObjectInformation(
|
|
|
|
GetThreadDesktop(GetCurrentThreadId()),
|
|
|
|
UOI_NAME,
|
|
|
|
di.desktop,
|
|
|
|
sizeof(di.desktop),
|
|
|
|
NULL
|
|
|
|
);
|
2008-08-18 22:09:22 +00:00
|
|
|
#else
|
|
|
|
char *p = getenv("DISPLAY");
|
|
|
|
if (p) strcpy(di.display, p);
|
|
|
|
|
|
|
|
graphics_application = 0;
|
|
|
|
#endif
|
|
|
|
retval = rpc->show_graphics(
|
2010-03-13 04:25:07 +00:00
|
|
|
rp->project_url,
|
|
|
|
rp->name,
|
2008-08-18 22:09:22 +00:00
|
|
|
MODE_FULLSCREEN,
|
|
|
|
di
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-15 08:28:51 +00:00
|
|
|
// Terminate any V6 acreensaver graphics application
|
|
|
|
//
|
|
|
|
#ifdef _WIN32
|
|
|
|
int CScreensaver::terminate_v6_screensaver(HANDLE& graphics_application)
|
|
|
|
#else
|
|
|
|
int CScreensaver::terminate_v6_screensaver(int& graphics_application)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
// Under sandbox security, use gfx_switcher to kill default gfx app
|
|
|
|
// as user boinc_master and group boinc_master. The man page for
|
|
|
|
// kill() says the user ID of the process sending the signal must
|
|
|
|
// match that of the target process, though in practice that seems
|
|
|
|
// not to be true on the Mac.
|
|
|
|
|
2009-12-04 14:39:35 +00:00
|
|
|
char current_dir[PATH_MAX];
|
2009-04-15 08:28:51 +00:00
|
|
|
char gfx_pid[16];
|
|
|
|
pid_t thePID;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sprintf(gfx_pid, "%d", graphics_application);
|
|
|
|
getcwd( current_dir, sizeof(current_dir));
|
|
|
|
|
|
|
|
char* argv[4];
|
|
|
|
argv[0] = "gfx_switcher";
|
|
|
|
argv[1] = "-kill_gfx";
|
|
|
|
argv[2] = gfx_pid;
|
|
|
|
argv[3] = 0;
|
|
|
|
|
|
|
|
retval = run_program(
|
|
|
|
current_dir,
|
|
|
|
m_gfx_Switcher_Path,
|
|
|
|
3,
|
|
|
|
argv,
|
|
|
|
0,
|
|
|
|
thePID
|
|
|
|
);
|
|
|
|
|
|
|
|
for (i=0; i<200; i++) {
|
|
|
|
boinc_sleep(0.01); // Wait 2 seconds max
|
|
|
|
// Prevent gfx_switcher from becoming a zombie
|
|
|
|
if (waitpid(thePID, 0, WNOHANG) == thePID) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// For safety, call kill_program even under Apple sandbox security
|
|
|
|
kill_program(graphics_application);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-02 10:25:16 +00:00
|
|
|
// Terminate the project (science) graphics application
|
2008-08-18 22:09:22 +00:00
|
|
|
//
|
|
|
|
#ifdef _WIN32
|
|
|
|
int CScreensaver::terminate_screensaver(HANDLE& graphics_application, RESULT *worker_app)
|
|
|
|
#else
|
|
|
|
int CScreensaver::terminate_screensaver(int& graphics_application, RESULT *worker_app)
|
|
|
|
#endif
|
|
|
|
{
|
2009-04-15 08:28:51 +00:00
|
|
|
int retval = 0;
|
|
|
|
|
2008-08-18 22:09:22 +00:00
|
|
|
if (graphics_application) {
|
|
|
|
// V6 Graphics
|
2009-04-15 08:28:51 +00:00
|
|
|
if (m_bScience_gfx_running) {
|
|
|
|
terminate_v6_screensaver(graphics_application);
|
2009-02-23 23:06:03 +00:00
|
|
|
}
|
2008-08-18 22:09:22 +00:00
|
|
|
} else {
|
|
|
|
// V5 and Older
|
|
|
|
DISPLAY_INFO di;
|
|
|
|
|
|
|
|
if (worker_app == NULL) return 0;
|
2010-03-13 04:25:07 +00:00
|
|
|
if (!strlen(worker_app->name)) return 0;
|
2008-08-18 22:09:22 +00:00
|
|
|
|
|
|
|
memset(di.window_station, 0, sizeof(di.window_station));
|
|
|
|
memset(di.desktop, 0, sizeof(di.desktop));
|
|
|
|
memset(di.display, 0, sizeof(di.display));
|
|
|
|
|
|
|
|
rpc->show_graphics(
|
2010-03-13 04:25:07 +00:00
|
|
|
worker_app->project_url,
|
|
|
|
worker_app->name,
|
2008-08-18 22:09:22 +00:00
|
|
|
MODE_HIDE_GRAPHICS,
|
|
|
|
di
|
|
|
|
);
|
|
|
|
}
|
2009-04-15 08:28:51 +00:00
|
|
|
return retval;
|
2008-08-18 22:09:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-02 01:48:44 +00:00
|
|
|
// Launch the default graphics application
|
2009-02-05 12:32:16 +00:00
|
|
|
//
|
|
|
|
#ifdef _WIN32
|
|
|
|
int CScreensaver::launch_default_screensaver(char *dir_path, HANDLE& graphics_application)
|
|
|
|
#else
|
|
|
|
int CScreensaver::launch_default_screensaver(char *dir_path, int& graphics_application)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
int retval = 0;
|
2009-04-02 01:48:44 +00:00
|
|
|
int num_args;
|
2009-02-05 12:32:16 +00:00
|
|
|
|
2009-04-02 01:48:44 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
// For sandbox security, use gfx_switcher to launch default
|
|
|
|
// gfx app as user boinc_master and group boinc_master.
|
|
|
|
char* argv[6];
|
|
|
|
|
|
|
|
argv[0] = "gfx_switcher";
|
|
|
|
argv[1] = "-default_gfx";
|
|
|
|
argv[2] = THE_DEFAULT_SS_EXECUTABLE; // Will be changed by gfx_switcher
|
|
|
|
argv[3] = "--fullscreen";
|
|
|
|
argv[4] = 0;
|
|
|
|
argv[5] = 0;
|
|
|
|
if (!m_bConnected) {
|
|
|
|
BOINCTRACE(_T("launch_default_screensaver using --retry_connect argument\n"));
|
|
|
|
argv[4] = "--retry_connect";
|
|
|
|
num_args = 5;
|
|
|
|
} else {
|
|
|
|
num_args = 4;
|
|
|
|
}
|
2009-02-05 12:32:16 +00:00
|
|
|
|
2009-04-02 01:48:44 +00:00
|
|
|
retval = run_program(
|
|
|
|
dir_path,
|
|
|
|
m_gfx_Switcher_Path,
|
|
|
|
num_args,
|
|
|
|
argv,
|
|
|
|
0,
|
|
|
|
graphics_application
|
|
|
|
);
|
2009-05-29 08:36:42 +00:00
|
|
|
|
|
|
|
BOINCTRACE(_T("launch_default_screensaver returned %d\n"), retval);
|
2009-04-02 01:48:44 +00:00
|
|
|
|
|
|
|
#else
|
2009-02-05 12:32:16 +00:00
|
|
|
// For unknown reasons, the graphics application exits with
|
|
|
|
// "RegisterProcess failed (error = -50)" unless we pass its
|
|
|
|
// full path twice in the argument list to execv on Macs.
|
|
|
|
|
2009-02-20 11:49:49 +00:00
|
|
|
char* argv[4];
|
2009-04-02 01:48:44 +00:00
|
|
|
char full_path[1024];
|
|
|
|
|
|
|
|
strlcpy(full_path, dir_path, sizeof(full_path));
|
|
|
|
strlcat(full_path, PATH_SEPARATOR, sizeof(full_path));
|
|
|
|
strlcat(full_path, THE_DEFAULT_SS_EXECUTABLE, sizeof(full_path));
|
|
|
|
|
2009-02-05 12:32:16 +00:00
|
|
|
argv[0] = full_path; // not used
|
|
|
|
argv[1] = "--fullscreen";
|
|
|
|
argv[2] = 0;
|
2009-02-20 11:49:49 +00:00
|
|
|
argv[3] = 0;
|
|
|
|
if (!m_bConnected) {
|
|
|
|
BOINCTRACE(_T("launch_default_screensaver using --retry_connect argument\n"));
|
|
|
|
argv[2] = "--retry_connect";
|
|
|
|
num_args = 3;
|
2009-04-02 01:48:44 +00:00
|
|
|
} else {
|
|
|
|
num_args = 2;
|
2009-02-20 11:49:49 +00:00
|
|
|
}
|
2009-04-02 01:48:44 +00:00
|
|
|
|
2009-02-05 12:32:16 +00:00
|
|
|
retval = run_program(
|
|
|
|
dir_path,
|
|
|
|
full_path,
|
2009-02-20 11:49:49 +00:00
|
|
|
num_args,
|
2009-02-05 12:32:16 +00:00
|
|
|
argv,
|
|
|
|
0,
|
|
|
|
graphics_application
|
|
|
|
);
|
2009-05-29 08:36:42 +00:00
|
|
|
|
2009-02-05 12:32:16 +00:00
|
|
|
BOINCTRACE(_T("launch_default_screensaver %s returned %d\n"), full_path, retval);
|
2009-05-29 08:36:42 +00:00
|
|
|
|
2009-04-02 01:48:44 +00:00
|
|
|
#endif
|
2009-02-05 12:32:16 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-02 10:25:16 +00:00
|
|
|
// Terminate the default graphics application
|
|
|
|
//
|
|
|
|
#ifdef _WIN32
|
|
|
|
int CScreensaver::terminate_default_screensaver(HANDLE& graphics_application)
|
|
|
|
#else
|
|
|
|
int CScreensaver::terminate_default_screensaver(int& graphics_application)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
if (! graphics_application) return 0;
|
2009-04-15 08:28:51 +00:00
|
|
|
retval = terminate_v6_screensaver(graphics_application);
|
2009-04-02 10:25:16 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-20 11:49:49 +00:00
|
|
|
// If we cannot connect to the core client:
|
|
|
|
// - we retry connecting every 10 seconds
|
|
|
|
// - we launch the default graphics application with the argument --retry_connect, so
|
|
|
|
// it will continue running and will also retry connecting every 10 seconds.
|
|
|
|
//
|
|
|
|
// If we successfully connected to the core client, launch the default graphics application
|
|
|
|
// without the argument --retry_connect. If it can't connect, it will return immediately
|
|
|
|
// with the exit code ERR_CONNECT. In that case, we assume it was blocked by a firewall
|
|
|
|
// and so we run only project (science) graphics.
|
|
|
|
|
2008-08-18 22:09:22 +00:00
|
|
|
#ifdef _WIN32
|
2009-02-10 12:35:12 +00:00
|
|
|
DWORD WINAPI CScreensaver::DataManagementProc()
|
2008-08-18 22:09:22 +00:00
|
|
|
#else
|
2009-02-10 12:35:12 +00:00
|
|
|
void *CScreensaver::DataManagementProc()
|
2008-08-18 22:09:22 +00:00
|
|
|
#endif
|
2009-02-10 12:35:12 +00:00
|
|
|
{
|
2009-02-06 11:17:13 +00:00
|
|
|
int retval = 0;
|
|
|
|
int suspend_reason = 0;
|
|
|
|
RESULT* theResult = NULL;
|
|
|
|
RESULT* graphics_app_result_ptr = NULL;
|
2008-08-18 22:09:22 +00:00
|
|
|
RESULT previous_result;
|
2008-08-18 23:39:50 +00:00
|
|
|
// previous_result_ptr = &previous_result when previous_result is valid, else NULL
|
2009-02-06 11:17:13 +00:00
|
|
|
RESULT* previous_result_ptr = NULL;
|
|
|
|
int iResultCount = 0;
|
|
|
|
int iIndex = 0;
|
|
|
|
double default_phase_start_time = 0.0;
|
|
|
|
double science_phase_start_time = 0.0;
|
|
|
|
double last_change_time = 0.0;
|
|
|
|
// If we run default screensaver during science phase because no science graphics
|
|
|
|
// are available, then shorten next default graphics phase by that much time.
|
2009-02-12 11:54:57 +00:00
|
|
|
double default_saver_start_time_in_science_phase = 0.0;
|
|
|
|
double default_saver_duration_in_science_phase = 0.0;
|
2009-02-06 11:17:13 +00:00
|
|
|
|
|
|
|
SS_PHASE ss_phase = DEFAULT_SS_PHASE;
|
|
|
|
bool switch_to_default_gfx = false;
|
2009-02-27 11:20:08 +00:00
|
|
|
bool killing_default_gfx = false;
|
2009-02-20 11:49:49 +00:00
|
|
|
int exit_status = 0;
|
2009-02-13 11:08:32 +00:00
|
|
|
|
|
|
|
char* default_ss_dir_path = NULL;
|
2009-02-05 12:32:16 +00:00
|
|
|
char full_path[1024];
|
2008-08-18 22:09:22 +00:00
|
|
|
|
|
|
|
BOINCTRACE(_T("CScreensaver::DataManagementProc - Display screen saver loading message\n"));
|
2009-02-27 11:20:08 +00:00
|
|
|
SetError(TRUE, SCRAPPERR_BOINCSCREENSAVERLOADING); // No GFX App is running: show moving BOINC logo
|
|
|
|
#ifdef _WIN32
|
2008-08-18 22:09:22 +00:00
|
|
|
m_tThreadCreateTime = time(0);
|
|
|
|
|
|
|
|
// Set the starting point for iterating through the results
|
|
|
|
m_iLastResultShown = 0;
|
|
|
|
m_tLastResultChangeTime = 0;
|
2009-02-05 12:32:16 +00:00
|
|
|
#endif
|
|
|
|
|
2009-02-06 02:17:45 +00:00
|
|
|
m_bDefault_ss_exists = false;
|
2009-02-10 12:35:12 +00:00
|
|
|
m_bScience_gfx_running = false;
|
|
|
|
m_bDefault_gfx_running = false;
|
2009-05-29 08:36:42 +00:00
|
|
|
m_bShow_default_ss_first = false;
|
2009-02-06 02:17:45 +00:00
|
|
|
|
2009-02-05 12:32:16 +00:00
|
|
|
#ifdef __APPLE__
|
2009-12-14 13:10:49 +00:00
|
|
|
default_ss_dir_path = "/Library/Application Support/BOINC Data";
|
2009-02-05 12:32:16 +00:00
|
|
|
#else
|
2009-02-23 06:09:16 +00:00
|
|
|
default_ss_dir_path = (char*)m_strBOINCInstallDirectory.c_str();
|
2009-02-05 12:32:16 +00:00
|
|
|
#endif
|
2009-02-23 06:09:16 +00:00
|
|
|
|
2009-02-05 12:32:16 +00:00
|
|
|
strlcpy(full_path, default_ss_dir_path, sizeof(full_path));
|
2009-02-06 02:17:45 +00:00
|
|
|
strlcat(full_path, PATH_SEPARATOR, sizeof(full_path));
|
2009-02-14 01:43:08 +00:00
|
|
|
strlcat(full_path, THE_DEFAULT_SS_EXECUTABLE, sizeof(full_path));
|
2009-12-14 13:10:49 +00:00
|
|
|
|
2009-02-05 12:32:16 +00:00
|
|
|
if (boinc_file_exists(full_path)) {
|
2009-02-06 02:17:45 +00:00
|
|
|
m_bDefault_ss_exists = true;
|
2009-05-29 08:36:42 +00:00
|
|
|
} else {
|
|
|
|
SetError(TRUE, SCRAPPERR_CANTLAUNCHDEFAULTGFXAPP); // No GFX App is running: show moving BOINC logo
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_bDefault_ss_exists && m_bShow_default_ss_first) {
|
2009-02-05 12:32:16 +00:00
|
|
|
ss_phase = DEFAULT_SS_PHASE;
|
|
|
|
default_phase_start_time = dtime();
|
|
|
|
science_phase_start_time = 0;
|
|
|
|
switch_to_default_gfx = true;
|
|
|
|
} else {
|
|
|
|
ss_phase = SCIENCE_SS_PHASE;
|
|
|
|
default_phase_start_time = 0;
|
|
|
|
science_phase_start_time = dtime();
|
|
|
|
}
|
2008-08-18 22:09:22 +00:00
|
|
|
|
|
|
|
while (true) {
|
2009-02-23 06:09:16 +00:00
|
|
|
|
2008-08-18 22:09:22 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2008-08-29 19:06:04 +00:00
|
|
|
// ***
|
|
|
|
// *** Things that should be run frequently.
|
|
|
|
// *** 4 times per second.
|
|
|
|
// ***
|
2008-08-18 22:09:22 +00:00
|
|
|
|
2008-08-29 19:06:04 +00:00
|
|
|
// Are we supposed to exit the screensaver?
|
2008-08-18 22:09:22 +00:00
|
|
|
if (m_QuitDataManagementProc) { // If main thread has requested we exit
|
|
|
|
if (m_hGraphicsApplication || graphics_app_result_ptr) {
|
2009-04-02 10:25:16 +00:00
|
|
|
if (m_bDefault_gfx_running) {
|
|
|
|
terminate_default_screensaver(m_hGraphicsApplication);
|
|
|
|
} else {
|
|
|
|
terminate_screensaver(m_hGraphicsApplication, graphics_app_result_ptr);
|
|
|
|
}
|
2008-08-18 22:09:22 +00:00
|
|
|
graphics_app_result_ptr = NULL;
|
|
|
|
previous_result_ptr = NULL;
|
|
|
|
m_hGraphicsApplication = 0;
|
|
|
|
}
|
2009-03-03 12:08:49 +00:00
|
|
|
m_hDataManagementThread = NULL; // Tell main thread that we exited
|
2008-08-18 22:09:22 +00:00
|
|
|
return 0; // Exit the thread
|
|
|
|
}
|
|
|
|
boinc_sleep(0.25);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ***
|
|
|
|
// *** Things that should be run frequently.
|
|
|
|
// *** 1 time per second.
|
|
|
|
// ***
|
|
|
|
|
|
|
|
// Blank screen saver?
|
2009-12-14 13:10:49 +00:00
|
|
|
if ((m_dwBlankScreen) && (time(0) > m_dwBlankTime) && (m_dwBlankTime > 0)) {
|
2008-08-18 22:09:22 +00:00
|
|
|
BOINCTRACE(_T("CScreensaver::DataManagementProc - Time to blank\n"));
|
2009-02-27 11:20:08 +00:00
|
|
|
SetError(FALSE, SCRAPPERR_SCREENSAVERBLANKED); // Blanked - hide moving BOINC logo
|
2008-08-18 22:09:22 +00:00
|
|
|
m_QuitDataManagementProc = true;
|
2009-02-23 23:16:02 +00:00
|
|
|
continue; // Code above will exit the thread
|
2008-08-18 22:09:22 +00:00
|
|
|
}
|
|
|
|
|
2009-02-20 11:49:49 +00:00
|
|
|
BOINCTRACE(_T("CScreensaver::DataManagementProc - ErrorMode = '%d', ErrorCode = '%x'\n"), m_bErrorMode, m_hrError);
|
|
|
|
|
2009-02-23 06:09:16 +00:00
|
|
|
if (!m_bConnected) {
|
2009-02-20 11:49:49 +00:00
|
|
|
HandleRPCError();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_bConnected) {
|
|
|
|
// Do we need to get the core client state?
|
|
|
|
if (m_bResetCoreState) {
|
|
|
|
// Try and get the current state of the CC
|
|
|
|
retval = rpc->get_state(state);
|
|
|
|
if (retval) {
|
|
|
|
// CC may not yet be running
|
|
|
|
HandleRPCError();
|
2009-03-03 12:08:49 +00:00
|
|
|
continue;
|
2009-02-20 11:49:49 +00:00
|
|
|
} else {
|
|
|
|
m_bResetCoreState = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update our task list
|
|
|
|
retval = rpc->get_screensaver_tasks(suspend_reason, results);
|
2008-08-18 22:09:22 +00:00
|
|
|
if (retval) {
|
2009-02-20 11:49:49 +00:00
|
|
|
// rpc call returned error
|
2008-08-18 22:09:22 +00:00
|
|
|
HandleRPCError();
|
2009-02-20 11:49:49 +00:00
|
|
|
m_bResetCoreState = true;
|
2008-08-18 22:09:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-02-20 11:49:49 +00:00
|
|
|
} else {
|
|
|
|
results.clear();
|
2008-08-18 22:09:22 +00:00
|
|
|
}
|
2009-02-20 11:49:49 +00:00
|
|
|
|
2009-02-06 11:17:13 +00:00
|
|
|
// Time to switch to default graphics phase?
|
2009-12-14 13:10:49 +00:00
|
|
|
if (m_bDefault_ss_exists && (ss_phase == SCIENCE_SS_PHASE) && (m_fGFXDefaultPeriod > 0)) {
|
|
|
|
if (science_phase_start_time && ((dtime() - science_phase_start_time) > m_fGFXSciencePeriod)) {
|
2009-02-12 12:58:24 +00:00
|
|
|
if (!m_bDefault_gfx_running) {
|
|
|
|
switch_to_default_gfx = true;
|
|
|
|
}
|
2009-02-05 12:32:16 +00:00
|
|
|
ss_phase = DEFAULT_SS_PHASE;
|
|
|
|
default_phase_start_time = dtime();
|
|
|
|
science_phase_start_time = 0;
|
2009-02-12 11:54:57 +00:00
|
|
|
if (m_bDefault_gfx_running && default_saver_start_time_in_science_phase) {
|
|
|
|
// Remember how long default graphics ran during science phase
|
|
|
|
default_saver_duration_in_science_phase += (dtime() - default_saver_start_time_in_science_phase);
|
|
|
|
}
|
|
|
|
default_saver_start_time_in_science_phase = 0;
|
2009-02-05 12:32:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-12 12:58:24 +00:00
|
|
|
// Time to switch to science graphics phase?
|
2009-12-14 13:10:49 +00:00
|
|
|
if ((ss_phase == DEFAULT_SS_PHASE) && m_bConnected && (m_fGFXSciencePeriod > 0)) {
|
2009-02-12 12:58:24 +00:00
|
|
|
if (default_phase_start_time &&
|
|
|
|
((dtime() - default_phase_start_time + default_saver_duration_in_science_phase)
|
|
|
|
> m_fGFXDefaultPeriod)) {
|
|
|
|
// BOINCTRACE(_T("CScreensaver::Ending Default phase: now=%f, default_phase_start_time=%f, default_saver_duration_in_science_phase=%f\n"),
|
|
|
|
// dtime(), default_phase_start_time, default_saver_duration_in_science_phase);
|
|
|
|
ss_phase = SCIENCE_SS_PHASE;
|
|
|
|
default_phase_start_time = 0;
|
|
|
|
default_saver_duration_in_science_phase = 0;
|
|
|
|
science_phase_start_time = dtime();
|
|
|
|
if (m_bDefault_gfx_running) {
|
|
|
|
default_saver_start_time_in_science_phase = science_phase_start_time;
|
|
|
|
}
|
|
|
|
switch_to_default_gfx = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Core client suspended?
|
2010-03-11 01:39:14 +00:00
|
|
|
if (suspend_reason && !(suspend_reason & SUSPEND_REASON_CPU_THROTTLE)) {
|
2009-02-27 11:20:08 +00:00
|
|
|
SetError(TRUE, m_hrError); // No GFX App is running: show moving BOINC logo
|
2009-02-12 12:58:24 +00:00
|
|
|
if (m_bDefault_ss_exists && !m_bDefault_gfx_running) {
|
|
|
|
switch_to_default_gfx = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-05 12:32:16 +00:00
|
|
|
if (switch_to_default_gfx) {
|
2009-02-10 12:35:12 +00:00
|
|
|
if (m_bScience_gfx_running) {
|
2009-02-05 12:32:16 +00:00
|
|
|
if (m_hGraphicsApplication || previous_result_ptr) {
|
|
|
|
// use previous_result_ptr because graphics_app_result_ptr may no longer be valid
|
|
|
|
terminate_screensaver(m_hGraphicsApplication, previous_result_ptr);
|
|
|
|
if (m_hGraphicsApplication == 0) {
|
|
|
|
graphics_app_result_ptr = NULL;
|
2009-02-10 12:35:12 +00:00
|
|
|
m_bScience_gfx_running = false;
|
2009-02-05 12:32:16 +00:00
|
|
|
} else {
|
2009-02-27 11:20:08 +00:00
|
|
|
// HasProcessExited() test will clear m_hGraphicsApplication and graphics_app_result_ptr
|
2009-02-05 12:32:16 +00:00
|
|
|
}
|
|
|
|
previous_result_ptr = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2009-02-12 11:54:57 +00:00
|
|
|
if (!m_bDefault_gfx_running) {
|
2009-02-05 12:32:16 +00:00
|
|
|
switch_to_default_gfx = false;
|
|
|
|
retval = launch_default_screensaver(default_ss_dir_path, m_hGraphicsApplication);
|
|
|
|
if (retval) {
|
|
|
|
m_hGraphicsApplication = 0;
|
|
|
|
previous_result_ptr = NULL;
|
|
|
|
graphics_app_result_ptr = NULL;
|
2009-02-10 12:35:12 +00:00
|
|
|
m_bDefault_gfx_running = false;
|
2009-02-27 11:20:08 +00:00
|
|
|
SetError(TRUE, SCRAPPERR_CANTLAUNCHDEFAULTGFXAPP); // No GFX App is running: show moving BOINC logo
|
|
|
|
} else {
|
2009-02-10 12:35:12 +00:00
|
|
|
m_bDefault_gfx_running = true;
|
2009-02-06 11:17:13 +00:00
|
|
|
if (ss_phase == SCIENCE_SS_PHASE) {
|
2009-02-12 11:54:57 +00:00
|
|
|
default_saver_start_time_in_science_phase = dtime();
|
2009-02-06 11:17:13 +00:00
|
|
|
}
|
2009-02-27 11:20:08 +00:00
|
|
|
SetError(FALSE, m_hrError); // A GFX App is running: hide moving BOINC logo
|
2009-02-05 12:32:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-12 12:58:24 +00:00
|
|
|
if ((ss_phase == SCIENCE_SS_PHASE) && !switch_to_default_gfx) {
|
2009-02-05 12:32:16 +00:00
|
|
|
|
2008-08-18 22:09:22 +00:00
|
|
|
#if SIMULATE_NO_GRAPHICS /* FOR TESTING */
|
|
|
|
|
2009-02-27 11:20:08 +00:00
|
|
|
SetError(TRUE, m_hrError); // No GFX App is running: show moving BOINC logo
|
2009-02-10 12:35:12 +00:00
|
|
|
if (m_bDefault_ss_exists && !m_bDefault_gfx_running) {
|
2009-02-05 12:32:16 +00:00
|
|
|
switch_to_default_gfx = true;
|
|
|
|
}
|
2008-08-18 22:09:22 +00:00
|
|
|
|
|
|
|
#else /* NORMAL OPERATION */
|
|
|
|
|
2009-02-10 12:35:12 +00:00
|
|
|
if (m_bScience_gfx_running) {
|
2009-02-05 12:32:16 +00:00
|
|
|
// Is the current graphics app's associated task still running?
|
|
|
|
|
|
|
|
if ((m_hGraphicsApplication) || (graphics_app_result_ptr)) {
|
2009-12-16 19:55:09 +00:00
|
|
|
iResultCount = (int)results.results.size();
|
2009-02-05 12:32:16 +00:00
|
|
|
graphics_app_result_ptr = NULL;
|
2008-08-18 22:09:22 +00:00
|
|
|
|
2009-02-05 12:32:16 +00:00
|
|
|
// Find the current task in the new results vector (if it still exists)
|
|
|
|
for (iIndex = 0; iIndex < iResultCount; iIndex++) {
|
|
|
|
theResult = results.results.at(iIndex);
|
2008-08-18 22:09:22 +00:00
|
|
|
|
2009-02-05 12:32:16 +00:00
|
|
|
if (is_same_task(theResult, previous_result_ptr)) {
|
|
|
|
graphics_app_result_ptr = theResult;
|
|
|
|
previous_result = *theResult;
|
|
|
|
previous_result_ptr = &previous_result;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-08-18 22:09:22 +00:00
|
|
|
|
2009-02-05 12:32:16 +00:00
|
|
|
// V6 graphics only: if worker application has stopped running, terminate_screensaver
|
|
|
|
if ((graphics_app_result_ptr == NULL) && (m_hGraphicsApplication != 0)) {
|
|
|
|
if (previous_result_ptr) {
|
|
|
|
BOINCTRACE(_T("CScreensaver::DataManagementProc - %s finished\n"),
|
2010-03-13 04:25:07 +00:00
|
|
|
previous_result.graphics_exec_path
|
|
|
|
);
|
2009-02-05 12:32:16 +00:00
|
|
|
}
|
|
|
|
terminate_screensaver(m_hGraphicsApplication, previous_result_ptr);
|
|
|
|
previous_result_ptr = NULL;
|
2009-02-10 12:35:12 +00:00
|
|
|
if (m_hGraphicsApplication == 0) {
|
|
|
|
graphics_app_result_ptr = NULL;
|
|
|
|
m_bScience_gfx_running = false;
|
|
|
|
// Save previous_result and previous_result_ptr for get_random_graphics_app() call
|
|
|
|
} else {
|
2009-02-27 11:20:08 +00:00
|
|
|
// HasProcessExited() test will clear m_hGraphicsApplication and graphics_app_result_ptr
|
2009-02-10 12:35:12 +00:00
|
|
|
}
|
2009-02-05 12:32:16 +00:00
|
|
|
}
|
2008-08-18 22:09:22 +00:00
|
|
|
|
2009-12-14 13:10:49 +00:00
|
|
|
if (last_change_time && (m_fGFXChangePeriod > 0) && ((dtime() - last_change_time) > m_fGFXChangePeriod) ) {
|
2009-02-05 12:32:16 +00:00
|
|
|
if (count_active_graphic_apps(results, previous_result_ptr) > 0) {
|
|
|
|
if (previous_result_ptr) {
|
|
|
|
BOINCTRACE(_T("CScreensaver::DataManagementProc - time to change: %s / %s\n"),
|
2010-03-13 04:25:07 +00:00
|
|
|
previous_result.name, previous_result.graphics_exec_path
|
|
|
|
);
|
2009-02-05 12:32:16 +00:00
|
|
|
}
|
|
|
|
terminate_screensaver(m_hGraphicsApplication, graphics_app_result_ptr);
|
|
|
|
if (m_hGraphicsApplication == 0) {
|
|
|
|
graphics_app_result_ptr = NULL;
|
2009-02-10 12:35:12 +00:00
|
|
|
m_bScience_gfx_running = false;
|
2009-02-05 12:32:16 +00:00
|
|
|
// Save previous_result and previous_result_ptr for get_random_graphics_app() call
|
|
|
|
} else {
|
2009-02-27 11:20:08 +00:00
|
|
|
// HasProcessExited() test will clear m_hGraphicsApplication and graphics_app_result_ptr
|
2009-02-05 12:32:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
last_change_time = dtime();
|
|
|
|
}
|
2008-08-18 22:09:22 +00:00
|
|
|
}
|
2009-02-10 12:35:12 +00:00
|
|
|
} // End if (m_bScience_gfx_running)
|
2009-02-05 12:32:16 +00:00
|
|
|
|
|
|
|
// If no current graphics app, pick an active task at random and launch its graphics app
|
2009-02-10 12:35:12 +00:00
|
|
|
if ((m_bDefault_gfx_running || (m_hGraphicsApplication == 0)) && (graphics_app_result_ptr == NULL)) {
|
2009-02-05 12:32:16 +00:00
|
|
|
graphics_app_result_ptr = get_random_graphics_app(results, previous_result_ptr);
|
2008-08-18 22:09:22 +00:00
|
|
|
previous_result_ptr = NULL;
|
2009-02-05 12:32:16 +00:00
|
|
|
|
|
|
|
if (graphics_app_result_ptr) {
|
2009-02-10 12:35:12 +00:00
|
|
|
if (m_bDefault_gfx_running) {
|
2009-04-02 10:25:16 +00:00
|
|
|
terminate_default_screensaver(m_hGraphicsApplication);
|
2009-02-27 11:20:08 +00:00
|
|
|
killing_default_gfx = true;
|
2009-02-12 11:54:57 +00:00
|
|
|
// Remember how long default graphics ran during science phase
|
|
|
|
if (default_saver_start_time_in_science_phase) {
|
|
|
|
default_saver_duration_in_science_phase += (dtime() - default_saver_start_time_in_science_phase);
|
|
|
|
//BOINCTRACE(_T("CScreensaver::During Science phase: now=%f, default_saver_start_time=%f, default_saver_duration=%f\n"),
|
|
|
|
// dtime(), default_saver_start_time_in_science_phase, default_saver_duration_in_science_phase);
|
|
|
|
}
|
|
|
|
default_saver_start_time_in_science_phase = 0;
|
2009-02-27 11:20:08 +00:00
|
|
|
// HasProcessExited() test will clear m_hGraphicsApplication and graphics_app_result_ptr
|
2009-02-05 12:32:16 +00:00
|
|
|
} else {
|
|
|
|
retval = launch_screensaver(graphics_app_result_ptr, m_hGraphicsApplication);
|
|
|
|
if (retval) {
|
|
|
|
m_hGraphicsApplication = 0;
|
|
|
|
previous_result_ptr = NULL;
|
|
|
|
graphics_app_result_ptr = NULL;
|
2009-02-10 12:35:12 +00:00
|
|
|
m_bScience_gfx_running = false;
|
2009-02-05 12:32:16 +00:00
|
|
|
} else {
|
2009-02-27 11:20:08 +00:00
|
|
|
SetError(FALSE, m_hrError); // A GFX App is running: hide moving BOINC logo
|
2009-02-05 12:32:16 +00:00
|
|
|
last_change_time = dtime();
|
2009-02-10 12:35:12 +00:00
|
|
|
m_bScience_gfx_running = true;
|
2009-02-05 12:32:16 +00:00
|
|
|
// Make a local copy of current result, since original pointer
|
|
|
|
// may have been freed by the time we perform later tests
|
|
|
|
previous_result = *graphics_app_result_ptr;
|
|
|
|
previous_result_ptr = &previous_result;
|
|
|
|
if (previous_result_ptr) {
|
|
|
|
BOINCTRACE(_T("CScreensaver::DataManagementProc - launching %s\n"),
|
2010-03-13 04:25:07 +00:00
|
|
|
previous_result.graphics_exec_path
|
|
|
|
);
|
2009-02-05 12:32:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-08-18 23:39:50 +00:00
|
|
|
}
|
2009-02-05 12:32:16 +00:00
|
|
|
} else {
|
2009-02-27 11:20:08 +00:00
|
|
|
SetError(TRUE, m_hrError); // No GFX App is running: show moving BOINC logo
|
2009-02-05 12:32:16 +00:00
|
|
|
// We can't run a science graphics app, so run the default graphics if available
|
2009-02-10 12:35:12 +00:00
|
|
|
if (m_bDefault_ss_exists && !m_bDefault_gfx_running) {
|
2009-02-05 12:32:16 +00:00
|
|
|
switch_to_default_gfx = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End if no science graphics available
|
|
|
|
} // End if no current science graphics app is running
|
|
|
|
|
|
|
|
#endif // ! SIMULATE_NO_GRAPHICS
|
|
|
|
|
|
|
|
if (switch_to_default_gfx) {
|
|
|
|
switch_to_default_gfx = false;
|
2009-02-12 12:58:24 +00:00
|
|
|
if (!m_bDefault_gfx_running) {
|
2009-02-06 02:17:45 +00:00
|
|
|
retval = launch_default_screensaver(default_ss_dir_path, m_hGraphicsApplication);
|
|
|
|
if (retval) {
|
|
|
|
m_hGraphicsApplication = 0;
|
|
|
|
previous_result_ptr = NULL;
|
|
|
|
graphics_app_result_ptr = NULL;
|
2009-02-10 12:35:12 +00:00
|
|
|
m_bDefault_gfx_running = false;
|
2009-02-27 11:20:08 +00:00
|
|
|
SetError(TRUE, SCRAPPERR_CANTLAUNCHDEFAULTGFXAPP); // No GFX App is running: show BOINC logo
|
2009-02-06 02:17:45 +00:00
|
|
|
} else {
|
2009-02-10 12:35:12 +00:00
|
|
|
m_bDefault_gfx_running = true;
|
2009-02-12 11:54:57 +00:00
|
|
|
default_saver_start_time_in_science_phase = dtime();
|
2009-02-27 11:20:08 +00:00
|
|
|
SetError(FALSE, m_hrError); // A GFX App is running: hide moving BOINC logo
|
2009-02-06 02:17:45 +00:00
|
|
|
}
|
2008-08-18 22:09:22 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-12 12:58:24 +00:00
|
|
|
} // End if ((ss_phase == SCIENCE_SS_PHASE) && !switch_to_default_gfx)
|
2009-02-05 12:32:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Is the graphics app still running?
|
|
|
|
if (m_hGraphicsApplication) {
|
2009-02-20 11:49:49 +00:00
|
|
|
if (HasProcessExited(m_hGraphicsApplication, exit_status)) {
|
2009-02-05 12:32:16 +00:00
|
|
|
// Something has happened to the previously selected screensaver
|
|
|
|
// application. Start a different one.
|
|
|
|
BOINCTRACE(_T("CScreensaver::DataManagementProc - Graphics application isn't running, start a new one.\n"));
|
2009-02-20 11:49:49 +00:00
|
|
|
if (m_bDefault_gfx_running) {
|
|
|
|
// If we were able to connect to core client but gfx app can't, don't use it.
|
|
|
|
BOINCTRACE(_T("CScreensaver::DataManagementProc - Default graphics application exited with code %d.\n"), exit_status);
|
2009-02-27 11:20:08 +00:00
|
|
|
if (!killing_default_gfx) { // If this is an unexpected exit
|
|
|
|
if (exit_status == DEFAULT_GFX_CANT_CONNECT) {
|
|
|
|
SetError(TRUE, SCRAPPERR_DEFAULTGFXAPPCANTCONNECT); // No GFX App is running: show moving BOINC logo
|
|
|
|
} else {
|
|
|
|
SetError(TRUE, SCRAPPERR_DEFAULTGFXAPPCRASHED); // No GFX App is running: show moving BOINC logo
|
|
|
|
}
|
2009-02-20 11:49:49 +00:00
|
|
|
m_bDefault_ss_exists = false;
|
|
|
|
ss_phase = SCIENCE_SS_PHASE;
|
|
|
|
}
|
2009-02-27 11:20:08 +00:00
|
|
|
killing_default_gfx = false;
|
2009-02-20 11:49:49 +00:00
|
|
|
}
|
2009-02-27 11:20:08 +00:00
|
|
|
SetError(TRUE, m_hrError); // No GFX App is running: show moving BOINC logo
|
2009-02-05 12:32:16 +00:00
|
|
|
m_hGraphicsApplication = 0;
|
|
|
|
graphics_app_result_ptr = NULL;
|
2009-02-10 12:35:12 +00:00
|
|
|
m_bDefault_gfx_running = false;
|
|
|
|
m_bScience_gfx_running = false;
|
2009-02-05 12:32:16 +00:00
|
|
|
continue;
|
2008-08-18 22:09:22 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-23 06:09:16 +00:00
|
|
|
} // end while(true)
|
2008-08-18 22:09:22 +00:00
|
|
|
}
|
2009-02-05 12:32:16 +00:00
|
|
|
|
|
|
|
|
2009-02-20 11:49:49 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
BOOL CScreensaver::HasProcessExited(HANDLE pid_handle, int &exitCode) {
|
|
|
|
unsigned long status = 1;
|
|
|
|
if (GetExitCodeProcess(pid_handle, &status)) {
|
|
|
|
if (status == STILL_ACTIVE) {
|
|
|
|
exitCode = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exitCode = (int)status;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
bool CScreensaver::HasProcessExited(pid_t pid, int &exitCode) {
|
|
|
|
int status;
|
|
|
|
pid_t p;
|
|
|
|
|
|
|
|
p = waitpid(pid, &status, WNOHANG);
|
|
|
|
exitCode = WEXITSTATUS(status);
|
|
|
|
if (p == pid) return true; // process has exited
|
|
|
|
if (p == -1) return true; // PID doesn't exist
|
|
|
|
exitCode = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-12-14 13:10:49 +00:00
|
|
|
void CScreensaver::GetDefaultDisplayPeriods(struct ss_periods &periods)
|
|
|
|
{
|
|
|
|
char* default_data_dir_path = NULL;
|
|
|
|
char buf[1024];
|
|
|
|
FILE* f;
|
|
|
|
MIOFILE mf;
|
|
|
|
|
|
|
|
periods.GFXDefaultPeriod = GFX_DEFAULT_PERIOD;
|
|
|
|
periods.GFXSciencePeriod = GFX_SCIENCE_PERIOD;
|
|
|
|
periods.GFXChangePeriod = GFX_CHANGE_PERIOD;
|
|
|
|
periods.Show_default_ss_first = false;
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
default_data_dir_path = "/Library/Application Support/BOINC Data";
|
|
|
|
#else
|
|
|
|
default_data_dir_path = (char*)m_strBOINCDataDirectory.c_str();
|
|
|
|
#endif
|
2009-02-06 11:17:13 +00:00
|
|
|
|
2009-12-14 13:10:49 +00:00
|
|
|
strlcpy(buf, default_data_dir_path, sizeof(buf));
|
2009-02-06 11:17:13 +00:00
|
|
|
strlcat(buf, PATH_SEPARATOR, sizeof(buf));
|
2009-02-14 01:43:08 +00:00
|
|
|
strlcat(buf, THE_SS_CONFIG_FILE, sizeof(buf));
|
2009-02-06 11:17:13 +00:00
|
|
|
|
|
|
|
f = boinc_fopen(buf, "r");
|
|
|
|
if (!f) return;
|
|
|
|
|
|
|
|
mf.init_file(f);
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
|
|
|
|
while (mf.fgets(buf, sizeof(buf))) {
|
2009-12-14 13:10:49 +00:00
|
|
|
if (parse_bool(buf, "default_ss_first", periods.Show_default_ss_first)) continue;
|
|
|
|
if (parse_double(buf, "<default_gfx_duration>", periods.GFXDefaultPeriod)) continue;
|
|
|
|
if (parse_double(buf, "<science_gfx_duration>", periods.GFXSciencePeriod)) continue;
|
|
|
|
if (parse_double(buf, "<science_gfx_change_interval>", periods.GFXChangePeriod)) continue;
|
2009-05-29 08:36:42 +00:00
|
|
|
|
2009-02-06 11:17:13 +00:00
|
|
|
}
|
|
|
|
fclose(f);
|
2009-05-29 08:36:42 +00:00
|
|
|
|
2009-12-14 13:10:49 +00:00
|
|
|
BOINCTRACE(_T("CScreensaver::GetDefaultDisplayPeriods: m_bShow_default_ss_first=%d, m_fGFXDefaultPeriod=%f, m_fGFXSciencePeriod=%f, m_fGFXChangePeriod=%f\n"),
|
|
|
|
(int)periods.Show_default_ss_first, periods.GFXDefaultPeriod, periods.GFXSciencePeriod, periods.GFXChangePeriod);
|
2009-02-22 04:05:34 +00:00
|
|
|
}
|