diff --git a/Src/InputStream.c b/Src/InputStream.c index 7613c23..4152c4c 100644 --- a/Src/InputStream.c +++ b/Src/InputStream.c @@ -169,3 +169,28 @@ void IStream_setCheckReceive(IStream* stream, IStream_CheckReceiveFn fn) { Stream_LenType IStream_incomingBytes(IStream* stream) { return stream->IncomingBytes; } +#if ISTREAM_LOCK +/** + * @brief lock input stream for fixed write + * + * @param stream + * @param lock + * @return Stream_Result + */ +Stream_Result IStream_lock(IStream* stream, IStream* lock, Stream_LenType len) { + Stream_Result res; + if ((res = Stream_lockRead(&stream->Buffer, &lock->Buffer, len) == Stream_Ok)) { + memcpy(&lock->receive, &stream->receive, sizeof(IStream) - sizeof(Stream)); + } + return res; +} +/** + * @brief unlock input stream for reading + * + * @param stream + * @param lock + */ +void IStream_unlock(IStream* stream, IStream* lock) { + Stream_unlockRead(&stream->Buffer, &lock->Buffer); +} +#endif // ISTREAM_LOCK diff --git a/Src/InputStream.h b/Src/InputStream.h index fc8004d..8960d32 100644 --- a/Src/InputStream.h +++ b/Src/InputStream.h @@ -33,6 +33,11 @@ extern "C" { * @brief enable checkTransmit function */ #define ISTREAM_CHECK_RECEIVE 1 +/** + * @brief enable lock read feature + */ +#define ISTREAM_LOCK STREAM_READ_LOCK + /************************************************************************/ @@ -90,6 +95,11 @@ Stream_LenType IStream_incomingBytes(IStream* stream); void IStream_setCheckReceive(IStream* stream, IStream_CheckReceiveFn fn); #endif // ISTREAM_CHECK_RECEIVE +#if ISTREAM_LOCK + Stream_Result IStream_lock(IStream* stream, IStream* lock, Stream_LenType len); + void IStream_unlock(IStream* stream, IStream* lock); +#endif // ISTREAM_LOCK + #define IStream_getDataPtr(STREAM) Stream_getWritePtr(&((STREAM)->Buffer)) #define IStream_clear(STREAM) Stream_clear(&((STREAM)->Buffer))