1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */
2 /* camel-stream.h : class for an abstract stream
3  *
4  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
5  *
6  * This library is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Authors: Bertrand Guiheneuf <bertrand@helixcode.com>
19  */
20 
21 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
22 #error "Only <camel/camel.h> can be included directly."
23 #endif
24 
25 #ifndef CAMEL_STREAM_H
26 #define CAMEL_STREAM_H
27 
28 #include <stdarg.h>
29 #include <unistd.h>
30 
31 #include <gio/gio.h>
32 
33 /* Standard GObject macros */
34 #define CAMEL_TYPE_STREAM \
35 	(camel_stream_get_type ())
36 #define CAMEL_STREAM(obj) \
37 	(G_TYPE_CHECK_INSTANCE_CAST \
38 	((obj), CAMEL_TYPE_STREAM, CamelStream))
39 #define CAMEL_STREAM_CLASS(cls) \
40 	(G_TYPE_CHECK_CLASS_CAST \
41 	((cls), CAMEL_TYPE_STREAM, CamelStreamClass))
42 #define CAMEL_IS_STREAM(obj) \
43 	(G_TYPE_CHECK_INSTANCE_TYPE \
44 	((obj), CAMEL_TYPE_STREAM))
45 #define CAMEL_IS_STREAM_CLASS(cls) \
46 	(G_TYPE_CHECK_CLASS_TYPE \
47 	((cls), CAMEL_TYPE_STREAM))
48 #define CAMEL_STREAM_GET_CLASS(obj) \
49 	(G_TYPE_INSTANCE_GET_CLASS \
50 	((obj), CAMEL_TYPE_STREAM, CamelStreamClass))
51 
52 G_BEGIN_DECLS
53 
54 typedef struct _CamelStream CamelStream;
55 typedef struct _CamelStreamClass CamelStreamClass;
56 typedef struct _CamelStreamPrivate CamelStreamPrivate;
57 
58 struct _CamelStream {
59 	GObject parent;
60 	CamelStreamPrivate *priv;
61 };
62 
63 struct _CamelStreamClass {
64 	GObjectClass parent_class;
65 
66 	gssize		(*read)			(CamelStream *stream,
67 						 gchar *buffer,
68 						 gsize n,
69 						 GCancellable *cancellable,
70 						 GError **error);
71 	gssize		(*write)		(CamelStream *stream,
72 						 const gchar *buffer,
73 						 gsize n,
74 						 GCancellable *cancellable,
75 						 GError **error);
76 	gint		(*close)		(CamelStream *stream,
77 						 GCancellable *cancellable,
78 						 GError **error);
79 	gint		(*flush)		(CamelStream *stream,
80 						 GCancellable *cancellable,
81 						 GError **error);
82 	gboolean	(*eos)			(CamelStream *stream);
83 
84 	/* Padding for future expansion */
85 	gpointer reserved[20];
86 };
87 
88 GType		camel_stream_get_type		(void);
89 CamelStream *	camel_stream_new		(GIOStream *base_stream);
90 GIOStream *	camel_stream_ref_base_stream	(CamelStream *stream);
91 void		camel_stream_set_base_stream	(CamelStream *stream,
92 						 GIOStream *base_stream);
93 gssize		camel_stream_read		(CamelStream *stream,
94 						 gchar *buffer,
95 						 gsize n,
96 						 GCancellable *cancellable,
97 						 GError **error);
98 gssize		camel_stream_write		(CamelStream *stream,
99 						 const gchar *buffer,
100 						 gsize n,
101 						 GCancellable *cancellable,
102 						 GError **error);
103 gint		camel_stream_flush		(CamelStream *stream,
104 						 GCancellable *cancellable,
105 						 GError **error);
106 gint		camel_stream_close		(CamelStream *stream,
107 						 GCancellable *cancellable,
108 						 GError **error);
109 gboolean	camel_stream_eos		(CamelStream *stream);
110 
111 /* utility macros and funcs */
112 gssize		camel_stream_write_string	(CamelStream *stream,
113 						 const gchar *string,
114 						 GCancellable *cancellable,
115 						 GError **error);
116 
117 /* Write a whole stream to another stream, until eof or error on
118  * either stream.  */
119 gssize		camel_stream_write_to_stream	(CamelStream *stream,
120 						 CamelStream *output_stream,
121 						 GCancellable *cancellable,
122 						 GError **error);
123 
124 G_END_DECLS
125 
126 #endif /* CAMEL_STREAM_H */
127