SDL_visualtest_process.h (3140B)
1/* See COPYING.txt for the full license governing this code. */ 2/** 3 * \file SDL_visualtest_process.h 4 * 5 * Provides cross-platfrom process launching and termination functionality. 6 */ 7 8#include <SDL_platform.h> 9 10#if defined(__WIN32__) 11#include <Windows.h> 12#include <Shlwapi.h> 13#elif defined(__LINUX__) 14#include <unistd.h> 15#else 16#error "Unsupported platform." 17#endif 18 19#ifndef _SDL_visualtest_process_h 20#define _SDL_visualtest_process_h 21 22/* Set up for C function definitions, even when using C++ */ 23#ifdef __cplusplus 24extern "C" { 25#endif 26 27/** 28 * Struct to store a platform specific handle to a process. 29 */ 30typedef struct SDL_ProcessInfo 31{ 32//#if defined(_WIN32) || defined(__WIN32__) 33#if defined(__WIN32__) 34 PROCESS_INFORMATION pi; 35//#elif defined(__linux__) 36#elif defined(__LINUX__) 37 int pid; 38#endif 39} SDL_ProcessInfo; 40 41/** 42 * This structure stores the exit status (value returned by main()) and 43 * whether the process exited sucessfully or not. 44 */ 45typedef struct SDL_ProcessExitStatus 46{ 47 int exit_success; /*!< Zero if the process exited successfully */ 48 int exit_status; /*!< The exit status of the process. 8-bit value. */ 49} SDL_ProcessExitStatus; 50 51/** 52 * Launches a process with the given commandline arguments. 53 * 54 * \param file The path to the executable to be launched. 55 * \param args The command line arguments to be passed to the process. 56 * \param pinfo Pointer to an SDL_ProcessInfo object to be populated with 57 * platform specific information about the launched process. 58 * 59 * \return Non-zero on success, zero on failure. 60 */ 61int SDL_LaunchProcess(char* file, char* args, SDL_ProcessInfo* pinfo); 62 63/** 64 * Checks if a process is running or not. 65 * 66 * \param pinfo Pointer to SDL_ProcessInfo object of the process that needs to be 67 * checked. 68 * 69 * \return 1 if the process is still running; zero if it is not and -1 if the 70 * status could not be retrieved. 71 */ 72int SDL_IsProcessRunning(SDL_ProcessInfo* pinfo); 73 74/** 75 * Kills a currently running process. 76 * 77 * \param pinfo Pointer to a SDL_ProcessInfo object of the process to be terminated. 78 * \param ps Pointer to a SDL_ProcessExitStatus object which will be populated 79 * with the exit status. 80 * 81 * \return 1 on success, 0 on failure. 82 */ 83int SDL_KillProcess(SDL_ProcessInfo* pinfo, SDL_ProcessExitStatus* ps); 84 85/** 86 * Cleanly exits the process represented by \c pinfo and stores the exit status 87 * in the exit status object pointed to by \c ps. 88 * 89 * \return 1 on success, 0 on failure. 90 */ 91int SDL_QuitProcess(SDL_ProcessInfo* pinfo, SDL_ProcessExitStatus* ps); 92 93/** 94 * Gets the exit status of a process. If the exit status is -1, the process is 95 * still running. 96 * 97 * \param pinfo Pointer to a SDL_ProcessInfo object of the process to be checked. 98 * \param ps Pointer to a SDL_ProcessExitStatus object which will be populated 99 * with the exit status. 100 * 101 * \return 1 on success, 0 on failure. 102 */ 103int SDL_GetProcessExitStatus(SDL_ProcessInfo* pinfo, SDL_ProcessExitStatus* ps); 104 105/* Ends C function definitions when using C++ */ 106#ifdef __cplusplus 107} 108#endif 109 110#endif /* _SDL_visualtest_process_h */ 111