]>
Commit | Line | Data |
---|---|---|
518b5d2f | 1 | ///////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: wx/unix/execute.h |
518b5d2f VZ |
3 | // Purpose: private details of wxExecute() implementation |
4 | // Author: Vadim Zeitlin | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling, Julian Smart, Vadim Zeitlin | |
821d856a | 7 | // (c) 2013 Vadim Zeitlin |
65571936 | 8 | // Licence: wxWindows licence |
518b5d2f VZ |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifndef _WX_UNIX_EXECUTE_H | |
12 | #define _WX_UNIX_EXECUTE_H | |
13 | ||
821d856a VZ |
14 | #include "wx/app.h" |
15 | #include "wx/hashmap.h" | |
16 | #include "wx/process.h" | |
e2478fde | 17 | |
821d856a VZ |
18 | #include "wx/unix/pipe.h" |
19 | #include "wx/private/streamtempinput.h" | |
e528a71b | 20 | |
821d856a | 21 | class wxEventLoopBase; |
518b5d2f | 22 | |
821d856a VZ |
23 | // Information associated with a running child process. |
24 | class wxExecuteData | |
e2478fde | 25 | { |
821d856a | 26 | public: |
e2478fde VZ |
27 | wxExecuteData() |
28 | { | |
29 | flags = | |
30 | pid = 0; | |
821d856a | 31 | exitcode = -1; |
e2478fde VZ |
32 | |
33 | process = NULL; | |
34 | ||
821d856a | 35 | syncEventLoop = NULL; |
33343395 | 36 | |
821d856a | 37 | #if wxUSE_STREAMS |
33343395 VZ |
38 | fdOut = |
39 | fdErr = wxPipe::INVALID_FD; | |
e2478fde VZ |
40 | #endif // wxUSE_STREAMS |
41 | } | |
42 | ||
821d856a VZ |
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(); } | |
33343395 VZ |
54 | |
55 | ||
e2478fde VZ |
56 | // wxExecute() flags |
57 | int flags; | |
58 | ||
59 | // the pid of the child process | |
60 | int pid; | |
61 | ||
821d856a VZ |
62 | // The exit code of the process, set once the child terminates. |
63 | int exitcode; | |
64 | ||
e2478fde VZ |
65 | // the associated process object or NULL |
66 | wxProcess *process; | |
67 | ||
821d856a VZ |
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; | |
e2478fde VZ |
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 | |
821d856a VZ |
77 | wxStreamTempInputBuffer bufOut, |
78 | bufErr; | |
33343395 VZ |
79 | |
80 | // the corresponding FDs, -1 if not redirected | |
81 | int fdOut, | |
82 | fdErr; | |
e2478fde | 83 | #endif // wxUSE_STREAMS |
e2478fde | 84 | |
821d856a VZ |
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 | }; | |
518b5d2f | 100 | |
518b5d2f | 101 | #endif // _WX_UNIX_EXECUTE_H |