implement event loop for console applications (heavily modified patch 1715735)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46029 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-05-14 23:43:39 +00:00
parent 9e9f08b5ed
commit b46b1d59d6
72 changed files with 3181 additions and 1128 deletions

54
include/wx/unix/app.h Normal file
View File

@@ -0,0 +1,54 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/app.h
// Purpose: wxAppConsole implementation for Unix
// Author: Lukasz Michalski
// Created: 28/01/2005
// RCS-ID: $Id$
// Copyright: (c) Lukasz Michalski
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// wxApp subclass implementing event processing for console applications
class WXDLLIMPEXP_BASE wxAppConsoleUnix : public wxAppConsole
{
public:
// override base class initialization
virtual bool Initialize(int& argc, wxChar** argv);
// Unix-specific: Unix signal handling
// -----------------------------------
// type of the function which can be registered as signal handler: notice
// that it isn't really a signal handler, i.e. it's not subject to the
// usual signal handlers constraints, because it is called later from
// CheckSignal() and not when the signal really occurs
typedef void (*SignalHandler)(int);
// Set signal handler for the given signal, SIG_DFL or SIG_IGN can be used
// instead of a function pointer
//
// Return true if handler was installed, false on error
bool SetSignalHandler(int signal, SignalHandler handler);
// Check if any Unix signals arrived since the last call and execute
// handlers for them
void CheckSignal();
private:
// signal handler set up by SetSignalHandler() for all signals we handle,
// it just adds the signal to m_signalsCaught -- the real processing is
// done later, when CheckSignal() is called
static void HandleSignal(int signal);
// signals for which HandleSignal() had been called (reset from
// CheckSignal())
sigset_t m_signalsCaught;
// the signal handlers
WX_DECLARE_HASH_MAP(int, SignalHandler, wxIntegerHash, wxIntegerEqual, SignalHandlerHash);
SignalHandlerHash m_signalHandlerHash;
friend class GSocketGUIFunctionsTableBase;
};

View File

@@ -19,6 +19,7 @@
class WXDLLEXPORT wxConsoleAppTraits : public wxConsoleAppTraitsBase
{
public:
virtual wxEventLoop *CreateEventLoop();
virtual bool CreateEndProcessPipe(wxExecuteData& execData);
virtual bool IsWriteFDOfEndProcessPipe(wxExecuteData& execData, int fd);
virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData);
@@ -33,6 +34,7 @@ public:
class WXDLLEXPORT wxGUIAppTraits : public wxGUIAppTraitsBase
{
public:
virtual wxEventLoop *CreateEventLoop();
virtual bool CreateEndProcessPipe(wxExecuteData& execData);
virtual bool IsWriteFDOfEndProcessPipe(wxExecuteData& execData, int fd);
virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData);
@@ -46,15 +48,15 @@ public:
#endif
virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const;
#ifdef __WXGTK__
#if wxUSE_INTL
#if defined(__WXGTK__) && wxUSE_INTL
virtual void SetLocale();
#endif
#endif // __WXGTK__
#ifdef __WXGTK20__
virtual wxString GetDesktopEnvironment() const;
virtual wxString GetStandardCmdLineOptions(wxArrayString& names,
wxArrayString& desc) const;
#endif // __WXGTK__
#endif // __WXGTK20____
#if defined(__WXDEBUG__) && defined(__WXGTK20__)
virtual bool ShowAssertDialog(const wxString& msg);

71
include/wx/unix/evtloop.h Normal file
View File

@@ -0,0 +1,71 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/evtloop.h
// Purpose: declares wxEventLoop class
// Author: Lukasz Michalski (lm@zork.pl)
// Created: 2007-05-07
// RCS-ID: $Id$
// Copyright: (c) 2007 Lukasz Michalski
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_EVTLOOP_H_
#define _WX_UNIX_EVTLOOP_H_
#include "wx/private/fdiodispatcher.h"
#include "wx/unix/private/timer.h"
#include "wx/unix/pipe.h"
// ----------------------------------------------------------------------------
// wxEventLoop
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxConsoleEventLoop : public wxEventLoopManual
{
public:
// initialize the event loop, use IsOk() to check if we were successful
wxConsoleEventLoop();
// implement base class pure virtuals
virtual bool Pending() const;
virtual bool Dispatch();
virtual void WakeUp();
virtual bool IsOk() const { return m_dispatcher != NULL; }
protected:
virtual void OnNextIteration();
private:
// pipe used for wake up messages: when a child thread wants to wake up
// the event loop in the main thread it writes to this pipe
class PipeIOHandler : public wxFDIOHandler
{
public:
// default ctor does nothing, call Create() to really initialize the
// object
PipeIOHandler() { }
bool Create();
// this method can be, and normally is, called from another thread
void WakeUp();
int GetReadFd() { return m_pipe[wxPipe::Read]; }
// implement wxFDIOHandler pure virtual methods
virtual void OnReadWaiting();
virtual void OnWriteWaiting() { }
virtual void OnExceptionWaiting() { }
private:
wxPipe m_pipe;
};
PipeIOHandler m_wakeupPipe;
// either wxSelectDispatcher or wxEpollDispatcher
wxFDIODispatcher *m_dispatcher;
DECLARE_NO_COPY_CLASS(wxConsoleEventLoop)
};
#endif // _WX_UNIX_EVTLOOP_H_

View File

@@ -0,0 +1,47 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/private/epolldispatcher.h
// Purpose: wxEpollDispatcher class
// Authors: Lukasz Michalski
// Created: April 2007
// Copyright: (c) Lukasz Michalski
// RCS-ID: $Id$
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PRIVATE_EPOLLDISPATCHER_H_
#define _WX_PRIVATE_EPOLLDISPATCHER_H_
#include "wx/defs.h"
#ifdef HAVE_SYS_EPOLL_H
#include "wx/private/fdiodispatcher.h"
class WXDLLIMPEXP_CORE wxEpollDispatcher : public wxFDIODispatcher
{
public:
// get pointer to the unique instance of this class, can return NULL if
// epoll() is not supported on this system
//
// do not delete the returned pointer
static wxEpollDispatcher *Get();
// implement base class pure virtual methods
virtual bool RegisterFD(int fd, wxFDIOHandler* handler, int flags = wxFDIO_ALL);
virtual bool ModifyFD(int fd, wxFDIOHandler* handler, int flags = wxFDIO_ALL);
virtual wxFDIOHandler *UnregisterFD(int fd, int flags = wxFDIO_ALL);
virtual void RunLoop(int timeout = TIMEOUT_INFINITE);
private:
// ctor is private, use Get()
wxEpollDispatcher();
// return true if the object was successfully initialized
bool IsOk() const { return m_epollDescriptor != -1; }
int m_epollDescriptor;
};
#endif // HAVE_SYS_EPOLL_H
#endif // _WX_PRIVATE_SOCKETEVTDISPATCH_H_