visualtest/include/SDL_visualtest_process.h
changeset 7924 fcb86d323770
child 11382 2c50e79b19e0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/visualtest/include/SDL_visualtest_process.h	Sun Nov 10 00:32:23 2013 -0500
     1.3 @@ -0,0 +1,111 @@
     1.4 +/* See COPYING.txt for the full license governing this code. */
     1.5 +/**
     1.6 + * \file SDL_visualtest_process.h
     1.7 + *
     1.8 + * Provides cross-platfrom process launching and termination functionality.
     1.9 + */
    1.10 +
    1.11 +#include <SDL_platform.h>
    1.12 +
    1.13 +#if defined(__WIN32__)
    1.14 +#include <Windows.h>
    1.15 +#include <Shlwapi.h>
    1.16 +#elif defined(__LINUX__)
    1.17 +#include <unistd.h>
    1.18 +#else
    1.19 +#error "Unsupported platform."
    1.20 +#endif
    1.21 +
    1.22 +#ifndef _SDL_visualtest_process_h
    1.23 +#define _SDL_visualtest_process_h
    1.24 +
    1.25 +/* Set up for C function definitions, even when using C++ */
    1.26 +#ifdef __cplusplus
    1.27 +extern "C" {
    1.28 +#endif
    1.29 +
    1.30 +/**
    1.31 + * Struct to store a platform specific handle to a process.
    1.32 + */
    1.33 +typedef struct SDL_ProcessInfo
    1.34 +{
    1.35 +//#if defined(_WIN32) || defined(__WIN32__)
    1.36 +#if defined(__WIN32__)
    1.37 +    PROCESS_INFORMATION pi;
    1.38 +//#elif defined(__linux__)
    1.39 +#elif defined(__LINUX__)
    1.40 +    int pid;
    1.41 +#endif
    1.42 +} SDL_ProcessInfo;
    1.43 +
    1.44 +/**
    1.45 + * This structure stores the exit status (value returned by main()) and
    1.46 + * whether the process exited sucessfully or not.
    1.47 + */
    1.48 +typedef struct SDL_ProcessExitStatus
    1.49 +{
    1.50 +    int exit_success;   /*!< Zero if the process exited successfully */
    1.51 +    int exit_status;    /*!< The exit status of the process. 8-bit value. */
    1.52 +} SDL_ProcessExitStatus;
    1.53 +
    1.54 +/**
    1.55 + * Launches a process with the given commandline arguments.
    1.56 + *
    1.57 + * \param file  The path to the executable to be launched.
    1.58 + * \param args  The command line arguments to be passed to the process.
    1.59 + * \param pinfo Pointer to an SDL_ProcessInfo object to be populated with
    1.60 + *              platform specific information about the launched process.
    1.61 + *
    1.62 + * \return Non-zero on success, zero on failure.
    1.63 + */
    1.64 +int SDL_LaunchProcess(char* file, char* args, SDL_ProcessInfo* pinfo);
    1.65 +
    1.66 +/**
    1.67 + * Checks if a process is running or not.
    1.68 + *
    1.69 + * \param pinfo Pointer to SDL_ProcessInfo object of the process that needs to be
    1.70 + *              checked.
    1.71 + *
    1.72 + * \return 1 if the process is still running; zero if it is not and -1 if the
    1.73 + *         status could not be retrieved.
    1.74 + */
    1.75 +int SDL_IsProcessRunning(SDL_ProcessInfo* pinfo);
    1.76 +
    1.77 +/**
    1.78 + * Kills a currently running process.
    1.79 + *
    1.80 + * \param pinfo Pointer to a SDL_ProcessInfo object of the process to be terminated.
    1.81 + * \param ps Pointer to a SDL_ProcessExitStatus object which will be populated
    1.82 + *           with the exit status.
    1.83 + *
    1.84 + * \return 1 on success, 0 on failure.
    1.85 + */
    1.86 +int SDL_KillProcess(SDL_ProcessInfo* pinfo, SDL_ProcessExitStatus* ps);
    1.87 +
    1.88 +/**
    1.89 + * Cleanly exits the process represented by \c pinfo and stores the exit status
    1.90 + * in the exit status object pointed to by \c ps.
    1.91 + *
    1.92 + * \return 1 on success, 0 on failure.
    1.93 + */
    1.94 +int SDL_QuitProcess(SDL_ProcessInfo* pinfo, SDL_ProcessExitStatus* ps);
    1.95 +
    1.96 +/**
    1.97 + * Gets the exit status of a process. If the exit status is -1, the process is
    1.98 + * still running.
    1.99 + *
   1.100 + * \param pinfo Pointer to a SDL_ProcessInfo object of the process to be checked.
   1.101 + * \param ps Pointer to a SDL_ProcessExitStatus object which will be populated
   1.102 + *           with the exit status.
   1.103 + *
   1.104 + * \return 1 on success, 0 on failure.
   1.105 + */
   1.106 +int SDL_GetProcessExitStatus(SDL_ProcessInfo* pinfo, SDL_ProcessExitStatus* ps);
   1.107 +
   1.108 +/* Ends C function definitions when using C++ */
   1.109 +#ifdef __cplusplus
   1.110 +}
   1.111 +#endif
   1.112 +
   1.113 +#endif /* _SDL_visualtest_process_h */
   1.114 +