mirror of https://github.com/BOINC/boinc.git
- SCR: Move more code into the shared code module
clientscr/ screensaver.cpp, .h screensaver_win.cpp svn path=/trunk/boinc/; revision=13473
This commit is contained in:
parent
4b0653b8f6
commit
10a59b8ad2
|
@ -8154,3 +8154,12 @@ Charlie 27 Aug 2007
|
|||
app_start.C
|
||||
lib/
|
||||
shmem.C,h
|
||||
|
||||
|
||||
Rom 28 Aug 2007
|
||||
- SCR: Move more code into the shared code module
|
||||
|
||||
clientscr/
|
||||
screensaver.cpp, .h
|
||||
screensaver_win.cpp
|
||||
|
||||
|
|
|
@ -29,23 +29,87 @@
|
|||
#include "screensaver.h"
|
||||
|
||||
|
||||
// Choose a random graphics application out of the vector.
|
||||
// NOTE: Right now it just selects the first graphics app
|
||||
// found.
|
||||
RESULT* random_graphics_app(RESULTS& results) {
|
||||
bool bIsActive = false;
|
||||
bool bIsExecuting = false;
|
||||
bool bIsDownloaded = false;
|
||||
// Determine if a task is active and executing
|
||||
//
|
||||
bool is_task_active(RESULT* result) {
|
||||
bool bIsActive = RESULT_FILES_DOWNLOADED == result->state;
|
||||
bool bIsDownloaded = CPU_SCHED_SCHEDULED == result->scheduler_state;
|
||||
bool bIsExecuting = result->active_task;
|
||||
|
||||
for (unsigned i=0; i < results.results.size(); i++) {
|
||||
if (!bIsActive || !bIsDownloaded || !bIsExecuting)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Choose a random graphics application out of the vector.
|
||||
//
|
||||
RESULT* get_random_graphics_app(RESULTS& results) {
|
||||
unsigned int i = 0;
|
||||
unsigned int graphics_app_count = 0;
|
||||
unsigned int random_selection = 0;
|
||||
unsigned int current_counter = 0;
|
||||
|
||||
// Count the number of graphics apps
|
||||
for (i = 0; i < results.results.size(); i++) {
|
||||
if (!is_task_active(results.results[i])) continue;
|
||||
if (results.results[i]->graphics_exec_path.size() > 0) {
|
||||
bIsDownloaded = (RESULT_FILES_DOWNLOADED == results.results[i]->state);
|
||||
bIsActive = (results.results[i]->active_task);
|
||||
bIsExecuting = (CPU_SCHED_SCHEDULED == results.results[i]->scheduler_state);
|
||||
if (!(bIsActive) || !(bIsDownloaded) || !(bIsExecuting)) continue;
|
||||
return results.results[i];
|
||||
graphics_app_count++;
|
||||
}
|
||||
}
|
||||
|
||||
// Choose which application to display.
|
||||
random_selection = rand() % graphics_app_count;
|
||||
|
||||
// Lets find the choosen graphics application.
|
||||
for (i = 0; i < results.results.size(); i++) {
|
||||
if (!is_task_active(results.results[i])) continue;
|
||||
if (results.results[i]->graphics_exec_path.size() > 0) {
|
||||
current_counter++;
|
||||
if (current_counter == random_selection) {
|
||||
return results.results[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// Launch the graphics application
|
||||
//
|
||||
#ifdef _WIN32
|
||||
int launch_screensaver(RESULT* rp, HANDLE& graphics_application)
|
||||
#else
|
||||
int launch_screensaver(RESULT* rp, int& graphics_application)
|
||||
#endif
|
||||
{
|
||||
int retval = 0;
|
||||
char* argv[3];
|
||||
argv[0] = "app_graphics"; // not used
|
||||
argv[1] = "--fullscreen";
|
||||
argv[2] = 0;
|
||||
retval = run_program(
|
||||
rp->slot_path.c_str(),
|
||||
rp->graphics_exec_path.c_str(),
|
||||
2,
|
||||
argv,
|
||||
0,
|
||||
graphics_application
|
||||
);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
// Terminate the graphics application
|
||||
//
|
||||
#ifdef _WIN32
|
||||
int terminate_screensaver(HANDLE& graphics_application)
|
||||
#else
|
||||
int terminate_screensaver(int& graphics_application)
|
||||
#endif
|
||||
{
|
||||
kill_program(graphics_application);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,25 @@
|
|||
#ifndef __SCREENSAVER_H__
|
||||
#define __SCREENSAVER_H__
|
||||
|
||||
// Determine if the result is active and executing
|
||||
extern bool is_task_active(RESULT* result);
|
||||
|
||||
// Choose a ramdom graphics application from the vector that
|
||||
// was passed in.
|
||||
extern RESULT* random_graphics_app(RESULTS& results);
|
||||
extern RESULT* get_random_graphics_app(RESULTS& results);
|
||||
|
||||
// Launch the screensaver
|
||||
#ifdef _WIN32
|
||||
extern int launch_screensaver(RESULT* rp, HANDLE& graphics_application);
|
||||
#else
|
||||
extern int launch_screensaver(RESULT* rp, int& graphics_application);
|
||||
#endif
|
||||
|
||||
// Terminate the screensaver
|
||||
#ifdef _WIN32
|
||||
extern int terminate_screensaver(HANDLE& graphics_application);
|
||||
#else
|
||||
extern int terminate_screensaver(int& graphics_application);
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -124,6 +124,10 @@ INT WINAPI WinMain(
|
|||
}
|
||||
}
|
||||
|
||||
// Initialize the CRT random number generator.
|
||||
srand((unsigned int)time(0));
|
||||
|
||||
// Initialize the Windows sockets interface.
|
||||
retval = WSAStartup(MAKEWORD(1, 1), &wsdata);
|
||||
if (retval) {
|
||||
BOINCTRACE("WinMain - Winsock Initialization Failure '%d'\n", retval);
|
||||
|
@ -138,6 +142,7 @@ INT WINAPI WinMain(
|
|||
|
||||
retval = BOINCSS.Run();
|
||||
|
||||
// Cleanup the Windows sockets interface.
|
||||
WSACleanup();
|
||||
|
||||
// Clean up function pointers.
|
||||
|
@ -868,9 +873,6 @@ BOOL CScreensaver::SetError(BOOL bErrorMode, HRESULT hrError) {
|
|||
VOID CScreensaver::UpdateErrorBoxText() {
|
||||
PROJECT* pProject;
|
||||
TCHAR szBuffer[256];
|
||||
bool bIsActive = false;
|
||||
bool bIsExecuting = false;
|
||||
bool bIsDownloaded = false;
|
||||
size_t iResultCount = 0;
|
||||
size_t iIndex = 0;
|
||||
|
||||
|
@ -880,10 +882,7 @@ VOID CScreensaver::UpdateErrorBoxText() {
|
|||
if (SCRAPPERR_BOINCNOGRAPHICSAPPSEXECUTING == m_hrError) {
|
||||
iResultCount = results.results.size();
|
||||
for (iIndex = 0; iIndex < iResultCount; iIndex++) {
|
||||
bIsDownloaded = (RESULT_FILES_DOWNLOADED == results.results.at(iIndex)->state);
|
||||
bIsActive = (results.results.at(iIndex)->active_task);
|
||||
bIsExecuting = (CPU_SCHED_SCHEDULED == results.results.at(iIndex)->scheduler_state);
|
||||
if (!(bIsActive) || !(bIsDownloaded) || !(bIsExecuting)) continue;
|
||||
if (!is_task_active(results.results.at(iIndex))) continue;
|
||||
|
||||
pProject = state.lookup_project(results.results.at(iIndex)->project_url);
|
||||
if (NULL != pProject) {
|
||||
|
@ -1013,7 +1012,7 @@ DWORD WINAPI CScreensaver::DataManagementProc() {
|
|||
tThreadCreateTime = time(0);
|
||||
|
||||
while(1) {
|
||||
bScreenSaverStarting = (2 >= (time(0) - tThreadCreateTime));
|
||||
bScreenSaverStarting = (3 >= (time(0) - tThreadCreateTime));
|
||||
|
||||
BOINCTRACE(_T("CScreensaver::DataManagementProc - ErrorMode = '%d', ErrorCode = '%x'\n"), m_bErrorMode, m_hrError);
|
||||
|
||||
|
@ -1059,23 +1058,11 @@ DWORD WINAPI CScreensaver::DataManagementProc() {
|
|||
if (!m_bScreensaverStarted) {
|
||||
|
||||
// Choose a random graphics application to start.
|
||||
RESULT* rp = random_graphics_app(results);
|
||||
RESULT* rp = get_random_graphics_app(results);
|
||||
|
||||
if (rp) {
|
||||
int retval = 0;
|
||||
char* argv[3];
|
||||
argv[0] = "app_graphics"; // not used
|
||||
argv[1] = "--fullscreen";
|
||||
argv[2] = 0;
|
||||
retval = run_program(
|
||||
rp->slot_path.c_str(),
|
||||
rp->graphics_exec_path.c_str(),
|
||||
2,
|
||||
argv,
|
||||
0,
|
||||
m_hGraphicsApplication
|
||||
);
|
||||
BOINCTRACE(_T("CScreensaver::DataManagementProc - run_program RetVal = '%d', m_hGraphicsApplication = '%d'\n"), retval, m_hGraphicsApplication);
|
||||
int retval = launch_screensaver(rp, m_hGraphicsApplication);
|
||||
BOINCTRACE(_T("CScreensaver::DataManagementProc - launch_screensaver RetVal = '%d', m_hGraphicsApplication = '%d'\n"), retval, m_hGraphicsApplication);
|
||||
if (!retval) {
|
||||
m_bScreensaverStarted = TRUE;
|
||||
}
|
||||
|
@ -1576,7 +1563,7 @@ VOID CScreensaver::ShutdownSaver() {
|
|||
}
|
||||
|
||||
// Kill the currently executing graphics application
|
||||
kill_program(m_hGraphicsApplication);
|
||||
terminate_screensaver(m_hGraphicsApplication);
|
||||
|
||||
// Post message to drop out of message loop
|
||||
// This can be called from the data management thread, so specifically
|
||||
|
|
Loading…
Reference in New Issue