iolayer modifications:
[imager.git] / iolayer.h
CommitLineData
02d1d628
AMH
1#ifndef _IOLAYER_H_
2#define _IOLAYER_H_
3
4
5/* How the IO layer works:
6 *
7 * Start by getting an io_glue object. Then define its
8 * datasource via io_obj_setp_buffer or io_obj_setp_cb. Before
9 * using the io_glue object be sure to call io_glue_commit_types().
10 * After that data can be read via the io_glue->readcb() method.
11 *
12 */
13
14
15#include <stdio.h>
16#ifndef _MSC_VER
17#include <unistd.h>
18#endif
19#include <sys/types.h>
20
21/* #define BBSIZ 1096 */
3e27d469 22#define BBSIZ 16384
02d1d628
AMH
23#define IO_FAKE_SEEK 1<<0L
24#define IO_TEMP_SEEK 1<<1L
25
26
02d1d628
AMH
27typedef enum { FDSEEK, FDNOSEEK, BUFFER, CBSEEK, CBNOSEEK, BUFCHAIN } io_type;
28
29#ifdef _MSC_VER
30typedef int ssize_t;
31#endif
32
299da279
TC
33typedef struct i_io_glue_t i_io_glue_t;
34
35/* compatibility for now */
36typedef i_io_glue_t io_glue;
02d1d628
AMH
37
38/* Callbacks we give out */
39
299da279
TC
40typedef ssize_t(*readp) (io_glue *ig, void *buf, size_t count);
41typedef ssize_t(*writep)(io_glue *ig, const void *buf, size_t count);
42typedef off_t (*seekp) (io_glue *ig, off_t offset, int whence);
43typedef void (*closep)(io_glue *ig);
44typedef ssize_t(*sizep) (io_glue *ig);
02d1d628 45
4dfa5522 46typedef void (*closebufp)(void *p);
02d1d628
AMH
47
48
49/* Callbacks we get */
50
10461f9a
TC
51typedef ssize_t(*readl) (void *p, void *buf, size_t count);
52typedef ssize_t(*writel)(void *p, const void *buf, size_t count);
53typedef off_t (*seekl) (void *p, off_t offset, int whence);
54typedef void (*closel)(void *p);
55typedef void (*destroyl)(void *p);
56typedef ssize_t(*sizel) (void *p);
02d1d628
AMH
57
58extern char *io_type_names[];
59
60
02d1d628
AMH
61
62/* Structures to describe data sources */
63
64typedef struct {
65 io_type type;
66 int fd;
67} io_fdseek;
68
69typedef struct {
70 io_type type; /* Must be first parameter */
71 char *name; /* Data source name */
4dfa5522 72 char *data;
02d1d628 73 size_t len;
4dfa5522
AMH
74 closebufp closecb; /* free memory mapped segment or decrement refcount */
75 void *closedata;
02d1d628
AMH
76} io_buffer;
77
78typedef struct {
79 io_type type; /* Must be first parameter */
80 char *name; /* Data source name */
81 void *p; /* Callback data */
82 readl readcb;
83 writel writecb;
84 seekl seekcb;
10461f9a
TC
85 closel closecb;
86 destroyl destroycb;
02d1d628
AMH
87} io_cb;
88
89typedef union {
90 io_type type;
91 io_fdseek fdseek;
92 io_buffer buffer;
93 io_cb cb;
94} io_obj;
95
299da279 96struct i_io_glue_t {
02d1d628
AMH
97 io_obj source;
98 int flags; /* Flags */
99 void *exdata; /* Pair specific data */
100 readp readcb;
101 writep writecb;
102 seekp seekcb;
103 closep closecb;
104 sizep sizecb;
299da279 105};
02d1d628 106
02d1d628
AMH
107void io_glue_commit_types(io_glue *ig);
108void io_glue_gettypes (io_glue *ig, int reqmeth);
109
110
111/* XS functions */
112io_glue *io_new_fd(int fd);
faa9b3e7 113io_glue *io_new_bufchain(void);
4dfa5522 114io_glue *io_new_buffer(char *data, size_t len, closebufp closecb, void *closedata);
10461f9a 115io_glue *io_new_cb(void *p, readl readcb, writel writecb, seekl seekcb, closel closecb, destroyl destroycb);
02d1d628 116size_t io_slurp(io_glue *ig, unsigned char **c);
527c0c3e 117void io_glue_DESTROY(io_glue *ig);
02d1d628 118
299da279
TC
119#define i_io_type(ig) ((ig)->source.ig_type)
120
02d1d628 121#endif /* _IOLAYER_H_ */