Extract wxPipeInputStream and wxPipeOutputStream in a header.

No real changes, just put these classes in a private header. They're still not
part of the public API but at least it will be easier to reuse them inside the
library itself in the upcoming commits.

See #10258.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74336 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2013-07-03 00:26:38 +00:00
parent d3ad22bdb3
commit bfabc7f47c
6 changed files with 122 additions and 76 deletions

View File

@ -0,0 +1,51 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/private/pipestream.h
// Purpose: MSW wxPipeInputStream and wxPipeOutputStream declarations
// Author: Vadim Zeitlin
// Created: 2013-06-08 (extracted from src/msw/utilsexc.cpp)
// RCS-ID: $Id$
// Copyright: (c) 2013 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MSW_PRIVATE_PIPESTREAM_H_
#define _WX_MSW_PRIVATE_PIPESTREAM_H_
class wxPipeInputStream : public wxInputStream
{
public:
wxEXPLICIT wxPipeInputStream(HANDLE hInput);
virtual ~wxPipeInputStream();
// returns true if the pipe is still opened
bool IsOpened() const { return m_hInput != INVALID_HANDLE_VALUE; }
// returns true if there is any data to be read from the pipe
virtual bool CanRead() const;
protected:
virtual size_t OnSysRead(void *buffer, size_t len);
protected:
HANDLE m_hInput;
wxDECLARE_NO_COPY_CLASS(wxPipeInputStream);
};
class wxPipeOutputStream: public wxOutputStream
{
public:
wxEXPLICIT wxPipeOutputStream(HANDLE hOutput);
virtual ~wxPipeOutputStream() { Close(); }
bool Close();
protected:
size_t OnSysWrite(const void *buffer, size_t len);
protected:
HANDLE m_hOutput;
wxDECLARE_NO_COPY_CLASS(wxPipeOutputStream);
};
#endif // _WX_MSW_PRIVATE_PIPESTREAM_H_

View File

@ -0,0 +1,30 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/private/pipestream.h
// Purpose: Declares wxPipeInputStream and wxPipeOutputStream.
// Author: Vadim Zeitlin
// Modified by: Rob Bresalier
// Created: 2013-04-27
// RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
// (c) 2013 Rob Bresalier
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PRIVATE_PIPESTREAM_H_
#define _WX_PRIVATE_PIPESTREAM_H_
#include "wx/platform.h"
// wxPipeInputStream is a platform-dependent input stream class (i.e. deriving,
// possible indirectly, from wxInputStream) for reading from a pipe, i.e. a
// pipe FD under Unix or a pipe HANDLE under MSW. It provides a single extra
// IsOpened() method.
//
// wxPipeOutputStream is similar but has no additional methods at all.
#ifdef __UNIX__
#include "wx/unix/private/pipestream.h"
#elif defined(__WINDOWS__) && !defined(__WXWINCE__)
#include "wx/msw/private/pipestream.h"
#endif
#endif // _WX_PRIVATE_PIPESTREAM_H_

View File

@ -98,41 +98,5 @@ private:
int m_fds[2];
};
#if wxUSE_STREAMS && wxUSE_FILE
#include "wx/wfstream.h"
// ----------------------------------------------------------------------------
// wxPipeInputStream: stream for reading from a pipe
// ----------------------------------------------------------------------------
class wxPipeInputStream : public wxFileInputStream
{
public:
wxPipeInputStream(int fd) : wxFileInputStream(fd) { }
// return TRUE if the pipe is still opened
bool IsOpened() const { return !Eof(); }
// return TRUE if we have anything to read, don't block
virtual bool CanRead() const;
};
// ----------------------------------------------------------------------------
// wxPipeOutputStream: stream for writing to a pipe
// ----------------------------------------------------------------------------
class wxPipeOutputStream : public wxFileOutputStream
{
public:
wxPipeOutputStream(int fd) : wxFileOutputStream(fd) { }
// Override the base class version to ignore "pipe full" errors: this is
// not an error for this class.
size_t OnSysWrite(const void *buffer, size_t size);
};
#endif // wxUSE_STREAMS && wxUSE_FILE
#endif // _WX_UNIX_PIPE_H_

View File

@ -0,0 +1,38 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/pipestream.h
// Purpose: Unix wxPipeInputStream and wxPipeOutputStream declarations
// Author: Vadim Zeitlin
// Created: 2013-06-08 (extracted from wx/unix/pipe.h)
// RCS-ID: $Id$
// Copyright: (c) 2013 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_PRIVATE_PIPESTREAM_H_
#define _WX_UNIX_PRIVATE_PIPESTREAM_H_
#include "wx/wfstream.h"
class wxPipeInputStream : public wxFileInputStream
{
public:
wxEXPLICIT wxPipeInputStream(int fd) : wxFileInputStream(fd) { }
// return true if the pipe is still opened
bool IsOpened() const { return !Eof(); }
// return true if we have anything to read, don't block
virtual bool CanRead() const;
};
class wxPipeOutputStream : public wxFileOutputStream
{
public:
wxPipeOutputStream(int fd) : wxFileOutputStream(fd) { }
// Override the base class version to ignore "pipe full" errors: this is
// not an error for this class.
size_t OnSysWrite(const void *buffer, size_t size);
};
#endif // _WX_UNIX_PRIVATE_PIPESTREAM_H_

View File

@ -201,46 +201,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxExecuteModule, wxModule)
#if wxUSE_STREAMS && !defined(__WXWINCE__)
// ----------------------------------------------------------------------------
// wxPipeStreams
// ----------------------------------------------------------------------------
class wxPipeInputStream: public wxInputStream
{
public:
wxPipeInputStream(HANDLE hInput);
virtual ~wxPipeInputStream();
// returns true if the pipe is still opened
bool IsOpened() const { return m_hInput != INVALID_HANDLE_VALUE; }
// returns true if there is any data to be read from the pipe
virtual bool CanRead() const;
protected:
size_t OnSysRead(void *buffer, size_t len);
protected:
HANDLE m_hInput;
wxDECLARE_NO_COPY_CLASS(wxPipeInputStream);
};
class wxPipeOutputStream: public wxOutputStream
{
public:
wxPipeOutputStream(HANDLE hOutput);
virtual ~wxPipeOutputStream() { Close(); }
bool Close();
protected:
size_t OnSysWrite(const void *buffer, size_t len);
protected:
HANDLE m_hOutput;
wxDECLARE_NO_COPY_CLASS(wxPipeOutputStream);
};
#include "wx/private/pipestream.h"
// define this to let wxexec.cpp know that we know what we're doing
#define _WX_USED_BY_WXEXECUTE_

View File

@ -63,6 +63,8 @@
#if HAS_PIPE_STREAMS
#include "wx/private/pipestream.h"
// define this to let wxexec.cpp know that we know what we're doing
#define _WX_USED_BY_WXEXECUTE_
#include "../common/execcmn.cpp"