AuroraRuntime/Source/IO/IOPipeProcessor.hpp

110 lines
2.7 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IOPipeProcessor.hpp
Date: 2022-6-6
Author: Reece
***/
#pragma once
namespace Aurora::IO
{
struct IOProcessor;
struct IOPipeWork;
struct IOPipeProcessor;
struct IOWorkStart : IIOProcessorWorkUnit
{
IOWorkStart(IOPipeWork *parent);
void OnRun() override;
void OnCanceled() override;
IOPipeWork *parent {};
};
struct IOWorkEnd : IIOProcessorWorkUnit
{
IOWorkEnd(IOPipeWork *parent);
void OnRun() override;
void OnCanceled() override;
IOPipeWork *parent {};
};
struct IOPipeWork : IIOPipeWork, IIOEventListenerFunctional, AuEnableSharedFromThis<IIOPipeWork>
{
IOPipeWork(const AuSPtr<IOPipeProcessor> &pParent, const IOPipeRequestAIO &request);
IOPipeWork(const AuSPtr<IOPipeProcessor> &pParent, const IOPipeRequestBasic &request);
AuSPtr<IIOProcessorItem> pWatch;
void Tick_FrameEpilogue() override;
void Tick_Any() override;
void OnFailureCompletion() override;
void OnNominalCompletion() override;
virtual bool Start() override;
virtual bool End() override;
void RunOnThread();
void TerminateOnThread(bool bError = false);
// INIT
void PrepareStream();
void PrepareAsync();
// PUMP
void AsyncPump();
void StreamPump();
// END/INIT
void ReadNext();
void ReadNextAsync();
AuUInt32 TryPump();
AuMemoryViewWrite nextWriteAsync_;
IOPipeRequest request {};
bool bShouldReadNext {false};
bool IsAtRequestedEnd();
AuByteBuffer *GetBuffer();
private:
AuSPtr<IOPipeProcessor> parent_;
struct /*not a union. the following members are mutex*/
{
IOPipeInputData input_;
AuSPtr<IAsyncTransaction> pAsyncTransaction_;
AuSPtr<IAsyncStreamAdapter> pAsyncAdapter_;
AuSPtr<IAsyncStreamReader> pAsyncStreamReader_;
};
IOPipeCallback output;
IOWorkStart startCallback;
IOWorkEnd endCallback;
bool bActive {true};
AuUInt32 uBufferSize_ {};
AuUInt32 uFrameCap_ {};
AuUInt uBytesWritten_ {};
AuUInt uBytesWrittenLimit_ {};
AuByteBuffer buffer_;
};
struct IOPipeProcessor : IIOPipeProcessor
{
IOPipeProcessor(IOProcessor *parent);
virtual AuSPtr<IIOPipeWork> NewBasicPipe(const IOPipeRequestBasic &request) override;
virtual AuSPtr<IIOPipeWork> NewAIOPipe(const IOPipeRequestAIO &request) override;
IOProcessor *parent_;
};
}