diff --git a/checkin_notes b/checkin_notes index 94f076ec17..ccf6c84edf 100644 --- a/checkin_notes +++ b/checkin_notes @@ -85,6 +85,9 @@ David 26 May 2006 David 29 May 2006 - moved wrapper application here from boinc/apps + win_build + sleeper.vcproj + wrapper.vcproj wrapper/ wrapper.C Makefile diff --git a/win_build/samples.sln b/win_build/samples.sln index 08acdab104..5f6b1a369d 100644 --- a/win_build/samples.sln +++ b/win_build/samples.sln @@ -28,12 +28,16 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "upper_case", "upper_case.vc {5F065EAC-B881-4E9A-9E34-7A21D7A01D98} = {5F065EAC-B881-4E9A-9E34-7A21D7A01D98} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sleeper", "sleeper.vcproj", "{8281D898-0E64-44EB-8356-4F0336F19A35}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wrapper", "wrapper.vcproj", "{8281D898-0E64-44EB-8356-4F0336F19A35}" ProjectSection(ProjectDependencies) = postProject {0BC1DB36-030A-4321-B387-1CEE2611E329} = {0BC1DB36-030A-4321-B387-1CEE2611E329} {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} = {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sleeper", "sleeper.vcproj", "{8281D898-0E64-44EB-8356-4F0336F19A35}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug @@ -68,6 +72,10 @@ Global {8281D898-0E64-44EB-8356-4F0336F19A35}.Debug.Build.0 = Debug|Win32 {8281D898-0E64-44EB-8356-4F0336F19A35}.Release.ActiveCfg = Release|Win32 {8281D898-0E64-44EB-8356-4F0336F19A35}.Release.Build.0 = Release|Win32 + {8281D898-0E64-44EB-8356-4F0336F19A35}.Debug.ActiveCfg = Debug|Win32 + {8281D898-0E64-44EB-8356-4F0336F19A35}.Debug.Build.0 = Debug|Win32 + {8281D898-0E64-44EB-8356-4F0336F19A35}.Release.ActiveCfg = Release|Win32 + {8281D898-0E64-44EB-8356-4F0336F19A35}.Release.Build.0 = Release|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection diff --git a/win_build/wrapper.vcproj b/win_build/wrapper.vcproj new file mode 100644 index 0000000000..96ad64aedc --- /dev/null +++ b/win_build/wrapper.vcproj @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wrapper/wrapper.C b/wrapper/wrapper.C index 5e24a51395..9b740679da 100644 --- a/wrapper/wrapper.C +++ b/wrapper/wrapper.C @@ -65,6 +65,7 @@ string application; bool first = true; #ifdef _WIN32 HANDLE pid_handle; +HANDLE thread_handle; #else int pid; #endif @@ -129,15 +130,13 @@ void parse_state_file() { } int run_application(char** argv) { - int retval; - #ifdef _WIN32 PROCESS_INFORMATION process_info; STARTUPINFO startup_info; memset(&process_info, 0, sizeof(process_info)); memset(&startup_info, 0, sizeof(startup_info)); - if (!CreateProcess(exec_path, + if (!CreateProcess(application.c_str(), (LPSTR)application.c_str(), NULL, NULL, @@ -150,7 +149,10 @@ int run_application(char** argv) { )) { return ERR_EXEC; } + pid_handle = process_info.hProcess; + thread_handle = process_info.hThread; #else + int retval; char progname[256], buf[256]; pid = fork(); if (pid == -1) { @@ -184,8 +186,8 @@ bool poll_application(int& status) { status = stat; return true; } - return false; #endif + return false; } void kill_app() { @@ -196,6 +198,22 @@ void kill_app() { #endif } +void stop_app() { +#ifdef _WIN32 + SuspendThread(thread_handle); +#else + kill(pid, SIGSTOP); +#endif +} + +void resume_app() { +#ifdef _WIN32 + ResumeThread(thread_handle); +#else + kill(pid, SIGCONT); +#endif +} + void poll_boinc_messages() { BOINC_STATUS status; boinc_get_status(&status); @@ -204,21 +222,21 @@ void poll_boinc_messages() { exit(0); } if (status.quit_request) { - kill(pid, SIGKILL); + kill_app(); exit(0); } if (status.abort_request) { - kill(pid, SIGKILL); + kill_app(); exit(0); } if (status.suspended) { if (!app_suspended) { - kill(pid, SIGSTOP); + stop_app(); app_suspended = true; } } else { if (app_suspended) { - kill(pid, SIGCONT); + resume_app(); app_suspended = false; } } @@ -261,3 +279,16 @@ int main(int argc, char** argv) { boinc_sleep(1.); } } + +#ifdef _WIN32 + +int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int WinMode) { + LPSTR command_line; + char* argv[100]; + int argc; + + command_line = GetCommandLine(); + argc = parse_command_line( command_line, argv ); + return main(argc, argv); +} +#endif \ No newline at end of file