mirror of https://github.com/BOINC/boinc.git
SCR: Create is_same_task() function which compares both task name and task URL
svn path=/trunk/boinc/; revision=13569
This commit is contained in:
parent
2692557dd5
commit
ca9e5694b2
|
@ -8396,4 +8396,12 @@ Rytis 11 Sep 2007
|
||||||
(protection from spam)
|
(protection from spam)
|
||||||
|
|
||||||
html/inc/uotd.inc
|
html/inc/uotd.inc
|
||||||
|
|
||||||
|
Charlie 5 Sep 2007
|
||||||
|
- SCR: Create is_same_task() function which compares both task name
|
||||||
|
and task URL; call it from count_active_graphic_apps () and
|
||||||
|
get_random_graphics_app().
|
||||||
|
|
||||||
|
clientscr/
|
||||||
|
mac_saver_module.cpp
|
||||||
|
screensaver.cpp,h
|
||||||
|
|
|
@ -484,8 +484,8 @@ OSStatus RPCThread(void* param) {
|
||||||
RESULT* theResult = NULL;
|
RESULT* theResult = NULL;
|
||||||
RESULT* graphics_app_result_ptr = NULL;
|
RESULT* graphics_app_result_ptr = NULL;
|
||||||
PROJECT* pProject;
|
PROJECT* pProject;
|
||||||
std::string current_result_name = "";
|
RESULT* current_result = NULL;
|
||||||
std::string avoid_old_result_name = "";
|
RESULT* avoid_old_result = NULL;
|
||||||
int iResultCount = 0;
|
int iResultCount = 0;
|
||||||
int iIndex = 0;
|
int iIndex = 0;
|
||||||
double percent_done;
|
double percent_done;
|
||||||
|
@ -581,7 +581,7 @@ OSStatus RPCThread(void* param) {
|
||||||
for (iIndex = 0; iIndex < iResultCount; iIndex++) {
|
for (iIndex = 0; iIndex < iResultCount; iIndex++) {
|
||||||
theResult = results.results.at(iIndex);
|
theResult = results.results.at(iIndex);
|
||||||
|
|
||||||
if (theResult->name == current_result_name) {
|
if (is_same_task(theResult, current_result)) {
|
||||||
graphics_app_result_ptr = theResult;
|
graphics_app_result_ptr = theResult;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -600,8 +600,8 @@ print_to_log_file("%s finished", graphics_app_result_ptr->name.c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (last_change_time && ((dtime() - last_change_time) > GFX_CHANGE_PERIOD)) {
|
if (last_change_time && ((dtime() - last_change_time) > GFX_CHANGE_PERIOD)) {
|
||||||
if (count_active_graphic_apps(results, ¤t_result_name) > 0) {
|
if (count_active_graphic_apps(results, current_result) > 0) {
|
||||||
avoid_old_result_name = current_result_name;
|
avoid_old_result = current_result;
|
||||||
terminate_screensaver(graphics_app_pid);
|
terminate_screensaver(graphics_app_pid);
|
||||||
// waitpid test will clear graphics_app_pid and graphics_app_result_ptr
|
// waitpid test will clear graphics_app_pid and graphics_app_result_ptr
|
||||||
}
|
}
|
||||||
|
@ -611,22 +611,22 @@ print_to_log_file("%s finished", graphics_app_result_ptr->name.c_str());
|
||||||
|
|
||||||
// If no current graphics app, pick an active task at random and launch its graphics app
|
// If no current graphics app, pick an active task at random and launch its graphics app
|
||||||
if (graphics_app_pid == 0) {
|
if (graphics_app_pid == 0) {
|
||||||
graphics_app_result_ptr = get_random_graphics_app(results, &avoid_old_result_name);
|
graphics_app_result_ptr = get_random_graphics_app(results, avoid_old_result);
|
||||||
avoid_old_result_name = "";
|
avoid_old_result = NULL;
|
||||||
|
|
||||||
if (graphics_app_result_ptr) {
|
if (graphics_app_result_ptr) {
|
||||||
retval = Mac_launch_screensaver(graphics_app_result_ptr, graphics_app_pid, launcher_shell_pid);
|
retval = Mac_launch_screensaver(graphics_app_result_ptr, graphics_app_pid, launcher_shell_pid);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
graphics_app_pid = 0;
|
graphics_app_pid = 0;
|
||||||
launcher_shell_pid = 0;
|
launcher_shell_pid = 0;
|
||||||
current_result_name = "";
|
current_result = NULL;
|
||||||
graphics_app_result_ptr = NULL;
|
graphics_app_result_ptr = NULL;
|
||||||
} else {
|
} else {
|
||||||
gClientSaverStatus = SS_STATUS_ENABLED;
|
gClientSaverStatus = SS_STATUS_ENABLED;
|
||||||
launch_time = dtime();
|
launch_time = dtime();
|
||||||
last_change_time = launch_time;
|
last_change_time = launch_time;
|
||||||
last_run_check_time = launch_time;
|
last_run_check_time = launch_time;
|
||||||
current_result_name = graphics_app_result_ptr->name;
|
current_result = graphics_app_result_ptr;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (state.projects.size() == 0) {
|
if (state.projects.size() == 0) {
|
||||||
|
@ -646,7 +646,7 @@ print_to_log_file("%s finished", graphics_app_result_ptr->name.c_str());
|
||||||
graphics_app_pid = 0;
|
graphics_app_pid = 0;
|
||||||
launcher_shell_pid = 0;
|
launcher_shell_pid = 0;
|
||||||
graphics_app_result_ptr = NULL;
|
graphics_app_result_ptr = NULL;
|
||||||
current_result_name = "";
|
current_result = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,13 +41,19 @@ bool is_task_active(RESULT* result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_same_task(RESULT* taska, RESULT* taskb) {
|
||||||
|
if ((taska == NULL) || (taskb == NULL)) return false;
|
||||||
|
if (taska->name != taskb->name) return false;
|
||||||
|
if (taska->project_url != taskb->project_url) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int count_active_graphic_apps(RESULTS& results, std::string *exclude) {
|
int count_active_graphic_apps(RESULTS& results, RESULT* exclude) {
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
unsigned int graphics_app_count = 0;
|
unsigned int graphics_app_count = 0;
|
||||||
|
|
||||||
// Count the number of active graphics-capable apps excluding the specified result.
|
// Count the number of active graphics-capable apps excluding the specified result.
|
||||||
// If exclude is NULL or an empty string, don't exclude any results.
|
// If exclude is NULL, don't exclude any results.
|
||||||
for (i = 0; i < results.results.size(); i++) {
|
for (i = 0; i < results.results.size(); i++) {
|
||||||
if (!is_task_active(results.results[i])) continue;
|
if (!is_task_active(results.results[i])) continue;
|
||||||
BOINCTRACE(_T("get_random_graphics_app -- active task detected\n"));
|
BOINCTRACE(_T("get_random_graphics_app -- active task detected\n"));
|
||||||
|
@ -58,7 +64,7 @@ int count_active_graphic_apps(RESULTS& results, std::string *exclude) {
|
||||||
if (results.results[i]->graphics_exec_path.size() == 0) continue;
|
if (results.results[i]->graphics_exec_path.size() == 0) continue;
|
||||||
BOINCTRACE(_T("get_random_graphics_app -- active task detected w/graphics\n"));
|
BOINCTRACE(_T("get_random_graphics_app -- active task detected w/graphics\n"));
|
||||||
|
|
||||||
if ((exclude != NULL) && (*exclude == results.results[i]->name)) continue;
|
if (is_same_task(results.results[i], exclude)) continue;
|
||||||
graphics_app_count++;
|
graphics_app_count++;
|
||||||
}
|
}
|
||||||
return graphics_app_count;
|
return graphics_app_count;
|
||||||
|
@ -69,13 +75,13 @@ int count_active_graphic_apps(RESULTS& results, std::string *exclude) {
|
||||||
// Exclude the specified result unless it is the only candidate.
|
// Exclude the specified result unless it is the only candidate.
|
||||||
// If exclude is NULL or an empty string, don't exclude any results.
|
// If exclude is NULL or an empty string, don't exclude any results.
|
||||||
//
|
//
|
||||||
RESULT* get_random_graphics_app(RESULTS& results, std::string *exclude) {
|
RESULT* get_random_graphics_app(RESULTS& results, RESULT* exclude) {
|
||||||
RESULT* rp = NULL;
|
RESULT* rp = NULL;
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
unsigned int graphics_app_count = 0;
|
unsigned int graphics_app_count = 0;
|
||||||
unsigned int random_selection = 0;
|
unsigned int random_selection = 0;
|
||||||
unsigned int current_counter = 0;
|
unsigned int current_counter = 0;
|
||||||
std::string *avoid = exclude;
|
RESULT *avoid = exclude;
|
||||||
|
|
||||||
BOINCTRACE(_T("get_random_graphics_app -- Function Start\n"));
|
BOINCTRACE(_T("get_random_graphics_app -- Function Start\n"));
|
||||||
|
|
||||||
|
@ -83,7 +89,7 @@ RESULT* get_random_graphics_app(RESULTS& results, std::string *exclude) {
|
||||||
BOINCTRACE(_T("get_random_graphics_app -- graphics_app_count = '%d'\n"), graphics_app_count);
|
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 no graphics app found other than the one excluded, count again without excluding any
|
||||||
if ((0 == graphics_app_count) && (avoid != NULL) && avoid->length()) {
|
if ((0 == graphics_app_count) && (avoid != NULL)) {
|
||||||
avoid = NULL;
|
avoid = NULL;
|
||||||
graphics_app_count = count_active_graphic_apps(results, avoid);
|
graphics_app_count = count_active_graphic_apps(results, avoid);
|
||||||
}
|
}
|
||||||
|
@ -101,7 +107,7 @@ RESULT* get_random_graphics_app(RESULTS& results, std::string *exclude) {
|
||||||
for (i = 0; i < results.results.size(); i++) {
|
for (i = 0; i < results.results.size(); i++) {
|
||||||
if (!is_task_active(results.results[i])) continue;
|
if (!is_task_active(results.results[i])) continue;
|
||||||
if (results.results[i]->graphics_exec_path.size() == 0) continue;
|
if (results.results[i]->graphics_exec_path.size() == 0) continue;
|
||||||
if ((avoid != NULL) && (*avoid == results.results[i]->name)) continue;
|
if (is_same_task(results.results[i], avoid)) continue;
|
||||||
|
|
||||||
current_counter++;
|
current_counter++;
|
||||||
if (current_counter == random_selection) {
|
if (current_counter == random_selection) {
|
||||||
|
|
|
@ -24,12 +24,15 @@
|
||||||
// Determine if the result is active and executing
|
// Determine if the result is active and executing
|
||||||
extern bool is_task_active(RESULT* result);
|
extern bool is_task_active(RESULT* result);
|
||||||
|
|
||||||
|
// Determine if two RESULT pointers refer to the same task
|
||||||
|
extern bool is_same_task(RESULT* taska, RESULT* taskb);
|
||||||
|
|
||||||
// Count the number of active graphics-capable apps
|
// Count the number of active graphics-capable apps
|
||||||
extern int count_active_graphic_apps(RESULTS& results, std::string *exclude=NULL);
|
extern int count_active_graphic_apps(RESULTS& results, RESULT* exclude);
|
||||||
|
|
||||||
// Choose a ramdom graphics application from the vector that
|
// Choose a ramdom graphics application from the vector that
|
||||||
// was passed in.
|
// was passed in.
|
||||||
extern RESULT* get_random_graphics_app(RESULTS& results, std::string *exclude=NULL);
|
extern RESULT* get_random_graphics_app(RESULTS& results, RESULT* exclude);
|
||||||
|
|
||||||
// Launch the screensaver
|
// Launch the screensaver
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
Loading…
Reference in New Issue