[monkey-bubble: 517/753] use bonobo-stream-fs directly, not via the storage plugin architecture.



commit 311825e001b0298b0e689fb08a4f2477e05bc6b8
Author: Michael Meeks <michael ximian com>
Date:   Tue Jul 10 11:39:52 2001 +0000

    use bonobo-stream-fs directly, not via the storage plugin architecture.
    
    2001-07-10  Michael Meeks  <michael ximian com>
    
    	* bonobo-moniker-file.c (bonobo_moniker_file_resolve):
    	use bonobo-stream-fs directly, not via the storage plugin
    	architecture.
    
    	* bonobo-stream-fs.c (bonobo_mode_to_fs): port to
    	BonoboObject / GObject.

 monikers/ChangeLog             |    9 ++
 monikers/Makefile.am-50588     |    2 +
 monikers/bonobo-moniker-file.c |    7 +-
 monikers/bonobo-stream-fs.c    |  253 +++++++++++++---------------------------
 monikers/bonobo-stream-fs.h    |   28 +++---
 5 files changed, 113 insertions(+), 186 deletions(-)
---
diff --git a/monikers/ChangeLog b/monikers/ChangeLog
index b4a157f..c7eb47e 100644
--- a/monikers/ChangeLog
+++ b/monikers/ChangeLog
@@ -1,3 +1,12 @@
+2001-07-10  Michael Meeks  <michael ximian com>
+
+	* bonobo-moniker-file.c (bonobo_moniker_file_resolve):
+	use bonobo-stream-fs directly, not via the storage plugin
+	architecture.
+
+	* bonobo-stream-fs.c (bonobo_mode_to_fs): port to
+	BonoboObject / GObject.
+
 2001-07-09  Michael Meeks  <michael ximian com>
 
 	* gnome-moniker-std.[ch]: add.
diff --git a/monikers/Makefile.am-50588 b/monikers/Makefile.am-50588
index c038380..a1cc88c 100644
--- a/monikers/Makefile.am-50588
+++ b/monikers/Makefile.am-50588
@@ -40,6 +40,8 @@ libmoniker_gnome_std_la_SOURCES = \
 	gnome-moniker-std.c		\
 	gnome-moniker-std.h		\
 	bonobo-moniker-extender-file.c	\
+	bonobo-stream-fs.h		\
+	bonobo-stream-fs.c		\
 	bonobo-moniker-file.c
 
 libmoniker_gnome_std_la_LIBADD = \
diff --git a/monikers/bonobo-moniker-file.c b/monikers/bonobo-moniker-file.c
index cc34055..1a8e016 100644
--- a/monikers/bonobo-moniker-file.c
+++ b/monikers/bonobo-moniker-file.c
@@ -15,6 +15,7 @@
 #include <bonobo/bonobo-moniker-util.h>
 
 #include "gnome-moniker-std.h"
+#include "bonobo-stream-fs.h"
 
 Bonobo_Unknown
 bonobo_moniker_file_resolve (BonoboMoniker               *moniker,
@@ -26,10 +27,10 @@ bonobo_moniker_file_resolve (BonoboMoniker               *moniker,
 	Bonobo_Unknown retval;
 
 	if (!strcmp (requested_interface, "IDL:Bonobo/Stream:1.0")) {
-		BonoboStream *stream;
+		BonoboObject *stream;
 		
-		stream = bonobo_stream_open ("fs", fname,
-					     Bonobo_Storage_READ, 0664, ev);
+		stream = BONOBO_OBJECT (bonobo_stream_fs_open (
+			fname, Bonobo_Storage_READ, 0664, ev));
 
 		if (BONOBO_EX (ev))
 			return CORBA_OBJECT_NIL;
diff --git a/monikers/bonobo-stream-fs.c b/monikers/bonobo-stream-fs.c
index a54f8af..e576566 100644
--- a/monikers/bonobo-stream-fs.c
+++ b/monikers/bonobo-stream-fs.c
@@ -10,19 +10,20 @@
  */
 #include <config.h>
 #include <stdio.h>
+#include <unistd.h>
 #include <fcntl.h>
 #include <sys/stat.h>
+#include <errno.h>
 #include <libgnome/gnome-defs.h>
 #include <libgnome/gnome-util.h>
 #include <libgnome/gnome-mime.h>
-#include <storage-modules/bonobo-stream-fs.h>
-#include <errno.h>
+#include "bonobo-stream-fs.h"
 
 struct _BonoboStreamFSPrivate {
 	gchar *mime_type;
 };
 
-static BonoboStreamClass *bonobo_stream_fs_parent_class;
+static BonoboObjectClass *bonobo_stream_fs_parent_class;
 
 static gint
 bonobo_mode_to_fs (Bonobo_Storage_OpenMode mode)
@@ -42,11 +43,12 @@ bonobo_mode_to_fs (Bonobo_Storage_OpenMode mode)
 }
 
 static Bonobo_StorageInfo*
-fs_get_info (BonoboStream                   *stream,
-	     const Bonobo_StorageInfoFields  mask,
-	     CORBA_Environment              *ev)
+fs_get_info (PortableServer_Servant         stream,
+	     const Bonobo_StorageInfoFields mask,
+	     CORBA_Environment             *ev)
 {
-	BonoboStreamFS *stream_fs = BONOBO_STREAM_FS (stream);
+	BonoboStreamFS *stream_fs = BONOBO_STREAM_FS (
+		bonobo_object (stream));
 	Bonobo_StorageInfo *si;
 	struct stat st;
 
@@ -83,20 +85,22 @@ fs_get_info (BonoboStream                   *stream,
 }
 
 static void
-fs_set_info (BonoboStream                   *stream,
-	     const Bonobo_StorageInfo       *info,
-	     const Bonobo_StorageInfoFields  mask,
-	     CORBA_Environment              *ev)
+fs_set_info (PortableServer_Servant         stream,
+	     const Bonobo_StorageInfo      *info,
+	     const Bonobo_StorageInfoFields mask,
+	     CORBA_Environment             *ev)
 {
 	CORBA_exception_set (ev, CORBA_USER_EXCEPTION, 
 			     ex_Bonobo_Stream_NotSupported, NULL);
 }
 
 static void
-fs_write (BonoboStream *stream, const Bonobo_Stream_iobuf *buffer,
-	  CORBA_Environment *ev)
+fs_write (PortableServer_Servant     stream,
+	  const Bonobo_Stream_iobuf *buffer,
+	  CORBA_Environment         *ev)
 {
-	BonoboStreamFS *stream_fs = BONOBO_STREAM_FS (stream);
+	BonoboStreamFS *stream_fs = BONOBO_STREAM_FS (
+		bonobo_object (stream));
 
 	errno = EINTR;
 	while ((write (stream_fs->fd, buffer->_buffer, buffer->_length) == -1)
@@ -113,12 +117,13 @@ fs_write (BonoboStream *stream, const Bonobo_Stream_iobuf *buffer,
 }
 
 static void
-fs_read (BonoboStream         *stream,
-	 CORBA_long            count,
-	 Bonobo_Stream_iobuf **buffer,
-	 CORBA_Environment    *ev)
+fs_read (PortableServer_Servant stream,
+	 CORBA_long             count,
+	 Bonobo_Stream_iobuf  **buffer,
+	 CORBA_Environment     *ev)
 {
-	BonoboStreamFS *stream_fs = BONOBO_STREAM_FS (stream);
+	BonoboStreamFS *stream_fs = BONOBO_STREAM_FS (
+		bonobo_object (stream));
 	CORBA_octet *data;
 	int bytes_read;
 	
@@ -155,12 +160,13 @@ fs_read (BonoboStream         *stream,
 }
 
 static CORBA_long
-fs_seek (BonoboStream           *stream,
-	 CORBA_long              offset, 
-	 Bonobo_Stream_SeekType  whence,
-	 CORBA_Environment      *ev)
+fs_seek (PortableServer_Servant stream,
+	 CORBA_long             offset, 
+	 Bonobo_Stream_SeekType whence,
+	 CORBA_Environment     *ev)
 {
-	BonoboStreamFS *stream_fs = BONOBO_STREAM_FS (stream);
+	BonoboStreamFS *stream_fs = BONOBO_STREAM_FS (
+		bonobo_object (stream));
 	int fs_whence;
 	CORBA_long pos;
 
@@ -187,11 +193,12 @@ fs_seek (BonoboStream           *stream,
 }
 
 static void
-fs_truncate (BonoboStream      *stream,
-	     const CORBA_long   new_size, 
-	     CORBA_Environment *ev)
+fs_truncate (PortableServer_Servant stream,
+	     const CORBA_long       new_size, 
+	     CORBA_Environment     *ev)
 {
-	BonoboStreamFS *stream_fs = BONOBO_STREAM_FS (stream);
+	BonoboStreamFS *stream_fs = BONOBO_STREAM_FS (
+		bonobo_object (stream));
 
 	if (ftruncate (stream_fs->fd, new_size) == 0)
 		return;
@@ -205,90 +212,23 @@ fs_truncate (BonoboStream      *stream,
 }
 
 static void
-fs_copy_to  (BonoboStream      *stream,
-	     const CORBA_char  *dest,
-	     const CORBA_long   bytes,
-	     CORBA_long        *read_bytes,
-	     CORBA_long        *written_bytes,
-	     CORBA_Environment *ev)
-{
-	BonoboStreamFS *stream_fs = BONOBO_STREAM_FS (stream);
-	gchar data[4096];
-	CORBA_unsigned_long more = bytes;
-	int v, w;
-	int fd_out;
-
-	*read_bytes = 0;
-	*written_bytes = 0;
-
-	if ((fd_out = creat(dest, 0644)) == -1)
-		goto copy_to_except;
-     
-	do {
-		if (bytes == -1) 
-			more = sizeof (data);
-
-		do {
-			v = read (stream_fs->fd, data, 
-				  MIN (sizeof (data), more));
-		} while ((v == -1) && (errno == EINTR));
-
-		if (v == -1) 
-			goto copy_to_except;
-
-		if (v <= 0) 
-			break;
-
-		*read_bytes += v;
-		more -= v;
-
-		do {
-			w = write (fd_out, data, v);
-		} while (w == -1 && errno == EINTR);
-		
-		if (w == -1)
-			goto copy_to_except;
-
-		*written_bytes += w;
-			
-	} while ((more > 0 || bytes == -1) && v > 0);
-
-	close (fd_out);
-
-	return;
-
- copy_to_except:
-
-	if (fd_out != -1)
-		close (fd_out);
-
-	if (errno == EACCES)
-		CORBA_exception_set (ev, CORBA_USER_EXCEPTION, 
-				     ex_Bonobo_Stream_NoPermission, NULL);
-	else
-		CORBA_exception_set (ev, CORBA_USER_EXCEPTION, 
-				     ex_Bonobo_Stream_IOError, NULL);
-}
-
-static void
-fs_commit (BonoboStream *stream,
-	   CORBA_Environment *ev)
+fs_commit (PortableServer_Servant stream,
+	   CORBA_Environment     *ev)
 {
         CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
                              ex_Bonobo_Stream_NotSupported, NULL);
 }
 
 static void
-fs_revert (BonoboStream *stream,
-	   CORBA_Environment *ev)
+fs_revert (PortableServer_Servant stream,
+	   CORBA_Environment     *ev)
 {
         CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
                              ex_Bonobo_Stream_NotSupported, NULL);
 }
 
-
 static void
-fs_destroy (GtkObject *object)
+fs_destroy (BonoboObject *object)
 {
 	BonoboStreamFS *stream_fs = BONOBO_STREAM_FS (object);
 	
@@ -303,39 +243,42 @@ fs_destroy (GtkObject *object)
 	if (stream_fs->priv->mime_type)
 		g_free (stream_fs->priv->mime_type);
 	stream_fs->priv->mime_type = NULL;
+
+	bonobo_stream_fs_parent_class->destroy (object);
 }
 
 static void
-fs_finalize (GtkObject *object)
+fs_finalize (GObject *object)
 {
 	BonoboStreamFS *stream_fs = BONOBO_STREAM_FS (object);
 	
 	if (stream_fs->priv)
 		g_free (stream_fs->priv);
 	stream_fs->priv = NULL;
+
+	bonobo_stream_fs_parent_class->parent_class.finalize (object);
 }
 
 static void
 bonobo_stream_fs_class_init (BonoboStreamFSClass *klass)
 {
-	GtkObjectClass    *oclass = (GtkObjectClass *) klass;
-	BonoboStreamClass *sclass = BONOBO_STREAM_CLASS (klass);
+	GObjectClass    *oclass = (GObjectClass *) klass;
+	POA_Bonobo_Stream__epv *epv = &klass->epv;
 	
 	bonobo_stream_fs_parent_class = 
-		gtk_type_class (bonobo_stream_get_type ());
-
-	sclass->get_info = fs_get_info;
-	sclass->set_info = fs_set_info;
-	sclass->write    = fs_write;
-	sclass->read     = fs_read;
-	sclass->seek     = fs_seek;
-	sclass->truncate = fs_truncate;
-	sclass->copy_to  = fs_copy_to;
-        sclass->commit   = fs_commit;
-        sclass->revert   = fs_revert;
-
-	oclass->destroy = fs_destroy;
+		g_type_class_peek_parent (klass);
+
+	epv->getInfo  = fs_get_info;
+	epv->setInfo  = fs_set_info;
+	epv->write    = fs_write;
+	epv->read     = fs_read;
+	epv->seek     = fs_seek;
+	epv->truncate = fs_truncate;
+        epv->commit   = fs_commit;
+        epv->revert   = fs_revert;
+
 	oclass->finalize = fs_finalize;
+	((BonoboObjectClass *)oclass)->destroy = fs_destroy;
 }
 
 static void
@@ -348,77 +291,49 @@ bonobo_stream_fs_init (BonoboStreamFS *stream_fs)
 /**
  * bonobo_stream_fs_get_type:
  *
- * Returns the GtkType for the BonoboStreamFS class.
+ * Returns the GType for the BonoboStreamFS class.
  */
-GtkType
+GType
 bonobo_stream_fs_get_type (void)
 {
-	static GtkType type = 0;
+	static GType type = 0;
 
-	if (!type){
-		GtkTypeInfo info = {
-			"BonoboStreamFS",
-			sizeof (BonoboStreamFS),
+	if (!type) {
+		GTypeInfo info = {
 			sizeof (BonoboStreamFSClass),
-			(GtkClassInitFunc) bonobo_stream_fs_class_init,
-			(GtkObjectInitFunc) bonobo_stream_fs_init,
-			NULL, /* reserved 1 */
-			NULL, /* reserved 2 */
-			(GtkClassInitFunc) NULL
+			(GBaseInitFunc) NULL,
+			(GBaseFinalizeFunc) NULL,
+			(GClassInitFunc) bonobo_stream_fs_class_init,
+			NULL, /* class_finalize */
+			NULL, /* class_data */
+			sizeof (BonoboStreamFS),
+			0, /* n_preallocs */
+			(GInstanceInitFunc) bonobo_stream_fs_init
 		};
 
-		type = gtk_type_unique (bonobo_stream_get_type (), &info);
+		type = bonobo_type_unique (
+			BONOBO_OBJECT_TYPE,
+			POA_Bonobo_Stream__init, NULL,
+			G_STRUCT_OFFSET (BonoboStreamFSClass, epv),
+			&info, "BonoboStreamFS");
 	}
 
 	return type;
 }
 
-/**
- * bonobo_stream_fs_construct:
- * @stream: The BonoboStreamFS object to initialize.
- * @corba_stream: The CORBA server which implements the BonoboStreamFS service.
- *
- * This function initializes an object of type BonoboStreamFS using the
- * provided CORBA server @corba_stream.
- *
- * Returns the constructed BonoboStreamFS @stream.
- */
-BonoboStream *
-bonobo_stream_fs_construct (BonoboStreamFS *stream,
-			   Bonobo_Stream corba_stream)
-{
-	g_return_val_if_fail (stream != NULL, NULL);
-	g_return_val_if_fail (BONOBO_IS_STREAM (stream), NULL);
-	g_return_val_if_fail (corba_stream != CORBA_OBJECT_NIL, NULL);
-
-	bonobo_object_construct (
-		BONOBO_OBJECT (stream), corba_stream);
-
-	return BONOBO_STREAM (stream);
-}
-
-static BonoboStream *
+static BonoboStreamFS *
 bonobo_stream_create (int fd, const char *path)
 {
 	BonoboStreamFS *stream_fs;
-	Bonobo_Stream corba_stream;
 
-	stream_fs = gtk_type_new (bonobo_stream_fs_get_type ());
-	if (stream_fs == NULL)
+	if (!(stream_fs = g_object_new (bonobo_stream_fs_get_type (), NULL)))
 		return NULL;
 	
 	stream_fs->fd = fd;
-	stream_fs->priv->mime_type = g_strdup (gnome_mime_type_of_file (path));
-	
-	corba_stream = bonobo_stream_corba_object_create (
-		BONOBO_OBJECT (stream_fs));
-
-	if (corba_stream == CORBA_OBJECT_NIL) {
-		bonobo_object_unref (BONOBO_OBJECT (stream_fs));
-		return NULL;
-	}
+	stream_fs->priv->mime_type = g_strdup (
+		gnome_mime_type_of_file (path));
 
-	return bonobo_stream_fs_construct (stream_fs, corba_stream);
+	return stream_fs;
 }
 
 
@@ -430,11 +345,11 @@ bonobo_stream_create (int fd, const char *path)
  * Creates a new BonoboStream object for the filename specified by
  * @path.  
  */
-BonoboStream *
+BonoboStreamFS *
 bonobo_stream_fs_open (const char *path, gint flags, gint mode,
 		       CORBA_Environment *ev)
 {
-	BonoboStream *stream;
+	BonoboStreamFS *stream;
 	struct stat st;
 	int v, fd;
 	gint fs_flags;
diff --git a/monikers/bonobo-stream-fs.h b/monikers/bonobo-stream-fs.h
index 29931e1..6fef111 100644
--- a/monikers/bonobo-stream-fs.h
+++ b/monikers/bonobo-stream-fs.h
@@ -11,15 +11,15 @@
 #ifndef _BONOBO_STREAM_FS_H_
 #define _BONOBO_STREAM_FS_H_
 
-#include <bonobo/bonobo-stream.h>
+#include <bonobo/bonobo-object.h>
 
-BEGIN_GNOME_DECLS
+G_BEGIN_DECLS
 
 #define BONOBO_STREAM_FS_TYPE        (bonobo_stream_fs_get_type ())
-#define BONOBO_STREAM_FS(o)          (GTK_CHECK_CAST ((o), BONOBO_STREAM_FS_TYPE, BonoboStreamFS))
-#define BONOBO_STREAM_FS_CLASS(k)    (GTK_CHECK_CLASS_CAST((k), BONOBO_STREAM_FS_TYPE, BonoboStreamFSClass))
-#define BONOBO_IS_STREAM_FS(o)       (GTK_CHECK_TYPE ((o), BONOBO_STREAM_FS_TYPE))
-#define BONOBO_IS_STREAM_FS_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), BONOBO_STREAM_FS_TYPE))
+#define BONOBO_STREAM_FS(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), BONOBO_STREAM_FS_TYPE, BonoboStreamFS))
+#define BONOBO_STREAM_FS_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST((k), BONOBO_STREAM_FS_TYPE, BonoboStreamFSClass))
+#define BONOBO_IS_STREAM_FS(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), BONOBO_STREAM_FS_TYPE))
+#define BONOBO_IS_STREAM_FS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), BONOBO_STREAM_FS_TYPE))
 
 typedef struct _BonoboStreamFS BonoboStreamFS;
 typedef struct _BonoboStreamFSPrivate BonoboStreamFSPrivate;
@@ -34,15 +34,15 @@ struct _BonoboStreamFS {
 
 typedef struct {
 	BonoboObjectClass parent_class;
+
+	POA_Bonobo_Stream__epv epv;
 } BonoboStreamFSClass;
 
-GtkType          bonobo_stream_fs_get_type     (void);
-BonoboStream    *bonobo_stream_fs_construct    (BonoboStreamFS *stream,
-						Bonobo_Stream corba_stream);
-BonoboStream    *bonobo_stream_fs_open         (const char *path, 
-						gint flags,
-						gint mode, 
-						CORBA_Environment *ev);	
-END_GNOME_DECLS
+GType           bonobo_stream_fs_get_type (void);
+BonoboStreamFS *bonobo_stream_fs_open     (const char *path, 
+					   gint flags, gint mode, 
+					   CORBA_Environment *ev);	
+
+G_END_DECLS
 
 #endif /* _BONOBO_STREAM_FS_H_ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]