0.84 release
[imager.git] / iolayert.h
CommitLineData
0778adbf
TC
1#ifndef IMAGER_IOLAYERT_H
2#define IMAGER_IOLAYERT_H
3
4#ifndef _MSC_VER
5#include <unistd.h>
6#endif
7#include <sys/types.h>
f6d10024 8#include <stddef.h>
0778adbf
TC
9
10typedef enum { FDSEEK, FDNOSEEK, BUFFER, CBSEEK, CBNOSEEK, BUFCHAIN } io_type;
11
12#ifdef _MSC_VER
13typedef int ssize_t;
14#endif
15
16typedef struct i_io_glue_t i_io_glue_t;
17
18/* compatibility for now */
19typedef i_io_glue_t io_glue;
20
21/* Callbacks we give out */
22
23typedef ssize_t(*i_io_readp_t) (io_glue *ig, void *buf, size_t count);
24typedef ssize_t(*i_io_writep_t)(io_glue *ig, const void *buf, size_t count);
25typedef off_t (*i_io_seekp_t) (io_glue *ig, off_t offset, int whence);
2b405c9e 26typedef int (*i_io_closep_t)(io_glue *ig);
0778adbf
TC
27typedef ssize_t(*i_io_sizep_t) (io_glue *ig);
28
29typedef void (*i_io_closebufp_t)(void *p);
30typedef void (*i_io_destroyp_t)(i_io_glue_t *ig);
31
32
33/* Callbacks we get */
34
35typedef ssize_t(*i_io_readl_t) (void *p, void *buf, size_t count);
36typedef ssize_t(*i_io_writel_t)(void *p, const void *buf, size_t count);
37typedef off_t (*i_io_seekl_t) (void *p, off_t offset, int whence);
2b405c9e 38typedef int (*i_io_closel_t)(void *p);
0778adbf
TC
39typedef void (*i_io_destroyl_t)(void *p);
40typedef ssize_t(*i_io_sizel_t) (void *p);
41
42extern char *io_type_names[];
43
44
45
46/* Structures to describe data sources */
47
48typedef struct {
49 io_type type;
50 int fd;
51} io_fdseek;
52
53typedef struct {
54 io_type type; /* Must be first parameter */
55 char *name; /* Data source name */
56 char *data;
57 size_t len;
58 i_io_closebufp_t closecb; /* free memory mapped segment or decrement refcount */
59 void *closedata;
60} io_buffer;
61
62typedef struct {
63 io_type type; /* Must be first parameter */
64 char *name; /* Data source name */
65 void *p; /* Callback data */
66 i_io_readl_t readcb;
67 i_io_writel_t writecb;
68 i_io_seekl_t seekcb;
69 i_io_closel_t closecb;
70 i_io_destroyl_t destroycb;
71} io_cb;
72
73typedef union {
74 io_type type;
75 io_fdseek fdseek;
76 io_buffer buffer;
77 io_cb cb;
78} io_obj;
79
80struct i_io_glue_t {
81 io_obj source;
82 int flags; /* Flags */
83 void *exdata; /* Pair specific data */
84 i_io_readp_t readcb;
85 i_io_writep_t writecb;
86 i_io_seekp_t seekcb;
87 i_io_closep_t closecb;
88 i_io_sizep_t sizecb;
89 i_io_destroyp_t destroycb;
90};
91
92#define i_io_type(ig) ((ig)->source.ig_type)
93#define i_io_read(ig, buf, size) ((ig)->readcb((ig), (buf), (size)))
94#define i_io_write(ig, data, size) ((ig)->writecb((ig), (data), (size)))
95#define i_io_seek(ig, offset, whence) ((ig)->seekcb((ig), (offset), (whence)))
96#define i_io_close(ig) ((ig)->closecb(ig))
97
98
99#endif