execute.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/unix/execute.h
  3. // Purpose: private details of wxExecute() implementation
  4. // Author: Vadim Zeitlin
  5. // Copyright: (c) 1998 Robert Roebling, Julian Smart, Vadim Zeitlin
  6. // (c) 2013 Vadim Zeitlin
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_UNIX_EXECUTE_H
  10. #define _WX_UNIX_EXECUTE_H
  11. #include "wx/app.h"
  12. #include "wx/hashmap.h"
  13. #include "wx/process.h"
  14. #if wxUSE_STREAMS
  15. #include "wx/unix/pipe.h"
  16. #include "wx/private/streamtempinput.h"
  17. #endif
  18. class wxEventLoopBase;
  19. // Information associated with a running child process.
  20. class wxExecuteData
  21. {
  22. public:
  23. wxExecuteData()
  24. {
  25. flags =
  26. pid = 0;
  27. exitcode = -1;
  28. process = NULL;
  29. syncEventLoop = NULL;
  30. #if wxUSE_STREAMS
  31. fdOut =
  32. fdErr = wxPipe::INVALID_FD;
  33. #endif // wxUSE_STREAMS
  34. }
  35. // This must be called in the parent process as soon as fork() returns to
  36. // update us with the effective child PID. It also ensures that we handle
  37. // SIGCHLD to be able to detect when this PID exits, so wxTheApp must be
  38. // available.
  39. void OnStart(int pid);
  40. // Called when the child process exits.
  41. void OnExit(int exitcode);
  42. // Return true if we should (or already did) redirect the child IO.
  43. bool IsRedirected() const { return process && process->IsRedirected(); }
  44. // wxExecute() flags
  45. int flags;
  46. // the pid of the child process
  47. int pid;
  48. // The exit code of the process, set once the child terminates.
  49. int exitcode;
  50. // the associated process object or NULL
  51. wxProcess *process;
  52. // Local event loop used to wait for the child process termination in
  53. // synchronous execution case. We can't create it ourselves as its exact
  54. // type depends on the application kind (console/GUI), so we rely on
  55. // wxAppTraits setting up this pointer to point to the appropriate object.
  56. wxEventLoopBase *syncEventLoop;
  57. #if wxUSE_STREAMS
  58. // the input buffer bufOut is connected to stdout, this is why it is
  59. // called bufOut and not bufIn
  60. wxStreamTempInputBuffer bufOut,
  61. bufErr;
  62. // the corresponding FDs, -1 if not redirected
  63. int fdOut,
  64. fdErr;
  65. #endif // wxUSE_STREAMS
  66. private:
  67. // SIGCHLD signal handler that checks whether any of the currently running
  68. // children have exited.
  69. static void OnSomeChildExited(int sig);
  70. // All currently running child processes indexed by their PID.
  71. //
  72. // Notice that the container doesn't own its elements.
  73. WX_DECLARE_HASH_MAP(int, wxExecuteData*, wxIntegerHash, wxIntegerEqual,
  74. ChildProcessesData);
  75. static ChildProcessesData ms_childProcesses;
  76. wxDECLARE_NO_COPY_CLASS(wxExecuteData);
  77. };
  78. #endif // _WX_UNIX_EXECUTE_H