🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.1 KiB

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