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