// Trap events on Windows so we can clean ourselves up. static LRESULT CALLBACK WindowsMonitorSystemPowerWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch(uMsg) { // On Windows power events are broadcast via the WM_POWERBROADCAST // window message. It has the following parameters: // PBT_APMQUERYSUSPEND // PBT_APMQUERYSUSPENDFAILED // PBT_APMSUSPEND // PBT_APMRESUMECRITICAL // PBT_APMRESUMESUSPEND // PBT_APMBATTERYLOW // PBT_APMPOWERSTATUSCHANGE // PBT_APMOEMEVENT // PBT_APMRESUMEAUTOMATIC case WM_POWERBROADCAST: switch(wParam) { // System is preparing to suspend. This is valid on // Windows versions older than Vista case PBT_APMQUERYSUSPEND: return TRUE; break; // System is resuming from a failed request to suspend // activity. This is only valid on Windows versions // older than Vista case PBT_APMQUERYSUSPENDFAILED: resume_client(); break; // System is critically low on battery power. This is // only valid on Windows versions older than Vista case PBT_APMBATTERYLOW: msg_printf(NULL, MSG_INFO, "Critical battery alarm, Windows is suspending operations"); suspend_client(); break; // System is suspending case PBT_APMSUSPEND: msg_printf(NULL, MSG_INFO, "Windows is suspending operations"); suspend_client(); break; // System is resuming from a normal power event case PBT_APMRESUMESUSPEND: gstate.set_now(); msg_printf(NULL, MSG_INFO, "Windows is resuming operations"); // Check for a proxy working_proxy_info.need_autodetect_proxy_settings = true; resume_client(); break; } break; default: break; } return (DefWindowProc(hWnd, uMsg, wParam, lParam)); }
// // FUNCTION: BOINCServiceCtrl // // PURPOSE: This function is called by the SCM whenever // ControlService() is called on this service. // // PARAMETERS: // dwCtrlCode - type of control requested // // RETURN VALUE: // none // // COMMENTS: // VOID WINAPI BOINCServiceCtrl(DWORD dwCtrlCode) { // Handle the requested control code. // switch(dwCtrlCode) { // Stop the service. // // SERVICE_STOP_PENDING should be reported before // setting the Stop Event - hServerStopEvent - in // ServiceStop(). This avoids a race condition // which may result in a 1053 - The Service did not respond... // error. case SERVICE_CONTROL_STOP: case SERVICE_CONTROL_SHUTDOWN: ReportStatus(SERVICE_STOP_PENDING, ERROR_SUCCESS, 30000); quit_client(); return; // Pause the service. // case SERVICE_CONTROL_PAUSE: ReportStatus(SERVICE_PAUSE_PENDING, ERROR_SUCCESS, 10000); suspend_client(); ReportStatus(SERVICE_PAUSED, ERROR_SUCCESS, 10000); return; // Continue the service. // case SERVICE_CONTROL_CONTINUE: ReportStatus(SERVICE_CONTINUE_PENDING, ERROR_SUCCESS, 10000); resume_client(); ReportStatus(SERVICE_RUNNING, ERROR_SUCCESS, 10000); return; // Update the service status. // case SERVICE_CONTROL_INTERROGATE: break; // invalid control code // default: break; } ReportStatus(ssStatus.dwCurrentState, ERROR_SUCCESS, 1000); }
// Trap events on Windows so we can clean ourselves up. // NOTE: this runs in a separate thread. // Be careful accessing global data structures. // static LRESULT CALLBACK WindowsMonitorSystemPowerWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch(uMsg) { // If we are not installed as a service, begin the task shutdown process // when we are notified that the system is going down. If we are installed // as a service, wait until the service control manager tells us to shutdown. // // The console handler happens a little to late in the cycle and leads // to BOINC attempting to start new tasks, which fail, when the OS has // shutdown some of the ones that were executing. // case WM_QUERYENDSESSION: if (!gstate.executing_as_daemon) { quit_client(); } return TRUE; break; // On Windows power events are broadcast via the WM_POWERBROADCAST // window message. It has the following parameters: // PBT_APMQUERYSUSPEND // PBT_APMQUERYSUSPENDFAILED // PBT_APMSUSPEND // PBT_APMRESUMECRITICAL // PBT_APMRESUMESUSPEND // PBT_APMBATTERYLOW // PBT_APMPOWERSTATUSCHANGE // PBT_APMOEMEVENT // PBT_APMRESUMEAUTOMATIC case WM_POWERBROADCAST: switch(wParam) { // System is preparing to suspend. This is valid on // Windows versions older than Vista case PBT_APMQUERYSUSPEND: return TRUE; break; // System is resuming from a failed request to suspend // activity. This is only valid on Windows versions // older than Vista case PBT_APMQUERYSUSPENDFAILED: resume_client(); break; // System is critically low on battery power. This is // only valid on Windows versions older than Vista case PBT_APMBATTERYLOW: post_sysmon_msg("Critical battery alarm, Windows is suspending operations"); suspend_client(); break; // System is suspending case PBT_APMSUSPEND: post_sysmon_msg("Windows is suspending operations"); suspend_client(); break; // System is resuming from a normal power event case PBT_APMRESUMESUSPEND: gstate.set_now(); post_sysmon_msg("Windows is resuming operations"); // Check for a proxy working_proxy_info.need_autodetect_proxy_settings = true; resume_client(); break; } break; default: break; } return (DefWindowProc(hWnd, uMsg, wParam, lParam)); }