13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _DEIOSTREAM_H
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _DEIOSTREAM_H
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Stream Library
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Input-output stream abstraction.
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deDefs.h"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
283c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_BEGIN_EXTERN_C
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/* Result of operation on stream */
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef enum deStreamResult_e
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_STREAMRESULT_SUCCESS = 0,
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_STREAMRESULT_END_OF_STREAM,
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_STREAMRESULT_ERROR,
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_STREAMRESULT_LAST
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} deStreamResult;
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef enum deStreamStatus_e
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_STREAMSTATUS_GOOD = 0,
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_STREAMSTATUS_ERROR,
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_STREAMSTATUS_LAST
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} deStreamStatus;
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/* Type for pointer to internal stream psecifig data */
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef void deStreamData;
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/* Function types for v_table */
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef deStreamResult	(*deIOStreamReadFunc)		(deStreamData* stream, void* buf, deInt32 bufSize, deInt32* numRead);
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef deStreamResult	(*deIOStreamWriteFunc)		(deStreamData* stream, const void* buf, deInt32 bufSize, deInt32* numWritten);
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef const char*		(*deIOStreamGetErrorFunc)	(deStreamData* stream);
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef deStreamResult	(*deIOStreamFlushFunc)		(deStreamData* stream);
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef deStreamResult	(*deIOStreamDeinitFunc)		(deStreamData* stream);
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef deStreamStatus	(*deIOStreamStatusFunc)		(deStreamData* stream);
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/* Virtual table type for specifying stream specifig behaviour */
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef struct deIOStreamVFTable_s
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deIOStreamReadFunc		readFunc;
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deIOStreamWriteFunc		writeFunc;
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deIOStreamGetErrorFunc	getErrorFunc;
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deIOStreamFlushFunc 	flushFunc;
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deIOStreamDeinitFunc	deinitFunc;
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deIOStreamStatusFunc	statusFunc;
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} deIOStreamVFTable;
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/* Generig IOStream struct */
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef struct deIOStream_s
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deStreamData*				streamData;
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deIOStreamVFTable*	vfTable;
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} deIOStream;
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
773c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_INLINE deStreamResult	deIOStream_read			(deIOStream* stream, void* buf, deInt32 bufSize, deInt32* numRead);
783c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_INLINE deStreamResult	deIOStream_write		(deIOStream* stream, const void* buf, deInt32 bufSize, deInt32* numWritten);
793c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_INLINE const char*		deIOStream_getError 	(deIOStream* stream);
803c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_INLINE deStreamStatus	deIOStream_getStatus	(deIOStream* stream);
813c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_INLINE deStreamResult	deIOStream_flush		(deIOStream* stream);
823c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_INLINE deStreamResult	deIOStream_deinit		(deIOStream* stream);
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
863c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_INLINE deStreamResult deIOStream_write (deIOStream* stream, const void* buf, deInt32 bufSize, deInt32* numWritten)
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream);
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream->vfTable);
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream->vfTable->writeFunc);
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stream->vfTable->writeFunc(stream->streamData, buf, bufSize, numWritten);
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
953c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_INLINE deStreamResult deIOStream_read (deIOStream* stream, void* buf, deInt32 bufSize, deInt32* numRead)
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream);
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream->vfTable);
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream->vfTable->readFunc);
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stream->vfTable->readFunc(stream->streamData, buf, bufSize, numRead);
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1043c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_INLINE const char* deIOStream_getError (deIOStream* stream)
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream);
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream->vfTable);
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream->vfTable->getErrorFunc);
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stream->vfTable->getErrorFunc(stream->streamData);
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1133c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_INLINE deStreamResult deIOStream_flush (deIOStream* stream)
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream);
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream->vfTable);
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream->vfTable->flushFunc);
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stream->vfTable->flushFunc(stream->streamData);
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1223c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_INLINE deStreamResult deIOStream_deinit (deIOStream* stream)
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deStreamResult result = DE_STREAMRESULT_ERROR;
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream);
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream->vfTable);
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream->vfTable->deinitFunc);
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	result = stream->vfTable->deinitFunc(stream->streamData);
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stream->vfTable		= DE_NULL;
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	stream->streamData	= DE_NULL;
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return result;
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1373c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_INLINE deStreamStatus deIOStream_getStatus (deIOStream* stream)
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream);
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream->vfTable);
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(stream->vfTable->statusFunc);
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return stream->vfTable->statusFunc(stream->streamData);
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1463c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_END_EXTERN_C
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif /* _DEIOSTREAM_H */
149