wxBase/GUI separation: 1st step, wxMSW should build, all the rest is broken

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21342 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-06-24 00:56:19 +00:00
parent 433f5675a9
commit e2478fde62
64 changed files with 7364 additions and 3583 deletions

View File

@@ -0,0 +1,63 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/apptbase.h
// Purpose: declaration of wxAppTraits for Unix systems
// Author: Vadim Zeitlin
// Modified by:
// Created: 23.06.2003
// RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_APPTBASE_H_
#define _WX_UNIX_APPTBASE_H_
class wxExecuteData;
class wxPipe;
// ----------------------------------------------------------------------------
// wxAppTraits: the Unix version adds extra hooks needed by Unix code
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxAppTraits : public wxAppTraitsBase
{
public:
// wxExecute() support methods
// ---------------------------
// called before starting the child process and creates the pipe used for
// detecting the process termination asynchronously in GUI, does nothing in
// wxBase
//
// if it returns false, we should return from wxExecute() with an error
virtual bool CreateEndProcessPipe(wxExecuteData& execData) = 0;
// test if the given descriptor is the end of the pipe create by the
// function above
virtual bool IsWriteFDOfEndProcessPipe(wxExecuteData& execData, int fd) = 0;
// ensure that the write end of the pipe is not closed by wxPipe dtor
virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData) = 0;
// wait for the process termination, return whatever wxExecute() must
// return
virtual int WaitForChild(wxExecuteData& execData) = 0;
// wxThread helpers
// ----------------
// TODO
// other miscellaneous helpers
// ---------------------------
// wxGetOsVersion() behaves differently in GUI and non-GUI builds udner
// Unix: in the former case it returns the information about the toolkit
// and in the latter -- about the OS, so we need to virtualize it
virtual int GetOSVersion(int *verMaj, int *verMin) = 0;
};
#endif // _WX_UNIX_APPTBASE_H_

View File

@@ -0,0 +1,46 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/apptrait.h
// Purpose: standard implementations of wxAppTraits for Unix
// Author: Vadim Zeitlin
// Modified by:
// Created: 23.06.2003
// RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_APPTRAIT_H_
#define _WX_UNIX_APPTRAIT_H_
// ----------------------------------------------------------------------------
// wxGUI/ConsoleAppTraits: must derive from wxAppTraits, not wxAppTraitsBase
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxConsoleAppTraits : public wxConsoleAppTraitsBase
{
public:
virtual bool CreateEndProcessPipe();
virtual bool IsWriteFDOfEndProcessPipe(wxExecuteData& execData, int fd);
virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData);
virtual int WaitForChild(wxExecuteData& execData);
virtual int GetOSVersion(int *verMaj, int *verMin);
};
#if wxUSE_GUI
class WXDLLEXPORT wxGUIAppTraits : public wxGUIAppTraitsBase
{
public:
virtual bool CreateEndProcessPipe(wxExecuteData& execData);
virtual bool IsWriteFDOfEndProcessPipe(wxExecuteData& execData, int fd);
virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData);
virtual int WaitForChild(wxExecuteData& execData);
virtual int GetOSVersion(int *verMaj, int *verMin);
};
#endif // wxUSE_GUI
#endif // _WX_UNIX_APPTRAIT_H_

View File

@@ -10,6 +10,11 @@
#ifndef _WX_UNIX_EXECUTE_H
#define _WX_UNIX_EXECUTE_H
#include "wx/unix/pipe.h"
class wxProcess;
class wxStreamTempInputBuffer;
// if pid > 0, the execution is async and the data is freed in the callback
// executed when the process terminates, if pid < 0, the execution is
// synchronous and the caller (wxExecute) frees the data
@@ -21,6 +26,43 @@ struct wxEndProcessData
int exitcode; // the exit code
};
// struct in which information is passed from wxExecute() to wxAppTraits
// methods
struct wxExecuteData
{
wxExecuteData()
{
flags =
pid = 0;
process = NULL;
#if wxUSE_STREAMS
bufOut =
bufErr = NULL;
#endif // wxUSE_STREAMS
}
// wxExecute() flags
int flags;
// the pid of the child process
int pid;
// the associated process object or NULL
wxProcess *process;
// pipe used for end process detection
wxPipe pipeEndProcDetect;
#if wxUSE_STREAMS
// the input buffer bufOut is connected to stdout, this is why it is
// called bufOut and not bufIn
wxStreamTempInputBuffer *bufOut,
*bufErr;
#endif // wxUSE_STREAMS
};
// this function is called when the process terminates from port specific
// callback function and is common to all ports (src/unix/utilsunx.cpp)
extern void wxHandleProcessTermination(wxEndProcessData *proc_data);
@@ -28,6 +70,7 @@ extern void wxHandleProcessTermination(wxEndProcessData *proc_data);
// this function is called to associate the port-specific callback with the
// child process. The return valus is port-specific.
extern int wxAddProcessCallback(wxEndProcessData *proc_data, int fd);
// For ports (e.g. DARWIN) which can add callbacks based on the pid
extern int wxAddProcessCallbackForPid(wxEndProcessData *proc_data, int pid);

95
include/wx/unix/pipe.h Normal file
View File

@@ -0,0 +1,95 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/pipe.h
// Purpose: wxPipe class
// Author: Vadim Zeitlin
// Modified by:
// Created: 24.06.2003 (extracted from src/unix/utilsunx.cpp)
// RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_PIPE_H_
#define _WX_UNIX_PIPE_H_
#include <unistd.h>
// ----------------------------------------------------------------------------
// wxPipe: this class encapsulates pipe() system call
// ----------------------------------------------------------------------------
class wxPipe
{
public:
// the symbolic names for the pipe ends
enum Direction
{
Read,
Write
};
enum
{
INVALID_FD = -1
};
// default ctor doesn't do anything
wxPipe() { m_fds[Read] = m_fds[Write] = INVALID_FD; }
// create the pipe, return TRUE if ok, FALSE on error
bool Create()
{
if ( pipe(m_fds) == -1 )
{
wxLogSysError(_("Pipe creation failed"));
return FALSE;
}
return TRUE;
}
// return TRUE if we were created successfully
bool IsOk() const { return m_fds[Read] != INVALID_FD; }
// return the descriptor for one of the pipe ends
int operator[](Direction which) const
{
wxASSERT_MSG( which >= 0 && (size_t)which < WXSIZEOF(m_fds),
_T("invalid pipe index") );
return m_fds[which];
}
// detach a descriptor, meaning that the pipe dtor won't close it, and
// return it
int Detach(Direction which)
{
wxASSERT_MSG( which >= 0 && (size_t)which < WXSIZEOF(m_fds),
_T("invalid pipe index") );
int fd = m_fds[which];
m_fds[which] = INVALID_FD;
return fd;
}
// close the pipe descriptors
void Close()
{
for ( size_t n = 0; n < WXSIZEOF(m_fds); n++ )
{
if ( m_fds[n] != INVALID_FD )
close(m_fds[n]);
}
}
// dtor closes the pipe descriptors
~wxPipe() { Close(); }
private:
int m_fds[2];
};
#endif // _WX_UNIX_PIPE_H_