2005-04-23 15:14:52 +00:00
|
|
|
// 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.,
|
2007-10-09 11:35:47 +00:00
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-04-23 15:14:52 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// mac_saver_module.cpp
|
|
|
|
// BOINC_Saver_Module
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/stat.h>
|
2007-09-19 09:41:23 +00:00
|
|
|
#include <sys/param.h> // for MAXPATHLEN
|
2005-04-23 15:14:52 +00:00
|
|
|
|
|
|
|
#include "gui_rpc_client.h"
|
2006-09-05 08:56:57 +00:00
|
|
|
#include "common_defs.h"
|
2007-08-31 14:23:07 +00:00
|
|
|
#include "util.h"
|
2007-10-05 13:28:11 +00:00
|
|
|
#include "Mac_Saver_Module.h"
|
2007-08-31 14:23:07 +00:00
|
|
|
#include "screensaver.h"
|
2007-10-05 13:28:11 +00:00
|
|
|
|
2005-04-23 15:14:52 +00:00
|
|
|
//#include <drivers/event_status_driver.h>
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2006-01-20 11:44:30 +00:00
|
|
|
// The science application can't display its graphics if, due to Fast User Switching,
|
|
|
|
// Switching, the active user is not the one who launched BOINC. If we always display
|
|
|
|
// the progress information as scrolled text whenever a science application is running,
|
|
|
|
// then the progress text would appear in this case. The text would be covered up by
|
|
|
|
// the graphics if they are displayed.
|
|
|
|
// But displaying the scrolled progress info takes up too much CPU time. We need to
|
|
|
|
// find a way to determine when Fast User Switching prevents graphics display and
|
|
|
|
// display scrolled progress text only in that case.
|
|
|
|
// Of course, we also display scrolled progress text when the science application does
|
|
|
|
// not support graphics).
|
|
|
|
#define ALWAYS_DISPLAY_PROGRESS_TEXT 0
|
|
|
|
|
2005-04-27 12:59:53 +00:00
|
|
|
// Flags for testing & debugging
|
2005-04-23 15:14:52 +00:00
|
|
|
#define CREATE_LOG 1
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
void print_to_log_file(const char *format, ...);
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
|
|
|
|
void strip_cr(char *buf);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define BANNER_GAP 30 /* Space between repeats of banner text */
|
2005-04-25 11:09:40 +00:00
|
|
|
#define BANNERDELTA 2 /* Number of pixels to move banner each frame */
|
2005-04-27 12:59:53 +00:00
|
|
|
#define BANNERFREQUENCY 90 /* Number of times per second to scroll banner */
|
2005-05-25 11:35:51 +00:00
|
|
|
#define NOBANNERFREQUENCY 4 /* Times per second to call drawGraphics if no banner */
|
2006-07-22 02:12:39 +00:00
|
|
|
#define STATUSUPDATEINTERVAL 5 /* seconds between status display updates */
|
2007-08-31 14:23:07 +00:00
|
|
|
#define TASK_RUN_CHECK_PERIOD 5 /* Seconds between safety check that task is actually running */
|
2005-04-23 15:14:52 +00:00
|
|
|
|
|
|
|
enum SaverState {
|
|
|
|
SaverState_Idle,
|
|
|
|
SaverState_LaunchingCoreClient,
|
|
|
|
SaverState_CoreClientRunning,
|
2007-03-01 02:46:13 +00:00
|
|
|
SaverState_RelaunchCoreClient,
|
2007-09-14 01:45:00 +00:00
|
|
|
SaverState_ConnectedToCoreClient,
|
2005-04-23 15:14:52 +00:00
|
|
|
|
|
|
|
SaverState_CantLaunchCoreClient,
|
2005-04-27 12:59:53 +00:00
|
|
|
SaverState_ControlPanelTestMode,
|
2005-04-23 15:14:52 +00:00
|
|
|
SaverState_UnrecoverableError
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
static CScreensaver* gspScreensaver = NULL;
|
|
|
|
|
2005-04-23 15:14:52 +00:00
|
|
|
extern int gGoToBlank; // True if we are to blank the screen
|
|
|
|
extern int gBlankingTime; // Delay in minutes before blanking the screen
|
2007-09-19 09:41:23 +00:00
|
|
|
extern CFStringRef gPathToBundleResources;
|
2005-04-23 15:14:52 +00:00
|
|
|
|
|
|
|
static SaverState saverState = SaverState_Idle;
|
2007-10-05 13:28:11 +00:00
|
|
|
// int gQuitCounter = 0;
|
2006-01-20 11:44:30 +00:00
|
|
|
RGBColor gBrandColor = {0xFFFF, 0xFFFF, 0xFFFF};
|
|
|
|
RGBColor gTextColor = {0xFFFF, 0xFFFF, 0xFFFF};
|
|
|
|
RGBColor gWhiteTextColor = {0xFFFF, 0xFFFF, 0xFFFF};
|
|
|
|
RGBColor gOrangeTextColor = {0xFFFF, 0x6262, 0x0000};
|
|
|
|
RGBColor gGrayTextColor = {0x9999, 0x9999, 0x9999};
|
2005-04-27 12:59:53 +00:00
|
|
|
|
2006-01-20 11:44:30 +00:00
|
|
|
const char * CantLaunchCCMsg = "Unable to launch BOINC application.";
|
|
|
|
const char * LaunchingCCMsg = "Launching BOINC application.";
|
|
|
|
const char * ConnectingCCMsg = "Connecting to BOINC application.";
|
|
|
|
const char * BOINCSuspendedMsg = "BOINC is currently suspended.";
|
|
|
|
const char * BOINCNoAppsExecutingMsg = "BOINC is currently idle.";
|
|
|
|
const char * BOINCNoProjectsDetectedMsg = "BOINC is not attached to any projects. Please attach to projects using the BOINC Manager.";
|
2006-02-21 12:22:23 +00:00
|
|
|
const char * BOINCNoGraphicAppsExecutingMsg = "Project does not support screensaver graphics: ";
|
2006-01-20 11:44:30 +00:00
|
|
|
const char * BOINCUnrecoverableErrorMsg = "Sorry, an unrecoverable error occurred";
|
2007-08-31 14:23:07 +00:00
|
|
|
const char * BOINCTestmodeMsg = "BOINC screensaver is running, but cannot display graphics in test mode.";
|
2006-01-20 11:44:30 +00:00
|
|
|
//const char * BOINCExitedSaverMode = "BOINC is no longer in screensaver mode.";
|
2005-04-23 15:14:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Returns desired Animation Frequency (per second) or 0 for no change
|
|
|
|
int initBOINCSaver(Boolean ispreview) {
|
|
|
|
if (ispreview)
|
|
|
|
return 8;
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
gspScreensaver = new CScreensaver();
|
|
|
|
|
|
|
|
return gspScreensaver->Create();
|
|
|
|
}
|
|
|
|
|
|
|
|
int drawGraphics(GrafPtr aPort) {
|
|
|
|
return gspScreensaver->drawGraphics(aPort);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void drawPreview(GrafPtr aPort) {
|
|
|
|
gspScreensaver->drawPreview(aPort);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void closeBOINCSaver() {
|
|
|
|
gspScreensaver->ShutdownSaver();
|
|
|
|
}
|
|
|
|
|
|
|
|
CScreensaver::CScreensaver() {
|
|
|
|
|
|
|
|
m_dwBlankScreen = 0;
|
|
|
|
m_dwBlankTime = 0;
|
|
|
|
m_bErrorMode = false;
|
|
|
|
m_hrError = 0;
|
2007-10-09 10:00:53 +00:00
|
|
|
m_StatusMessageUpdated = false;
|
|
|
|
// Display first status update after 5 seconds
|
|
|
|
m_statusUpdateCounter = ((STATUSUPDATEINTERVAL-5) * BANNERFREQUENCY);
|
2007-10-05 13:28:11 +00:00
|
|
|
|
|
|
|
saverState = SaverState_Idle;
|
|
|
|
m_wasAlreadyRunning = false;
|
|
|
|
m_CoreClientPID = nil;
|
|
|
|
m_MsgBuf[0] = 0;
|
2005-04-23 15:14:52 +00:00
|
|
|
setBannerText(0, NULL);
|
2007-10-05 13:28:11 +00:00
|
|
|
m_BannerWidth = 0;
|
|
|
|
m_CurrentBannerMessage = 0;
|
|
|
|
m_QuitDataManagementProc = false;
|
|
|
|
m_BrandText = "BOINC";
|
|
|
|
m_updating_results = false;
|
|
|
|
|
|
|
|
m_hDataManagementThread = NULL;
|
|
|
|
m_hGraphicsApplication = NULL;
|
|
|
|
m_bResetCoreState = TRUE;
|
|
|
|
rpc = 0;
|
|
|
|
}
|
2005-04-23 15:14:52 +00:00
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
|
|
|
|
int CScreensaver::Create() {
|
|
|
|
int newFrequency = 15;
|
|
|
|
ProcessSerialNumber psn;
|
|
|
|
ProcessInfoRec pInfo;
|
|
|
|
OSStatus err;
|
|
|
|
|
2005-04-27 12:59:53 +00:00
|
|
|
// Ugly workaround for a problem with the System Preferences app
|
|
|
|
// For an unknown reason, when this screensaver is run using the
|
|
|
|
// Test button in the System Prefs Screensaver control panel, the
|
|
|
|
// control panel calls our stopAnimation function as soon as the
|
|
|
|
// science application opens a GLUT window. This problem does not
|
2007-03-01 02:46:13 +00:00
|
|
|
// occur when the screensaver is run normally (from the screensaver
|
2005-04-27 12:59:53 +00:00
|
|
|
// engine.) So we just display a message and don't access the core
|
|
|
|
// client.
|
|
|
|
GetCurrentProcess(&psn);
|
|
|
|
memset(&pInfo, 0, sizeof(pInfo));
|
|
|
|
pInfo.processInfoLength = sizeof( ProcessInfoRec );
|
|
|
|
pInfo.processName = NULL;
|
|
|
|
err = GetProcessInformation(&psn, &pInfo);
|
|
|
|
if ( (err == noErr) && (pInfo.processSignature == 'sprf') ) {
|
|
|
|
saverState = SaverState_ControlPanelTestMode;
|
|
|
|
}
|
|
|
|
|
2005-04-23 15:14:52 +00:00
|
|
|
// If there are multiple displays, initBOINCSaver may get called
|
|
|
|
// multiple times (once for each display), so we need to guard
|
|
|
|
// against launching multiple instances of the core client
|
|
|
|
if (saverState == SaverState_Idle) {
|
2007-10-05 13:28:11 +00:00
|
|
|
// Calculate the estimated blank time by adding the starting
|
|
|
|
// time and and the user-specified time which is in minutes
|
|
|
|
m_dwBlankScreen = gGoToBlank;
|
|
|
|
if (gGoToBlank)
|
|
|
|
m_dwBlankTime = time(0) + (gBlankingTime * 60);
|
|
|
|
else
|
|
|
|
m_dwBlankTime = 0;
|
|
|
|
|
|
|
|
CFStringGetCString(gPathToBundleResources, m_gfx_Switcher_Path, sizeof(m_gfx_Switcher_Path), kCFStringEncodingMacRoman);
|
|
|
|
strlcat(m_gfx_Switcher_Path, "/gfx_switcher", sizeof(m_gfx_Switcher_Path));
|
2007-09-19 09:41:23 +00:00
|
|
|
|
2005-04-23 15:14:52 +00:00
|
|
|
err = initBOINCApp();
|
|
|
|
|
|
|
|
if (saverState == SaverState_LaunchingCoreClient)
|
|
|
|
{
|
2007-10-05 13:28:11 +00:00
|
|
|
SetError(FALSE, 0);
|
|
|
|
m_QuitDataManagementProc = false;
|
2005-04-23 15:14:52 +00:00
|
|
|
if (rpc == NULL)
|
|
|
|
rpc = new RPC_CLIENT;
|
2005-05-25 11:35:51 +00:00
|
|
|
newFrequency = NOBANNERFREQUENCY;
|
2005-04-23 15:14:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return newFrequency;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
OSStatus CScreensaver::initBOINCApp() {
|
2006-10-28 11:18:09 +00:00
|
|
|
char boincPath[2048];
|
2005-04-23 15:14:52 +00:00
|
|
|
pid_t myPid;
|
|
|
|
int status;
|
|
|
|
OSStatus err;
|
2007-02-28 08:34:54 +00:00
|
|
|
static int retryCount = 0;
|
2007-10-05 13:28:11 +00:00
|
|
|
long brandId = 0;
|
2007-02-28 08:34:54 +00:00
|
|
|
|
2005-04-23 15:14:52 +00:00
|
|
|
saverState = SaverState_CantLaunchCoreClient;
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
m_CoreClientPID = FindProcessPID("boinc", 0);
|
|
|
|
if (m_CoreClientPID) {
|
|
|
|
m_wasAlreadyRunning = true;
|
2005-04-23 15:14:52 +00:00
|
|
|
saverState = SaverState_LaunchingCoreClient;
|
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
m_wasAlreadyRunning = false;
|
2007-02-28 08:34:54 +00:00
|
|
|
|
2007-03-01 02:46:13 +00:00
|
|
|
if (++retryCount > 3) // Limit to 3 relaunches to prevent thrashing
|
2007-02-28 08:34:54 +00:00
|
|
|
return -1;
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
brandId = GetBrandID();
|
|
|
|
switch(brandId) {
|
|
|
|
case 1:
|
|
|
|
m_BrandText = "GridRepublic";
|
|
|
|
gBrandColor = gOrangeTextColor; // Orange
|
|
|
|
gTextColor = gGrayTextColor; // Gray
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m_BrandText = "BOINC";
|
|
|
|
gBrandColor = gWhiteTextColor; // White
|
|
|
|
gTextColor = gWhiteTextColor; // White
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-23 15:14:52 +00:00
|
|
|
err = GetpathToBOINCManagerApp(boincPath, sizeof(boincPath));
|
2006-01-20 14:04:06 +00:00
|
|
|
if (err) { // If we couldn't find BOINCManager.app, try default path
|
|
|
|
strcpy(boincPath, "/Applications/");
|
2007-10-05 13:28:11 +00:00
|
|
|
if (brandId)
|
|
|
|
strcat(boincPath, m_BrandText);
|
2006-01-20 14:04:06 +00:00
|
|
|
else
|
|
|
|
strcat(boincPath, "BOINCManager");
|
|
|
|
strcat(boincPath, ".app");
|
|
|
|
}
|
|
|
|
|
2005-04-23 15:14:52 +00:00
|
|
|
strcat(boincPath, "/Contents/Resources/boinc");
|
|
|
|
|
|
|
|
if ( (myPid = fork()) < 0)
|
|
|
|
return -1;
|
|
|
|
else if (myPid == 0) // child
|
|
|
|
{
|
2006-10-28 11:18:09 +00:00
|
|
|
// We don't customize BOINC Data directory name for branding
|
2005-04-27 12:59:53 +00:00
|
|
|
#if 0 // Code for separate data in each user's private directory
|
2006-10-28 11:18:09 +00:00
|
|
|
char buf[256];
|
2005-04-23 15:14:52 +00:00
|
|
|
strcpy(buf, getenv("HOME"));
|
2006-10-28 11:18:09 +00:00
|
|
|
strcat(buf, "/Library/Application Support/BOINC Data");
|
|
|
|
status = chdir(buf);
|
2005-04-27 12:59:53 +00:00
|
|
|
#else // All users share the same data
|
2006-10-28 11:18:09 +00:00
|
|
|
status = chdir("/Library/Application Support/BOINC Data");
|
2005-04-27 12:59:53 +00:00
|
|
|
#endif
|
2005-04-23 15:14:52 +00:00
|
|
|
if (status) {
|
|
|
|
perror("chdir");
|
2005-10-05 20:39:00 +00:00
|
|
|
fflush(NULL);
|
2005-04-23 15:14:52 +00:00
|
|
|
_exit(status);
|
|
|
|
}
|
|
|
|
|
2007-02-28 08:34:54 +00:00
|
|
|
status = execl(boincPath, boincPath, "-redirectio", "-saver", (char *) 0);
|
2005-10-05 20:39:00 +00:00
|
|
|
fflush(NULL);
|
2005-04-23 15:14:52 +00:00
|
|
|
_exit(127); // execl error (execl should never return)
|
|
|
|
} else {
|
2007-10-05 13:28:11 +00:00
|
|
|
m_CoreClientPID = myPid; // make this available globally
|
2005-04-23 15:14:52 +00:00
|
|
|
saverState = SaverState_LaunchingCoreClient;
|
|
|
|
}
|
|
|
|
|
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns new desired Animation Frequency (per second) or 0 for no change
|
2007-10-05 13:28:11 +00:00
|
|
|
int CScreensaver::drawGraphics(GrafPtr aPort) {
|
2005-04-23 15:14:52 +00:00
|
|
|
CGrafPtr savePort;
|
|
|
|
GDHandle saveGDH;
|
|
|
|
int newFrequency = 15;
|
|
|
|
pid_t myPid;
|
|
|
|
OSStatus err;
|
|
|
|
|
|
|
|
ObscureCursor();
|
2005-04-27 12:59:53 +00:00
|
|
|
|
2007-10-09 10:00:53 +00:00
|
|
|
m_statusUpdateCounter++;
|
2005-04-23 15:14:52 +00:00
|
|
|
|
|
|
|
switch (saverState) {
|
2007-03-01 02:46:13 +00:00
|
|
|
case SaverState_RelaunchCoreClient:
|
|
|
|
err = initBOINCApp();
|
|
|
|
break;
|
|
|
|
|
2005-04-23 15:14:52 +00:00
|
|
|
case SaverState_LaunchingCoreClient:
|
2007-10-05 13:28:11 +00:00
|
|
|
if (m_wasAlreadyRunning)
|
2005-04-27 12:59:53 +00:00
|
|
|
setBannerText(ConnectingCCMsg, aPort);
|
2005-04-26 15:51:40 +00:00
|
|
|
else
|
|
|
|
setBannerText(LaunchingCCMsg, aPort);
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
myPid = FindProcessPID(NULL, m_CoreClientPID);
|
2005-04-23 15:14:52 +00:00
|
|
|
if (myPid) {
|
|
|
|
saverState = SaverState_CoreClientRunning;
|
|
|
|
rpc->init(NULL); // Initialize communications with Core Client
|
|
|
|
|
|
|
|
// Set up a separate thread for communicating with Core Client
|
2007-10-05 13:28:11 +00:00
|
|
|
CreateDataManagementThread();
|
2007-03-01 02:46:13 +00:00
|
|
|
// ToDo: Add a timeout after which we display error message
|
|
|
|
} else
|
|
|
|
// Take care of the possible race condition where the Core Client was in the
|
|
|
|
// process of shutting down just as ScreenSaver started, so initBOINCApp()
|
|
|
|
// found it already running but now it has shut down.
|
2007-10-05 13:28:11 +00:00
|
|
|
if (m_wasAlreadyRunning) // If we launched it, then just wait for it to start
|
2007-03-01 02:46:13 +00:00
|
|
|
saverState = SaverState_RelaunchCoreClient;
|
|
|
|
break;
|
2005-04-23 15:14:52 +00:00
|
|
|
|
|
|
|
case SaverState_CoreClientRunning:
|
2007-10-05 13:28:11 +00:00
|
|
|
// RPC called in DataManagementProc()
|
2005-05-25 11:18:05 +00:00
|
|
|
setBannerText(ConnectingCCMsg, aPort);
|
2007-10-05 13:28:11 +00:00
|
|
|
if (! m_bResetCoreState) {
|
|
|
|
saverState = SaverState_ConnectedToCoreClient;
|
|
|
|
}
|
2005-04-23 15:14:52 +00:00
|
|
|
break;
|
|
|
|
|
2007-09-14 01:45:00 +00:00
|
|
|
case SaverState_ConnectedToCoreClient:
|
2007-10-05 13:28:11 +00:00
|
|
|
switch (m_hrError) {
|
2005-04-23 15:14:52 +00:00
|
|
|
case 0:
|
2007-10-05 13:28:11 +00:00
|
|
|
break; // No status response yet from DataManagementProc
|
|
|
|
case SCRAPPERR_SCREENSAVERBLANKED:
|
2006-01-20 11:44:30 +00:00
|
|
|
default:
|
2005-04-23 15:14:52 +00:00
|
|
|
setBannerText(0, aPort); // No text message
|
|
|
|
break;
|
2007-10-05 13:28:11 +00:00
|
|
|
case SCRAPPERR_BOINCSUSPENDED:
|
2005-04-23 15:14:52 +00:00
|
|
|
setBannerText(BOINCSuspendedMsg, aPort);
|
|
|
|
break;
|
2007-10-05 13:28:11 +00:00
|
|
|
case SCRAPPERR_BOINCNOAPPSEXECUTING:
|
2005-04-23 15:14:52 +00:00
|
|
|
setBannerText(BOINCNoAppsExecutingMsg, aPort);
|
|
|
|
break;
|
2007-10-05 13:28:11 +00:00
|
|
|
case SCRAPPERR_BOINCNOPROJECTSDETECTED:
|
2005-04-23 15:14:52 +00:00
|
|
|
setBannerText(BOINCNoProjectsDetectedMsg, aPort);
|
|
|
|
break;
|
2007-10-05 13:28:11 +00:00
|
|
|
case SCRAPPERR_SCREENSAVERRUNNING:
|
2006-01-20 11:44:30 +00:00
|
|
|
#if ! ALWAYS_DISPLAY_PROGRESS_TEXT
|
|
|
|
setBannerText(0, aPort); // No text message
|
|
|
|
// Let the science app draw over our window
|
|
|
|
break;
|
|
|
|
#endif
|
2007-10-05 13:28:11 +00:00
|
|
|
case SCRAPPERR_BOINCNOGRAPHICSAPPSEXECUTING:
|
2007-10-09 10:00:53 +00:00
|
|
|
if (m_StatusMessageUpdated) {
|
2007-10-05 13:28:11 +00:00
|
|
|
setBannerText(m_MsgBuf, aPort);
|
|
|
|
updateBannerText(m_MsgBuf, aPort);
|
2007-10-09 10:00:53 +00:00
|
|
|
m_StatusMessageUpdated = false;
|
|
|
|
}
|
2005-04-23 15:14:52 +00:00
|
|
|
break;
|
2007-08-31 14:23:07 +00:00
|
|
|
#if 0
|
2007-10-05 13:28:11 +00:00
|
|
|
case SCRAPPERR_QUITSCREENSAVERREQUESTED:
|
2005-05-25 11:18:05 +00:00
|
|
|
// setBannerText(BOINCExitedSaverMode, aPort);
|
2007-10-05 13:28:11 +00:00
|
|
|
// Wait 1 second to allow ScreenSaver engine to close us down
|
2005-05-25 11:35:51 +00:00
|
|
|
if (++gQuitCounter > (bannerText[0] ? BANNERFREQUENCY : NOBANNERFREQUENCY)) {
|
2005-05-25 11:18:05 +00:00
|
|
|
closeBOINCSaver();
|
|
|
|
KillScreenSaver(); // Stop the ScreenSaver Engine
|
|
|
|
}
|
2005-04-23 15:14:52 +00:00
|
|
|
break;
|
2007-08-31 14:23:07 +00:00
|
|
|
#endif
|
2007-10-05 13:28:11 +00:00
|
|
|
} // end switch (m_hrError)
|
2005-04-23 15:14:52 +00:00
|
|
|
break;
|
|
|
|
|
2005-04-27 12:59:53 +00:00
|
|
|
case SaverState_ControlPanelTestMode:
|
2007-08-31 14:23:07 +00:00
|
|
|
setBannerText(BOINCTestmodeMsg, aPort);
|
2005-04-27 12:59:53 +00:00
|
|
|
break;
|
|
|
|
|
2005-04-23 15:14:52 +00:00
|
|
|
case SaverState_UnrecoverableError:
|
|
|
|
setBannerText(BOINCUnrecoverableErrorMsg, aPort);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SaverState_CantLaunchCoreClient:
|
|
|
|
setBannerText(CantLaunchCCMsg, aPort);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SaverState_Idle:
|
|
|
|
break; // Should never get here; fixes compiler warning
|
|
|
|
} // end switch (saverState)
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
if (m_BannerText[0]) {
|
2005-04-23 15:14:52 +00:00
|
|
|
GetGWorld(&savePort, &saveGDH);
|
|
|
|
SetPort(aPort);
|
|
|
|
drawBanner(aPort);
|
|
|
|
SetGWorld(savePort, saveGDH);
|
2005-04-27 12:59:53 +00:00
|
|
|
newFrequency = BANNERFREQUENCY;
|
2005-04-23 15:14:52 +00:00
|
|
|
} else
|
2005-05-25 11:35:51 +00:00
|
|
|
newFrequency = NOBANNERFREQUENCY;
|
2005-04-23 15:14:52 +00:00
|
|
|
|
|
|
|
return newFrequency;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
void CScreensaver::drawPreview(GrafPtr aPort) {
|
2005-04-23 15:14:52 +00:00
|
|
|
SetPort(aPort);
|
2006-01-20 11:44:30 +00:00
|
|
|
setBannerText(" BOINC", aPort);
|
2005-04-23 15:14:52 +00:00
|
|
|
drawBanner(aPort);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If there are multiple displays, closeBOINCSaver may get called
|
|
|
|
// multiple times (once for each display), so we need to guard
|
|
|
|
// against any problems that may cause.
|
2007-10-05 13:28:11 +00:00
|
|
|
void CScreensaver::ShutdownSaver() {
|
2007-10-09 10:00:53 +00:00
|
|
|
DestroyDataManagementThread();
|
2005-04-23 15:14:52 +00:00
|
|
|
|
2007-02-28 16:10:17 +00:00
|
|
|
if (rpc) {
|
2007-09-11 23:21:58 +00:00
|
|
|
#if 0 // OS X calls closeBOINCSaver() when energy saver puts display
|
2007-09-12 00:39:41 +00:00
|
|
|
// to sleep, but we want to keep crunching. So don't kill it.
|
2007-02-28 08:34:54 +00:00
|
|
|
// Code in core client now quits on user activity if screen
|
|
|
|
// saver launched it (2/28/07).
|
2007-09-11 23:21:58 +00:00
|
|
|
// Also, under sandbox security, screensaver doesn't have access
|
|
|
|
// to rpc password in gui_rpc_auth.cfg file, so core client won't
|
|
|
|
// accept rpc->quit from screensaver.
|
2007-10-05 13:28:11 +00:00
|
|
|
if (m_CoreClientPID && (!m_wasAlreadyRunning)) {
|
2007-02-28 16:10:17 +00:00
|
|
|
rpc->quit(); // Kill core client if we launched it
|
2005-04-23 15:14:52 +00:00
|
|
|
}
|
2007-02-28 08:34:54 +00:00
|
|
|
#endif
|
2007-02-28 16:10:17 +00:00
|
|
|
delete rpc;
|
2007-09-21 11:46:31 +00:00
|
|
|
rpc = NULL;
|
2007-02-28 16:10:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setBannerText(0, NULL);
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
m_CoreClientPID = 0;
|
|
|
|
// gQuitCounter = 0;
|
|
|
|
m_wasAlreadyRunning = false;
|
|
|
|
m_QuitDataManagementProc = false;
|
2007-02-28 08:34:54 +00:00
|
|
|
saverState = SaverState_Idle;
|
2005-04-23 15:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
// This function forwards to DataManagementProc, which has access to the
|
|
|
|
// "this" pointer.
|
|
|
|
//
|
|
|
|
void * CScreensaver::DataManagementProcStub(void* param) {
|
|
|
|
return gspScreensaver->DataManagementProc();
|
2005-04-23 15:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
void CScreensaver::HandleRPCError() {
|
2007-03-01 02:46:13 +00:00
|
|
|
// Attempt to restart BOINC Client if needed, reinitialize the RPC client and state
|
|
|
|
rpc->close();
|
|
|
|
|
|
|
|
// There is a possible race condition where the Core Client was in the
|
|
|
|
// process of shutting down just as ScreenSaver started, so initBOINCApp()
|
|
|
|
// found it already running but now it has shut down. This code takes
|
|
|
|
// care of that and other situations where the Core Client quits unexpectedy.
|
2007-09-19 09:41:23 +00:00
|
|
|
if (FindProcessPID("boinc", 0) == 0) {
|
2007-03-01 02:46:13 +00:00
|
|
|
saverState = SaverState_RelaunchCoreClient;
|
2007-10-05 13:28:11 +00:00
|
|
|
m_bResetCoreState = true;
|
2007-03-01 02:46:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpc->init(NULL); // Otherwise just reinitialize the RPC client and state and keep trying
|
|
|
|
// Error message after timeout?
|
|
|
|
}
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
bool CScreensaver::CreateDataManagementThread() {
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (m_hDataManagementThread == NULL) {
|
|
|
|
retval = pthread_create(&m_hDataManagementThread, NULL, DataManagementProcStub, 0);
|
|
|
|
if (retval) {
|
|
|
|
saverState = SaverState_UnrecoverableError;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-09 10:00:53 +00:00
|
|
|
bool CScreensaver::DestroyDataManagementThread() {
|
2007-10-05 13:28:11 +00:00
|
|
|
m_QuitDataManagementProc = true; // Tell DataManagementProc thread to exit
|
|
|
|
if (m_hDataManagementThread) { // Wait for DataManagementProc thread to exit
|
|
|
|
pthread_join(m_hDataManagementThread, NULL);
|
|
|
|
m_hDataManagementThread = NULL;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-03-01 02:46:13 +00:00
|
|
|
|
2007-10-09 10:00:53 +00:00
|
|
|
bool CScreensaver::SetError(bool bErrorMode, unsigned int hrError) {
|
2007-10-05 13:28:11 +00:00
|
|
|
m_bErrorMode = bErrorMode;
|
|
|
|
m_hrError = hrError;
|
2007-10-09 10:00:53 +00:00
|
|
|
if ((hrError == SCRAPPERR_BOINCNOGRAPHICSAPPSEXECUTING)
|
|
|
|
#if ALWAYS_DISPLAY_PROGRESS_TEXT
|
|
|
|
|| (hrError == SCRAPPERR_SCREENSAVERRUNNING)
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UpdateProgressText();
|
|
|
|
}
|
2007-10-05 13:28:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-10-09 10:00:53 +00:00
|
|
|
void CScreensaver::UpdateProgressText() {
|
|
|
|
int iResultCount;
|
|
|
|
int iIndex;
|
|
|
|
unsigned int len;
|
|
|
|
RESULT* theResult;
|
|
|
|
PROJECT* pProject;
|
|
|
|
char statusBuf[256];
|
|
|
|
double percent_done;
|
|
|
|
|
|
|
|
if ( (m_statusUpdateCounter >= (STATUSUPDATEINTERVAL * BANNERFREQUENCY) ) && !m_updating_results ) {
|
|
|
|
if (! m_StatusMessageUpdated) {
|
|
|
|
m_statusUpdateCounter = 0;
|
|
|
|
strcpy(m_MsgBuf, BOINCNoGraphicAppsExecutingMsg);
|
|
|
|
|
|
|
|
iResultCount = results.results.size();
|
|
|
|
theResult = NULL;
|
|
|
|
for (iIndex = 0; iIndex < iResultCount; iIndex++) {
|
|
|
|
theResult = results.results.at(iIndex);
|
|
|
|
|
|
|
|
// The get_state rpc is time-consuming, so we assume the list of
|
|
|
|
// attached projects does not change while the screensaver is active.
|
|
|
|
pProject = state.lookup_project(theResult->project_url);
|
|
|
|
if (pProject != NULL) {
|
|
|
|
percent_done = theResult->fraction_done * 100;
|
|
|
|
if (percent_done < 0.01)
|
|
|
|
len = sprintf(statusBuf, (" %s"), pProject->project_name.c_str());
|
|
|
|
else // Display percent_done only after we have a valid value
|
|
|
|
len = sprintf(statusBuf, (" %s: %.2f%%"),
|
|
|
|
pProject->project_name.c_str(), percent_done);
|
|
|
|
|
|
|
|
strlcat(m_MsgBuf, statusBuf, sizeof(m_MsgBuf));
|
|
|
|
} else { // (pProject == NULL): re-synch with client
|
|
|
|
HandleRPCError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} // end for() loop
|
|
|
|
m_StatusMessageUpdated = true;
|
|
|
|
} // end if (! m_StatusMessageUpdated)
|
|
|
|
} // end if (m_statusUpdateCounter > time to update)
|
|
|
|
}
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
|
|
|
|
void CScreensaver::setBannerText(const char * msg, GrafPtr aPort) {
|
2005-04-27 12:59:53 +00:00
|
|
|
if (msg == 0)
|
2007-10-05 13:28:11 +00:00
|
|
|
m_BannerText[0] = 0;
|
2005-04-27 12:59:53 +00:00
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
if ((char *)m_CurrentBannerMessage != msg)
|
2006-01-20 11:44:30 +00:00
|
|
|
updateBannerText((char *)msg, aPort);
|
2005-04-27 12:59:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
void CScreensaver::updateBannerText(char *msg, GrafPtr aPort) {
|
2005-04-23 15:14:52 +00:00
|
|
|
CGrafPtr savePort;
|
|
|
|
RGBColor saveBackColor;
|
|
|
|
Rect wRect;
|
2006-01-20 11:44:30 +00:00
|
|
|
char *p, *s;
|
2005-04-23 15:14:52 +00:00
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
m_CurrentBannerMessage = (StringPtr)msg;
|
2005-04-27 12:59:53 +00:00
|
|
|
|
|
|
|
if (aPort == NULL)
|
2005-04-23 15:14:52 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
GetPort(&savePort);
|
|
|
|
SetPort(aPort);
|
|
|
|
|
|
|
|
GetPortBounds(aPort, &wRect);
|
|
|
|
|
|
|
|
GetBackColor(&saveBackColor);
|
|
|
|
BackColor ( blackColor );
|
|
|
|
EraseRect(&wRect);
|
|
|
|
RGBBackColor(&saveBackColor);
|
|
|
|
|
2005-04-27 12:59:53 +00:00
|
|
|
if (msg) {
|
|
|
|
TextSize(24);
|
|
|
|
TextFace(bold);
|
2006-01-20 11:44:30 +00:00
|
|
|
s = msg;
|
2007-10-05 13:28:11 +00:00
|
|
|
m_BannerText[0] = '\0';
|
2006-01-20 11:44:30 +00:00
|
|
|
do {
|
|
|
|
p = strstr(s, "BOINC");
|
|
|
|
if (p == NULL) {
|
2007-10-05 13:28:11 +00:00
|
|
|
strcat(m_BannerText, s);
|
2006-01-20 11:44:30 +00:00
|
|
|
} else {
|
2007-10-05 13:28:11 +00:00
|
|
|
strncat(m_BannerText, s, p - s);
|
|
|
|
strcat(m_BannerText, m_BrandText);
|
2006-01-20 11:44:30 +00:00
|
|
|
s = p + 5; // s = p + strlen("BOINC");
|
|
|
|
}
|
|
|
|
} while (p);
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
m_BannerWidth = TextWidth(m_BannerText, 0, strlen(m_BannerText)) + BANNER_GAP;
|
|
|
|
// Round up m_BannerWidth to an integral multiple of BANNERDELTA
|
|
|
|
m_BannerWidth = ((m_BannerWidth + BANNERDELTA - 1) / BANNERDELTA) * BANNERDELTA;
|
2005-04-27 12:59:53 +00:00
|
|
|
}
|
|
|
|
|
2005-04-23 15:14:52 +00:00
|
|
|
SetPort(savePort);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
void CScreensaver::drawBanner(GrafPtr aPort) {
|
2005-04-23 15:14:52 +00:00
|
|
|
CGrafPtr savePort;
|
|
|
|
GDHandle saveGDH;
|
|
|
|
RGBColor saveForeColor, saveBackColor;
|
|
|
|
short x, y;
|
|
|
|
Rect wRect;
|
|
|
|
FontInfo fInfo;
|
|
|
|
static short bannerPos;
|
2006-01-20 11:44:30 +00:00
|
|
|
char *p, *s;
|
2005-04-23 15:14:52 +00:00
|
|
|
|
2005-04-27 12:59:53 +00:00
|
|
|
if (aPort == NULL)
|
|
|
|
return;
|
|
|
|
|
2005-04-23 15:14:52 +00:00
|
|
|
GetGWorld(&savePort, &saveGDH);
|
|
|
|
SetPort(aPort);
|
|
|
|
|
|
|
|
GetForeColor(&saveForeColor);
|
|
|
|
GetBackColor(&saveBackColor);
|
2006-01-20 11:44:30 +00:00
|
|
|
RGBForeColor(&gTextColor);
|
2005-04-23 15:14:52 +00:00
|
|
|
BackColor(blackColor);
|
|
|
|
GetPortBounds(aPort, &wRect);
|
2007-10-05 13:28:11 +00:00
|
|
|
if ( (bannerPos + m_BannerWidth) <= (wRect.left + BANNERDELTA) )
|
2005-04-23 15:14:52 +00:00
|
|
|
bannerPos = wRect.left;
|
|
|
|
else
|
2005-04-25 11:09:40 +00:00
|
|
|
bannerPos -= BANNERDELTA;
|
2005-04-23 15:14:52 +00:00
|
|
|
|
|
|
|
x = bannerPos;
|
|
|
|
y = (wRect.bottom - wRect.top) / 3 + wRect.top;
|
|
|
|
|
|
|
|
GetFontInfo(&fInfo);
|
|
|
|
wRect.top = y - fInfo.ascent;
|
|
|
|
wRect.bottom = y + fInfo.descent;
|
|
|
|
EraseRect(&wRect);
|
|
|
|
|
|
|
|
do {
|
|
|
|
MoveTo(x, y);
|
2007-10-05 13:28:11 +00:00
|
|
|
s = m_BannerText;
|
2006-01-20 11:44:30 +00:00
|
|
|
do {
|
2007-10-05 13:28:11 +00:00
|
|
|
p = strstr(s, m_BrandText);
|
2006-01-20 11:44:30 +00:00
|
|
|
if (p == NULL) {
|
|
|
|
DrawText(s, 0, strlen(s));
|
|
|
|
} else {
|
|
|
|
DrawText(s, 0, p - s);
|
|
|
|
RGBForeColor(&gBrandColor);
|
2007-10-05 13:28:11 +00:00
|
|
|
DrawText(m_BrandText, 0, strlen(m_BrandText));
|
|
|
|
s = p + strlen(m_BrandText);
|
2006-01-20 11:44:30 +00:00
|
|
|
RGBForeColor(&gTextColor);
|
|
|
|
}
|
|
|
|
} while (p);
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
x+= m_BannerWidth;
|
2005-04-23 15:14:52 +00:00
|
|
|
} while (x < wRect.right);
|
|
|
|
|
|
|
|
RGBForeColor(&saveForeColor);
|
|
|
|
RGBBackColor(&saveBackColor);
|
|
|
|
|
|
|
|
SetGWorld(savePort, saveGDH);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
int CScreensaver::GetBrandID()
|
2006-01-20 11:44:30 +00:00
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
long iBrandId;
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
iBrandId = 0; // Default value
|
|
|
|
|
|
|
|
err = GetpathToBOINCManagerApp(buf, sizeof(buf));
|
2006-10-28 11:18:09 +00:00
|
|
|
if (err) {
|
|
|
|
// If we couldn't find our application bundle, look in BOINC Data Directory
|
|
|
|
// (the installer put a copy there for us)
|
|
|
|
strcpy(buf, "/Library/Application Support/BOINC Data/Branding");
|
|
|
|
} else
|
|
|
|
strcat(buf, "/Contents/Resources/Branding");
|
2006-01-20 14:04:06 +00:00
|
|
|
|
|
|
|
FILE *f = fopen(buf, "r");
|
|
|
|
if (f) {
|
|
|
|
fscanf(f, "BrandId=%ld\n", &iBrandId);
|
|
|
|
fclose(f);
|
2006-01-20 11:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return iBrandId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
char * CScreensaver::PersistentFGets(char *buf, size_t buflen, FILE *f) {
|
2005-09-20 00:45:00 +00:00
|
|
|
char *p = buf;
|
|
|
|
size_t len = buflen;
|
|
|
|
size_t datalen = 0;
|
|
|
|
|
|
|
|
*buf = '\0';
|
|
|
|
while (datalen < (buflen - 1)) {
|
|
|
|
fgets(p, len, f);
|
|
|
|
if (feof(f)) break;
|
|
|
|
if (ferror(f) && (errno != EINTR)) break;
|
|
|
|
if (strchr(buf, '\n')) break;
|
|
|
|
datalen = strlen(buf);
|
|
|
|
p = buf + datalen;
|
|
|
|
len -= datalen;
|
|
|
|
}
|
|
|
|
return (buf[0] ? buf : NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
pid_t CScreensaver::FindProcessPID(char* name, pid_t thePID)
|
2005-04-23 15:14:52 +00:00
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char buf[1024];
|
2005-04-27 12:59:53 +00:00
|
|
|
size_t n = 0;
|
2007-09-19 09:41:23 +00:00
|
|
|
pid_t aPID;
|
2005-04-23 15:14:52 +00:00
|
|
|
|
2007-10-03 06:16:58 +00:00
|
|
|
if (name != NULL) // Search ny name
|
2005-04-23 15:14:52 +00:00
|
|
|
n = strlen(name);
|
|
|
|
|
2007-10-03 06:16:58 +00:00
|
|
|
f = popen("ps -a -x -c -o command,pid", "r");
|
2005-04-23 15:14:52 +00:00
|
|
|
if (f == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2005-09-20 00:45:00 +00:00
|
|
|
while (PersistentFGets(buf, sizeof(buf), f))
|
2005-04-23 15:14:52 +00:00
|
|
|
{
|
2007-10-03 06:16:58 +00:00
|
|
|
if (name != NULL) { // Search ny name
|
|
|
|
if (strncmp(buf, name, n) == 0)
|
2005-04-23 15:14:52 +00:00
|
|
|
{
|
2007-10-03 06:16:58 +00:00
|
|
|
aPID = atol(buf+16);
|
2005-04-23 15:14:52 +00:00
|
|
|
pclose(f);
|
|
|
|
return aPID;
|
|
|
|
}
|
2007-10-03 06:16:58 +00:00
|
|
|
} else { // Search by PID
|
|
|
|
aPID = atol(buf+16);
|
2005-04-23 15:14:52 +00:00
|
|
|
if (aPID == thePID) {
|
|
|
|
pclose(f);
|
|
|
|
return aPID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
OSErr CScreensaver::GetpathToBOINCManagerApp(char* path, int maxLen)
|
2005-04-23 15:14:52 +00:00
|
|
|
{
|
|
|
|
CFStringRef bundleID = CFSTR("edu.berkeley.boinc");
|
|
|
|
OSType creator = 'BNC!';
|
|
|
|
FSRef theFSRef;
|
|
|
|
OSStatus status = noErr;
|
|
|
|
|
|
|
|
status = LSFindApplicationForInfo(creator, bundleID, NULL, &theFSRef, NULL);
|
|
|
|
if (status == noErr)
|
|
|
|
status = FSRefMakePath(&theFSRef, (unsigned char *)path, maxLen);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-25 11:18:05 +00:00
|
|
|
// Send a Quit AppleEvent to the process which called this module
|
|
|
|
// (i.e., tell the ScreenSaver engine to quit)
|
2007-10-05 13:28:11 +00:00
|
|
|
OSErr CScreensaver::KillScreenSaver() {
|
2005-05-25 11:18:05 +00:00
|
|
|
ProcessSerialNumber thisPSN;
|
|
|
|
pid_t thisPID;
|
|
|
|
OSErr err = noErr;
|
|
|
|
|
|
|
|
GetCurrentProcess(&thisPSN);
|
|
|
|
err = GetProcessPID(&thisPSN , &thisPID);
|
|
|
|
if (err == noErr)
|
|
|
|
err = kill(thisPID, SIGABRT); // SIGINT
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-05 13:28:11 +00:00
|
|
|
void CScreensaver::print_to_log_file(const char *format, ...) {
|
2005-04-23 15:14:52 +00:00
|
|
|
#if CREATE_LOG
|
|
|
|
FILE *f;
|
|
|
|
va_list args;
|
|
|
|
char buf[256];
|
|
|
|
time_t t;
|
|
|
|
strcpy(buf, getenv("HOME"));
|
|
|
|
strcat(buf, "/Documents/test_log.txt");
|
|
|
|
f = fopen(buf, "a");
|
|
|
|
if (!f) return;
|
|
|
|
|
|
|
|
// freopen(buf, "a", stdout);
|
|
|
|
// freopen(buf, "a", stderr);
|
|
|
|
|
|
|
|
time(&t);
|
|
|
|
strcpy(buf, asctime(localtime(&t)));
|
|
|
|
strip_cr(buf);
|
|
|
|
|
|
|
|
fputs(buf, f);
|
|
|
|
fputs(" ", f);
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
vfprintf(f, format, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
fputs("\n", f);
|
2007-08-31 14:23:07 +00:00
|
|
|
fflush(f);
|
2005-04-23 15:14:52 +00:00
|
|
|
fclose(f);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CREATE_LOG
|
2007-10-05 13:28:11 +00:00
|
|
|
void CScreensaver::strip_cr(char *buf)
|
2005-04-23 15:14:52 +00:00
|
|
|
{
|
|
|
|
char *theCR;
|
|
|
|
|
|
|
|
theCR = strrchr(buf, '\n');
|
|
|
|
if (theCR)
|
|
|
|
*theCR = '\0';
|
|
|
|
theCR = strrchr(buf, '\r');
|
|
|
|
if (theCR)
|
|
|
|
*theCR = '\0';
|
|
|
|
}
|
|
|
|
#endif // CREATE_LOG
|
2005-09-13 09:01:56 +00:00
|
|
|
const char *BOINC_RCSID_7ce0778d35="$Id$";
|