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 (TnyStreamIface *klass)
152 klass->read_func = modest_count_stream_read;
153 klass->write_func = modest_count_stream_write;
154 klass->flush_func = modest_count_stream_flush;
155 klass->close_func = modest_count_stream_close;
156 klass->is_eos_func = modest_count_stream_is_eos;
157 klass->reset_func = modest_count_stream_reset;
158 klass->write_to_stream_func = modest_count_stream_write_to_stream;
162 modest_count_stream_class_init (ModestCountStreamClass *klass)
164 GObjectClass *object_class;
166 parent_class = g_type_class_peek_parent (klass);
167 object_class = (GObjectClass*) klass;
168 object_class->finalize = modest_count_stream_finalize;
170 g_type_class_add_private (object_class, sizeof(ModestCountStream));
173 modest_count_stream_get_type (void)
175 static GType type = 0;
176 if (G_UNLIKELY(type == 0))
178 static const GTypeInfo info =
180 sizeof (ModestCountStreamClass),
181 NULL, /* base_init */
182 NULL, /* base_finalize */
183 (GClassInitFunc) modest_count_stream_class_init, /* class_init */
184 NULL, /* class_finalize */
185 NULL, /* class_data */
186 sizeof (ModestCountStream),
188 modest_count_stream_instance_init, /* instance_init */
193 static const GInterfaceInfo tny_stream_info =
195 (GInterfaceInitFunc) tny_stream_init, /* interface_init */
196 NULL, /* interface_finalize */
197 NULL /* interface_data */
200 type = g_type_register_static (G_TYPE_OBJECT,
204 /* TODO? : FIX THIS (ADD _TYPE): */
205 g_type_add_interface_static (type, TNY_TYPE_STREAM,