wxProcess() fixes: will really call parent's event handler and will pass the

exited process status now


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1637 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-02-07 21:26:54 +00:00
parent 07b7327093
commit 5336ece42c
5 changed files with 57 additions and 45 deletions

View File

@@ -13,46 +13,55 @@
#define _WX_PROCESSH__ #define _WX_PROCESSH__
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface "process.h" #pragma interface "process.h"
#endif #endif
#include "wx/defs.h" #include "wx/defs.h"
#include "wx/object.h" #include "wx/object.h"
#include "wx/event.h" #include "wx/event.h"
class WXDLLEXPORT wxProcess: public wxEvtHandler // Process Event handling
class WXDLLEXPORT wxProcessEvent : public wxEvent
{ {
DECLARE_DYNAMIC_CLASS(wxProcess) DECLARE_DYNAMIC_CLASS(wxProcessEvent)
public:
wxProcess(wxEvtHandler *parent = (wxEvtHandler *) NULL, int id = -1); public:
virtual ~wxProcess(); wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0) : wxEvent(id)
{
m_eventType = wxEVT_END_PROCESS;
m_pid = pid;
m_exitcode = exitcode;
}
virtual void OnTerminate(int pid); // accessors
// PID of process which terminated
int GetPid() { return m_pid; }
protected: // the exit code
int m_id; int GetExitCode() { return m_exitcode; }
public:
int m_pid, m_exitcode;
}; };
// Process Event handling // A wxProcess object should be passed to wxExecute - than its OnTerminate()
// function will be called when the process terminates.
class WXDLLEXPORT wxProcessEvent: public wxEvent class WXDLLEXPORT wxProcess : public wxEvtHandler
{ {
DECLARE_DYNAMIC_CLASS(wxProcessEvent) DECLARE_DYNAMIC_CLASS(wxProcess)
public:
wxProcessEvent(int id = 0, int pid = -1); public:
wxProcess(wxEvtHandler *parent = (wxEvtHandler *) NULL, int id = -1);
inline int GetPid() { return m_pid; }
inline void SetPid(int pid) { m_pid = pid; }
public: virtual void OnTerminate(int pid, int status);
int m_pid;
protected:
int m_id;
}; };
typedef void (wxObject::*wxProcessEventFunction)(wxProcessEvent&); typedef void (wxObject::*wxProcessEventFunction)(wxProcessEvent&);
#define EVT_END_PROCESS(id, func) { wxEVT_END_PROCESS, id, -1, (wxObjectEvent) (wxEventFunction) (wxProcessEventFunction) & fn, NULL}, #define EVT_END_PROCESS(id, func) { wxEVT_END_PROCESS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxProcessEventFunction) & func, NULL},
#endif #endif
// _WX_PROCESSH__ // _WX_PROCESSH__

View File

@@ -10,48 +10,38 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "process.h" #pragma implementation "process.h"
#endif #endif
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma hdrstop #pragma hdrstop
#endif #endif
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/defs.h" #include "wx/defs.h"
#endif #endif
#include "wx/process.h" #include "wx/process.h"
#if !USE_SHARED_LIBRARY #if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxProcess, wxEvtHandler) IMPLEMENT_DYNAMIC_CLASS(wxProcess, wxEvtHandler)
IMPLEMENT_DYNAMIC_CLASS(wxProcessEvent, wxEvent) IMPLEMENT_DYNAMIC_CLASS(wxProcessEvent, wxEvent)
#endif #endif
wxProcess::wxProcess(wxEvtHandler *parent, int id) wxProcess::wxProcess(wxEvtHandler *parent, int id)
{ {
if (parent) if (parent)
SetPreviousHandler(parent); SetNextHandler(parent);
m_id = id; m_id = id;
} }
wxProcess::~wxProcess() void wxProcess::OnTerminate(int pid, int status)
{ {
} wxProcessEvent event(m_id, pid, status);
void wxProcess::OnTerminate(int pid)
{
wxProcessEvent event(m_id, pid);
ProcessEvent(event); ProcessEvent(event);
} }
wxProcessEvent::wxProcessEvent(int id, int pid):
wxEvent(id), m_pid(pid)
{
}

View File

@@ -67,6 +67,7 @@ LIB_CPP_SRC=\
common/tokenzr.cpp \ common/tokenzr.cpp \
common/resource.cpp \ common/resource.cpp \
common/wxexpr.cpp \ common/wxexpr.cpp \
common/process.cpp \
\ \
gtk/accel.cpp \ gtk/accel.cpp \
gtk/app.cpp \ gtk/app.cpp \

View File

@@ -18,6 +18,8 @@
#include "wx/intl.h" #include "wx/intl.h"
#include "wx/log.h" #include "wx/log.h"
#include "wx/process.h"
#include <stdarg.h> #include <stdarg.h>
#include <dirent.h> #include <dirent.h>
#include <string.h> #include <string.h>
@@ -266,17 +268,21 @@ static void GTK_EndProcessDetector(gpointer data, gint source,
/* wait4 is not part of any standard, use at own risk /* wait4 is not part of any standard, use at own risk
* not sure what wait4 does, but wait3 seems to be closest, whats a digit ;-) * not sure what wait4 does, but wait3 seems to be closest, whats a digit ;-)
* --- offer@sgi.com */ * --- offer@sgi.com */
// VZ: wait4() will be woken up by a signal, not wait3 - so it's quite
// different (also, wait3() waits for any child, wait4() only for this
// one)
int status = -1;
#if !defined(__sgi) #if !defined(__sgi)
wait4(proc_data->pid, (int*) NULL, 0, (rusage *) NULL); wait4(proc_data->pid, &status, 0, (rusage *) NULL);
#else #else
wait3((int *) NULL, 0, (rusage *) NULL); wait3(&status, 0, (rusage *) NULL);
#endif #endif
close(source); close(source);
gdk_input_remove(proc_data->tag); gdk_input_remove(proc_data->tag);
if (proc_data->process) if (proc_data->process)
proc_data->process->OnTerminate(proc_data->pid); proc_data->process->OnTerminate(proc_data->pid, status);
if (proc_data->pid > 0) if (proc_data->pid > 0)
delete proc_data; delete proc_data;

View File

@@ -18,6 +18,8 @@
#include "wx/intl.h" #include "wx/intl.h"
#include "wx/log.h" #include "wx/log.h"
#include "wx/process.h"
#include <stdarg.h> #include <stdarg.h>
#include <dirent.h> #include <dirent.h>
#include <string.h> #include <string.h>
@@ -266,17 +268,21 @@ static void GTK_EndProcessDetector(gpointer data, gint source,
/* wait4 is not part of any standard, use at own risk /* wait4 is not part of any standard, use at own risk
* not sure what wait4 does, but wait3 seems to be closest, whats a digit ;-) * not sure what wait4 does, but wait3 seems to be closest, whats a digit ;-)
* --- offer@sgi.com */ * --- offer@sgi.com */
// VZ: wait4() will be woken up by a signal, not wait3 - so it's quite
// different (also, wait3() waits for any child, wait4() only for this
// one)
int status = -1;
#if !defined(__sgi) #if !defined(__sgi)
wait4(proc_data->pid, (int*) NULL, 0, (rusage *) NULL); wait4(proc_data->pid, &status, 0, (rusage *) NULL);
#else #else
wait3((int *) NULL, 0, (rusage *) NULL); wait3(&status, 0, (rusage *) NULL);
#endif #endif
close(source); close(source);
gdk_input_remove(proc_data->tag); gdk_input_remove(proc_data->tag);
if (proc_data->process) if (proc_data->process)
proc_data->process->OnTerminate(proc_data->pid); proc_data->process->OnTerminate(proc_data->pid, status);
if (proc_data->pid > 0) if (proc_data->pid > 0)
delete proc_data; delete proc_data;