aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mail-remote/em-message-stream.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2005-05-27 19:18:41 +0800
committerMichael Zucci <zucchi@src.gnome.org>2005-05-27 19:18:41 +0800
commit7265cc314c68f9b9b0196661540bed628b5aad16 (patch)
tree33ad1883f3d4a77c202fbd242a0d06313b870e21 /plugins/mail-remote/em-message-stream.c
parent07419207d4478491adfbcc63776388db5723787b (diff)
downloadgsoc2013-evolution-7265cc314c68f9b9b0196661540bed628b5aad16.tar
gsoc2013-evolution-7265cc314c68f9b9b0196661540bed628b5aad16.tar.gz
gsoc2013-evolution-7265cc314c68f9b9b0196661540bed628b5aad16.tar.bz2
gsoc2013-evolution-7265cc314c68f9b9b0196661540bed628b5aad16.tar.lz
gsoc2013-evolution-7265cc314c68f9b9b0196661540bed628b5aad16.tar.xz
gsoc2013-evolution-7265cc314c68f9b9b0196661540bed628b5aad16.tar.zst
gsoc2013-evolution-7265cc314c68f9b9b0196661540bed628b5aad16.zip
A camel-stream to wrap Evolution_Mail_MessageStream.
2005-05-27 Not Zed <NotZed@Ximian.com> * em-message-stream.[ch]: A camel-stream to wrap Evolution_Mail_MessageStream. * evolution-mail-messagestream.[ch]: simplified read-only stream interface rather than using bonobo-stream. It wraps a camel-stream only & simplified lifecycle management. * evolution-mail-store.c (evolution_mail_store_changed): if we have no more listeners, close the camelstore object off. * Evolution-DataServer-Mail.idl: changed exceptions to use one exception type with details. Fixed code to use these. svn path=/trunk/; revision=29418
Diffstat (limited to 'plugins/mail-remote/em-message-stream.c')
-rw-r--r--plugins/mail-remote/em-message-stream.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/plugins/mail-remote/em-message-stream.c b/plugins/mail-remote/em-message-stream.c
new file mode 100644
index 0000000000..77f6300cb5
--- /dev/null
+++ b/plugins/mail-remote/em-message-stream.c
@@ -0,0 +1,144 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Authors: Michael Zucchi <notzed@novel.com>
+ *
+ * Copyright 2005 Novell, Inc. (www.novell.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <camel/camel-stream.h>
+#include "em-message-stream.h"
+
+#define d(x)
+
+#define EMSS_CLASS(x) ((EMMessageStreamClass *)(((CamelObject *)(x))->klass))
+
+static CamelStreamClass *parent_class = NULL;
+
+static ssize_t
+emms_read(CamelStream *stream, char *buffer, size_t n)
+{
+ EMMessageStream *emms = (EMMessageStream *)stream;
+ ssize_t len;
+ Evolution_Mail_Buffer *buf;
+ CORBA_Environment ev = { 0 };
+
+ /* To avoid all of the rount-trip overhead, this could always fire off
+ one request in advance, to pipeline the data. Using another thread. */
+
+ if (emms->source == CORBA_OBJECT_NIL) {
+ errno = EBADF;
+ return -1;
+ }
+
+ buf = Evolution_Mail_MessageStream_next(emms->source, n, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ CORBA_exception_free(&ev);
+ Evolution_Mail_MessageStream_dispose(emms->source, &ev);
+ emms->source = CORBA_OBJECT_NIL;
+ stream->eos = TRUE;
+ errno = EBADF;
+ return -1;
+ }
+
+ if (buf->_length == 0)
+ stream->eos = TRUE;
+
+ len = buf->_length;
+ memcpy(buffer, buf->_buffer, buf->_length);
+ CORBA_free(buf);
+
+ return len;
+}
+
+static void
+em_message_stream_init (CamelObject *object)
+{
+ /*EMMessageStream *emss = (EMMessageStream *)object;*/
+}
+
+static void
+em_message_stream_finalize (CamelObject *object)
+{
+ EMMessageStream *emms = (EMMessageStream *)object;
+
+ printf("EMMessageStream.finalise()\n");
+
+ if (emms->source) {
+ CORBA_Environment ev = { 0 };
+
+ Evolution_Mail_MessageStream_dispose(emms->source, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION)
+ CORBA_exception_free(&ev);
+
+ CORBA_Object_release(emms->source, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION)
+ CORBA_exception_free(&ev);
+ }
+}
+
+static void
+em_message_stream_class_init (EMMessageStreamClass *klass)
+{
+ CamelStreamClass *stream_class = CAMEL_STREAM_CLASS (klass);
+
+ parent_class = (CamelStreamClass *) CAMEL_STREAM_TYPE;
+
+ stream_class->read = emms_read;
+}
+
+CamelType
+em_message_stream_get_type (void)
+{
+ static CamelType type = CAMEL_INVALID_TYPE;
+
+ if (type == CAMEL_INVALID_TYPE) {
+ type = camel_type_register (CAMEL_STREAM_TYPE,
+ "EMMessageStream",
+ sizeof (EMMessageStream),
+ sizeof (EMMessageStreamClass),
+ (CamelObjectClassInitFunc) em_message_stream_class_init,
+ NULL,
+ (CamelObjectInitFunc) em_message_stream_init,
+ (CamelObjectFinalizeFunc) em_message_stream_finalize);
+ }
+
+ return type;
+}
+
+CamelStream *
+em_message_stream_new(const Evolution_Mail_MessageStream source)
+{
+ EMMessageStream *ems = (EMMessageStream *)camel_object_new(em_message_stream_get_type());
+ CORBA_Environment ev = { 0 };
+
+ ems->source = CORBA_Object_duplicate(source, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ CORBA_exception_free(&ev);
+ camel_object_unref(ems);
+ ems = NULL;
+ }
+
+ return (CamelStream *)ems;
+}