diff --git a/checkin_notes b/checkin_notes index 3a84cf457b..6056569811 100755 --- a/checkin_notes +++ b/checkin_notes @@ -8396,4 +8396,12 @@ Rytis 11 Sep 2007 (protection from spam) html/inc/uotd.inc - \ No newline at end of file + +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 diff --git a/clientscr/mac_saver_module.cpp b/clientscr/mac_saver_module.cpp index 87b0bdc210..a5e548f2c9 100755 --- a/clientscr/mac_saver_module.cpp +++ b/clientscr/mac_saver_module.cpp @@ -484,8 +484,8 @@ OSStatus RPCThread(void* param) { RESULT* theResult = NULL; RESULT* graphics_app_result_ptr = NULL; PROJECT* pProject; - std::string current_result_name = ""; - std::string avoid_old_result_name = ""; + RESULT* current_result = NULL; + RESULT* avoid_old_result = NULL; int iResultCount = 0; int iIndex = 0; double percent_done; @@ -581,7 +581,7 @@ OSStatus RPCThread(void* param) { for (iIndex = 0; iIndex < iResultCount; iIndex++) { theResult = results.results.at(iIndex); - if (theResult->name == current_result_name) { + if (is_same_task(theResult, current_result)) { graphics_app_result_ptr = theResult; break; } @@ -600,8 +600,8 @@ print_to_log_file("%s finished", graphics_app_result_ptr->name.c_str()); } #endif if (last_change_time && ((dtime() - last_change_time) > GFX_CHANGE_PERIOD)) { - if (count_active_graphic_apps(results, ¤t_result_name) > 0) { - avoid_old_result_name = current_result_name; + if (count_active_graphic_apps(results, current_result) > 0) { + avoid_old_result = current_result; terminate_screensaver(graphics_app_pid); // 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 (graphics_app_pid == 0) { - graphics_app_result_ptr = get_random_graphics_app(results, &avoid_old_result_name); - avoid_old_result_name = ""; + graphics_app_result_ptr = get_random_graphics_app(results, avoid_old_result); + avoid_old_result = NULL; if (graphics_app_result_ptr) { retval = Mac_launch_screensaver(graphics_app_result_ptr, graphics_app_pid, launcher_shell_pid); if (retval) { graphics_app_pid = 0; launcher_shell_pid = 0; - current_result_name = ""; + current_result = NULL; graphics_app_result_ptr = NULL; } else { gClientSaverStatus = SS_STATUS_ENABLED; launch_time = dtime(); last_change_time = launch_time; last_run_check_time = launch_time; - current_result_name = graphics_app_result_ptr->name; + current_result = graphics_app_result_ptr; } } else { 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; launcher_shell_pid = 0; graphics_app_result_ptr = NULL; - current_result_name = ""; + current_result = NULL; continue; } } diff --git a/clientscr/screensaver.cpp b/clientscr/screensaver.cpp index 538736d2b9..d0d2c7c649 100644 --- a/clientscr/screensaver.cpp +++ b/clientscr/screensaver.cpp @@ -41,13 +41,19 @@ bool is_task_active(RESULT* result) { 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 graphics_app_count = 0; // 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++) { if (!is_task_active(results.results[i])) continue; 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; 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++; } 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. // 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; unsigned int i = 0; unsigned int graphics_app_count = 0; unsigned int random_selection = 0; unsigned int current_counter = 0; - std::string *avoid = exclude; + RESULT *avoid = exclude; 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); // 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; 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++) { if (!is_task_active(results.results[i])) 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++; if (current_counter == random_selection) { diff --git a/clientscr/screensaver.h b/clientscr/screensaver.h index c37e38f308..0db862f8c5 100644 --- a/clientscr/screensaver.h +++ b/clientscr/screensaver.h @@ -24,12 +24,15 @@ // Determine if the result is active and executing 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 -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 // 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 #ifdef _WIN32