Kaydet (Commit) f1161285 authored tarafından Matúš Kukan's avatar Matúš Kukan

implement very simple SvScriptStream to read from process

It inherits from SvStream, so it could be used easily.
Basically, it's just a simple wrapper around
osl_executeProcess_WithRedirectedIO() and osl_readFile().

Change-Id: Ifa225c87d2c9be7e71ea113b0832a4fe83ec65b3
üst f2b3cedc
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#define INCLUDED_TOOLS_STREAM_HXX #define INCLUDED_TOOLS_STREAM_HXX
#include <limits> #include <limits>
#include <osl/process.h>
#include <tools/toolsdllapi.h> #include <tools/toolsdllapi.h>
#include <tools/solar.h> #include <tools/solar.h>
#include <tools/lineend.hxx> #include <tools/lineend.hxx>
...@@ -362,7 +363,7 @@ public: ...@@ -362,7 +363,7 @@ public:
@endcode @endcode
causing endless loops ... causing endless loops ...
*/ */
bool ReadLine( OString& rStr, sal_Int32 nMaxBytesToRead = 0xFFFE ); virtual bool ReadLine( OString& rStr, sal_Int32 nMaxBytesToRead = 0xFFFE );
bool WriteLine( const OString& rStr ); bool WriteLine( const OString& rStr );
/** Read a line of bytes. /** Read a line of bytes.
...@@ -470,10 +471,10 @@ public: ...@@ -470,10 +471,10 @@ public:
friend SvStream& operator<<( SvStream& rStr, SvStrPtr f ); // for Manips friend SvStream& operator<<( SvStream& rStr, SvStrPtr f ); // for Manips
/// end of input seen during previous i/o operation /// end of input seen during previous i/o operation
bool eof() const { return bIsEof; } virtual bool eof() const { return bIsEof; }
/// stream is broken /// stream is broken
bool bad() const { return GetError() != 0; } virtual bool bad() const { return GetError() != 0; }
/** Get state /** Get state
...@@ -488,7 +489,7 @@ public: ...@@ -488,7 +489,7 @@ public:
If we try to read into a variable v and the operation fails, the value If we try to read into a variable v and the operation fails, the value
of v should be unchanged, of v should be unchanged,
*/ */
bool good() const { return !(eof() || bad()); } virtual bool good() const { return !(eof() || bad()); }
}; };
inline SvStream& operator<<( SvStream& rStr, SvStrPtr f ) inline SvStream& operator<<( SvStream& rStr, SvStrPtr f )
...@@ -759,6 +760,19 @@ public: ...@@ -759,6 +760,19 @@ public:
virtual sal_Size remainingSize() { return GetBufSize() - Tell(); } virtual sal_Size remainingSize() { return GetBufSize() - Tell(); }
}; };
class TOOLS_DLLPUBLIC SvScriptStream: public SvStream
{
oslProcess mpProcess;
oslFileHandle mpHandle;
public:
SvScriptStream(const OUString& rUrl);
~SvScriptStream();
virtual bool ReadLine(OString &rStr, sal_Int32) SAL_OVERRIDE;
virtual bool good() const SAL_OVERRIDE;
};
/** Data Copy Stream /** Data Copy Stream
This class is the foundation for all classes, using SvData This class is the foundation for all classes, using SvData
......
...@@ -1961,6 +1961,63 @@ void SvMemoryStream::SetSize( sal_Size nNewSize ) ...@@ -1961,6 +1961,63 @@ void SvMemoryStream::SetSize( sal_Size nNewSize )
ReAllocateMemory( nDiff ); ReAllocateMemory( nDiff );
} }
SvScriptStream::SvScriptStream(const OUString& rUrl):
mpProcess(NULL), mpHandle(NULL)
{
oslProcessError rc;
rc = osl_executeProcess_WithRedirectedIO(
rUrl.pData,
NULL, 0,
osl_Process_HIDDEN,
NULL,
NULL,
NULL, 0,
&mpProcess,
NULL, &mpHandle, NULL);
if (osl_Process_E_None != rc)
{
mpProcess = NULL;
mpHandle = NULL;
}
}
SvScriptStream::~SvScriptStream()
{
if (mpProcess)
{
osl_terminateProcess(mpProcess);
osl_freeProcessHandle(mpProcess);
}
if (mpHandle)
osl_closeFile(mpHandle);
}
bool SvScriptStream::ReadLine(OString &rStr, sal_Int32)
{
rStr = OString();
if (!good())
return false;
OStringBuffer sBuf;
sal_Char aChar('\n');
sal_uInt64 nBytesRead;
while (osl_File_E_None == osl_readFile(mpHandle, &aChar, 1, &nBytesRead)
&& nBytesRead == 1 && aChar != '\n')
{
sBuf.append( aChar );
}
rStr = sBuf.makeStringAndClear();
if (!rStr.isEmpty())
return true;
return false;
}
bool SvScriptStream::good() const
{
return mpHandle != NULL;
}
TYPEINIT0 ( SvDataCopyStream ) TYPEINIT0 ( SvDataCopyStream )
void SvDataCopyStream::Assign( const SvDataCopyStream& ) void SvDataCopyStream::Assign( const SvDataCopyStream& )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment