kill camel-log
[platform/upstream/evolution-data-server.git] / camel / camel-seekable-stream.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* 
4  *
5  * Author : 
6  *  Bertrand Guiheneuf <bertrand@helixcode.com>
7  *
8  * Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com)
9  *
10  * This program is free software; you can redistribute it and/or 
11  * modify it under the terms of the GNU General Public License as 
12  * published by the Free Software Foundation; either version 2 of the
13  * License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  */
25
26
27
28 #include <config.h>
29 #include "camel-seekable-stream.h"
30
31 static CamelStreamClass *parent_class=NULL;
32
33
34 /* Returns the class for a CamelSeekableStream */
35 #define CSS_CLASS(so) CAMEL_SEEKABLE_STREAM_CLASS (GTK_OBJECT(so)->klass)
36
37 static gint      _seek      (CamelSeekableStream *stream, 
38                              gint offset, 
39                              CamelStreamSeekPolicy policy);
40 static void      _reset     (CamelStream *stream);
41
42
43 static void
44 camel_seekable_stream_class_init (CamelSeekableStreamClass *camel_seekable_stream_class)
45 {
46         CamelStreamClass *camel_stream_class = CAMEL_STREAM_CLASS (camel_seekable_stream_class);
47
48         parent_class = gtk_type_class (camel_stream_get_type ());
49         
50         /* seekable stream methods */
51         camel_seekable_stream_class->seek = _seek;
52
53         /* camel stream methods overload */
54         camel_stream_class->reset = _reset;
55 }
56
57 GtkType
58 camel_seekable_stream_get_type (void)
59 {
60         static GtkType camel_seekable_stream_type = 0;
61         
62         if (!camel_seekable_stream_type)        {
63                 GtkTypeInfo camel_seekable_stream_info =        
64                 {
65                         "CamelSeekableStream",
66                         sizeof (CamelSeekableStream),
67                         sizeof (CamelSeekableStreamClass),
68                         (GtkClassInitFunc) camel_seekable_stream_class_init,
69                         (GtkObjectInitFunc) NULL,
70                                 /* reserved_1 */ NULL,
71                                 /* reserved_2 */ NULL,
72                         (GtkClassInitFunc) NULL,
73                 };
74                 
75                 camel_seekable_stream_type = gtk_type_unique (camel_stream_get_type (), &camel_seekable_stream_info);
76         }
77         
78         return camel_seekable_stream_type;
79 }
80
81
82
83
84 static gint
85 _seek (CamelSeekableStream *stream, 
86        gint offset, 
87        CamelStreamSeekPolicy policy)
88 {
89         g_warning ("CamelSeekableStream::seek called on default implementation \n");
90         return -1;
91 }
92
93
94
95 /**
96  * camel_stream_seek:
97  * @stream: a CamelStream object.
98  * @offset: offset value
99  * @policy: what to do with the offset
100  * 
101  * 
102  * 
103  * Return value: new position, -1 if operation failed.
104  **/
105 gint
106 camel_seekable_stream_seek (CamelSeekableStream *stream, 
107                             gint offset, 
108                             CamelStreamSeekPolicy policy)
109 {
110         return CSS_CLASS (stream)->seek (stream, offset, policy);
111 }
112
113
114
115
116 /**
117  * camel_seekable_stream_get_current_position: get the position of a stream
118  * @stream: seekable stream object 
119  * 
120  * Get the current position of a seekable stream.
121  * 
122  * Return value: the position.
123  **/
124 guint32  
125 camel_seekable_stream_get_current_position  (CamelSeekableStream *stream)
126 {
127         return stream->cur_pos;         
128 }
129
130
131
132 /* a default implementation of reset for seekable streams */
133 static void 
134 _reset (CamelStream *stream)
135 {
136         CamelSeekableStream *seekable_stream;
137
138         g_assert (stream);
139         seekable_stream = CAMEL_SEEKABLE_STREAM (stream);
140
141         camel_seekable_stream_seek (seekable_stream, 0, CAMEL_STREAM_SET);      
142 }
143
144
145
146
147
148