1 /* Copyright (c) 2007, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 /* modest-count-stream.h */
34 #include <glib/gi18n-lib.h>
36 #include <tny-stream.h>
37 #include "modest-count-stream.h"
39 typedef struct _ModestCountStreamPrivate ModestCountStreamPrivate;
40 struct _ModestCountStreamPrivate {
43 #define MODEST_COUNT_STREAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
44 MODEST_TYPE_COUNT_STREAM, \
45 ModestCountStreamPrivate))
47 static GObjectClass *parent_class = NULL;
50 modest_count_stream_read (TnyStream *self, char *buffer, gsize n)
56 modest_count_stream_write (TnyStream *self, const char *buffer, gsize n)
58 ModestCountStreamPrivate *priv;
59 priv = MODEST_COUNT_STREAM_GET_PRIVATE(self);
66 modest_count_stream_flush (TnyStream *self)
72 modest_count_stream_close (TnyStream *self)
78 modest_count_stream_is_eos (TnyStream *self)
84 modest_count_stream_reset (TnyStream *self)
90 modest_count_stream_write_to_stream (TnyStream *self, TnyStream *output)
96 * modest_count_stream_get_count
97 * @self: the ModestCountStream
99 * returns the number of bytes that have been written through this stream
101 * Returns: number of bytes that have passed through this stream
104 modest_count_stream_get_count (ModestCountStream *self)
106 ModestCountStreamPrivate *priv;
107 priv = MODEST_COUNT_STREAM_GET_PRIVATE(self);
113 * modest_count_stream_reset_count
114 * @self: the ModestCountStream
116 * resets the internal counter
121 modest_count_stream_reset_count (ModestCountStream *self)
123 ModestCountStreamPrivate *priv;
124 priv = MODEST_COUNT_STREAM_GET_PRIVATE(self);
130 modest_count_stream_new ()
132 return TNY_STREAM (g_object_new (MODEST_TYPE_COUNT_STREAM, NULL));
136 modest_count_stream_finalize (GObject *object)
138 parent_class->finalize (object);
141 modest_count_stream_instance_init (GTypeInstance *instance, gpointer g_class)
143 ModestCountStreamPrivate *priv;
144 priv = MODEST_COUNT_STREAM_GET_PRIVATE(instance);
150 tny_stream_init (gpointer g_iface, gpointer iface_data)
152 TnyStreamIface *klass = (TnyStreamIface *) g_iface;
154 klass->read = modest_count_stream_read;
155 klass->write = modest_count_stream_write;
156 klass->flush = modest_count_stream_flush;
157 klass->close = modest_count_stream_close;
158 klass->is_eos = modest_count_stream_is_eos;
159 klass->reset = modest_count_stream_reset;
160 klass->write_to_stream = modest_count_stream_write_to_stream;
164 modest_count_stream_class_init (ModestCountStreamClass *klass)
166 GObjectClass *object_class;
168 parent_class = g_type_class_peek_parent (klass);
169 object_class = (GObjectClass*) klass;
170 object_class->finalize = modest_count_stream_finalize;
172 g_type_class_add_private (object_class, sizeof(ModestCountStream));
175 modest_count_stream_get_type (void)
177 static GType type = 0;
178 if (G_UNLIKELY(type == 0))
180 static const GTypeInfo info =
182 sizeof (ModestCountStreamClass),
183 NULL, /* base_init */
184 NULL, /* base_finalize */
185 (GClassInitFunc) modest_count_stream_class_init, /* class_init */
186 NULL, /* class_finalize */
187 NULL, /* class_data */
188 sizeof (ModestCountStream),
190 modest_count_stream_instance_init, /* instance_init */
195 static const GInterfaceInfo tny_stream_info =
197 (GInterfaceInitFunc) tny_stream_init, /* interface_init */
198 NULL, /* interface_finalize */
199 NULL /* interface_data */
202 type = g_type_register_static (G_TYPE_OBJECT,
206 g_type_add_interface_static (type, TNY_TYPE_STREAM,