gmio/src/datax_core/stream.h

63 lines
2.1 KiB
C
Raw Normal View History

#ifndef FOUG_C_STREAM_H
#define FOUG_C_STREAM_H
2013-01-16 00:56:24 +08:00
#include "global.h"
#include <stdio.h>
FOUG_C_LINKAGE_BEGIN
/*! Stream that can get input from an arbitrary data source or can write output to an arbitrary
2014-02-13 23:25:37 +08:00
* data sink
2014-01-21 17:51:23 +08:00
*/
struct foug_stream
{
/*! Opaque pointer on the user stream, passed as first argument to hook functions */
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 */
foug_bool_t (*at_end_func)(void* cookie);
2014-02-13 23:25:37 +08:00
/*! Pointer on a function that checks error indicator */
int (*error_func)(void* cookie);
2014-02-13 23:25:37 +08:00
/*! Pointer on a function that reads block of data from stream */
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 */
size_t (*write_func)(void* cookie, const void* ptr, size_t size, size_t count);
};
typedef struct foug_stream foug_stream_t;
2013-03-27 20:00:48 +08:00
/* Initialization */
/*! Installs a null stream */
FOUG_LIB_EXPORT void foug_stream_set_null(foug_stream_t* stream);
/*! Configures \p stream for standard FILE* (cookie will hold \p file) */
FOUG_LIB_EXPORT void foug_stream_set_stdio(foug_stream_t* stream, FILE* file);
/* Services */
2013-02-21 21:51:29 +08:00
2014-02-13 23:25:37 +08:00
/*! Safe and convenient function for foug_stream::at_end_func() */
FOUG_LIB_EXPORT foug_bool_t foug_stream_at_end(foug_stream_t* stream);
2013-02-21 21:51:29 +08:00
2014-02-13 23:25:37 +08:00
/*! Safe and convenient function for foug_stream::error_func() */
FOUG_LIB_EXPORT int foug_stream_error(foug_stream_t* stream);
2013-02-21 21:51:29 +08:00
2014-02-13 23:25:37 +08:00
/*! Safe and convenient function for foug_stream::read_func() */
FOUG_LIB_EXPORT size_t foug_stream_read(foug_stream_t* stream,
2013-02-21 21:51:29 +08:00
void* ptr,
size_t size,
size_t count);
2013-02-21 21:51:29 +08:00
2014-02-13 23:25:37 +08:00
/*! Safe and convenient function for foug_stream::write_func() */
FOUG_LIB_EXPORT size_t foug_stream_write(foug_stream_t* stream,
2013-02-21 21:51:29 +08:00
const void* ptr,
size_t size,
size_t count);
2013-02-21 21:51:29 +08:00
FOUG_C_LINKAGE_END
#endif /* FOUG_C_STREAM_H */