2014-03-28 23:33:35 +08:00
|
|
|
#ifndef GMIO_STREAM_H
|
|
|
|
#define GMIO_STREAM_H
|
2013-01-11 01:48:46 +08:00
|
|
|
|
2013-01-16 00:56:24 +08:00
|
|
|
#include "global.h"
|
2013-03-03 04:51:08 +08:00
|
|
|
#include <stdio.h>
|
2013-01-11 01:48:46 +08:00
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
GMIO_C_LINKAGE_BEGIN
|
2014-03-13 22:57:04 +08:00
|
|
|
|
2014-02-13 18:18:46 +08:00
|
|
|
/*! Stream that can get input from an arbitrary data source or can write output to an arbitrary
|
2014-11-19 16:39:56 +08:00
|
|
|
* data sink. It can be seen as generalization of the standard FILE*
|
2014-01-21 17:51:23 +08:00
|
|
|
*/
|
2014-03-28 23:33:35 +08:00
|
|
|
struct gmio_stream
|
2013-01-11 01:48:46 +08:00
|
|
|
{
|
2014-02-13 18:18:46 +08:00
|
|
|
/*! Opaque pointer on the user stream, passed as first argument to hook functions */
|
2013-03-03 04:51:08 +08:00
|
|
|
void* cookie;
|
2014-01-21 17:51:23 +08:00
|
|
|
|
2014-02-13 23:25:37 +08:00
|
|
|
/*! Pointer on a function that checks end-of-stream indicator */
|
2014-03-28 23:33:35 +08:00
|
|
|
gmio_bool_t (*at_end_func)(void* cookie);
|
2014-02-13 18:18:46 +08:00
|
|
|
|
2014-02-13 23:25:37 +08:00
|
|
|
/*! Pointer on a function that checks error indicator */
|
2014-02-13 18:18:46 +08:00
|
|
|
int (*error_func)(void* cookie);
|
|
|
|
|
2014-02-13 23:25:37 +08:00
|
|
|
/*! Pointer on a function that reads block of data from stream */
|
2014-02-13 18:18:46 +08:00
|
|
|
size_t (*read_func)(void* cookie, void* ptr, size_t size, size_t count);
|
|
|
|
|
2014-02-13 23:25:37 +08:00
|
|
|
/*! Pointer on a function that writes block of data to stream */
|
2014-02-13 18:18:46 +08:00
|
|
|
size_t (*write_func)(void* cookie, const void* ptr, size_t size, size_t count);
|
|
|
|
};
|
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
typedef struct gmio_stream gmio_stream_t;
|
2013-01-11 01:48:46 +08:00
|
|
|
|
2013-03-27 20:00:48 +08:00
|
|
|
/* Initialization */
|
|
|
|
|
2014-02-13 18:18:46 +08:00
|
|
|
/*! Installs a null stream */
|
2014-03-28 23:33:35 +08:00
|
|
|
GMIO_LIB_EXPORT void gmio_stream_set_null(gmio_stream_t* stream);
|
2014-02-13 18:18:46 +08:00
|
|
|
|
|
|
|
/*! Configures \p stream for standard FILE* (cookie will hold \p file) */
|
2014-03-28 23:33:35 +08:00
|
|
|
GMIO_LIB_EXPORT void gmio_stream_set_stdio(gmio_stream_t* stream, FILE* file);
|
2013-01-11 01:48:46 +08:00
|
|
|
|
|
|
|
/* Services */
|
2013-02-21 21:51:29 +08:00
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
/*! Safe and convenient function for gmio_stream::at_end_func() */
|
|
|
|
GMIO_LIB_EXPORT gmio_bool_t gmio_stream_at_end(gmio_stream_t* stream);
|
2013-02-21 21:51:29 +08:00
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
/*! Safe and convenient function for gmio_stream::error_func() */
|
|
|
|
GMIO_LIB_EXPORT int gmio_stream_error(gmio_stream_t* stream);
|
2013-02-21 21:51:29 +08:00
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
/*! Safe and convenient function for gmio_stream::read_func() */
|
|
|
|
GMIO_LIB_EXPORT size_t gmio_stream_read(gmio_stream_t* stream,
|
2013-02-21 21:51:29 +08:00
|
|
|
void* ptr,
|
2014-02-13 18:18:46 +08:00
|
|
|
size_t size,
|
|
|
|
size_t count);
|
2013-02-21 21:51:29 +08:00
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
/*! Safe and convenient function for gmio_stream::write_func() */
|
|
|
|
GMIO_LIB_EXPORT size_t gmio_stream_write(gmio_stream_t* stream,
|
2013-02-21 21:51:29 +08:00
|
|
|
const void* ptr,
|
2014-02-13 18:18:46 +08:00
|
|
|
size_t size,
|
|
|
|
size_t count);
|
2013-02-21 21:51:29 +08:00
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
GMIO_C_LINKAGE_END
|
2014-03-13 22:57:04 +08:00
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
#endif /* GMIO_STREAM_H */
|