[+] IFileStream::ToStreamReader()

[+] IFileStreamToStreamWriter()
[+] IProcess::ToStreamReader(EStandardHandle stream)
[+] IProcess::ToStreamWriter()
This commit is contained in:
Reece Wilson 2023-12-02 16:40:58 +00:00
parent 9fea60a9ed
commit baf31e32d0
10 changed files with 160 additions and 11 deletions

View File

@ -15,58 +15,68 @@ namespace Aurora::IO::FS
* @brief Read memoryview from the filestream at an auto-incrementing offset
* @param parameters
* @return
*/
*/
virtual bool Read(const Memory::MemoryViewStreamWrite &parameters) = 0;
/**
* @brief Writes memoryview to the filestream at an auto-incrementing offset
* @param parameters
* @return
*/
*/
virtual bool Write(const Memory::MemoryViewStreamRead &parameters) = 0;
/**
* @brief Returns the length of the file
* @return
*/
*/
virtual AuUInt64 GetLength() = 0;
/**
* @brief Returns the offset of the internal streams
* @return
*/
*/
virtual AuUInt64 GetOffset() = 0;
/**
* @brief Updates the stream pointer
* @param offset
* @return
*/
*/
virtual bool SetOffset(AuUInt64 offset) = 0;
/**
* @brief Flush read/write streams
*/
*/
virtual void Flush() = 0;
/**
* @brief Termiantes/truncates the file at the current offset
*/
*/
virtual void WriteEoS() = 0;
/**
* @brief Close IFileStream resource
*/
*/
virtual void Close() = 0;
/**
* @brief Indicates that the file should automatically be deleted upon destruction of the stream
*/
*/
virtual void MakeTemporary() = 0;
/**
* @brief Returns the IO handle backing the file stream, if available.
*/
*/
virtual AuSPtr<IIOHandle> GetHandle() = 0;
/**
* @brief
*/
virtual IO::IStreamReader *ToStreamReader() = 0;
/**
* @brief
*/
virtual IO::IStreamWriter *ToStreamWriter() = 0;
};
}

View File

@ -106,5 +106,17 @@ namespace Aurora::Processes
* @return
*/
virtual AuSPtr<IO::IIOHandle> GetErrorStreamHandle() = 0;
/**
* @brief
* @return
*/
virtual AuSPtr<IO::IStreamReader> ToStreamReader(EStandardHandle stream) = 0;
/**
* @brief
* @return
*/
virtual AuSPtr<IO::IStreamWriter> ToStreamWriter() = 0;
};
}

View File

@ -16,6 +16,13 @@ namespace Aurora::IO::FS
{
static const AuUInt64 kFileCopyBlock = 0xFFFF * 128;
WinFileStream::WinFileStream() :
reader_(AuUnsafeRaiiToShared(this)),
writer_(AuUnsafeRaiiToShared(this))
{
}
WinFileStream::~WinFileStream()
{
Close();
@ -432,6 +439,16 @@ namespace Aurora::IO::FS
return this->pHandle_;
}
IO::IStreamReader *WinFileStream::ToStreamReader()
{
return &this->reader_;
}
IO::IStreamWriter *WinFileStream::ToStreamWriter()
{
return &this->writer_;
}
HANDLE WinFileStream::GetWin32Handle(bool bReadOnly)
{
if (auto pHandle = this->pHandle_)

View File

@ -13,6 +13,7 @@ namespace Aurora::IO::FS
{
struct WinFileStream : IFileStream
{
WinFileStream();
~WinFileStream();
void Init(AuSPtr<IIOHandle> pHandle);
@ -27,6 +28,8 @@ namespace Aurora::IO::FS
void WriteEoS() override;
void MakeTemporary() override;
AuSPtr<IIOHandle> GetHandle() override;
IO::IStreamReader *ToStreamReader() override;
IO::IStreamWriter *ToStreamWriter() override;
HANDLE GetWin32Handle(bool bReadOnly = false);
@ -34,6 +37,8 @@ namespace Aurora::IO::FS
AuSPtr<IIOHandle> pHandle_;
bool bShouldDelete {};
HANDLE hEventHandle_ { INVALID_HANDLE_VALUE };
AuFS::FileReader reader_;
AuFS::FileWriter writer_;
};
}
#endif

View File

@ -118,7 +118,13 @@ namespace Aurora::IO::FS
return true;
}
PosixFileStream::PosixFileStream() :
reader_(AuUnsafeRaiiToShared(this)),
writer_(AuUnsafeRaiiToShared(this))
{
}
PosixFileStream::~PosixFileStream()
{
@ -416,6 +422,16 @@ namespace Aurora::IO::FS
return this->pHandle_;
}
IO::IStreamReader *PosixFileStream::ToStreamReader()
{
return &this->reader_;
}
IO::IStreamWriter *PosixFileStream::ToStreamWriter()
{
return &this->writer_;
}
AUKN_SYM AuSPtr<IFileStream> OpenBlockingFileStreamFromHandle(AuSPtr<IIOHandle> pIOHandle)
{
auto pStream = AuMakeShared<PosixFileStream>();

View File

@ -19,6 +19,7 @@ namespace Aurora::IO::FS
struct PosixFileStream : IFileStream
{
PosixFileStream();
~PosixFileStream();
bool Init(AuSPtr<IIOHandle> pHandle);
@ -33,6 +34,8 @@ namespace Aurora::IO::FS
void WriteEoS() override;
void MakeTemporary() override;
AuSPtr<IIOHandle> GetHandle() override;
IO::IStreamReader *ToStreamReader() override;
IO::IStreamWriter *ToStreamWriter() override;
int GetUnixHandle();
private:
@ -40,6 +43,8 @@ namespace Aurora::IO::FS
AuString path_;
AuThreadPrimitives::SpinLock spinlock_;
bool bMadeTemporary {};
AuFS::FileReader reader_;
AuFS::FileWriter writer_;
};
}
#endif

View File

@ -506,6 +506,45 @@ namespace Aurora::Processes
return this->fsErrorHandle_;
}
AuSPtr<IO::IStreamReader> ProcessImpl::ToStreamReader(EStandardHandle stream)
{
if (stream == EStandardHandle::eErrorStream)
{
if (auto pThat = this->GetErrorStreamHandle())
{
if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandle(pThat))
{
return { pThat2, pThat2->ToStreamReader() };
}
}
}
else
{
if (auto pThat = this->GetOutputAndInputHandles())
{
if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandle(pThat))
{
return { pThat2, pThat2->ToStreamReader() };
}
}
}
return {};
}
AuSPtr<IO::IStreamWriter> ProcessImpl::ToStreamWriter()
{
if (auto pThat = this->GetErrorStreamHandle())
{
if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandle(pThat))
{
return { pThat2, pThat2->ToStreamWriter() };
}
}
return {};
}
bool ProcessImpl::Start()
{
if (this->process_ != INVALID_HANDLE_VALUE)

View File

@ -38,6 +38,9 @@ namespace Aurora::Processes
AuSPtr<IO::IIOHandle> GetOutputAndInputHandles() override;
AuSPtr<IO::IIOHandle> GetErrorStreamHandle() override;
AuSPtr<IO::IStreamReader> ToStreamReader(EStandardHandle stream) override;
AuSPtr<IO::IStreamWriter> ToStreamWriter() override;
bool Start() override;
bool Init();

View File

@ -481,6 +481,45 @@ namespace Aurora::Processes
return this->fsErrorHandle_;
}
AuSPtr<IO::IStreamReader> ProcessImpl::ToStreamReader(EStandardHandle stream)
{
if (stream == EStandardHandle::eErrorStream)
{
if (auto pThat = this->GetErrorStreamHandle())
{
if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandle(pThat))
{
return { pThat2, pThat2->ToStreamReader() };
}
}
}
else
{
if (auto pThat = this->GetOutputAndInputHandles())
{
if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandle(pThat))
{
return { pThat2, pThat2->ToStreamReader() };
}
}
}
return {};
}
AuSPtr<IO::IStreamWriter> ProcessImpl::ToStreamWriter()
{
if (auto pThat = this->GetErrorStreamHandle())
{
if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandle(pThat))
{
return { pThat2, pThat2->ToStreamWriter() };
}
}
return {};
}
void ProcessImpl::ForkMain()
{
{

View File

@ -49,6 +49,9 @@ namespace Aurora::Processes
AuSPtr<IO::IIOHandle> GetOutputAndInputHandles() override;
AuSPtr<IO::IIOHandle> GetErrorStreamHandle() override;
AuSPtr<IO::IStreamReader> ToStreamReader(EStandardHandle stream) override;
AuSPtr<IO::IStreamWriter> ToStreamWriter() override;
bool Start() override;
bool Init();