1
/* libtinymail - The Tiny Mail base library
2
* Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with self library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
22
#include <tny-stream.h>
26
* tny_stream_write_to_stream:
27
* @self: a #TnyStream object
28
* @output: a #TnyStream object
30
* Write @self to @output in an efficient way
32
* Return value: the number of bytes written to the output stream, or -1 on
33
* error along with setting errno.
37
tny_stream_write_to_stream (TnyStream *self, TnyStream *output)
39
#ifdef DBC /* require */
40
g_assert (TNY_IS_STREAM (self));
42
g_assert (TNY_IS_STREAM (output));
43
g_assert (TNY_STREAM_GET_IFACE (self)->write_to_stream_func != NULL);
46
return TNY_STREAM_GET_IFACE (self)->write_to_stream_func (self, output);
51
* @self: a #TnyStream object
52
* @buffer: a buffer that is at least n in size
53
* @n: the max amount of bytes to read from self and to write into buffer
55
* Read n bytes @self and write it into @buffer. It's your responsibility
56
* to pass a buffer that is large enough to hold n bytes.
58
* Return value: the number of bytes actually read, or -1 on error and
63
tny_stream_read (TnyStream *self, char *buffer, gsize n)
65
#ifdef DBC /* require */
66
g_assert (TNY_IS_STREAM (self));
67
g_assert (TNY_STREAM_GET_IFACE (self)->read_func != NULL);
70
return TNY_STREAM_GET_IFACE (self)->read_func (self, buffer, n);
75
* @self: a #TnyStream object
76
* @buffer: a buffer that has at least n bytes
77
* @n: the amount of bytes to read from buffer and to write to self
79
* Write n bytes of @buffer into @self. It's your responsibility to pass
80
* a buffer that has at least n bytes.
82
* Return value: the number of bytes written to the stream, or -1 on error
83
* along with setting errno.
87
tny_stream_write (TnyStream *self, const char *buffer, gsize n)
89
#ifdef DBC /* require */
90
g_assert (TNY_IS_STREAM (self));
91
g_assert (TNY_STREAM_GET_IFACE (self)->write_func != NULL);
94
return TNY_STREAM_GET_IFACE (self)->write_func (self, buffer, n);
100
* @self: a #TnyStream object
102
* Flushes any buffered data to the stream's backing store.
104
* Return value: 0 on success or -1 on fail along with setting errno.
108
tny_stream_flush (TnyStream *self)
110
#ifdef DBC /* require */
111
g_assert (TNY_IS_STREAM (self));
112
g_assert (TNY_STREAM_GET_IFACE (self)->flush_func != NULL);
115
return TNY_STREAM_GET_IFACE (self)->flush_func (self);
120
* @self: a #TnyStream object
124
* Return value: 0 on success or -1 on fail.
127
tny_stream_close (TnyStream *self)
129
#ifdef DBC /* require */
130
g_assert (TNY_IS_STREAM (self));
131
g_assert (TNY_STREAM_GET_IFACE (self)->close_func != NULL);
134
return TNY_STREAM_GET_IFACE (self)->close_func (self);
140
* @self: a #TnyStream object
142
* Tests if there are bytes left to read on @self.
144
* Return value: TRUE on EOS or FALSE otherwise.
148
tny_stream_is_eos (TnyStream *self)
150
#ifdef DBC /* require */
151
g_assert (TNY_IS_STREAM (self));
152
g_assert (TNY_STREAM_GET_IFACE (self)->is_eos_func != NULL);
155
return TNY_STREAM_GET_IFACE (self)->is_eos_func (self);
160
* @self: a #TnyStream object
162
* Resets @self. That is, put it in a state where it can be read from
163
* the beginning again.
165
* Return value: 0 on success or -1 on error along with setting errno.
169
tny_stream_reset (TnyStream *self)
171
#ifdef DBC /* require */
172
g_assert (TNY_IS_STREAM (self));
173
g_assert (TNY_STREAM_GET_IFACE (self)->reset_func != NULL);
176
return TNY_STREAM_GET_IFACE (self)->reset_func (self);
180
tny_stream_base_init (gpointer g_class)
182
static gboolean initialized = FALSE;
185
/* create interface signals here. */
191
tny_stream_get_type (void)
193
static GType type = 0;
195
if (G_UNLIKELY(type == 0))
197
static const GTypeInfo info =
199
sizeof (TnyStreamIface),
200
tny_stream_base_init, /* base_init */
201
NULL, /* base_finalize */
202
NULL, /* class_init */
203
NULL, /* class_finalize */
204
NULL, /* class_data */
207
NULL, /* instance_init */
210
type = g_type_register_static (G_TYPE_INTERFACE,
211
"TnyStream", &info, 0);