/*============================================================================ * OpcUa_MemoryStream_Read *===========================================================================*/ OpcUa_StatusCode OpcUa_MemoryStream_Read( struct _OpcUa_InputStream* istrm, OpcUa_Byte* buffer, OpcUa_UInt32* count, OpcUa_Stream_PfnOnReadyToRead* callback, OpcUa_Void* callbackData) { OpcUa_MemoryStream* handle = OpcUa_Null; OpcUa_DeclareErrorTraceModule(OpcUa_Module_MemoryStream); OpcUa_ReturnErrorIfArgumentNull(istrm); OpcUa_ReturnErrorIfArgumentNull(buffer); OpcUa_ReturnErrorIfArgumentNull(count); OpcUa_ReturnErrorIfInvalidStream(istrm, Read); OpcUa_ReferenceParameter(callback); OpcUa_ReferenceParameter(callbackData); handle = (OpcUa_MemoryStream*)istrm->Handle; if (handle->Closed) { return OpcUa_BadInvalidState; } return OpcUa_Buffer_Read(handle->pBuffer, buffer, count); }
/*============================================================================ * OpcUa_MemoryStream_Close *===========================================================================*/ static OpcUa_StatusCode OpcUa_MemoryStream_Close( OpcUa_Stream* strm) { OpcUa_MemoryStream* handle = OpcUa_Null; OpcUa_StatusCode uStatus = OpcUa_Good; OpcUa_DeclareErrorTraceModule(OpcUa_Module_MemoryStream); OpcUa_ReturnErrorIfArgumentNull(strm); OpcUa_ReturnErrorIfInvalidStream(strm, Close); handle = (OpcUa_MemoryStream*)strm->Handle; if (handle->Closed) { return OpcUa_BadInvalidState; } if(strm->Type == OpcUa_StreamType_Output) { /* flush content when stream gets closed */ uStatus = OpcUa_MemoryStream_Flush( (OpcUa_OutputStream*)strm, OpcUa_True); } handle->Closed = OpcUa_True; return uStatus; }
/*============================================================================ * OpcUa_MemoryStream_GetPosition *===========================================================================*/ OpcUa_StatusCode OpcUa_MemoryStream_GetPosition( struct _OpcUa_Stream* strm, OpcUa_UInt32* position) { OpcUa_MemoryStream* handle = OpcUa_Null; OpcUa_DeclareErrorTraceModule(OpcUa_Module_MemoryStream); OpcUa_ReturnErrorIfArgumentNull(strm); OpcUa_ReturnErrorIfArgumentNull(position); OpcUa_ReturnErrorIfInvalidStream(strm, GetPosition); handle = (OpcUa_MemoryStream*)strm->Handle; return OpcUa_Buffer_GetPosition(handle->pBuffer, position); }
/*============================================================================ * OpcUa_Stream_SetPosition *===========================================================================*/ OpcUa_StatusCode OpcUa_MemoryStream_SetPosition( OpcUa_Stream* strm, OpcUa_UInt32 position) { OpcUa_MemoryStream* handle = OpcUa_Null; OpcUa_DeclareErrorTraceModule(OpcUa_Module_MemoryStream); OpcUa_ReturnErrorIfArgumentNull(strm); OpcUa_ReturnErrorIfInvalidStream(strm, SetPosition); handle = (OpcUa_MemoryStream*)strm->Handle; if (handle->Closed) { return OpcUa_BadInvalidState; } return OpcUa_Buffer_SetPosition(handle->pBuffer, position); }
/*============================================================================ * OpcUa_MemoryStream_Write *===========================================================================*/ OpcUa_StatusCode OpcUa_MemoryStream_Write( struct _OpcUa_OutputStream* ostrm, OpcUa_Byte* buffer, OpcUa_UInt32 count) { OpcUa_MemoryStream* handle = OpcUa_Null; OpcUa_DeclareErrorTraceModule(OpcUa_Module_MemoryStream); OpcUa_ReturnErrorIfArgumentNull(ostrm); OpcUa_ReturnErrorIfArgumentNull(buffer); OpcUa_ReturnErrorIfInvalidStream(ostrm, Write); handle = (OpcUa_MemoryStream*)ostrm->Handle; if (handle->Closed) { return OpcUa_BadInvalidState; } return OpcUa_Buffer_Write(handle->pBuffer, buffer, count); }
/*============================================================================ * OpcUa_MemoryStream_Flush *===========================================================================*/ static OpcUa_StatusCode OpcUa_MemoryStream_Flush( OpcUa_OutputStream* ostrm, OpcUa_Boolean lastCall) { OpcUa_MemoryStream* handle = OpcUa_Null; OpcUa_InitializeStatus(OpcUa_Module_MemoryStream, "Flush"); OpcUa_ReturnErrorIfArgumentNull(ostrm); OpcUa_ReturnErrorIfInvalidStream(ostrm, Flush); OpcUa_ReferenceParameter(lastCall); handle = (OpcUa_MemoryStream*)ostrm->Handle; if(handle->Closed) { return OpcUa_BadInvalidState; } if(!OpcUa_Buffer_IsEmpty((OpcUa_Buffer *)handle->pBuffer)) { OpcUa_Byte* pData = OpcUa_Null; OpcUa_UInt32 uDataLength = 0; uStatus = OpcUa_Buffer_GetData(handle->pBuffer, &pData, &uDataLength); if (OpcUa_IsBad(uStatus)) { OpcUa_Trace(OPCUA_TRACE_LEVEL_ERROR, "Flush: FAILED with 0x%X\n", uStatus); OpcUa_GotoError; } } OpcUa_ReturnStatusCode; OpcUa_BeginErrorHandling; OpcUa_FinishErrorHandling; }
/*============================================================================ * OpcUa_MemoryStream_Read *===========================================================================*/ OpcUa_StatusCode OpcUa_MemoryStream_Read( OpcUa_InputStream* istrm, OpcUa_Byte* buffer, OpcUa_UInt32* count) { OpcUa_MemoryStream* handle = OpcUa_Null; OpcUa_DeclareErrorTraceModule(OpcUa_Module_MemoryStream); OpcUa_ReturnErrorIfArgumentNull(istrm); OpcUa_ReturnErrorIfArgumentNull(buffer); OpcUa_ReturnErrorIfArgumentNull(count); OpcUa_ReturnErrorIfInvalidStream(istrm, Read); handle = (OpcUa_MemoryStream*)istrm->Handle; if (handle->Closed) { return OpcUa_BadInvalidState; } return OpcUa_Buffer_Read(handle->pBuffer, buffer, count); }