Process.h.in 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*=========================================================================
  2. Program: KWSys - Kitware System Library
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef @KWSYS_NAMESPACE@_Process_h
  14. #define @KWSYS_NAMESPACE@_Process_h
  15. #define kwsys(x) @KWSYS_NAMESPACE@##x
  16. #define kwsysProcess_STDOUT kwsys(Process_STDOUT)
  17. #define kwsysProcess_STDERR kwsys(Process_STDERR)
  18. #define kwsysProcess_Timeout kwsys(Process_Timeout)
  19. #define kwsysProcess_Starting kwsys(Process_Starting)
  20. #define kwsysProcess_Executing kwsys(Process_Executing)
  21. #define kwsysProcess_Expired kwsys(Process_Expired)
  22. #define kwsysProcess_Exited kwsys(Process_Exited)
  23. #define kwsysProcess_Killed kwsys(Process_Killed)
  24. #define kwsysProcess_Signalled kwsys(Process_Signalled)
  25. #define kwsysProcess_Error kwsys(Process_Error)
  26. #define kwsysProcess_State kwsys(Process_State)
  27. #define kwsysProcess_Pipes_e kwsys(Process_Pipes_e)
  28. #define kwsysProcess_State_e kwsys(Process_State_e)
  29. #define kwsysProcess_s kwsys(Process_s)
  30. #define kwsysProcess kwsys(Process)
  31. #define kwsysProcess_New kwsys(Process_New)
  32. #define kwsysProcess_Delete kwsys(Process_Delete)
  33. #define kwsysProcess_SetCommand kwsys(Process_SetCommand)
  34. #define kwsysProcess_SetTimeout kwsys(Process_SetTimeout)
  35. #define kwsysProcess_GetState kwsys(Process_GetState)
  36. #define kwsysProcess_GetExitCode kwsys(Process_GetExitCode)
  37. #define kwsysProcess_GetErrorString kwsys(Process_GetErrorString)
  38. #define kwsysProcess_Execute kwsys(Process_Execute)
  39. #define kwsysProcess_WaitForData kwsys(Process_WaitForData)
  40. #define kwsysProcess_WaitForExit kwsys(Process_WaitForExit)
  41. #define kwsysProcess_Kill kwsys(Process_Kill)
  42. #if defined(__cplusplus)
  43. extern "C"
  44. {
  45. #endif
  46. typedef enum kwsysProcess_Pipes_e
  47. {
  48. kwsysProcess_STDOUT=1,
  49. kwsysProcess_STDERR=2,
  50. kwsysProcess_Timeout=255
  51. } kwsysProcess_Pipes;
  52. typedef enum kwsysProcess_State_e
  53. {
  54. kwsysProcess_Starting, /* Between New and Execute; No process run yet */
  55. kwsysProcess_Executing, /* Process is running */
  56. kwsysProcess_Expired, /* Process timeout expired and was killed */
  57. kwsysProcess_Exited, /* Process exited */
  58. kwsysProcess_Killed, /* Process was killed by Kill */
  59. kwsysProcess_Signalled, /* Process was terminated by a signal (crash / ctrl-C) */
  60. kwsysProcess_Error /* Internal error of Process */
  61. } kwsysProcess_State;
  62. typedef struct kwsysProcess_s kwsysProcess;
  63. kwsysProcess* kwsysProcess_New();
  64. void kwsysProcess_Delete(kwsysProcess* cp);
  65. void kwsysProcess_SetCommand(kwsysProcess* cp, char const* const* command);
  66. void kwsysProcess_SetTimeout(kwsysProcess* cp, double timeout);
  67. /*
  68. * Get the current internal state of the kwsysProcess instance
  69. */
  70. int kwsysProcess_GetState(kwsysProcess* cp);
  71. /*
  72. * Get process return code or when signalled, get the signal code
  73. */
  74. int kwsysProcess_GetExitCode(kwsysProcess* cp);
  75. /*
  76. * On kwsysProcess_Error get the error message
  77. */
  78. const char* kwsysProcess_GetErrorString(kwsysProcess* cp);
  79. void kwsysProcess_Execute(kwsysProcess* cp);
  80. /*
  81. * Block until data available on requested pipe or one of the timeouts expired,
  82. * or the process exits. If the pipe is not specified, data on that pipe are
  83. * ignored.
  84. *
  85. * pipes - a list of interested pipes - kwsysProcess_STDOUT | kwsysProcess_STDERR
  86. * data - returns pointer to data if read, NULL otherwise
  87. * length - length of the returned data
  88. * userTimeout - timeout for the current kwsysProcess_WaitForData call
  89. * the userTimeout will contain the remaining time
  90. *
  91. * Returns:
  92. * 0 - Process exited or killed or process timeout expired with no data
  93. * available, or no process running.
  94. * PIPE id otherwise:
  95. * kwsysProcess_STDOUT - if stdout is returned
  96. * kwsysProcess_STDERR - if stderr is returned
  97. * kwsysProcess_Timeout - if user timeout expired
  98. */
  99. int kwsysProcess_WaitForData(kwsysProcess* cp, int pipes, char** data, int* length,
  100. double* userTimeout);
  101. /*
  102. * Block until the process exits or the timeout expires. If no process is
  103. * running, return immediatly.
  104. *
  105. * Returns:
  106. * 0 - When user timeout expires
  107. * 1 - Otherwise
  108. */
  109. int kwsysProcess_WaitForExit(kwsysProcess* cp, double* userTimeout);
  110. /*
  111. * Kills the process. kwsysProcess_WaitForExit should still be called
  112. * after kwsysProcess_Kill.
  113. */
  114. void kwsysProcess_Kill(kwsysProcess* cp);
  115. #if defined(__cplusplus)
  116. } /* extern "C" */
  117. #endif
  118. /* If we are building a kwsysProcess .c file, let it use these macros. */
  119. #if !defined(KWSYS_IN_PROCESS_C)
  120. # undef kwsys
  121. # undef kwsysProcess_STDOUT
  122. # undef kwsysProcess_STDERR
  123. # undef kwsysProcess_Timeout
  124. # undef kwsysProcess_Starting
  125. # undef kwsysProcess_Executing
  126. # undef kwsysProcess_Expired
  127. # undef kwsysProcess_Exited
  128. # undef kwsysProcess_Killed
  129. # undef kwsysProcess_Signalled
  130. # undef kwsysProcess_Error
  131. # undef kwsysProcess_State
  132. # undef kwsysProcess_Pipes_e
  133. # undef kwsysProcess_State_e
  134. # undef kwsysProcess_s
  135. # undef kwsysProcess
  136. # undef kwsysProcess_New
  137. # undef kwsysProcess_Delete
  138. # undef kwsysProcess_SetCommand
  139. # undef kwsysProcess_SetTimeout
  140. # undef kwsysProcess_GetState
  141. # undef kwsysProcess_GetExitCode
  142. # undef kwsysProcess_GetErrorString
  143. # undef kwsysProcess_Execute
  144. # undef kwsysProcess_WaitForData
  145. # undef kwsysProcess_WaitForExit
  146. # undef kwsysProcess_Kill
  147. #endif
  148. #endif