Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / camel-stream-null.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */
2 /* camel-stream.c : abstract class for a stream */
3
4 /*
5  * Author:
6  *  Michael Zucchi <notzed@ximian.com>
7  *
8  * Copyright 1999, 2000 Ximian, Inc. (www.ximian.com)
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of version 2 of the GNU Lesser General Public
12  * License as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 #include "camel-stream-null.h"
30
31 static CamelObjectClass *parent_class = NULL;
32
33 /* Returns the class for a CamelStream */
34 #define CS_CLASS(so) CAMEL_STREAM_NULL_CLASS(CAMEL_OBJECT_GET_CLASS(so))
35
36 /* dummy implementations, for a NULL stream */
37 static ssize_t   stream_read       (CamelStream *stream, char *buffer, size_t n) { return 0; }
38 static ssize_t   stream_write      (CamelStream *stream, const char *buffer, size_t n) { ((CamelStreamNull *)stream)->written += n; return n; }
39 static int       stream_close      (CamelStream *stream) { return 0; }
40 static int       stream_flush      (CamelStream *stream) { return 0; }
41 static gboolean  stream_eos        (CamelStream *stream) { return TRUE; }
42 static int       stream_reset      (CamelStream *stream) { ((CamelStreamNull *)stream)->written = 0; return 0; }
43
44 static void
45 camel_stream_null_class_init (CamelStreamClass *camel_stream_null_class)
46 {
47         CamelStreamClass *camel_stream_class = (CamelStreamClass *)camel_stream_null_class;
48
49         parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
50
51         /* virtual method definition */
52         camel_stream_class->read = stream_read;
53         camel_stream_class->write = stream_write;
54         camel_stream_class->close = stream_close;
55         camel_stream_class->flush = stream_flush;
56         camel_stream_class->eos = stream_eos;
57         camel_stream_class->reset = stream_reset;
58 }
59
60 CamelType
61 camel_stream_null_get_type (void)
62 {
63         static CamelType camel_stream_null_type = CAMEL_INVALID_TYPE;
64
65         if (camel_stream_null_type == CAMEL_INVALID_TYPE) {
66                 camel_stream_null_type = camel_type_register( camel_stream_get_type(),
67                                                               "CamelStreamNull",
68                                                               sizeof( CamelStreamNull ),
69                                                               sizeof( CamelStreamNullClass ),
70                                                               (CamelObjectClassInitFunc) camel_stream_null_class_init,
71                                                               NULL,
72                                                               NULL,
73                                                               NULL );
74         }
75
76         return camel_stream_null_type;
77 }
78
79 /**
80  * camel_stream_null_new:
81  *
82  * Returns a null stream.  A null stream is always at eof, and
83  * always returns success for all reads and writes.
84  *
85  * Returns a new #CamelStreamNull
86  **/
87 CamelStream *
88 camel_stream_null_new(void)
89 {
90         return (CamelStream *)camel_object_new(camel_stream_null_get_type ());
91 }