From 7286dbdd18dfb52ae7b6ab9d7d962cf7cb60f5a0 Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Mon, 23 Jan 2006 08:47:05 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=9284 --- checkin_notes | 36 +++ client/main.C | 42 +-- client/win/hostinfo_win.cpp | 6 +- clientgui/AccountManagerPropertiesPage.cpp | 2 +- clientgui/BOINCGUIApp.cpp | 135 ++++++--- clientgui/BOINCGUIApp.h | 8 +- clientgui/MainFrame.cpp | 7 +- clientgui/ProjectPropertiesPage.cpp | 2 +- clientlib/win/BOINCSENSSink.cpp | 180 ++++++++++++ clientlib/win/BOINCSENSSink.h | 101 +++++++ clientlib/win/Identification.cpp | 163 ++++++++++ clientlib/win/Identification.h | 24 ++ clientlib/win/IdleTracker.cpp | 298 +++++++++++++++++++ clientlib/win/IdleTracker.h | 23 ++ clientlib/win/NetworkTracker.cpp | 327 +++++++++++++++++++++ clientlib/win/NetworkTracker.h | 23 ++ clientlib/win/SENSLogonSubscriptions.h | 142 +++++++++ clientlib/win/SENSNetworkSubscriptions.h | 110 +++++++ clientlib/win/SENSOnNowSubscriptions.h | 78 +++++ clientlib/win/SENSSubscriptions.h | 58 ++++ clientlib/win/boinc_dll.cpp | 55 ++++ clientlib/win/boinc_dll.h | 29 ++ clientlib/win/boinc_dll.rc | 205 +++++++++++++ clientlib/win/boincsens.rgs | 11 + clientlib/win/resource.h | 17 ++ clientlib/win/stdafx.cpp | 5 + clientlib/win/stdafx.h | 56 ++++ lib/network.C | 26 +- lib/network.h | 14 + win_build/boinc_dll.vcproj | 188 ++++++------ win_build/installerv2/BOINC.ism | Bin 205312 -> 205312 bytes win_build/installerv2/CPDNBBC.ism | Bin 205848 -> 205848 bytes win_build/installerv2/GridRepublic.ism | Bin 205852 -> 205852 bytes 33 files changed, 2203 insertions(+), 168 deletions(-) create mode 100755 clientlib/win/BOINCSENSSink.cpp create mode 100755 clientlib/win/BOINCSENSSink.h create mode 100755 clientlib/win/Identification.cpp create mode 100755 clientlib/win/Identification.h create mode 100755 clientlib/win/IdleTracker.cpp create mode 100755 clientlib/win/IdleTracker.h create mode 100755 clientlib/win/NetworkTracker.cpp create mode 100755 clientlib/win/NetworkTracker.h create mode 100755 clientlib/win/SENSLogonSubscriptions.h create mode 100755 clientlib/win/SENSNetworkSubscriptions.h create mode 100755 clientlib/win/SENSOnNowSubscriptions.h create mode 100755 clientlib/win/SENSSubscriptions.h create mode 100755 clientlib/win/boinc_dll.cpp create mode 100755 clientlib/win/boinc_dll.h create mode 100755 clientlib/win/boinc_dll.rc create mode 100755 clientlib/win/boincsens.rgs create mode 100755 clientlib/win/resource.h create mode 100755 clientlib/win/stdafx.cpp create mode 100755 clientlib/win/stdafx.h diff --git a/checkin_notes b/checkin_notes index 26f3406f25..51ebe8c5c8 100755 --- a/checkin_notes +++ b/checkin_notes @@ -768,3 +768,39 @@ Bruce 22 Jan 2006 sched/ update_stats.C +Rom 23 Jan 2007 + - On Windows use the System Event Notification Service to determine + network connectivity instead of using InternetGetConnectedState + since it was proving to be unreliable. + + NOTE: This is a big change on Windows. SENS uses COM as it's + communication infrastructure and so therefore boinc.dll now has + to be regsvr32'ed before network notification messages will be + sent to the client. If, for whatever reason SENS isn't working + we'll fall back to InternetGetConnectedState. + + client/ + main.C + client/win/ + hostinfo_win.cpp + clientgui/ + AccountManagerPropertiesPage.cpp + BOINCGUIApp.cpp, .h + MainFrame.cpp + ProjectPropertiesPage.cpp + clientlib/win/ + boinc_dll.cpp, .h (Added) + BOINCSENSSink.cpp, .h (Added) + Identification.cpp, .h (Added) + IdleTracker.cpp, .h (Added) + NetworkTracker.cpp, .h (Added) + resource.h (Added) + SENSLogonSubscriptions.h (Added) + SENSNetworkSubscriptions.h (Added) + SENSOnNowSubscriptions.h (Added) + SENSSubscriptions.h (Added) + stdafx.cpp, .h (Added) + lib/ + network.C, .h + win_build/ + boinc_dll.vcproj diff --git a/client/main.C b/client/main.C index 964a9abf0f..6e86fcdd43 100644 --- a/client/main.C +++ b/client/main.C @@ -28,13 +28,13 @@ #include "win_service.h" #include "win_util.h" -extern HINSTANCE g_hIdleDetectionDll; +extern HINSTANCE g_hClientLibraryDll; static HANDLE g_hWin9xMonitorSystemThread = NULL; static DWORD g_Win9xMonitorSystemThreadID = NULL; static BOOL g_bIsWin9x = FALSE; -typedef BOOL (CALLBACK* IdleTrackerInit)(); -typedef void (CALLBACK* IdleTrackerTerm)(); +typedef BOOL (CALLBACK* ClientLibraryStartup)(); +typedef void (CALLBACK* ClientLibraryShutdown)(); #ifndef _T #define _T(X) X #endif @@ -558,8 +558,8 @@ int main(int argc, char** argv) { } #endif - g_hIdleDetectionDll = LoadLibrary("boinc.dll"); - if(!g_hIdleDetectionDll) { + g_hClientLibraryDll = LoadLibrary("boinc.dll"); + if(!g_hClientLibraryDll) { printf( "BOINC Core Client Error Message\n" "Failed to initialize the BOINC Idle Detection Interface\n" @@ -567,16 +567,16 @@ int main(int argc, char** argv) { ); } - if(g_hIdleDetectionDll) { - IdleTrackerInit fnIdleTrackerInit; - fnIdleTrackerInit = (IdleTrackerInit)GetProcAddress(g_hIdleDetectionDll, _T("IdleTrackerInit")); - if(!fnIdleTrackerInit) { - FreeLibrary(g_hIdleDetectionDll); - g_hIdleDetectionDll = NULL; + if(g_hClientLibraryDll) { + ClientLibraryStartup fnClientLibraryStartup; + fnClientLibraryStartup = (ClientLibraryStartup)GetProcAddress(g_hClientLibraryDll, _T("ClientLibraryStartup")); + if(!fnClientLibraryStartup) { + FreeLibrary(g_hClientLibraryDll); + g_hClientLibraryDll = NULL; } else { - if(!fnIdleTrackerInit()) { - FreeLibrary(g_hIdleDetectionDll); - g_hIdleDetectionDll = NULL; + if(!fnClientLibraryStartup()) { + FreeLibrary(g_hClientLibraryDll); + g_hClientLibraryDll = NULL; } } } @@ -617,19 +617,19 @@ int main(int argc, char** argv) { #endif #ifdef _WIN32 - if(g_hIdleDetectionDll) { - IdleTrackerTerm fnIdleTrackerTerm; - fnIdleTrackerTerm = (IdleTrackerTerm)GetProcAddress(g_hIdleDetectionDll, _T("IdleTrackerTerm")); - if(fnIdleTrackerTerm) { - fnIdleTrackerTerm(); + if(g_hClientLibraryDll) { + ClientLibraryShutdown fnClientLibraryShutdown; + fnClientLibraryShutdown = (ClientLibraryShutdown)GetProcAddress(g_hClientLibraryDll, _T("ClientLibraryShutdown")); + if(fnClientLibraryShutdown) { + fnClientLibraryShutdown(); } - if(!FreeLibrary(g_hIdleDetectionDll)) { + if(!FreeLibrary(g_hClientLibraryDll)) { printf( "BOINC Core Client Error Message\n" "Failed to cleanup the BOINC Idle Detection Interface\n" ); } - g_hIdleDetectionDll = NULL; + g_hClientLibraryDll = NULL; } #ifdef USE_WINSOCK diff --git a/client/win/hostinfo_win.cpp b/client/win/hostinfo_win.cpp index 7fe37c6d09..400097a599 100755 --- a/client/win/hostinfo_win.cpp +++ b/client/win/hostinfo_win.cpp @@ -26,7 +26,7 @@ #include "hostinfo_network.h" #include "hostinfo.h" -HINSTANCE g_hIdleDetectionDll; +HINSTANCE g_hClientLibraryDll; // Memory Status Structure for Win2K and WinXP based systems. typedef struct _MYMEMORYSTATUSEX { @@ -426,9 +426,9 @@ bool HOST_INFO::host_is_running_on_batteries() { bool HOST_INFO::users_idle(bool check_all_logins, double idle_time_to_run) { typedef DWORD (CALLBACK* GetFn)(); - static GetFn fn = (GetFn)GetProcAddress(g_hIdleDetectionDll, "IdleTrackerGetIdleTickCount"); + static GetFn fn = (GetFn)GetProcAddress(g_hClientLibraryDll, "BOINCGetIdleTickCount"); - if (g_hIdleDetectionDll) { + if (g_hClientLibraryDll) { if (fn) { double seconds_idle = fn() / 1000; double seconds_time_to_run = 60 * idle_time_to_run; diff --git a/clientgui/AccountManagerPropertiesPage.cpp b/clientgui/AccountManagerPropertiesPage.cpp index e4d151f02f..f5a43997c4 100644 --- a/clientgui/AccountManagerPropertiesPage.cpp +++ b/clientgui/AccountManagerPropertiesPage.cpp @@ -24,8 +24,8 @@ #include "stdwx.h" #include "wizardex.h" #include "error_numbers.h" -#include "BOINCGUIApp.h" #include "network.h" +#include "BOINCGUIApp.h" #include "BOINCWizards.h" #include "BOINCBaseWizard.h" #include "WizardAccountManager.h" diff --git a/clientgui/BOINCGUIApp.cpp b/clientgui/BOINCGUIApp.cpp index 81b44ac097..e1c319e3f5 100644 --- a/clientgui/BOINCGUIApp.cpp +++ b/clientgui/BOINCGUIApp.cpp @@ -28,6 +28,7 @@ #include "stdwx.h" #include "BOINCGUIApp.h" #include "diagnostics.h" +#include "network.h" #include "MainFrame.h" #include "Events.h" #include "MainDocument.h" @@ -49,9 +50,11 @@ #ifdef __WXMSW__ -typedef BOOL (CALLBACK* IdleTrackerInit)(); -typedef void (CALLBACK* IdleTrackerTerm)(); -typedef DWORD (CALLBACK* IdleTrackerGetIdleTickCount)(); +typedef BOOL (*pfnClientLibraryStartup)(); +typedef void (*pfnClientLibraryShutdown)(); +typedef int (*pfnBOINCIsNetworkAlive)(LPDWORD lpdwFlags); +typedef int (*pfnBOINCIsNetworkAlwaysOnline)(); +typedef DWORD (*pfnBOINCGetIdleTickCount)(); #endif IMPLEMENT_APP(CBOINCGUIApp) @@ -184,6 +187,19 @@ bool CBrandingScheme::OnInit( wxConfigBase *pConfig ) { bool CBOINCGUIApp::OnInit() { + + // Setup variables with default values + m_bBOINCStartedByManager = false; + m_bFrameVisible = true; + m_lBOINCCoreProcessId = 0; +#ifdef __WXMSW__ + m_hBOINCCoreProcess = NULL; + m_hClientLibraryDll = NULL; +#endif + m_strDefaultWindowStation = wxT(""); + m_strDefaultDesktop = wxT(""); + m_strDefaultDisplay = wxT(""); + #ifdef __WXMSW__ TCHAR szPath[MAX_PATH-1]; @@ -198,13 +214,6 @@ bool CBOINCGUIApp::OnInit() { } #endif - - // Setup the branding scheme - m_pBranding = new CBrandingScheme; - wxASSERT(m_pBranding); - - m_pBranding->OnInit(m_pConfig); - #ifdef __WXMAC__ wxString strDirectory = wxEmptyString; @@ -236,22 +245,25 @@ bool CBOINCGUIApp::OnInit() { #endif // __WXMAC__ + // Setup application and company information SetAppName(wxT("BOINC Manager")); SetVendorName(wxT("Space Sciences Laboratory, U.C. Berkeley")); - // Setup variables with default values - m_bBOINCStartedByManager = false; - m_bFrameVisible = true; - m_lBOINCCoreProcessId = 0; -#ifdef __WXMSW__ - m_hBOINCCoreProcess = NULL; - m_hIdleDetectionDll = NULL; -#endif - m_strDefaultWindowStation = wxT(""); - m_strDefaultDesktop = wxT(""); - m_strDefaultDisplay = wxT(""); + // Initialize the configuration storage module + m_pConfig = new wxConfig(GetAppName()); + wxConfigBase::Set(m_pConfig); + wxASSERT(m_pConfig); + + m_pConfig->SetPath(wxT("/")); + + + // Setup the branding scheme + m_pBranding = new CBrandingScheme; + wxASSERT(m_pBranding); + + m_pBranding->OnInit(m_pConfig); // Initialize the BOINC Diagnostics Framework @@ -271,13 +283,6 @@ bool CBOINCGUIApp::OnInit() { "stderrgui" ); - // Initialize the configuration storage module - m_pConfig = new wxConfig(GetAppName()); - wxConfigBase::Set(m_pConfig); - wxASSERT(m_pConfig); - - m_pConfig->SetPath(wxT("/")); - // Enable Logging and Trace Masks m_pLog = new wxLogBOINC(); wxLog::SetActiveTarget(m_pLog); @@ -343,7 +348,7 @@ bool CBOINCGUIApp::OnInit() { DetectDisplayInfo(); // Startup the System Idle Detection code - StartupSystemIdleDetection(); + ClientLibraryStartup(); // Detect if we need to start the BOINC Core Client due to configuration StartupBOINCCore(); @@ -396,7 +401,7 @@ int CBOINCGUIApp::OnExit() { ShutdownBOINCCore(); // Shutdown the System Idle Detection code - ShutdownSystemIdleDetection(); + ClientLibraryShutdown(); #if defined(__WXMSW__) || defined(__WXMAC__) if (m_pTaskBarIcon) { @@ -779,21 +784,21 @@ void CBOINCGUIApp::ShutdownBOINCCore() { #endif -wxInt32 CBOINCGUIApp::StartupSystemIdleDetection() { +int CBOINCGUIApp::ClientLibraryStartup() { #ifdef __WXMSW__ // load dll and start idle detection - m_hIdleDetectionDll = LoadLibrary("boinc.dll"); - if(m_hIdleDetectionDll) { - IdleTrackerInit fn; - fn = (IdleTrackerInit)GetProcAddress(m_hIdleDetectionDll, wxT("IdleTrackerInit")); + m_hClientLibraryDll = LoadLibrary("boinc.dll"); + if(m_hClientLibraryDll) { + pfnClientLibraryStartup fn; + fn = (pfnClientLibraryStartup)GetProcAddress(m_hClientLibraryDll, wxT("ClientLibraryStartup")); if(!fn) { - FreeLibrary(m_hIdleDetectionDll); - m_hIdleDetectionDll = NULL; + FreeLibrary(m_hClientLibraryDll); + m_hClientLibraryDll = NULL; return -1; } else { if(!fn()) { - FreeLibrary(m_hIdleDetectionDll); - m_hIdleDetectionDll = NULL; + FreeLibrary(m_hClientLibraryDll); + m_hClientLibraryDll = NULL; return -1; } } @@ -803,29 +808,61 @@ wxInt32 CBOINCGUIApp::StartupSystemIdleDetection() { } -wxInt32 CBOINCGUIApp::ShutdownSystemIdleDetection() { +int CBOINCGUIApp::ClientLibraryShutdown() { #ifdef __WXMSW__ - if(m_hIdleDetectionDll) { - IdleTrackerTerm fn; - fn = (IdleTrackerTerm)GetProcAddress(m_hIdleDetectionDll, wxT("IdleTrackerTerm")); + if(m_hClientLibraryDll) { + pfnClientLibraryShutdown fn; + fn = (pfnClientLibraryShutdown)GetProcAddress(m_hClientLibraryDll, wxT("ClientLibraryShutdown")); if(fn) { fn(); } else { return -1; } - FreeLibrary(m_hIdleDetectionDll); - m_hIdleDetectionDll = NULL; + FreeLibrary(m_hClientLibraryDll); + m_hClientLibraryDll = NULL; } #endif return 0; } -wxInt32 CBOINCGUIApp::UpdateSystemIdleDetection() { +int CBOINCGUIApp::IsNetworkAlive(LPDWORD lpdwFlags) { #ifdef __WXMSW__ - if (m_hIdleDetectionDll) { - IdleTrackerGetIdleTickCount fn; - fn = (IdleTrackerGetIdleTickCount)GetProcAddress(m_hIdleDetectionDll, wxT("IdleTrackerGetIdleTickCount")); + if(m_hClientLibraryDll) { + pfnBOINCIsNetworkAlive fn; + fn = (pfnBOINCIsNetworkAlive)GetProcAddress(m_hClientLibraryDll, wxT("BOINCIsNetworkAlive")); + if(fn) { + return fn(lpdwFlags); + } else { + return -1; + } + } +#endif + return TRUE; +} + + +int CBOINCGUIApp::IsNetworkAlwaysOnline() { +#ifdef __WXMSW__ + if(m_hClientLibraryDll) { + pfnBOINCIsNetworkAlwaysOnline fn; + fn = (pfnBOINCIsNetworkAlwaysOnline)GetProcAddress(m_hClientLibraryDll, wxT("BOINCIsNetworkAlwaysOnline")); + if(fn) { + return fn(); + } else { + return -1; + } + } +#endif + return TRUE; +} + + +int CBOINCGUIApp::UpdateSystemIdleDetection() { +#ifdef __WXMSW__ + if (m_hClientLibraryDll) { + pfnBOINCGetIdleTickCount fn; + fn = (pfnBOINCGetIdleTickCount)GetProcAddress(m_hClientLibraryDll, wxT("BOINCGetIdleTickCount")); if(fn) { fn(); } else { diff --git a/clientgui/BOINCGUIApp.h b/clientgui/BOINCGUIApp.h index 0e923c4e1b..a13943b5ad 100644 --- a/clientgui/BOINCGUIApp.h +++ b/clientgui/BOINCGUIApp.h @@ -100,8 +100,8 @@ protected: bool ProcessExists(pid_t thePID); #endif - int StartupSystemIdleDetection(); - int ShutdownSystemIdleDetection(); + int ClientLibraryStartup(); + int ClientLibraryShutdown(); wxConfig* m_pConfig; wxLocale* m_pLocale; @@ -124,7 +124,7 @@ protected: #ifdef __WXMSW__ HANDLE m_hBOINCCoreProcess; - HINSTANCE m_hIdleDetectionDll; + HINSTANCE m_hClientLibraryDll; #endif // The last value defined in the wxLanguage enum is wxLANGUAGE_USER_DEFINED. @@ -139,6 +139,8 @@ public: bool OnInit(); + int IsNetworkAlive(LPDWORD lpdwFlags); + int IsNetworkAlwaysOnline(); int UpdateSystemIdleDetection(); CBrandingScheme* GetBrand() { return m_pBranding; } diff --git a/clientgui/MainFrame.cpp b/clientgui/MainFrame.cpp index 2a5fa7a722..3e500fc3a0 100644 --- a/clientgui/MainFrame.cpp +++ b/clientgui/MainFrame.cpp @@ -23,6 +23,7 @@ #include "stdwx.h" #include "hyperlink.h" +#include "network.h" #include "BOINCGUIApp.h" #include "MainFrame.h" #include "Events.h" @@ -1548,6 +1549,8 @@ void CMainFrame::OnFrameRender(wxTimerEvent &event) { bool is_online = false; int want_network = 0; int answer = 0; + DWORD dwConnectionFlags = + NETWORK_ALIVE_LAN | NETWORK_ALIVE_WAN | NETWORK_ALIVE_AOL; wxString strConnectionName = wxEmptyString; wxString strConnectionUsername = wxEmptyString; wxString strConnectionPassword = wxEmptyString; @@ -1576,7 +1579,7 @@ void CMainFrame::OnFrameRender(wxTimerEvent &event) { tsLastDialupIsAlreadyOnlineCheck = wxDateTime::Now() - dtLastDialupIsAlreadyOnlineCheck; if (tsLastDialupIsAlreadyOnlineCheck.GetSeconds() > 60) { dtLastDialupIsAlreadyOnlineCheck = wxDateTime::Now(); - is_already_online = m_pDialupManager->IsAlwaysOnline(); + is_already_online = wxGetApp().IsNetworkAlwaysOnline() ? true : false; } // Are we configured to detect a network or told one already exists? @@ -1596,7 +1599,7 @@ void CMainFrame::OnFrameRender(wxTimerEvent &event) { // cache the various states is_dialing = m_pDialupManager->IsDialing(); - is_online = m_pDialupManager->IsOnline(); + is_online = wxGetApp().IsNetworkAlive(&dwConnectionFlags) ? true : false; pDoc->rpc.network_query(want_network); wxLogTrace(wxT("Function Status"), wxT("CMainFrame::OnFrameRender - Dialup Flags")); diff --git a/clientgui/ProjectPropertiesPage.cpp b/clientgui/ProjectPropertiesPage.cpp index 162df576b2..38de5131cd 100644 --- a/clientgui/ProjectPropertiesPage.cpp +++ b/clientgui/ProjectPropertiesPage.cpp @@ -24,8 +24,8 @@ #include "stdwx.h" #include "wizardex.h" #include "error_numbers.h" -#include "BOINCGUIApp.h" #include "network.h" +#include "BOINCGUIApp.h" #include "BOINCWizards.h" #include "BOINCBaseWizard.h" #include "WizardAttachProject.h" diff --git a/clientlib/win/BOINCSENSSink.cpp b/clientlib/win/BOINCSENSSink.cpp new file mode 100755 index 0000000000..f2f8351b68 --- /dev/null +++ b/clientlib/win/BOINCSENSSink.cpp @@ -0,0 +1,180 @@ +// 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., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +#include "stdafx.h" +#include "BOINCSENSSink.h" +#include "SENSSubscriptions.h" + + +// CBOINCSENSSink + +CBOINCSENSSink::CBOINCSENSSink() +{ +} + +HRESULT CBOINCSENSSink::FinalConstruct() +{ + return S_OK; +} + +void CBOINCSENSSink::FinalRelease() +{ +} + + +// ISensNetwork Methods +HRESULT CBOINCSENSSink::ConnectionMade(BSTR bstrConnection, unsigned long ulType, SENS_QOCINFO * lpQOCInfo) +{ + USES_CONVERSION; + ATLTRACE(TEXT("ConnectionMade: Connection: '%s' Type '%d'\n"), COLE2T(bstrConnection), ulType); + ATLTRACE(TEXT("ConnectionMade: dwSize '%d' dwFlags: '%d' dwOutSpeed '%d' dwInSpeed '%d'\n"), + lpQOCInfo->dwSize, lpQOCInfo->dwFlags, lpQOCInfo->dwOutSpeed, lpQOCInfo->dwInSpeed); + std::vector::iterator iter; + BOOL bCachedConnectionFound = FALSE; + + // Check cached connection state + for (iter = gpNetworkConnections.begin(); iter != gpNetworkConnections.end(); iter++) { + if ((*iter)->bstrConnection == bstrConnection) { + ATLTRACE(TEXT("ConnectionMade: Updating existing record.\n")); + // Either we missed a disconnect notification or the + // ConnectionMadeNoQOCInfo event was fired first. + bCachedConnectionFound = TRUE; + (*iter)->ulType = ulType; + (*iter)->QOCInfo = *lpQOCInfo; + } + } + + if (!bCachedConnectionFound) { + ATLTRACE(TEXT("ConnectionMade: Creating new record.\n")); + PNETWORK_CONNECTION pNetworkConnection = new NETWORK_CONNECTION; + pNetworkConnection->bstrConnection = bstrConnection; + pNetworkConnection->ulType = ulType; + pNetworkConnection->QOCInfo = *lpQOCInfo; + gpNetworkConnections.push_back(pNetworkConnection); + } + + return S_OK; +} + +HRESULT CBOINCSENSSink::ConnectionMadeNoQOCInfo(BSTR bstrConnection, unsigned long ulType) +{ + USES_CONVERSION; + ATLTRACE(TEXT("ConnectionMadeNoQOCInfo: Connection: '%s' Type '%d'\n"), COLE2T(bstrConnection), ulType); + std::vector::iterator iter; + BOOL bCachedConnectionFound = FALSE; + + // Check cached connection state + for (iter = gpNetworkConnections.begin(); iter != gpNetworkConnections.end(); iter++) { + if ((*iter)->bstrConnection == bstrConnection) { + ATLTRACE(TEXT("ConnectionMadeNoQOCInfo: Updating existing record.\n")); + // Either we missed a disconnect notification or the + // ConnectionMade event was fired first. + bCachedConnectionFound = TRUE; + (*iter)->ulType = ulType; + } + } + + if (!bCachedConnectionFound) { + ATLTRACE(TEXT("ConnectionMadeNoQOCInfo: Creating new record.\n")); + PNETWORK_CONNECTION pNetworkConnection = new NETWORK_CONNECTION; + pNetworkConnection->bstrConnection = bstrConnection; + pNetworkConnection->ulType = ulType; + gpNetworkConnections.push_back(pNetworkConnection); + } + + return S_OK; +} + +HRESULT CBOINCSENSSink::ConnectionLost(BSTR bstrConnection, unsigned long ulType) +{ + USES_CONVERSION; + ATLTRACE(TEXT("ConnectionLost: Connection: '%s' Type '%d'\n"), COLE2T(bstrConnection), ulType); + std::vector::iterator iter; + for (iter = gpNetworkConnections.begin(); iter != gpNetworkConnections.end(); iter++) { + if ((*iter)->bstrConnection == bstrConnection) { + gpNetworkConnections.erase(iter); + delete *iter; + } + } + return S_OK; +} + +HRESULT CBOINCSENSSink::DestinationReachable(BSTR bstrDestination, BSTR bstrConnection, unsigned long ulType, SENS_QOCINFO * lpQOCInfo) +{ + return E_NOTIMPL; +} + +HRESULT CBOINCSENSSink::DestinationReachableNoQOCInfo(BSTR bstrDestination, BSTR bstrConnection, unsigned long ulType) +{ + return E_NOTIMPL; +} + +// ISensOnNow Methods +HRESULT CBOINCSENSSink::OnACPower() +{ + return E_NOTIMPL; +} + +HRESULT CBOINCSENSSink::OnBatteryPower(unsigned long dwBatteryLifePercent) +{ + return E_NOTIMPL; +} + +HRESULT CBOINCSENSSink::BatteryLow(unsigned long dwBatteryLifePercent) +{ + return E_NOTIMPL; +} + +// ISensLogon Methods +HRESULT CBOINCSENSSink::Logon(BSTR bstrUserName) +{ + return E_NOTIMPL; +} + +HRESULT CBOINCSENSSink::Logoff(BSTR bstrUserName) +{ + return E_NOTIMPL; +} + +HRESULT CBOINCSENSSink::StartShell(BSTR bstrUserName) +{ + return E_NOTIMPL; +} + +HRESULT CBOINCSENSSink::DisplayLock(BSTR bstrUserName) +{ + return E_NOTIMPL; +} + +HRESULT CBOINCSENSSink::DisplayUnlock(BSTR bstrUserName) +{ + return E_NOTIMPL; +} + +HRESULT CBOINCSENSSink::StartScreenSaver(BSTR bstrUserName) +{ + return E_NOTIMPL; +} + +HRESULT CBOINCSENSSink::StopScreenSaver(BSTR bstrUserName) +{ + return E_NOTIMPL; +} + diff --git a/clientlib/win/BOINCSENSSink.h b/clientlib/win/BOINCSENSSink.h new file mode 100755 index 0000000000..bff8427080 --- /dev/null +++ b/clientlib/win/BOINCSENSSink.h @@ -0,0 +1,101 @@ +// 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., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +#pragma once +#include "resource.h" // main symbols + +#ifndef MIDL_DEFINE_GUID +#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \ + const type name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}} +#endif + +#ifndef IID_IBOINCSENSSink +MIDL_DEFINE_GUID(IID, IID_IBOINCSENSSink,0x30DFEB87,0xFDFB,0x48BB,0xA9,0x02,0xDB,0x4F,0x4C,0x13,0xE0,0x87); +#endif + +#ifndef CLSID_CBOINCSENSSink +MIDL_DEFINE_GUID(CLSID, CLSID_CBOINCSENSSink,0x33955752,0x24F7,0x4DA4,0x81,0xC9,0xE5,0xEA,0x66,0x94,0xA5,0x74); +#endif + +// IBOINCSENSSink +[ + object, + uuid("30DFEB87-FDFB-48BB-A902-DB4F4C13E087"), + dual, + helpstring("IBOINCSENSSink Interface"), + pointer_default(unique) +] +__interface IBOINCSENSSink : IDispatch +{ +}; + + + +// CBOINCSENSSink + +[ + coclass, + threading("free"), + vi_progid("BOINCSENS.BOINCSENSSink"), + progid("BOINCSENS.BOINCSENSSink.1"), + version(1.0), + uuid("33955752-24F7-4DA4-81C9-E5EA6694A574"), + helpstring("BOINCSENSSink Class") +] +class ATL_NO_VTABLE CBOINCSENSSink : + public IBOINCSENSSink, + public IDispatchImpl, + public IDispatchImpl, + public IDispatchImpl +{ +public: + CBOINCSENSSink(); + HRESULT FinalConstruct(); + void FinalRelease(); + + DECLARE_PROTECT_FINAL_CONSTRUCT() + +public: + + // ISensNetwork Methods +public: + STDMETHOD(ConnectionMade)(BSTR bstrConnection, unsigned long ulType, SENS_QOCINFO * lpQOCInfo); + STDMETHOD(ConnectionMadeNoQOCInfo)(BSTR bstrConnection, unsigned long ulType); + STDMETHOD(ConnectionLost)(BSTR bstrConnection, unsigned long ulType); + STDMETHOD(DestinationReachable)(BSTR bstrDestination, BSTR bstrConnection, unsigned long ulType, SENS_QOCINFO * lpQOCInfo); + STDMETHOD(DestinationReachableNoQOCInfo)(BSTR bstrDestination, BSTR bstrConnection, unsigned long ulType); + + // ISensOnNow Methods +public: + STDMETHOD(OnACPower)(); + STDMETHOD(OnBatteryPower)(unsigned long dwBatteryLifePercent); + STDMETHOD(BatteryLow)(unsigned long dwBatteryLifePercent); + + // ISensLogon Methods +public: + STDMETHOD(Logon)(BSTR bstrUserName); + STDMETHOD(Logoff)(BSTR bstrUserName); + STDMETHOD(StartShell)(BSTR bstrUserName); + STDMETHOD(DisplayLock)(BSTR bstrUserName); + STDMETHOD(DisplayUnlock)(BSTR bstrUserName); + STDMETHOD(StartScreenSaver)(BSTR bstrUserName); + STDMETHOD(StopScreenSaver)(BSTR bstrUserName); +}; + diff --git a/clientlib/win/Identification.cpp b/clientlib/win/Identification.cpp new file mode 100755 index 0000000000..032b4a2175 --- /dev/null +++ b/clientlib/win/Identification.cpp @@ -0,0 +1,163 @@ +// 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., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +#include "stdafx.h" +#include "Identification.h" + + +/** + * Find out if we are on a Windows 2000 compatible system + **/ +BOOL IsWindows2000Compatible() +{ + OSVERSIONINFO osvi; + ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + + if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) + return FALSE; + + return (osvi.dwMajorVersion >= 5); +} + +/** + * This function performs the basic check to see if + * the platform on which it is running is Terminal + * services enabled. Note, this code is compatible on + * all Win32 platforms. For the Windows 2000 platform + * we perform a "lazy" bind to the new product suite + * APIs that were first introduced on that platform. + **/ +BOOL IsTerminalServicesEnabled() +{ + BOOL bResult = FALSE; // assume Terminal Services is not enabled + + DWORD dwVersion; + OSVERSIONINFOEXA osVersionInfo; + DWORDLONG dwlConditionMask = 0; + HMODULE hmodK32 = NULL; + HMODULE hmodNtDll = NULL; + typedef ULONGLONG (WINAPI *PFnVerSetConditionMask)(ULONGLONG,ULONG,UCHAR); + typedef BOOL (WINAPI *PFnVerifyVersionInfoA)(POSVERSIONINFOEXA, DWORD, DWORDLONG); + PFnVerSetConditionMask pfnVerSetConditionMask; + PFnVerifyVersionInfoA pfnVerifyVersionInfoA; + + dwVersion = GetVersion(); + + // are we running NT ? + if (!(dwVersion & 0x80000000)) + { + // Is it Windows 2000 (NT 5.0) or greater ? + if (LOBYTE(LOWORD(dwVersion)) > 4) + { + // In Windows 2000 we need to use the Product Suite APIs + // Don't static link because it won't load on non-Win2000 systems + hmodNtDll = GetModuleHandle( "NTDLL.DLL" ); + if (hmodNtDll != NULL) + { + pfnVerSetConditionMask = (PFnVerSetConditionMask )GetProcAddress( hmodNtDll, "VerSetConditionMask"); + if (pfnVerSetConditionMask != NULL) + { + dwlConditionMask = (*pfnVerSetConditionMask)( dwlConditionMask, VER_SUITENAME, VER_AND ); + hmodK32 = GetModuleHandle( "KERNEL32.DLL" ); + if (hmodK32 != NULL) + { + pfnVerifyVersionInfoA = (PFnVerifyVersionInfoA)GetProcAddress( hmodK32, "VerifyVersionInfoA") ; + if (pfnVerifyVersionInfoA != NULL) + { + ZeroMemory(&osVersionInfo, sizeof(osVersionInfo)); + osVersionInfo.dwOSVersionInfoSize = sizeof(osVersionInfo); + osVersionInfo.wSuiteMask = VER_SUITE_TERMINAL | VER_SUITE_SINGLEUSERTS; + bResult = (*pfnVerifyVersionInfoA)( + &osVersionInfo, + VER_SUITENAME, + dwlConditionMask); + } + } + } + } + } + else + { + // This is NT 4.0 or older + bResult = ValidateProductSuite( "Terminal Server" ); + } + } + + return bResult; +} + +/** + * This function compares the passed in "suite name" string + * to the product suite information stored in the registry. + * This only works on the Terminal Server 4.0 platform. + **/ +BOOL ValidateProductSuite (LPSTR SuiteName) +{ + BOOL rVal = FALSE; + LONG Rslt; + HKEY hKey = NULL; + DWORD Type = 0; + DWORD Size = 0; + LPSTR ProductSuite = NULL; + LPSTR p; + + Rslt = RegOpenKeyA( + HKEY_LOCAL_MACHINE, + "System\\CurrentControlSet\\Control\\ProductOptions", + &hKey + ); + + if (Rslt != ERROR_SUCCESS) + goto exit; + + Rslt = RegQueryValueExA( hKey, "ProductSuite", NULL, &Type, NULL, &Size ); + if (Rslt != ERROR_SUCCESS || !Size) + goto exit; + + ProductSuite = (LPSTR) LocalAlloc( LPTR, Size ); + if (!ProductSuite) + goto exit; + + Rslt = RegQueryValueExA( hKey, "ProductSuite", NULL, &Type, + (LPBYTE) ProductSuite, &Size ); + if (Rslt != ERROR_SUCCESS || Type != REG_MULTI_SZ) + goto exit; + + p = ProductSuite; + while (*p) + { + if (lstrcmpA( p, SuiteName ) == 0) + { + rVal = TRUE; + break; + } + p += (lstrlenA( p ) + 1); + } + +exit: + if (ProductSuite) + LocalFree( ProductSuite ); + + if (hKey) + RegCloseKey( hKey ); + + return rVal; +} diff --git a/clientlib/win/Identification.h b/clientlib/win/Identification.h new file mode 100755 index 0000000000..ba86164669 --- /dev/null +++ b/clientlib/win/Identification.h @@ -0,0 +1,24 @@ +// 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., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#pragma once + +extern BOOL IsWindows2000Compatible(); +extern BOOL IsTerminalServicesEnabled(); +extern BOOL ValidateProductSuite (LPSTR SuiteName); diff --git a/clientlib/win/IdleTracker.cpp b/clientlib/win/IdleTracker.cpp new file mode 100755 index 0000000000..9a797950f7 --- /dev/null +++ b/clientlib/win/IdleTracker.cpp @@ -0,0 +1,298 @@ +/** + * IdleTracker - a DLL that tracks the user's idle input time + * system-wide. + * + * Usage + * ===== + * - call IdleTrackerInit() when you want to start monitoring. + * - call IdleTrackerTerm() when you want to stop monitoring. + * - to get the time past since last user input, do the following: + * GetTickCount() - IdleTrackerGetLastTickCount() + * + * Author: Sidney Chong + * Date: 25/5/2000 + * Version: 1.0 + **/ + +#include "stdafx.h" +#include "Identification.h" + + +/** + * The following global data is only shared in this instance of the DLL + **/ +HMODULE g_hUser32 = NULL; +HANDLE g_hMemoryMappedData = NULL; +BOOL g_bIsWindows2000Compatible = FALSE; +BOOL g_bIsTerminalServicesEnabled = FALSE; + +/** + * The following global data is SHARED among all instances of the DLL + * (processes) within a terminal services session. + **/ +#pragma data_seg(".IdleTrac") // you must define as SHARED in .def +HHOOK g_hHkKeyboard = NULL; // handle to the keyboard hook +HHOOK g_hHkMouse = NULL; // handle to the mouse hook +LONG g_mouseLocX = -1; // x-location of mouse position +LONG g_mouseLocY = -1; // y-location of mouse position +DWORD g_dwLastTick = 0; // tick time of last input event +#pragma data_seg() +#pragma comment(linker, "/section:.IdleTrac,rws") + +/** + * The following global data is SHARED among all instances of the DLL + * (processes); i.e., these are system-wide globals. + **/ +struct SystemWideIdleData +{ + DWORD dwLastTick; // tick time of last input event +}; + +struct SystemWideIdleData* g_pSystemWideIdleData = NULL; + +/** + * Define stuff that only exists on Windows 2000 compatible machines + **/ +typedef struct tagLASTINPUTINFO { + UINT cbSize; + DWORD dwTime; +} LASTINPUTINFO, *PLASTINPUTINFO; + +typedef BOOL (WINAPI *GETLASTINPUTINFO)(PLASTINPUTINFO); + +GETLASTINPUTINFO g_fnGetLastInputInfo = NULL; + +/** + * Keyboard hook: record tick count + **/ +LRESULT CALLBACK KeyboardTracker(int code, WPARAM wParam, LPARAM lParam) +{ + if (code==HC_ACTION) + { + g_dwLastTick = GetTickCount(); + } + return ::CallNextHookEx(g_hHkKeyboard, code, wParam, lParam); +} + +/** + * Mouse hook: record tick count + **/ +LRESULT CALLBACK MouseTracker(int code, WPARAM wParam, LPARAM lParam) +{ + if (code==HC_ACTION) + { + MOUSEHOOKSTRUCT* pStruct = (MOUSEHOOKSTRUCT*)lParam; + //we will assume that any mouse msg with the same locations as spurious + if (pStruct->pt.x != g_mouseLocX || pStruct->pt.y != g_mouseLocY) + { + g_mouseLocX = pStruct->pt.x; + g_mouseLocY = pStruct->pt.y; + g_dwLastTick = GetTickCount(); + } + } + return ::CallNextHookEx(g_hHkMouse, code, wParam, lParam); +} + +/** + * Get tick count of last keyboard or mouse event + **/ +EXTERN_C __declspec(dllexport) DWORD BOINCGetIdleTickCount() +{ + DWORD dwCurrentTickCount = GetTickCount(); + DWORD dwLastTickCount = 0; + + if ( g_bIsWindows2000Compatible ) + { + LASTINPUTINFO lii; + ZeroMemory( &lii, sizeof(lii) ); + lii.cbSize = sizeof(lii); + g_fnGetLastInputInfo( &lii ); + + /** + * If both values are greater than the system tick count then + * the system must have looped back to the begining. + **/ + if ( ( dwCurrentTickCount < lii.dwTime ) && + ( dwCurrentTickCount < g_pSystemWideIdleData->dwLastTick ) ) + { + lii.dwTime = dwCurrentTickCount; + g_pSystemWideIdleData->dwLastTick = dwCurrentTickCount; + } + + if ( lii.dwTime > g_pSystemWideIdleData->dwLastTick ) + g_pSystemWideIdleData->dwLastTick = lii.dwTime; + + dwLastTickCount = g_pSystemWideIdleData->dwLastTick; + } + else + { + dwLastTickCount = g_dwLastTick; + } + + return (dwCurrentTickCount - dwLastTickCount); +} + +/** + * Initialize DLL: install kbd/mouse hooks. + **/ +BOOL IdleTrackerStartup() +{ + BOOL bExists = FALSE; + BOOL bResult = FALSE; + SECURITY_ATTRIBUTES sec_attr; + SECURITY_DESCRIPTOR sd; + + + g_bIsWindows2000Compatible = IsWindows2000Compatible(); + g_bIsTerminalServicesEnabled = IsTerminalServicesEnabled(); + + + if ( !g_bIsWindows2000Compatible ) + { + if ( NULL == g_hHkKeyboard ) + { + g_hHkKeyboard = SetWindowsHookEx( + WH_KEYBOARD, + KeyboardTracker, + _AtlBaseModule.GetModuleInstance(), + 0 + ); + } + if ( NULL == g_hHkMouse ) + { + g_hHkMouse = SetWindowsHookEx( + WH_MOUSE, + MouseTracker, + _AtlBaseModule.GetModuleInstance(), + 0 + ); + } + + _ASSERT( g_hHkKeyboard ); + _ASSERT( g_hHkMouse ); + } + else + { + g_hUser32 = LoadLibrary("user32.dll"); + if (g_hUser32) + g_fnGetLastInputInfo = (GETLASTINPUTINFO)GetProcAddress(g_hUser32, "GetLastInputInfo"); + + + /* + * Create a security descriptor that will allow + * everyone full access. + */ + InitializeSecurityDescriptor( &sd, SECURITY_DESCRIPTOR_REVISION ); + SetSecurityDescriptorDacl( &sd, TRUE, NULL, FALSE ); + + sec_attr.nLength = sizeof(sec_attr); + sec_attr.bInheritHandle = TRUE; + sec_attr.lpSecurityDescriptor = &sd; + + /* + * Create a filemap object that is global for everyone, + * including users logged in via terminal services. + */ + if( g_bIsTerminalServicesEnabled ) + { + g_hMemoryMappedData = + CreateFileMapping( + INVALID_HANDLE_VALUE, + &sec_attr, + PAGE_READWRITE, + 0, + 4096, + "Global\\BoincIdleTracker" + ); + } + else + { + g_hMemoryMappedData = + CreateFileMapping( + INVALID_HANDLE_VALUE, + &sec_attr, + PAGE_READWRITE, + 0, + 4096, + "BoincIdleTracker" + ); + } + _ASSERT( g_hMemoryMappedData ); + + if( NULL != g_hMemoryMappedData ) + { + if( ERROR_ALREADY_EXISTS == GetLastError() ) + bExists = TRUE; + + g_pSystemWideIdleData = (struct SystemWideIdleData*) + MapViewOfFile( + g_hMemoryMappedData, + FILE_MAP_ALL_ACCESS, + 0, + 0, + 0 + ); + + _ASSERT( g_pSystemWideIdleData ); + } + + if( !bExists ) + { + g_pSystemWideIdleData->dwLastTick = GetTickCount(); + } + } + + + if ( !g_bIsWindows2000Compatible ) + { + if ( !g_hHkKeyboard || !g_hHkMouse ) + bResult = FALSE; + else + bResult = TRUE; + } + else + { + if ( !g_hUser32 || !g_fnGetLastInputInfo || !g_hMemoryMappedData || !g_pSystemWideIdleData ) + bResult = FALSE; + else + bResult = TRUE; + } + + return bResult; +} + +/** + * Terminate DLL: remove hooks. + **/ +void IdleTrackerShutdown() +{ + if ( !g_bIsWindows2000Compatible ) + { + BOOL bResult; + if ( g_hHkKeyboard ) + { + bResult = UnhookWindowsHookEx( g_hHkKeyboard ); + _ASSERT( bResult ); + g_hHkKeyboard = NULL; + } + if ( g_hHkMouse ) + { + bResult = UnhookWindowsHookEx(g_hHkMouse); + _ASSERT( bResult ); + g_hHkMouse = NULL; + } + } + else + { + if( NULL != g_pSystemWideIdleData ) + { + UnmapViewOfFile(g_pSystemWideIdleData); + CloseHandle(g_hMemoryMappedData); + } + + if ( NULL != g_hUser32 ) + FreeLibrary(g_hUser32); + } +} + +const char *BOINC_RCSID_14d432d5b3 = "$Id$"; diff --git a/clientlib/win/IdleTracker.h b/clientlib/win/IdleTracker.h new file mode 100755 index 0000000000..9ec01487d3 --- /dev/null +++ b/clientlib/win/IdleTracker.h @@ -0,0 +1,23 @@ +// 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., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#pragma once + +extern BOOL IdleTrackerStartup(); +extern void IdleTrackerShutdown(); diff --git a/clientlib/win/NetworkTracker.cpp b/clientlib/win/NetworkTracker.cpp new file mode 100755 index 0000000000..88639f082a --- /dev/null +++ b/clientlib/win/NetworkTracker.cpp @@ -0,0 +1,327 @@ +// 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., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +#include "stdafx.h" +#include "BOINCSENSSink.h" +#include "SENSSubscriptions.h" +#include "SENSNetworkSubscriptions.h" +#include "SENSOnNowSubscriptions.h" +#include "SENSLogonSubscriptions.h" + + +IEventSystem* gpIEventSystem = NULL; + +SENS_SUBSCRIPTION_GROUP gSubscriptionGroups[3]; +unsigned int giSubscriptionGroupCount = 0; + +std::vector gpNetworkConnections; + + +EXTERN_C __declspec(dllexport) BOOL BOINCIsNetworkAlive( LPDWORD lpdwFlags ) +{ + USES_CONVERSION; + unsigned int i = 0; + BOOL bReturnValue = FALSE; + BOOL bCachePopulated = FALSE; + PNETWORK_CONNECTION pNetworkConnection = NULL; + + ATLTRACE(TEXT("BOINCIsNetworkAlive - Function Begin\n")); + + // Check cached connection state + if (!gpNetworkConnections.empty()) { + ATLTRACE(TEXT("BOINCIsNetworkAlive - Using cached connection list\n")); + bCachePopulated = TRUE; + for (i=0; iulType & *lpdwFlags) { + ATLTRACE(TEXT("BOINCIsNetworkAlive - Cached connection type found\n")); + bReturnValue = TRUE; + } + } + } + + // If we do not have any cached information, then fall back to other + // methods + if (!bCachePopulated) { + ATLTRACE(TEXT("BOINCIsNetworkAlive - Calling SENS IsNetworkAlive()\n")); + bReturnValue = IsNetworkAlive( lpdwFlags ); + if (!bReturnValue) { + DWORD current_flags = NULL; + DWORD desired_flags = NULL; + + if (NETWORK_ALIVE_LAN & *lpdwFlags) + desired_flags |= INTERNET_CONNECTION_LAN; + + if (NETWORK_ALIVE_WAN & *lpdwFlags) + desired_flags |= INTERNET_CONNECTION_MODEM; + + // TODO: Find out if AOL is registered as a LAN or WAN connection. + // Until then, assume both are okay. + if (NETWORK_ALIVE_AOL & *lpdwFlags) + desired_flags |= INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_MODEM; + + ATLTRACE(TEXT("BOINCIsNetworkAlive - Calling InternetGetConnectedState()\n")); + BOOL retval = InternetGetConnectedState(¤t_flags, 0); + if (retval && (current_flags & desired_flags)) { + bReturnValue = TRUE; + } else { + bReturnValue = FALSE; + } + } + } + + ATLTRACE(TEXT("BOINCIsNetworkAlive - Returning '%d'\n"), bReturnValue); + ATLTRACE(TEXT("BOINCIsNetworkAlive - Function End\n")); + return bReturnValue; +} + + +EXTERN_C __declspec(dllexport) BOOL BOINCIsNetworkAlwaysOnline() +{ + BOOL bReturnValue = FALSE; + DWORD dwFlags = NETWORK_ALIVE_LAN; + + ATLTRACE(TEXT("BOINCIsNetworkAlwaysOnline - Function Begin\n")); + + bReturnValue = BOINCIsNetworkAlive(&dwFlags); + + ATLTRACE(TEXT("BOINCIsNetworkAlwaysOnline - Returning '%d'\n"), bReturnValue); + ATLTRACE(TEXT("BOINCIsNetworkAlwaysOnline - Function End\n")); + return bReturnValue; +} + + +BOOL NetworkTrackerStartup() +{ + USES_CONVERSION; + unsigned int i = 0, j = 0; + HRESULT hr = 0; + IBOINCSENSSink* pIBOINCSENSSink = NULL; + + CComBSTR bstrPROGID_EventSubscription; + IEventSubscription* pIEventSubscription = NULL; + + PSENS_SUBSCRIPTION_GROUP pSubscriptionGroup = NULL; + PSENS_SUBSCRIPTION pSubscription = NULL; + + CComBSTR bstrSubscriberCLSID; + CComBSTR bstrSubscriptionID; + CComBSTR bstrSubscriptionName; + CComBSTR bstrMethodName; + + + // Assign the correct program is value to be used by the event + // registration store. + bstrPROGID_EventSubscription = PROGID_EventSubscription; + + + // Clear the cache + gpNetworkConnections.clear(); + + + // Try and create some important references to COM objects before + // doing anything else. + // + + // IEventSystem + hr = CoCreateInstance( + CLSID_CEventSystem, + NULL, + CLSCTX_SERVER, + IID_IEventSystem, + (LPVOID*)&gpIEventSystem); + if (FAILED(hr)) + { + ATLTRACE(TEXT("Error creating event system! (0x%x)"), hr); + return FALSE; + } + + // IBOINCSENSSink + hr = CoCreateInstance( + CLSID_CBOINCSENSSink, + NULL, + CLSCTX_SERVER, + IID_IBOINCSENSSink, + (LPVOID*)&pIBOINCSENSSink); + if (FAILED(hr)) + { + ATLTRACE(TEXT("Failed to create pIBOINCSENSSink (0x%x)"), hr); + return FALSE; + } + + + // Prepare for registration by pre-populating the registration + // multidimensional array with the known good stuff. + + // Prepare the SENS Network registration group. + gSubscriptionGroups[0].bstrPublisherID = SENSGUID_PUBLISHER; + gSubscriptionGroups[0].bstrEventClassID = SENSGUID_EVENTCLASS_NETWORK; + gSubscriptionGroups[0].bstrInterfaceID = IID_ISensNetwork; + gSubscriptionGroups[0].uiSubscriptionCount = SENS_NETWORK_SUBSCRIPTIONS_COUNT; + gSubscriptionGroups[0].pSubscriptions = (PSENS_SUBSCRIPTION)&gSENSNetworkSubscriptions; + + // Prepare the SENS OnNow registration group. + gSubscriptionGroups[1].bstrPublisherID = SENSGUID_PUBLISHER; + gSubscriptionGroups[1].bstrEventClassID = SENSGUID_EVENTCLASS_ONNOW; + gSubscriptionGroups[1].bstrInterfaceID = IID_ISensOnNow; + gSubscriptionGroups[1].uiSubscriptionCount = SENS_ONNOW_SUBSCRIPTIONS_COUNT; + gSubscriptionGroups[1].pSubscriptions = (PSENS_SUBSCRIPTION)&gSENSOnNowSubscriptions; + + // Prepare the SENS Logon registration group. + gSubscriptionGroups[2].bstrPublisherID = SENSGUID_PUBLISHER; + gSubscriptionGroups[2].bstrEventClassID = SENSGUID_EVENTCLASS_LOGON; + gSubscriptionGroups[2].bstrInterfaceID = IID_ISensLogon; + gSubscriptionGroups[2].uiSubscriptionCount = SENS_LOGON_SUBSCRIPTIONS_COUNT; + gSubscriptionGroups[2].pSubscriptions = (PSENS_SUBSCRIPTION)&gSENSLogonSubscriptions; + + + // Start to register the events by walking through the registration groups + // + giSubscriptionGroupCount = + sizeof(gSubscriptionGroups) / sizeof(SENS_SUBSCRIPTION_GROUP); + + for (i = 0; i < giSubscriptionGroupCount; i++) + { + pSubscriptionGroup = &gSubscriptionGroups[i]; + for (j = 0; j < pSubscriptionGroup->uiSubscriptionCount; j++) + { + pSubscription = &pSubscriptionGroup->pSubscriptions[j]; + + // Get a new IEventSubscription object. + hr = CoCreateInstance( + CLSID_CEventSubscription, + NULL, + CLSCTX_SERVER, + IID_IEventSubscription, + (LPVOID*) &pIEventSubscription); + + if (FAILED(hr)) + { + ATLTRACE(TEXT("Error getting IEventSubscription object (0x%x)"), hr); + return FALSE; + } + + bstrSubscriptionID = *pSubscription->pSubscriptionID; + hr = pIEventSubscription->put_SubscriptionID(bstrSubscriptionID); + if (FAILED(hr)) + { + ATLTRACE(TEXT("pIEventSubscription->put_SubscriptionID (0x%x)"), hr); + return FALSE; + } + + bstrSubscriptionName = pSubscription->strSubscriptionName; + hr = pIEventSubscription->put_SubscriptionName(bstrSubscriptionName); + if (FAILED(hr)) + { + ATLTRACE(TEXT("pIEventSubscription->put_SubscriptionName (0x%x)"), hr); + return FALSE; + } + + bstrMethodName = pSubscription->strMethodName; + hr = pIEventSubscription->put_MethodName(bstrMethodName); + if (FAILED(hr)) + { + ATLTRACE(TEXT("pIEventSubscription->put_MethodName (0x%x)"), hr); + return FALSE; + } + + hr = pIEventSubscription->put_EventClassID(pSubscriptionGroup->bstrEventClassID); + if (FAILED(hr)) + { + ATLTRACE(TEXT("pIEventSubscription->put_EventClassID (0x%x)"), hr); + return FALSE; + } + + hr = pIEventSubscription->put_SubscriberInterface(pIBOINCSENSSink); + if (FAILED(hr)) + { + ATLTRACE(TEXT("pIEventSubscription->put_SubscriberInterface (0x%x)"), hr); + return FALSE; + } + + // Initialize it. + hr = gpIEventSystem->Store( + bstrPROGID_EventSubscription, + pIEventSubscription); + if (FAILED(hr)) + { + ATLTRACE(TEXT("gpIEventSystem->Store (0x%x)"), hr); + return FALSE; + } + else + { + ATLTRACE(TEXT("Subscription Sucess: %s\n"), COLE2T(pSubscription->strMethodName)); + } + + pIEventSubscription->Release(); + pIEventSubscription = NULL; + } + } + + if (pIEventSubscription != NULL) + pIEventSubscription->Release(); + + if (pIBOINCSENSSink != NULL) + pIBOINCSENSSink->Release(); + + return TRUE; +} + + +void NetworkTrackerShutdown() +{ + USES_CONVERSION; + unsigned int i = 0, j = 0; + HRESULT hr = 0; + int errorIndex = 0; + CComBSTR bstrQuery; + PSENS_SUBSCRIPTION_GROUP pSubscriptionGroup = NULL; + PSENS_SUBSCRIPTION pSubscription = NULL; + PNETWORK_CONNECTION pNetworkConnection = NULL; + + for (i = 0; i < giSubscriptionGroupCount; i++) + { + pSubscriptionGroup = &gSubscriptionGroups[i]; + for (j = 0; j < pSubscriptionGroup->uiSubscriptionCount; j++) + { + pSubscription = &pSubscriptionGroup->pSubscriptions[j]; + + bstrQuery.Empty(); + bstrQuery = TEXT("SubscriptionID="); + bstrQuery += *pSubscription->pSubscriptionID; + + hr = gpIEventSystem->Remove( + PROGID_EventSubscription, + bstrQuery, + &errorIndex); + if (FAILED(hr)) + { + ATLTRACE(TEXT("gpIEventSystem->Remove (0x%x)"), hr); + } + } + } + + + // Clear the cache + for (i=0; i gpNetworkConnections; + +EXTERN_C __declspec(dllexport) BOOL BOINCRegisterSubscriptions(void); +EXTERN_C __declspec(dllexport) BOOL BOINCUnregisterSubscriptions(void); + +EXTERN_C __declspec(dllexport) BOOL BOINCIsNetworkActive(); diff --git a/clientlib/win/boinc_dll.cpp b/clientlib/win/boinc_dll.cpp new file mode 100755 index 0000000000..e0ae760a89 --- /dev/null +++ b/clientlib/win/boinc_dll.cpp @@ -0,0 +1,55 @@ +// 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., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +#include "stdafx.h" +#include "resource.h" +#include "IdleTracker.h" +#include "NetworkTracker.h" + + +// The module attribute causes DllMain, DllRegisterServer and DllUnregisterServer to be automatically implemented for you +[ module(dll, + uuid = "{16B09F41-6216-4131-AADD-D66276A88089}", + name = "BOINCSENS", + helpstring = "BOINCSENS 1.0 Type Library", + resource_name = "IDR_BOINCSENS") ] +class CBOINCSENSModule +{ +public: +// Override CAtlDllModuleT members +}; + + +EXTERN_C __declspec(dllexport) BOOL ClientLibraryStartup() +{ + if (!IdleTrackerStartup()) + return FALSE; + if (!NetworkTrackerStartup()) + return FALSE; + + return TRUE; +} + +EXTERN_C __declspec(dllexport) void ClientLibraryShutdown() +{ + IdleTrackerShutdown(); + NetworkTrackerShutdown(); +} + diff --git a/clientlib/win/boinc_dll.h b/clientlib/win/boinc_dll.h new file mode 100755 index 0000000000..9d296355bf --- /dev/null +++ b/clientlib/win/boinc_dll.h @@ -0,0 +1,29 @@ +// 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., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#pragma once + +#ifndef MIDL_DEFINE_GUID +#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \ + const type name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}} +#endif + +#ifndef LIBID_BOINCSENS +MIDL_DEFINE_GUID(IID, LIBID_BOINCSENS,0x16B09F41,0x6216,0x4131,0xAA,0xDD,0xD6,0x62,0x76,0xA8,0x80,0x89); +#endif diff --git a/clientlib/win/boinc_dll.rc b/clientlib/win/boinc_dll.rc new file mode 100755 index 0000000000..b28e07c071 --- /dev/null +++ b/clientlib/win/boinc_dll.rc @@ -0,0 +1,205 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" +#include "version.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "#include ""version.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Visual Studio 2005 Compatibility +// +#ifndef IDC_STATIC +#define IDC_STATIC (-1) // all static controls +#endif + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +#if defined(_GRIDREPUBLIC) + +VS_VERSION_INFO VERSIONINFO + FILEVERSION BOINC_MAJOR_VERSION,BOINC_MINOR_VERSION,BOINC_RELEASE,0 + PRODUCTVERSION BOINC_MAJOR_VERSION,BOINC_MINOR_VERSION,BOINC_RELEASE,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "GridRepublic" + VALUE "FileDescription", "GridRepublic Client Platform Library" + VALUE "FileVersion", BOINC_VERSION_STRING "\0" + VALUE "InternalName", "boinc_dll" + VALUE "LegalCopyright", "© 2003-2006 University of California" + VALUE "OriginalFilename", "boinc.dll" + VALUE "ProductName", "BOINC Core Client" + VALUE "ProductVersion", BOINC_VERSION_STRING "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#elif defined(_CPDNBBC) + +VS_VERSION_INFO VERSIONINFO + FILEVERSION BOINC_MAJOR_VERSION,BOINC_MINOR_VERSION,BOINC_RELEASE,0 + PRODUCTVERSION BOINC_MAJOR_VERSION,BOINC_MINOR_VERSION,BOINC_RELEASE,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "ClimatePrediction.net" + VALUE "FileDescription", "CPDNBBC Client Platform Library" + VALUE "FileVersion", BOINC_VERSION_STRING "\0" + VALUE "InternalName", "boinc_dll" + VALUE "LegalCopyright", "© 2003-2006 University of California" + VALUE "OriginalFilename", "boinc.dll" + VALUE "ProductName", "CPDNBBC Core Client" + VALUE "ProductVersion", BOINC_VERSION_STRING "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#else + +VS_VERSION_INFO VERSIONINFO + FILEVERSION BOINC_MAJOR_VERSION,BOINC_MINOR_VERSION,BOINC_RELEASE,0 + PRODUCTVERSION BOINC_MAJOR_VERSION,BOINC_MINOR_VERSION,BOINC_RELEASE,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "Space Sciences Laboratory" + VALUE "FileDescription", "BOINC Client Platform Library" + VALUE "FileVersion", BOINC_VERSION_STRING "\0" + VALUE "InternalName", "boinc_dll" + VALUE "LegalCopyright", "© 2003-2006 University of California" + VALUE "OriginalFilename", "boinc.dll" + VALUE "ProductName", "BOINC Core Client" + VALUE "ProductVersion", BOINC_VERSION_STRING "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif + + +///////////////////////////////////////////////////////////////////////////// +// +// REGISTRY +// + +IDR_BOINCSENS REGISTRY "boincsens.rgs" + +///////////////////////////////////////////////////////////////////////////// +// +// String Table +// + +STRINGTABLE +BEGIN + IDS_PROJNAME "BOINC Client Platform Library" +END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/clientlib/win/boincsens.rgs b/clientlib/win/boincsens.rgs new file mode 100755 index 0000000000..1de8fc3c18 --- /dev/null +++ b/clientlib/win/boincsens.rgs @@ -0,0 +1,11 @@ +HKCR +{ + NoRemove AppID + { + '%APPID%' = s 'boincsens' + 'boincsens.DLL' + { + val AppID = s '%APPID%' + } + } +} diff --git a/clientlib/win/resource.h b/clientlib/win/resource.h new file mode 100755 index 0000000000..da4d45e6e4 --- /dev/null +++ b/clientlib/win/resource.h @@ -0,0 +1,17 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by boinc_dll.rc +// +#define IDS_PROJNAME 100 +#define IDR_BOINCSENS 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 201 +#define _APS_NEXT_COMMAND_VALUE 32768 +#define _APS_NEXT_CONTROL_VALUE 201 +#define _APS_NEXT_SYMED_VALUE 102 +#endif +#endif diff --git a/clientlib/win/stdafx.cpp b/clientlib/win/stdafx.cpp new file mode 100755 index 0000000000..cbaf94738d --- /dev/null +++ b/clientlib/win/stdafx.cpp @@ -0,0 +1,5 @@ +// stdafx.cpp : source file that includes just the standard includes +// boincsens.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" diff --git a/clientlib/win/stdafx.h b/clientlib/win/stdafx.h new file mode 100755 index 0000000000..3149a0f793 --- /dev/null +++ b/clientlib/win/stdafx.h @@ -0,0 +1,56 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +#ifndef STRICT +#define STRICT +#endif + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later. +#define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. +#endif + +#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later. +#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target Windows 2000 or later. +#endif + +#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later. +#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. +#endif + +#ifndef _WIN32_IE // Allow use of features specific to IE 5.01 or later. +#define _WIN32_IE 0x0501 // Change this to the appropriate value to target IE 6.0 or later. +#endif + +#define _ATL_APARTMENT_THREADED +#define _ATL_NO_AUTOMATIC_NAMESPACE + +#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit + +// turns off ATL's hiding of some common and often safely ignored warning messages +#define _ATL_ALL_WARNINGS + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#import "SENS.DLL" raw_interfaces_only, raw_native_types, no_namespace, named_guids + +using namespace ATL; \ No newline at end of file diff --git a/lib/network.C b/lib/network.C index 7fa3870f81..4e89d71863 100644 --- a/lib/network.C +++ b/lib/network.C @@ -180,23 +180,37 @@ int get_socket_error(int fd) { #if defined(_WIN32) && defined(USE_WINSOCK) typedef BOOL (WINAPI *GetStateProc)( OUT LPDWORD lpdwFlags, IN DWORD dwReserved); +typedef int (*pfnBOINCIsNetworkAlive)(LPDWORD lpdwFlags); int get_connected_state( ) { int online = 0; static bool first=true; - static HMODULE libmodule; + static HMODULE lib_wininet_module; static GetStateProc GetState; + static HMODULE lib_boinc_module; + static pfnBOINCIsNetworkAlive BOINCIsNetworkAlive; DWORD connectionFlags; if (first) { - libmodule = LoadLibrary("wininet.dll"); - if (libmodule) { - GetState = (GetStateProc) GetProcAddress(libmodule, "InternetGetConnectedState"); + lib_wininet_module = LoadLibrary("wininet.dll"); + if (lib_wininet_module) { + GetState = (GetStateProc) GetProcAddress(lib_wininet_module, "InternetGetConnectedState"); + } + lib_boinc_module = LoadLibrary("boinc.dll"); + if (lib_boinc_module) { + BOINCIsNetworkAlive = (pfnBOINCIsNetworkAlive) GetProcAddress(lib_boinc_module, "BOINCIsNetworkAlive"); } first = false; } - if (libmodule && GetState) { - online = (*GetState)(&connectionFlags, 0); + if (lib_boinc_module && BOINCIsNetworkAlive) { + connectionFlags = NETWORK_ALIVE_LAN | NETWORK_ALIVE_WAN | NETWORK_ALIVE_AOL; + online = BOINCIsNetworkAlive(&connectionFlags); + if (online) { + return CONNECTED_STATE_CONNECTED; + } + } + if (lib_wininet_module && GetState) { + online = GetState(&connectionFlags, 0); if (online) { return CONNECTED_STATE_CONNECTED; } else { diff --git a/lib/network.h b/lib/network.h index 1971d87277..96381e2ce6 100644 --- a/lib/network.h +++ b/lib/network.h @@ -56,6 +56,20 @@ typedef int boinc_socklen_t; typedef BOINC_SOCKLEN_T boinc_socklen_t; #endif + +#ifndef NETWORK_ALIVE_LAN +#define NETWORK_ALIVE_LAN 0x00000001 +#endif + +#ifndef NETWORK_ALIVE_WAN +#define NETWORK_ALIVE_WAN 0x00000002 +#endif + +#ifndef NETWORK_ALIVE_AOL +#define NETWORK_ALIVE_AOL 0x00000004 +#endif + + #define CONNECTED_STATE_NOT_CONNECTED 0 #define CONNECTED_STATE_CONNECTED 1 #define CONNECTED_STATE_UNKNOWN 2 diff --git a/win_build/boinc_dll.vcproj b/win_build/boinc_dll.vcproj index 8b4d9ac003..87c07b8dcd 100644 --- a/win_build/boinc_dll.vcproj +++ b/win_build/boinc_dll.vcproj @@ -3,9 +3,9 @@ ProjectType="Visual C++" Version="7.10" Name="boinc_dll" - ProjectGUID="{B06280CB-82A4-46DE-8956-602643078BDF}" - SccProjectName="" - SccLocalPath=""> + ProjectGUID="{ADA6451B-CFEA-402A-9681-227CD1FDE08C}" + RootNamespace="boinc" + Keyword="AtlProj"> @@ -16,54 +16,48 @@ OutputDirectory=".\Build\Debug" IntermediateDirectory=".\Build\Debug\boinc_dll\obj" ConfigurationType="2" - UseOfMFC="0" + UseOfATL="1" ATLMinimizesCRunTimeLibraryUsage="FALSE" CharacterSet="2"> + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="4"/> + GenerateStublessProxies="TRUE" + TypeLibraryName="$(IntDir)/boinc_dll.tlb" + HeaderFileName="boinc_dll.h" + DLLDataFileName="" + InterfaceIdentifierFileName="boinc_dll_i.c" + ProxyFileName="boinc_dll_p.c"/> + Name="VCPostBuildEventTool" + Description="Performing registration" + CommandLine="regsvr32 /s /c "$(TargetPath)""/> + AdditionalIncludeDirectories=""$(IntDir)";../"/> + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="3"/> + GenerateStublessProxies="TRUE" + TypeLibraryName="$(IntDir)/boinc_dll.tlb" + HeaderFileName="boinc_dll.h" + DLLDataFileName="" + InterfaceIdentifierFileName="boinc_dll_i.c" + ProxyFileName="boinc_dll_p.c"/> + Name="VCPostBuildEventTool" + Description="Performing registration" + CommandLine="regsvr32 /s /c "$(TargetPath)""/> + AdditionalIncludeDirectories=""$(IntDir)";../"/> + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> + RelativePath="..\clientlib\win\boinc_dll.cpp"> + + + + + + + + + + + UsePrecompiledHeader="1"/> + UsePrecompiledHeader="1"/> - - + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> + RelativePath="..\clientlib\win\boinc_dll.h"> + RelativePath="..\clientlib\win\BOINCSENSSink.h"> + + + + + + + + + + + + + + + + + + + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> + RelativePath="..\clientlib\win\boinc_dll.rc"> + + diff --git a/win_build/installerv2/BOINC.ism b/win_build/installerv2/BOINC.ism index 87e74ab927e340719fd5bfb95a2f381450963045..dbefb58fa4ca54817648ce25aa7e27d4b304ac49 100644 GIT binary patch delta 60 zcmZoT!qaesXG1Ov>-~=8pYqK`EZd7%7?n~aMHmj7lkzf(#4|6M+~;!`OoDYcm+Pugzcz-U$FT COA-M9 diff --git a/win_build/installerv2/CPDNBBC.ism b/win_build/installerv2/CPDNBBC.ism index 68733ddf521b627a4dca2fc3a11be654cb6362d1..a57a5dca3ca17723937f577cbaa78ca95f556333 100644 GIT binary patch delta 471 zcmXYr%}X0$5XRqmXB$ns`|8H1l?_oMw51dw{Qxh89D)jhsRwUumk^dF5~IdYj0cT{ zwg<&lBN_jI5{e)M7JM(_NyL8Lq);>g!9PGOSbEUyuJjpx!^1Ef|M7fKZl$3s88{Pe z!nH2Mg>b}ALA4{exBV491(Yktap?0gq~Qzcb!cn;?rvTWV;m1F4R{WJcF2+s%b-u?C&#T+!OY|`g}&K|>_eGt#&xI&9ID<#rFt9rb}Rly zctfMh&@UeZ@eriy;~}7sf$A+UT4(MnjL{16JeWzMAXmX(`HzP9px)~rP h7HaLrC@qF@fnE~C%gV}5wFfy(M{o_IvK+y;@DHI`j_m*d delta 586 zcmYLDUr1AN6u#%4tMlsauQro;*|hKm{h>x{8U;S24%TSQoa?E^=Kg?-HP@QB_0sL3 zMrh8p@FzsCBLZnK@YhrLl4vTuL{Dxo>ot%Hd#ZJfM(5)@-*@;9hqJV9iVrP!vM_?Hl zbD$f!=I{&;kI)`7rb+~PwyNVTKrJTJcO2z_GiW@;0kxa(y3WS&+#zkqoA4?MoQ_sa zsL&q-9n4|DUm&Pq4AXiU&XSxsD?SnP;)3{Gd?8Y`7gc(>7l(@HgpQ(nzW?dGS~`Y2 U&71KKecgs475nfpLj}9w4;5Cdt^fc4 diff --git a/win_build/installerv2/GridRepublic.ism b/win_build/installerv2/GridRepublic.ism index e09d3ac4bad0b5e15b2afc1ee4569e456046385f..c828f12721dac7e4801e2ba056bd872fa23488f6 100644 GIT binary patch delta 61 zcmbPpf@jVNo((xHY#;V+toSM4T*R`yh=oxpMN));p