2011-03-20 18:05:19 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/unix/execute.h
|
|
|
|
// Purpose: private details of wxExecute() implementation
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Copyright: (c) 1998 Robert Roebling, Julian Smart, Vadim Zeitlin
|
2013-09-22 22:44:55 +00:00
|
|
|
// (c) 2013 Vadim Zeitlin
|
2011-03-20 18:05:19 +00:00
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_UNIX_EXECUTE_H
|
|
|
|
#define _WX_UNIX_EXECUTE_H
|
|
|
|
|
2013-09-22 22:44:55 +00:00
|
|
|
#include "wx/app.h"
|
|
|
|
#include "wx/hashmap.h"
|
|
|
|
#include "wx/process.h"
|
2011-03-20 18:05:19 +00:00
|
|
|
|
2013-09-22 22:44:55 +00:00
|
|
|
#if wxUSE_STREAMS
|
|
|
|
#include "wx/unix/pipe.h"
|
|
|
|
#include "wx/private/streamtempinput.h"
|
|
|
|
#endif
|
2011-03-20 18:05:19 +00:00
|
|
|
|
2013-09-22 22:44:55 +00:00
|
|
|
class wxEventLoopBase;
|
2011-03-20 18:05:19 +00:00
|
|
|
|
2013-09-22 22:44:55 +00:00
|
|
|
// Information associated with a running child process.
|
|
|
|
class wxExecuteData
|
2011-03-20 18:05:19 +00:00
|
|
|
{
|
2013-09-22 22:44:55 +00:00
|
|
|
public:
|
2011-03-20 18:05:19 +00:00
|
|
|
wxExecuteData()
|
|
|
|
{
|
|
|
|
flags =
|
|
|
|
pid = 0;
|
2013-09-22 22:44:55 +00:00
|
|
|
exitcode = -1;
|
2011-03-20 18:05:19 +00:00
|
|
|
|
|
|
|
process = NULL;
|
|
|
|
|
2013-09-22 22:44:55 +00:00
|
|
|
syncEventLoop = NULL;
|
2011-03-20 18:05:19 +00:00
|
|
|
|
2013-09-22 22:44:55 +00:00
|
|
|
#if wxUSE_STREAMS
|
2011-03-20 18:05:19 +00:00
|
|
|
fdOut =
|
|
|
|
fdErr = wxPipe::INVALID_FD;
|
|
|
|
#endif // wxUSE_STREAMS
|
|
|
|
}
|
|
|
|
|
2013-09-22 22:44:55 +00:00
|
|
|
// This must be called in the parent process as soon as fork() returns to
|
|
|
|
// update us with the effective child PID. It also ensures that we handle
|
|
|
|
// SIGCHLD to be able to detect when this PID exits, so wxTheApp must be
|
|
|
|
// available.
|
|
|
|
void OnStart(int pid);
|
|
|
|
|
|
|
|
// Called when the child process exits.
|
|
|
|
void OnExit(int exitcode);
|
|
|
|
|
|
|
|
// Return true if we should (or already did) redirect the child IO.
|
|
|
|
bool IsRedirected() const { return process && process->IsRedirected(); }
|
2011-03-20 18:05:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
// wxExecute() flags
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
// the pid of the child process
|
|
|
|
int pid;
|
|
|
|
|
2013-09-22 22:44:55 +00:00
|
|
|
// The exit code of the process, set once the child terminates.
|
|
|
|
int exitcode;
|
|
|
|
|
2011-03-20 18:05:19 +00:00
|
|
|
// the associated process object or NULL
|
|
|
|
wxProcess *process;
|
|
|
|
|
2013-09-22 22:44:55 +00:00
|
|
|
// Local event loop used to wait for the child process termination in
|
|
|
|
// synchronous execution case. We can't create it ourselves as its exact
|
|
|
|
// type depends on the application kind (console/GUI), so we rely on
|
|
|
|
// wxAppTraits setting up this pointer to point to the appropriate object.
|
|
|
|
wxEventLoopBase *syncEventLoop;
|
2011-03-20 18:05:19 +00:00
|
|
|
|
|
|
|
#if wxUSE_STREAMS
|
|
|
|
// the input buffer bufOut is connected to stdout, this is why it is
|
|
|
|
// called bufOut and not bufIn
|
2013-09-22 22:44:55 +00:00
|
|
|
wxStreamTempInputBuffer bufOut,
|
|
|
|
bufErr;
|
2011-03-20 18:05:19 +00:00
|
|
|
|
|
|
|
// the corresponding FDs, -1 if not redirected
|
|
|
|
int fdOut,
|
|
|
|
fdErr;
|
|
|
|
#endif // wxUSE_STREAMS
|
|
|
|
|
2013-09-22 22:44:55 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// SIGCHLD signal handler that checks whether any of the currently running
|
|
|
|
// children have exited.
|
|
|
|
static void OnSomeChildExited(int sig);
|
|
|
|
|
|
|
|
// All currently running child processes indexed by their PID.
|
|
|
|
//
|
|
|
|
// Notice that the container doesn't own its elements.
|
|
|
|
WX_DECLARE_HASH_MAP(int, wxExecuteData*, wxIntegerHash, wxIntegerEqual,
|
|
|
|
ChildProcessesData);
|
|
|
|
static ChildProcessesData ms_childProcesses;
|
|
|
|
|
|
|
|
wxDECLARE_NO_COPY_CLASS(wxExecuteData);
|
|
|
|
};
|
2011-03-20 18:05:19 +00:00
|
|
|
|
|
|
|
#endif // _WX_UNIX_EXECUTE_H
|