1 /* -*- Mode: C; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3 -*- */
2 
3 /*
4  * GImageView
5  * Copyright (C) 2001 Takuro Ashie
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *
21  * $Id: gimv_io.h,v 1.5 2004/09/21 08:44:32 makeinu Exp $
22  */
23 
24 #ifndef __GIMV_IO__
25 #define __GIMV_IO__
26 
27 #ifdef HAVE_CONFIG_H
28 #  include "config.h"
29 #endif
30 
31 #include <stdio.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <glib.h>
36 
37 
38 typedef struct GimvIO_Tag GimvIO;
39 typedef struct GimvIOFuncs_Tag GimvIOFuncs;
40 typedef struct GimvIOPlugin_Tag GimvIOPlugin;
41 
42 
43 typedef enum
44 {
45    GIMV_IO_STATUS_NORMAL,
46    GIMV_IO_STATUS_ERROR,
47    GIMV_IO_STATUS_EOF,
48    GIMV_IO_STATUS_AGAIN
49 } GimvIOStatus;
50 
51 
52 struct GimvIO_Tag
53 {
54    GimvIOFuncs *funcs;
55    gchar       *url;
56    gint         ref_count;
57 };
58 
59 
60 struct GimvIOFuncs_Tag
61 {
62    GimvIOStatus (*read)   (GimvIO         *gio,
63                            gchar          *buf,
64                            guint           count,
65                            guint          *bytes_read);
66    GimvIOStatus (*write)  (GimvIO         *gio,
67                            const gchar    *buf,
68                            guint           count,
69                            guint          *bytes_written);
70    GimvIOStatus (*seek)   (GimvIO         *gio,
71                            glong           offset,
72                            gint            whence);
73    GimvIOStatus (*tell)   (GimvIO         *gio,
74                            glong          *offset);
75    void         (*close)  (GimvIO         *gio);
76 };
77 
78 
79 #define GIMV_IO_IF_VERSION 1
80 
81 typedef GimvIO *(*GimvIONewFn) (const gchar *url,
82                                 const gchar *mode);
83 
84 #define GIMV_IO_PLUGIN_PRIORITY_DEFAULT 0
85 
86 
87 struct GimvIOPlugin_Tag
88 {
89    const guint32       if_version; /* plugin interface version */
90    const gchar * const id;
91    gint                priority_hint;
92    GimvIONewFn         new_func;
93 };
94 
95 
96 void           gimv_io_init  (GimvIO      *gio,
97                               const gchar *url);
98 GimvIO        *gimv_io_new   (const gchar *url,
99                               const gchar *mode);
100 GimvIO        *gimv_io_ref   (GimvIO      *gio);
101 void           gimv_io_unref (GimvIO      *gio);
102 GimvIOStatus   gimv_io_read  (GimvIO      *gio,
103                               gchar       *buf,
104                               guint        count,
105                               guint       *bytes_read);
106 GimvIOStatus   gimv_io_write (GimvIO      *gio,
107                               const gchar *buf,
108                               guint        count,
109                               guint       *bytes_written);
110 GimvIOStatus   gimv_io_seek  (GimvIO      *gio,
111                               glong        offset,
112                               gint         whence);
113 GimvIOStatus   gimv_io_tell  (GimvIO      *gio,
114                               glong       *offset);
115 void           gimv_io_close (GimvIO      *gio);
116 
117 
118 gint           gimv_io_getc  (GimvIO       *gio,
119                               GimvIOStatus *status);
120 GimvIOStatus   gimv_io_fgets (GimvIO       *gio,
121                               gchar        *buf,
122                               guint         count);
123 
124 /* for plugin loader */
125 gboolean       gimv_io_plugin_regist (const gchar *plugin_name,
126                                       const gchar *module_name,
127                                       gpointer     impl,
128                                       gint         size);
129 
130 #endif /* __GIMV_IO__ */
131