No changes, move wxStreamTempInputBuffer to a header file.
Get rid of the surprising src/common/execcmn.cpp which had a .cpp extension but was supposed to be used as an included file only and move its contents to a new private header to make using wxStreamTempInputBuffer class simpler. See #10258. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74337 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,23 +1,20 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: src/common/execcmn.cpp
|
// Name: wx/private/streamtempinput.h
|
||||||
// Purpose: defines wxStreamTempInputBuffer which is used by Unix and MSW
|
// Purpose: defines wxStreamTempInputBuffer which is used by Unix and MSW
|
||||||
// implementations of wxExecute; this file is only used by the
|
// implementations of wxExecute; this file is only used by the
|
||||||
// library and never by the user code
|
// library and never by the user code
|
||||||
// Author: Vadim Zeitlin
|
// Author: Vadim Zeitlin
|
||||||
// Modified by:
|
// Modified by: Rob Bresalier
|
||||||
// Created: 20.08.02
|
// Created: 2013-05-04
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) 2002 Vadim Zeitlin <vadim@wxwindows.org>
|
// Copyright: (c) 2002 Vadim Zeitlin <vadim@wxwindows.org>
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef _WX_WXEXEC_CPP_
|
#ifndef _WX_PRIVATE_STREAMTEMPINPUT_H
|
||||||
#define _WX_WXEXEC_CPP_
|
#define _WX_PRIVATE_STREAMTEMPINPUT_H
|
||||||
|
|
||||||
// this file should never be compiled directly, just included by other code
|
#include "wx/private/pipestream.h"
|
||||||
#ifndef _WX_USED_BY_WXEXECUTE_
|
|
||||||
#error "You should never directly build this file!"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxStreamTempInputBuffer
|
// wxStreamTempInputBuffer
|
||||||
@@ -41,22 +38,73 @@
|
|||||||
needed! However it's not easy to devise a way to do this keeping backwards
|
needed! However it's not easy to devise a way to do this keeping backwards
|
||||||
compatibility with the existing wxExecute(wxEXEC_SYNC)...
|
compatibility with the existing wxExecute(wxEXEC_SYNC)...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class wxStreamTempInputBuffer
|
class wxStreamTempInputBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxStreamTempInputBuffer();
|
wxStreamTempInputBuffer()
|
||||||
|
{
|
||||||
|
m_stream = NULL;
|
||||||
|
m_buffer = NULL;
|
||||||
|
m_size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// call to associate a stream with this buffer, otherwise nothing happens
|
// call to associate a stream with this buffer, otherwise nothing happens
|
||||||
// at all
|
// at all
|
||||||
void Init(wxPipeInputStream *stream);
|
void Init(wxPipeInputStream *stream)
|
||||||
|
{
|
||||||
|
wxASSERT_MSG( !m_stream, wxS("Can only initialize once") );
|
||||||
|
|
||||||
|
m_stream = stream;
|
||||||
|
}
|
||||||
|
|
||||||
// check for input on our stream and cache it in our buffer if any
|
// check for input on our stream and cache it in our buffer if any
|
||||||
//
|
//
|
||||||
// return true if anything was done
|
// return true if anything was done
|
||||||
bool Update();
|
bool Update()
|
||||||
|
{
|
||||||
|
if ( !m_stream || !m_stream->CanRead() )
|
||||||
|
return false;
|
||||||
|
|
||||||
~wxStreamTempInputBuffer();
|
// realloc in blocks of 4Kb: this is the default (and minimal) buffer
|
||||||
|
// size of the Unix pipes so it should be the optimal step
|
||||||
|
//
|
||||||
|
// NB: don't use "static int" in this inline function, some compilers
|
||||||
|
// (e.g. IBM xlC) don't like it
|
||||||
|
enum { incSize = 4096 };
|
||||||
|
|
||||||
|
void *buf = realloc(m_buffer, m_size + incSize);
|
||||||
|
if ( !buf )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_buffer = buf;
|
||||||
|
m_stream->Read((char *)m_buffer + m_size, incSize);
|
||||||
|
m_size += m_stream->LastRead();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if can continue reading from the stream, this is used to disable
|
||||||
|
// the callback once we can't read anything more
|
||||||
|
bool Eof() const
|
||||||
|
{
|
||||||
|
// If we have no stream, always return true as we can't read any more.
|
||||||
|
return !m_stream || m_stream->Eof();
|
||||||
|
}
|
||||||
|
|
||||||
|
// dtor puts the data buffered during this object lifetime into the
|
||||||
|
// associated stream
|
||||||
|
~wxStreamTempInputBuffer()
|
||||||
|
{
|
||||||
|
if ( m_buffer )
|
||||||
|
{
|
||||||
|
m_stream->Ungetch(m_buffer, m_size);
|
||||||
|
free(m_buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const void *GetBuffer() const { return m_buffer; }
|
||||||
|
|
||||||
|
size_t GetSize() const { return m_size; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// the stream we're buffering, if NULL we don't do anything at all
|
// the stream we're buffering, if NULL we don't do anything at all
|
||||||
@@ -71,56 +119,4 @@ private:
|
|||||||
wxDECLARE_NO_COPY_CLASS(wxStreamTempInputBuffer);
|
wxDECLARE_NO_COPY_CLASS(wxStreamTempInputBuffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline wxStreamTempInputBuffer::wxStreamTempInputBuffer()
|
#endif // _WX_PRIVATE_STREAMTEMPINPUT_H
|
||||||
{
|
|
||||||
m_stream = NULL;
|
|
||||||
m_buffer = NULL;
|
|
||||||
m_size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void wxStreamTempInputBuffer::Init(wxPipeInputStream *stream)
|
|
||||||
{
|
|
||||||
m_stream = stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
bool wxStreamTempInputBuffer::Update()
|
|
||||||
{
|
|
||||||
if ( !m_stream || !m_stream->CanRead() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// realloc in blocks of 4Kb: this is the default (and minimal) buffer
|
|
||||||
// size of the Unix pipes so it should be the optimal step
|
|
||||||
//
|
|
||||||
// NB: don't use "static int" in this inline function, some compilers
|
|
||||||
// (e.g. IBM xlC) don't like it
|
|
||||||
enum { incSize = 4096 };
|
|
||||||
|
|
||||||
void *buf = realloc(m_buffer, m_size + incSize);
|
|
||||||
if ( !buf )
|
|
||||||
{
|
|
||||||
// don't read any more, we don't have enough memory to do it
|
|
||||||
m_stream = NULL;
|
|
||||||
}
|
|
||||||
else // got memory for the buffer
|
|
||||||
{
|
|
||||||
m_buffer = buf;
|
|
||||||
m_stream->Read((char *)m_buffer + m_size, incSize);
|
|
||||||
m_size += m_stream->LastRead();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
wxStreamTempInputBuffer::~wxStreamTempInputBuffer()
|
|
||||||
{
|
|
||||||
if ( m_buffer )
|
|
||||||
{
|
|
||||||
m_stream->Ungetch(m_buffer, m_size);
|
|
||||||
free(m_buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // _WX_WXEXEC_CPP_
|
|
||||||
|
|
@@ -202,10 +202,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxExecuteModule, wxModule)
|
|||||||
#if wxUSE_STREAMS && !defined(__WXWINCE__)
|
#if wxUSE_STREAMS && !defined(__WXWINCE__)
|
||||||
|
|
||||||
#include "wx/private/pipestream.h"
|
#include "wx/private/pipestream.h"
|
||||||
|
#include "wx/private/streamtempinput.h"
|
||||||
// define this to let wxexec.cpp know that we know what we're doing
|
|
||||||
#define _WX_USED_BY_WXEXECUTE_
|
|
||||||
#include "../common/execcmn.cpp"
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxPipe represents a Win32 anonymous pipe
|
// wxPipe represents a Win32 anonymous pipe
|
||||||
|
@@ -64,10 +64,7 @@
|
|||||||
#if HAS_PIPE_STREAMS
|
#if HAS_PIPE_STREAMS
|
||||||
|
|
||||||
#include "wx/private/pipestream.h"
|
#include "wx/private/pipestream.h"
|
||||||
|
#include "wx/private/streamtempinput.h"
|
||||||
// define this to let wxexec.cpp know that we know what we're doing
|
|
||||||
#define _WX_USED_BY_WXEXECUTE_
|
|
||||||
#include "../common/execcmn.cpp"
|
|
||||||
|
|
||||||
#endif // HAS_PIPE_STREAMS
|
#endif // HAS_PIPE_STREAMS
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user