From 6881fd1bf710f0ce0bd55f9975855bb23622077a Mon Sep 17 00:00:00 2001 From: bertrand Date: Tue, 24 Aug 1999 21:01:10 +0000 Subject: new class. Will handle all sort of information media (Mime mail messages, 1999-08-24 bertrand * camel/camel-medium.c (camel_medium_class_init): new class. Will handle all sort of information media (Mime mail messages, Lotus Notes mail messages, postit notes, faxes, who knows .... :) CamelMimePart will inherit from it. * camel/camel-mime-part.c (_set_disposition): (_set_description): description and disposition parameters are now const. * camel/gmime-content-field.c (gmime_content_field_free): added assertion code. * camel/providers/MH/camel-mh-folder.c (_get_message): uses buffered stream. * camel/camel-stream-buffered-fs.c: new stream to accelerate file ops. Thanks to jwz, I've decided to add a level of abstraction to Camel. In the future, it should be able to handle other mail systems, but also non-mail information vehicles. Enough for today. Roller time! svn path=/trunk/; revision=1140 --- camel/camel-stream-fs.c | 50 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) (limited to 'camel/camel-stream-fs.c') diff --git a/camel/camel-stream-fs.c b/camel/camel-stream-fs.c index e96250bd29..e540665dd3 100644 --- a/camel/camel-stream-fs.c +++ b/camel/camel-stream-fs.c @@ -33,7 +33,7 @@ static CamelStreamClass *parent_class=NULL; /* Returns the class for a CamelStreamFS */ -#define CS_CLASS(so) CAMEL_STREAM_FS_CLASS (GTK_OBJECT(so)->klass) +#define CSFS_CLASS(so) CAMEL_STREAM_FS_CLASS (GTK_OBJECT(so)->klass) static gint _read (CamelStream *stream, gchar *buffer, gint n); static gint _write (CamelStream *stream, const gchar *buffer, gint n); @@ -46,6 +46,9 @@ static gint _seek (CamelStream *stream, gint offset, CamelStreamSeekPolicy polic static void _finalize (GtkObject *object); static void _destroy (GtkObject *object); +static void _init_with_fd (CamelStreamFs *stream_fs, int fd); +static void _init_with_name (CamelStreamFs *stream_fs, const gchar *name, CamelStreamFsMode mode); + static void camel_stream_fs_class_init (CamelStreamFsClass *camel_stream_fs_class) { @@ -55,6 +58,8 @@ camel_stream_fs_class_init (CamelStreamFsClass *camel_stream_fs_class) parent_class = gtk_type_class (camel_stream_get_type ()); /* virtual method definition */ + camel_stream_fs_class->init_with_fd = _init_with_fd; + camel_stream_fs_class->init_with_name = _init_with_name; /* virtual method overload */ camel_stream_class->read = _read; @@ -70,6 +75,13 @@ camel_stream_fs_class_init (CamelStreamFsClass *camel_stream_fs_class) } +static void +camel_stream_fs_init (gpointer object, gpointer klass) +{ + CamelStreamFs *stream = CAMEL_STREAM_FS (object); + + stream->name = NULL; +} GtkType @@ -84,7 +96,7 @@ camel_stream_fs_get_type (void) sizeof (CamelStreamFs), sizeof (CamelStreamFsClass), (GtkClassInitFunc) camel_stream_fs_class_init, - (GtkObjectInitFunc) NULL, + (GtkObjectInitFunc) camel_stream_fs_init, /* reserved_1 */ NULL, /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, @@ -130,14 +142,18 @@ _finalize (GtkObject *object) CAMEL_LOG_FULL_DEBUG ("Leaving CamelStreamFs::finalize\n"); } +static void +_init_with_fd (CamelStreamFs *stream_fs, int fd) +{ + stream_fs->fd = fd; +} -CamelStream * -camel_stream_fs_new_with_name (const gchar *name, CamelStreamFsMode mode) +static void +_init_with_name (CamelStreamFs *stream_fs, const gchar *name, CamelStreamFsMode mode) { struct stat s; int v, fd; int flags; - CamelStreamFs *stream_fs; g_assert (name); CAMEL_LOG_FULL_DEBUG ( "Entering CamelStream::new_with_name, name=\"%s\", mode=%d\n", name, mode); @@ -152,21 +168,33 @@ camel_stream_fs_new_with_name (const gchar *name, CamelStreamFsMode mode) if (mode & CAMEL_STREAM_FS_WRITE) flags = O_WRONLY | O_CREAT; else - return NULL; + return; } if ( (mode & CAMEL_STREAM_FS_READ) && !(mode & CAMEL_STREAM_FS_WRITE) ) - if (v == -1) return NULL; + if (v == -1) return; fd = open (name, flags, 0600); if (fd==-1) { CAMEL_LOG_WARNING ( "CamelStreamFs::new_with_name can not obtain fd for file \"%s\"\n", name); CAMEL_LOG_FULL_DEBUG ( " Full error text is : %s\n", strerror(errno)); - return NULL; + return; } - stream_fs = CAMEL_STREAM_FS (camel_stream_fs_new_with_fd (fd)); stream_fs->name = g_strdup (name); + CSFS_CLASS (stream_fs)->init_with_fd (stream_fs, fd); + + + +} + +CamelStream * +camel_stream_fs_new_with_name (const gchar *name, CamelStreamFsMode mode) +{ + CamelStreamFs *stream_fs; + stream_fs = gtk_type_new (camel_stream_fs_get_type ()); + CSFS_CLASS (stream_fs)->init_with_name (stream_fs, name, mode); + return CAMEL_STREAM (stream_fs); } @@ -178,7 +206,9 @@ camel_stream_fs_new_with_fd (int fd) CAMEL_LOG_FULL_DEBUG ( "Entering CamelStream::new_with_fd fd=%d\n",fd); stream_fs = gtk_type_new (camel_stream_fs_get_type ()); - stream_fs->fd = fd; + CSFS_CLASS (stream_fs)->init_with_fd (stream_fs, fd); + + return CAMEL_STREAM (stream_fs); } -- cgit