wxWidgets/include/wx/unix/private/executeiohandler.h
Vadim Zeitlin 3f66f6a5b3 Remove all lines containing cvs/svn "$Id$" keyword.
This keyword is not expanded by Git which means it's not replaced with the
correct revision value in the releases made using git-based scripts and it's
confusing to have lines with unexpanded "$Id$" in the released files. As
expanding them with Git is not that simple (it could be done with git archive
and export-subst attribute) and there are not many benefits in having them in
the first place, just remove all these lines.

If nothing else, this will make an eventual transition to Git simpler.

Closes #14487.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74602 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2013-07-26 16:02:46 +00:00

137 lines
3.9 KiB
C++

///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/executeiohandler.h
// Purpose: IO handler class for the FD used by wxExecute() under Unix
// Author: Rob Bresalier, Vadim Zeitlin
// Created: 2013-01-06
// Copyright: (c) 2013 Rob Bresalier, Vadim Zeitlin
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_PRIVATE_EXECUTEIOHANDLER_H_
#define _WX_UNIX_PRIVATE_EXECUTEIOHANDLER_H_
#include "wx/private/streamtempinput.h"
// This class handles IO events on the pipe FD connected to the child process
// stdout/stderr and is used by wxExecute().
//
// Currently it can derive from either wxEventLoopSourceHandler or
// wxFDIOHandler depending on the kind of dispatcher/event loop it is used
// with. In the future, when we get rid of wxFDIOHandler entirely, it will
// derive from wxEventLoopSourceHandler only.
template <class T>
class wxExecuteIOHandlerBase : public T
{
public:
wxExecuteIOHandlerBase(int fd, wxStreamTempInputBuffer& buf)
: m_fd(fd),
m_buf(buf)
{
m_callbackDisabled = false;
}
// Called when the associated descriptor is available for reading.
virtual void OnReadWaiting()
{
// Sync process, process all data coming at us from the pipe so that
// the pipe does not get full and cause a deadlock situation.
m_buf.Update();
if ( m_buf.Eof() )
DisableCallback();
}
// These methods are never called as we only monitor the associated FD for
// reading, but we still must implement them as they're pure virtual in the
// base class.
virtual void OnWriteWaiting() { }
virtual void OnExceptionWaiting() { }
// Disable any future calls to our OnReadWaiting(), can be called when
// we're sure that no more input is forthcoming.
void DisableCallback()
{
if ( !m_callbackDisabled )
{
m_callbackDisabled = true;
DoDisable();
}
}
protected:
const int m_fd;
private:
virtual void DoDisable() = 0;
wxStreamTempInputBuffer& m_buf;
// If true, DisableCallback() had been already called.
bool m_callbackDisabled;
wxDECLARE_NO_COPY_CLASS(wxExecuteIOHandlerBase);
};
// This is the version used with wxFDIODispatcher, which must be passed to the
// ctor in order to register this handler with it.
class wxExecuteFDIOHandler : public wxExecuteIOHandlerBase<wxFDIOHandler>
{
public:
wxExecuteFDIOHandler(wxFDIODispatcher& dispatcher,
int fd,
wxStreamTempInputBuffer& buf)
: wxExecuteIOHandlerBase<wxFDIOHandler>(fd, buf),
m_dispatcher(dispatcher)
{
dispatcher.RegisterFD(fd, this, wxFDIO_INPUT);
}
virtual ~wxExecuteFDIOHandler()
{
DisableCallback();
}
private:
virtual void DoDisable()
{
m_dispatcher.UnregisterFD(m_fd);
}
wxFDIODispatcher& m_dispatcher;
wxDECLARE_NO_COPY_CLASS(wxExecuteFDIOHandler);
};
// And this is the version used with an event loop. As AddSourceForFD() is
// static, we don't require passing the event loop to the ctor but an event
// loop must be running to handle our events.
class wxExecuteEventLoopSourceHandler
: public wxExecuteIOHandlerBase<wxEventLoopSourceHandler>
{
public:
wxExecuteEventLoopSourceHandler(int fd, wxStreamTempInputBuffer& buf)
: wxExecuteIOHandlerBase<wxEventLoopSourceHandler>(fd, buf)
{
m_source = wxEventLoop::AddSourceForFD(fd, this, wxEVENT_SOURCE_INPUT);
}
virtual ~wxExecuteEventLoopSourceHandler()
{
DisableCallback();
}
private:
virtual void DoDisable()
{
delete m_source;
m_source = NULL;
}
wxEventLoopSource* m_source;
wxDECLARE_NO_COPY_CLASS(wxExecuteEventLoopSourceHandler);
};
#endif // _WX_UNIX_PRIVATE_EXECUTEIOHANDLER_H_