[+] IProtocolStack::PrependInterceptorEx

[+] IProtocolStack::PrependSingleFrameProcessor
[+] IProtocolStack::PrependSingleFrameProcessorEx
[+] IProtocolStack::GetArrayOfInterceptors
[+] IProtocolStack::GetInterceptorAtIndex
[+] IProtocolPiece::ToInputWriter
[+] IProtocolPiece::GetExtendedInterceptor
[+] IProtocolPiece::GetShortPipeInterceptor
This commit is contained in:
Reece Wilson 2023-04-28 02:41:45 +01:00
parent f8219542c5
commit da69428d7e
6 changed files with 135 additions and 14 deletions

View File

@ -16,6 +16,12 @@ namespace Aurora::IO::Protocol
*/
virtual void Remove() = 0;
/**
* @brief
* @return
*/
virtual AuSPtr<IStreamWriter> ToInputWriter() = 0;
/**
* @brief Fetches an IStreamWriter representation of the next piece in the stack
* @return
@ -28,5 +34,17 @@ namespace Aurora::IO::Protocol
* @return
*/
virtual AuSPtr<Memory::ByteBuffer> GetNextPieceBuffer() = 0;
/**
* @brief
* @return
*/
virtual AuSPtr<IProtocolInterceptorEx> GetExtendedInterceptor() = 0;
/**
* @brief
* @return
*/
virtual AuSPtr<IProtocolInterceptor> GetShortPipeInterceptor() = 0;
};
}

View File

@ -13,6 +13,7 @@ namespace Aurora::IO::Protocol
{
/**
* @brief
* Warning: AppendInterceptorEx is preferred
* @param pInterceptor
* @param uOutputBufferSize When 0, a hopefully not stupid default is used.
* @return
@ -20,7 +21,8 @@ namespace Aurora::IO::Protocol
virtual AuSPtr<IProtocolPiece> AppendInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize) = 0;
/**
* @brief Inserts the interceptor at the bottom of the protocol stack
* @brief Inserts the interceptor at the bottom of the protocol stack.
* Warning: AppendInterceptorEx is preferred
* @param pInterceptor
* @param uOutputBufferSize When 0, a hopefully not stupid default is used.
* @return
@ -35,6 +37,14 @@ namespace Aurora::IO::Protocol
*/
virtual AuSPtr<IProtocolPiece> AppendInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) = 0;
/**
* @brief Inserts the interceptor at the bottom of the protocol stack
* @param pInterceptorEx
* @param uOutputBufferSize When 0, a hopefully not stupid default is used.
* @return
*/
virtual AuSPtr<IProtocolPiece> PrependInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) = 0;
/**
* @brief Same as AppendInterceptor, except that DoTick will repeat until the input is fully consumed.
*
@ -55,6 +65,13 @@ namespace Aurora::IO::Protocol
*/
virtual AuSPtr<IProtocolPiece> AppendSingleFrameProcessor(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx) = 0;
/**
* @brief
* @param pInterceptorEx
* @return
*/
virtual AuSPtr<IProtocolPiece> PrependSingleFrameProcessor(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx) = 0;
/**
* @brief See: AppendSingleFrameProcessor
* @param pInterceptorEx
@ -63,12 +80,13 @@ namespace Aurora::IO::Protocol
virtual AuSPtr<IProtocolPiece> AppendSingleFrameProcessorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) = 0;
/**
* @brief Inserts the interceptor at the bottom of the protocol stack
* @brief
* @param pInterceptorEx
* @param uOutputBufferSize When 0, a hopefully not stupid default is used.
* @param uOutputBufferSize
* @return
*/
virtual AuSPtr<IProtocolPiece> PrependInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) = 0;
virtual AuSPtr<IProtocolPiece> PrependSingleFrameProcessorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) = 0;
/**
* @brief
@ -88,6 +106,20 @@ namespace Aurora::IO::Protocol
* @brief
*/
virtual void Destroy() = 0;
/**
* @brief
* @return
*/
virtual AuList<AuSPtr<IProtocolPiece>> GetArrayOfInterceptors() = 0;
/**
* @brief
* @param uIndex
* @return
*/
virtual AuSPtr<IProtocolPiece> GetInterceptorAtIndex(AuUInt32 uIndex) = 0;
};
/**

View File

@ -27,6 +27,11 @@ namespace Aurora::IO::Protocol
this->pOuputWriter;
}
AuSPtr<IStreamWriter> ProtocolPiece::ToInputWriter()
{
return this->pWriteInteface ? this->pWriteInteface->GetStreamWriter() : AuSPtr<IStreamWriter> {};
}
void ProtocolPiece::Remove()
{
auto &pBottomPiece = this->pParent->pBottomPiece;
@ -67,4 +72,14 @@ namespace Aurora::IO::Protocol
{
return AuSPtr<AuByteBuffer>(AuSharedFromThis(), &this->outputBuffer);
}
AuSPtr<IProtocolInterceptorEx> ProtocolPiece::GetExtendedInterceptor()
{
return this->pInterceptorEx;
}
AuSPtr<IProtocolInterceptor> ProtocolPiece::GetShortPipeInterceptor()
{
return this->pInterceptor;
}
}

View File

@ -25,6 +25,9 @@ namespace Aurora::IO::Protocol
void Remove() override;
AuSPtr<IStreamWriter> ToNextWriter() override;
AuSPtr<IStreamWriter> ToInputWriter() override;
AuSPtr<Memory::ByteBuffer> GetNextPieceBuffer() override;
AuSPtr<IProtocolInterceptorEx> GetExtendedInterceptor() override;
AuSPtr<IProtocolInterceptor> GetShortPipeInterceptor() override;
};
}

View File

@ -40,6 +40,17 @@ namespace Aurora::IO::Protocol
return this->AddInterceptorWhereEx(false, pInterceptorEx, uOutputBufferSize, true);
}
AuSPtr<IProtocolPiece> ProtocolStack::PrependSingleFrameProcessor(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx)
{
return this->AddInterceptorWhereEx(true, pInterceptorEx, 0, true);
}
AuSPtr<IProtocolPiece> ProtocolStack::PrependSingleFrameProcessorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferSize)
{
return this->AddInterceptorWhereEx(true, pInterceptorEx, uOutputBufferSize, true);
}
AuSPtr<IProtocolPiece> ProtocolStack::PrependInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor,
AuUInt uOutputBufferSize)
{
@ -85,7 +96,7 @@ namespace Aurora::IO::Protocol
struct StreamWrapper : IStreamWriter, IProtocolNext, AuEnableSharedFromThis<StreamWrapper>
{
ProtocolStack *pStack;
AuWPtr<ProtocolStack> pStack;
AuWPtr<IProtocolInterceptor> pInterceptor;
AuWPtr<ProtocolPiece> pParent;
@ -96,7 +107,7 @@ namespace Aurora::IO::Protocol
EStreamError Write(const Memory::MemoryViewStreamRead &parameters) override
{
return pStack->DoTick(AuMakeShared<AuByteBuffer>(parameters), pParent.lock()) ?
return pStack.lock()->DoTick(AuMakeShared<AuByteBuffer>(parameters), pParent.lock()) ?
EStreamError::eErrorNone :
EStreamError::eErrorStreamInterrupted;
}
@ -130,7 +141,7 @@ namespace Aurora::IO::Protocol
}
pWrapper->pInterceptor = pInterceptor;
pWrapper->pStack = this;
pWrapper->pStack = AuSharedFromThis();
pWrapper->pParent = pNew;
pNew->pWriteInteface = pWrapper;
@ -203,7 +214,7 @@ namespace Aurora::IO::Protocol
struct StreamWrapper : IStreamWriter, IProtocolNext, AuEnableSharedFromThis<StreamWrapper>
{
ProtocolStack *pStack;
AuWPtr<ProtocolStack> pStack;
AuWPtr<IProtocolInterceptorEx> pInterceptor;
AuWPtr<ProtocolPiece> pParent;
@ -214,7 +225,7 @@ namespace Aurora::IO::Protocol
EStreamError Write(const Memory::MemoryViewStreamRead &parameters) override
{
return pStack->DoTick(AuMakeShared<AuByteBuffer>(parameters), pParent.lock()) ?
return pStack.lock()->DoTick(AuMakeShared<AuByteBuffer>(parameters), pParent.lock()) ?
EStreamError::eErrorNone :
EStreamError::eErrorStreamInterrupted;
}
@ -248,7 +259,7 @@ namespace Aurora::IO::Protocol
}
pWrapper->pInterceptor = pInterceptor;
pWrapper->pStack = this;
pWrapper->pStack = AuSharedFromThis();
pWrapper->pParent = pNew;
pNew->pWriteInteface = pWrapper;
@ -304,7 +315,7 @@ namespace Aurora::IO::Protocol
struct StreamWrapper : IStreamWriter, IProtocolNext, AuEnableSharedFromThis<StreamWrapper>
{
ProtocolStack *pStack;
AuWPtr<ProtocolStack> pStack;
AuWPtr<IProtocolInterceptorEx> pInterceptor;
AuWPtr<ProtocolPiece> pParent;
@ -315,7 +326,7 @@ namespace Aurora::IO::Protocol
EStreamError Write(const Memory::MemoryViewStreamRead &parameters) override
{
return pStack->DoTick(AuMakeShared<AuByteBuffer>(parameters), pParent.lock()) ?
return pStack.lock()->DoTick(AuMakeShared<AuByteBuffer>(parameters), pParent.lock()) ?
EStreamError::eErrorNone :
EStreamError::eErrorStreamInterrupted;
}
@ -349,7 +360,7 @@ namespace Aurora::IO::Protocol
}
pWrapper->pInterceptor = pInterceptor;
pWrapper->pStack = this;
pWrapper->pStack = AuSharedFromThis();
pWrapper->pParent = pNew;
pNew->pWriteInteface = pWrapper;
@ -580,6 +591,40 @@ namespace Aurora::IO::Protocol
}
}
AuList<AuSPtr<IProtocolPiece>> ProtocolStack::GetArrayOfInterceptors()
{
AuList<AuSPtr<IProtocolPiece>> list;
auto pItr = this->pBottomPiece;
while (pItr)
{
auto pCur = pItr;
pItr = pCur->pNext;
list.push_back(pCur);
}
return list;
}
AuSPtr<IProtocolPiece> ProtocolStack::GetInterceptorAtIndex(AuUInt32 uIndex)
{
AuUInt32 uCounter {};
auto pItr = this->pBottomPiece;
while (pItr)
{
auto pCur = pItr;
pItr = pCur->pNext;
if (uIndex == uCounter++)
{
return pCur;
}
}
return {};
}
AUKN_SYM AuSPtr<IProtocolStack> NewBufferedProtocolStack(AuUInt uLength)
{
if (!uLength)

View File

@ -13,7 +13,8 @@ namespace Aurora::IO::Protocol
{
struct ProtocolPiece;
struct ProtocolStack : IProtocolStack
struct ProtocolStack : IProtocolStack,
AuEnableSharedFromThis<ProtocolStack>
{
~ProtocolStack();
@ -24,8 +25,12 @@ namespace Aurora::IO::Protocol
AuSPtr<IProtocolPiece> AppendInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize) override;
AuSPtr<IProtocolPiece> AppendSingleFrameProcessor(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx) override;
AuSPtr<IProtocolPiece> AppendSingleFrameProcessorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) override;
AuSPtr<IProtocolPiece> PrependInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize) override;
AuSPtr<IProtocolPiece> PrependInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize) override;
AuSPtr<IProtocolPiece> PrependSingleFrameProcessor(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx) override;
AuSPtr<IProtocolPiece> PrependSingleFrameProcessorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) override;
AuSPtr<IProtocolPiece> AddEndInterceptor(const AuSPtr<IProtocolInterceptorEx> &pInterceptor) override;
void Destroy() override;
@ -39,6 +44,9 @@ namespace Aurora::IO::Protocol
AuSPtr<IStreamReader> AsStreamReader() override;
AuSPtr<Memory::ByteBuffer> AsReadableByteBuffer() override;
AuList<AuSPtr<IProtocolPiece>> GetArrayOfInterceptors() override;
AuSPtr<IProtocolPiece> GetInterceptorAtIndex(AuUInt32 uIndex) override;
AuSPtr<AuByteBuffer> pSourceBufer;
bool bOwnsSource {};