From ba1eb5dc5e7eb99648f4fddd12c4ffc067a472ee Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Sat, 18 Dec 2004 20:52:14 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=4899 --- checkin_notes | 20 +++++++++++++++++++- client/main.C | 23 +++++++++++++++++++++++ client/win/hostinfo_win.cpp | 20 ++++++-------------- client/win/win_idle_tracker.cpp | 24 +++++------------------- lib/hostinfo.h | 2 +- 5 files changed, 54 insertions(+), 35 deletions(-) diff --git a/checkin_notes b/checkin_notes index ba2268f18d..c64cb05c3b 100755 --- a/checkin_notes +++ b/checkin_notes @@ -21569,4 +21569,22 @@ Janus 18 Dec 2004 html/user explain_state.php results.php - filtered_post.png [new] \ No newline at end of file + filtered_post.png [new] + +Rom 18 Dec 2004 + - Make the idle detection code work again on the Windows platform. + + Thanks to Eric Toungdale for pointing out what needed to be done to + fix it. + + I claened up the orginal implementation a bit, reenabled some of the + debugging code that was remarked out. + + client/ + main.C + client/win/ + hostinfo_win.cpp + win_idle_tracker.cpp + lib/ + hostinfo.h + diff --git a/client/main.C b/client/main.C index e512fd62aa..98c381f000 100644 --- a/client/main.C +++ b/client/main.C @@ -328,6 +328,17 @@ int main(int argc, char** argv) { return ERR_IO; } + g_hIdleDetectionDll = LoadLibrary("boinc.dll"); + if(!g_hIdleDetectionDll) + { + printf( + "BOINC Core Client Error Message\n" + "Failed to initialize the BOINC Idle Detection Interface\n" + "BOINC will not be able to determine if the user is idle or not...\n" + ); + } + + SERVICE_TABLE_ENTRY dispatchTable[] = { { TEXT(SZSERVICENAME), (LPSERVICE_MAIN_FUNCTION)service_main }, { NULL, NULL } @@ -353,6 +364,18 @@ int main(int argc, char** argv) { retval = boinc_main_loop(argc, argv); } + + if(g_hIdleDetectionDll) + { + if(!FreeLibrary(g_hIdleDetectionDll)) + { + printf( + "BOINC Core Client Error Message\n" + "Failed to cleanup the BOINC Idle Detection Interface\n" + ); + } + } + if ( WinsockCleanup() != 0 ) { printf( "BOINC Core Client Error Message\n" diff --git a/client/win/hostinfo_win.cpp b/client/win/hostinfo_win.cpp index 0fb4feb29b..3195494a01 100755 --- a/client/win/hostinfo_win.cpp +++ b/client/win/hostinfo_win.cpp @@ -25,7 +25,7 @@ #include "hostinfo_network.h" #include "hostinfo.h" -HINSTANCE m_hIdleDll; +HINSTANCE g_hIdleDetectionDll; // Returns the number of seconds difference from UTC // @@ -374,23 +374,15 @@ bool HOST_INFO::host_is_running_on_batteries() { } bool HOST_INFO::users_idle(bool check_all_logins, double idle_time_to_run) { - if (m_hIdleDll) { - typedef DWORD (CALLBACK* GetFn)(); - GetFn fn; - fn = (GetFn)GetProcAddress(m_hIdleDll, "IdleTrackerGetLastTickCount"); + typedef DWORD (CALLBACK* GetFn)(); + static GetFn fn = (GetFn)GetProcAddress(g_hIdleDetectionDll, "IdleTrackerGetLastTickCount"); + + if (g_hIdleDetectionDll) { if (fn) { return (GetTickCount() - fn()) / 1000 > 60 * idle_time_to_run; - } else { - typedef void (CALLBACK* TermFn)(); - TermFn tfn; - tfn = (TermFn)GetProcAddress(m_hIdleDll, "IdleTrackerTerm"); - if(tfn) { - tfn(); - } - FreeLibrary(m_hIdleDll); - m_hIdleDll = NULL; } } + return false; } diff --git a/client/win/win_idle_tracker.cpp b/client/win/win_idle_tracker.cpp index af969ba58a..e8ac9fcfd0 100644 --- a/client/win/win_idle_tracker.cpp +++ b/client/win/win_idle_tracker.cpp @@ -16,7 +16,7 @@ **/ #include -//#include +#include /** * The following global data is SHARED among all instances of the DLL @@ -82,8 +82,8 @@ __declspec(dllexport) BOOL IdleTrackerInit() g_hHkMouse = SetWindowsHookEx(WH_MOUSE, MouseTracker, g_hInstance, 0); } - //_ASSERT(g_hHkKeyboard); - //_ASSERT(g_hHkMouse); + _ASSERT(g_hHkKeyboard); + _ASSERT(g_hHkMouse); g_dwLastTick = GetTickCount(); // init count @@ -102,13 +102,13 @@ __declspec(dllexport) void IdleTrackerTerm() if (g_hHkKeyboard) { bResult = UnhookWindowsHookEx(g_hHkKeyboard); - //_ASSERT(bResult); + _ASSERT(bResult); g_hHkKeyboard = NULL; } if (g_hHkMouse) { bResult = UnhookWindowsHookEx(g_hHkMouse); - //_ASSERT(bResult); + _ASSERT(bResult); g_hHkMouse = NULL; } } @@ -123,24 +123,10 @@ int WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) DisableThreadLibraryCalls(hInstance); g_hInstance = hInstance; break; - case DLL_PROCESS_DETACH: - //we do an unhook here just in case the user has forgotten. - //IdleTrackerTerm(); - break; } return TRUE; } -/** - * This is to prevent the CRT from loading, thus making this a smaller - * and faster dll. - **/ -/*extern "C" BOOL __stdcall _DllMainCRTStartup( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { - return DllMain( hinstDLL, fdwReason, lpvReserved ); -} - -*/ - #ifdef __GNUC__ static volatile const char __attribute__((unused)) *BOINCrcsid="$Id$"; #else diff --git a/lib/hostinfo.h b/lib/hostinfo.h index e5b0414ca6..f8060762ba 100644 --- a/lib/hostinfo.h +++ b/lib/hostinfo.h @@ -69,7 +69,7 @@ struct HOST_INFO { }; #ifdef _WIN32 - extern HINSTANCE m_hIdleDll; // handle to DLL for user idle + extern HINSTANCE g_hIdleDetectionDll; // handle to DLL for user idle #endif #endif