storage interface cleanup
- From: Dietmar Maurer <dietmar maurer-it com>
- To: Michael Meeks <michael helixcode com>, "gnome-components-list gnome org" <gnome-components-list gnome org>
- Subject: storage interface cleanup
- Date: Thu, 19 Oct 2000 14:04:01 +0200
Here is a first patch to cleanup the storage (stream) interface:
Index: idl/bonobo-storage.idl
===================================================================
RCS file: /cvs/gnome/bonobo/idl/bonobo-storage.idl,v
retrieving revision 1.18
diff -u -r1.18 bonobo-storage.idl
--- idl/bonobo-storage.idl 2000/10/19 08:44:23 1.18
+++ idl/bonobo-storage.idl 2000/10/19 10:52:00
@@ -46,7 +46,7 @@
*
* writes the buffer to this stream.
*/
- long write (in iobuf buffer)
+ void write (in iobuf buffer)
raises (NoPermission, IOError);
/**
@@ -57,7 +57,7 @@
* Sets the read/write pointer to @offset (relative to @whence)
*/
long seek (in long offset, in SeekType whence)
- raises (IOError);
+ raises (IOError, NotSupported);
/**
@@ -66,7 +66,7 @@
*
*/
void truncate (in long length)
- raises (NoPermission);
+ raises (IOError, NoPermission, NotSupported);
/**
* copy_to:
@@ -81,48 +81,8 @@
*/
void copy_to (in string dest, in long bytes,
inout long read, inout long written)
- raises (NoPermission);
-
+ raises (IOError, NoPermission);
- /**
- * commit:
- *
- * Commits any pending changes to the Storage
- */
- void commit ();
-
- /**
- * close:
- *
- * Close the Stream
- */
- void close ();
-
- /**
- * eos:
- *
- * End of Stream?
- */
-
- boolean eos ();
-
- /**
- * length:
- *
- * Returns the length of the stream
- */
- long length ()
- raises (NotSupported);
-
- /**
- * lock_region:
- *
- */
-
- /**
- * unlock_region:
- *
- */
};
interface Storage : Unknown {
Index: bonobo/bonobo-stream-client.c
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-stream-client.c,v
retrieving revision 1.11
diff -u -r1.11 bonobo-stream-client.c
--- bonobo/bonobo-stream-client.c 2000/10/17 16:58:46 1.11
+++ bonobo/bonobo-stream-client.c 2000/10/19 10:52:14
@@ -49,19 +49,17 @@
goto alloc_error;
for (pos = 0; pos < size;) {
- CORBA_long v;
-
buf->_buffer = (mem + pos);
buf->_length = (pos + CORBA_BLOCK_SIZE < size) ?
CORBA_BLOCK_SIZE : size - pos;
buf->_maximum = buf->_length;
- v = Bonobo_Stream_write (stream, buf, ev);
+ Bonobo_Stream_write (stream, buf, ev);
if (ev->_major != CORBA_NO_EXCEPTION) {
CORBA_free (buf);
return;
}
- pos += v;
+ pos += buf->_length;
}
CORBA_free (buf);
Index: bonobo/bonobo-stream-memory.c
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-stream-memory.c,v
retrieving revision 1.30
diff -u -r1.30 bonobo-stream-memory.c
--- bonobo/bonobo-stream-memory.c 2000/10/17 16:58:46 1.30
+++ bonobo/bonobo-stream-memory.c 2000/10/19 10:52:14
@@ -42,7 +42,7 @@
smem->pos = new_size;
}
-static CORBA_long
+static void
mem_write (BonoboStream *stream, const Bonobo_Stream_iobuf *buffer,
CORBA_Environment *ev)
{
@@ -51,7 +51,7 @@
if (smem->read_only){
g_warning ("Should signal an exception here");
- return 0;
+ return;
}
if (smem->pos + len > smem->size){
@@ -70,7 +70,7 @@
memcpy (smem->buffer + smem->pos, buffer->_buffer, len);
smem->pos += len;
- return len;
+ return;
}
static void
@@ -171,12 +171,6 @@
}
static void
-mem_commit (BonoboStream *stream,
- CORBA_Environment *ev)
-{
-}
-
-static void
mem_destroy (GtkObject *object)
{
BonoboStreamMem *smem = BONOBO_STREAM_MEM (object);
@@ -218,7 +212,6 @@
sclass->seek = mem_seek;
sclass->truncate = mem_truncate;
sclass->copy_to = mem_copy_to;
- sclass->commit = mem_commit;
klass->get_buffer = mem_get_buffer;
klass->get_size = mem_get_size;
Index: bonobo/bonobo-stream.c
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-stream.c,v
retrieving revision 1.25
diff -u -r1.25 bonobo-stream.c
--- bonobo/bonobo-stream.c 2000/10/19 08:44:10 1.25
+++ bonobo/bonobo-stream.c 2000/10/19 10:52:14
@@ -34,14 +34,14 @@
CLASS (stream)->read (stream, count, buffer, ev);
}
-static CORBA_long
+static void
impl_write (PortableServer_Servant servant,
const Bonobo_Stream_iobuf *buffer,
CORBA_Environment *ev)
{
BonoboStream *stream = bonobo_stream_from_servant (servant);
- return CLASS (stream)->write (stream, buffer, ev);
+ CLASS (stream)->write (stream, buffer, ev);
}
static CORBA_long
@@ -78,38 +78,6 @@
CLASS (stream)->copy_to (stream, dest, bytes, read, written, ev);
}
-static void
-impl_commit (PortableServer_Servant servant, CORBA_Environment * ev)
-{
- BonoboStream *stream = bonobo_stream_from_servant (servant);
-
- CLASS (stream)->commit (stream, ev);
-}
-
-static void
-impl_close (PortableServer_Servant servant, CORBA_Environment * ev)
-{
- BonoboStream *stream = bonobo_stream_from_servant (servant);
-
- CLASS (stream)->close (stream, ev);
-}
-
-static CORBA_boolean
-impl_eos (PortableServer_Servant servant, CORBA_Environment * ev)
-{
- BonoboStream *stream = bonobo_stream_from_servant (servant);
-
- return CLASS (stream)->eos (stream, ev);
-}
-
-static CORBA_long
-impl_length (PortableServer_Servant servant, CORBA_Environment * ev)
-{
- BonoboStream *stream = bonobo_stream_from_servant (servant);
-
- return CLASS (stream)->length (stream, ev);
-}
-
/**
* bonobo_stream_get_epv:
*/
@@ -125,10 +93,6 @@
epv->seek = impl_seek;
epv->truncate = impl_truncate;
epv->copy_to = impl_copy_to;
- epv->commit = impl_commit;
- epv->close = impl_close;
- epv->eos = impl_eos;
- epv->length = impl_length;
return epv;
}
Index: bonobo/bonobo-stream.h
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-stream.h,v
retrieving revision 1.18
diff -u -r1.18 bonobo-stream.h
--- bonobo/bonobo-stream.h 2000/10/19 08:44:10 1.18
+++ bonobo/bonobo-stream.h 2000/10/19 10:52:14
@@ -30,7 +30,7 @@
/*
* virtual methods
*/
- CORBA_long (*write) (BonoboStream *stream,
+ void (*write) (BonoboStream *stream,
const Bonobo_Stream_iobuf *buffer,
CORBA_Environment *ev);
void (*read) (BonoboStream *stream, CORBA_long count,
@@ -47,14 +47,6 @@
const CORBA_long bytes,
CORBA_long *read,
CORBA_long *written,
- CORBA_Environment *ev);
- void (*commit) (BonoboStream *stream,
- CORBA_Environment *ev);
- void (*close) (BonoboStream *stream,
- CORBA_Environment *ev);
- CORBA_boolean (*eos) (BonoboStream *stream,
- CORBA_Environment *ev);
- CORBA_long (*length) (BonoboStream *stream,
CORBA_Environment *ev);
} BonoboStreamClass;
Index: storage-modules/bonobo-storage-efs.c
===================================================================
RCS file: /cvs/gnome/bonobo/storage-modules/bonobo-storage-efs.c,v
retrieving revision 1.19
diff -u -r1.19 bonobo-storage-efs.c
--- storage-modules/bonobo-storage-efs.c 2000/10/19 08:45:05 1.19
+++ storage-modules/bonobo-storage-efs.c 2000/10/19 10:52:28
@@ -2,7 +2,7 @@
* bonobo-storage-efs.c: libefs based Storage implementation
*
* Author:
- * Dietmar Maurer (dm vlsivie tuwien ac at)
+ * Dietmar Maurer (dietmar maurer-it com)
*
*
* Problems:
Index: storage-modules/bonobo-stream-efs.c
===================================================================
RCS file: /cvs/gnome/bonobo/storage-modules/bonobo-stream-efs.c,v
retrieving revision 1.14
diff -u -r1.14 bonobo-stream-efs.c
--- storage-modules/bonobo-stream-efs.c 2000/10/11 17:07:17 1.14
+++ storage-modules/bonobo-stream-efs.c 2000/10/19 10:52:28
@@ -2,7 +2,7 @@
* bonobo-stream-efs.c: libefs based Stream implementation
*
* Author:
- * Dietmar Maurer (dm vlsivie tuwien ac at)
+ * Dietmar Maurer (dietmar maurer-it com)
*
*/
@@ -31,11 +31,13 @@
if (stream_efs->file)
efs_file_close (stream_efs->file);
+ stream_efs->file = NULL;
+
if (stream_efs->storage)
bonobo_object_unref (BONOBO_OBJECT (stream_efs->storage));
}
-static CORBA_long
+static void
real_write (BonoboStream *stream, const Bonobo_Stream_iobuf *buffer,
CORBA_Environment *ev)
{
@@ -45,10 +47,10 @@
buffer->_length)) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_Bonobo_Stream_IOError, NULL);
- return 0;
+ return;
}
- return buffer->_length;
+ return;
}
static void
@@ -114,22 +116,64 @@
CORBA_Environment *ev)
{
BonoboStreamEFS *stream_efs = BONOBO_STREAM_EFS (stream);
+ EFSResult res;
+
+ res = efs_file_trunc (stream_efs->file, new_size);
- if (efs_file_trunc (stream_efs->file, new_size) < 0)
+ if (res == EFS_ERR_NOSEEK)
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_Bonobo_Stream_NotSupported, NULL);
+
+ else if (res == EFS_ERR_PERM)
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_Bonobo_Stream_NoPermission, NULL);
+
+ else if (res != EFS_ERR_OK)
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_Bonobo_Stream_IOError, NULL);
+
}
static void
-real_close (BonoboStream *stream,
- CORBA_Environment *ev)
+real_copy_to (BonoboStream *stream, const CORBA_char *dest,
+ const CORBA_long bytes, CORBA_long *read_bytes,
+ CORBA_long *written_bytes, CORBA_Environment *ev)
{
- BonoboStreamEFS *stream_efs = BONOBO_STREAM_EFS (stream);
+ BonoboStreamEFS *sfs = BONOBO_STREAM_EFS (stream);
+ gchar data[4096];
+ CORBA_unsigned_long more = bytes;
+ gint v;
+ EFSFile *out_file;
- if (efs_file_close (stream_efs->file) < 0)
- CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
- ex_Bonobo_Stream_IOError, NULL);
- stream_efs->file = NULL;
+ *read_bytes = 0;
+ *written_bytes = 0;
+
+ if (efs_file_open (&out_file, sfs->storage->dir, dest,
+ EFS_CREATE|EFS_EXCL)) return;
+
+ do {
+ if (bytes == -1) more = 4096;
+
+ if (efs_file_read (sfs->file, data, MIN (4096, more), &v)) {
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_Bonobo_Stream_IOError, NULL);
+ break;
+ }
+
+ if (v <= 0) break;
+
+ *read_bytes += v;
+ more -= v;
+
+ if (efs_file_write (out_file, data, v)) {
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_Bonobo_Stream_IOError, NULL);
+ break;
+ }
+
+ } while(more > 0 && v > 0);
+
+ efs_close (out_file);
}
static void
@@ -142,8 +186,7 @@
sclass->read = real_read;
sclass->seek = real_seek;
sclass->truncate = real_truncate;
- sclass->close = real_close;
- /* FIXME: impl eof ! */
+ sclass->copy_to = real_copy_to;
object_class->destroy = bonobo_stream_efs_destroy;
}
Index: storage-modules/bonobo-stream-efs.h
===================================================================
RCS file: /cvs/gnome/bonobo/storage-modules/bonobo-stream-efs.h,v
retrieving revision 1.4
diff -u -r1.4 bonobo-stream-efs.h
--- storage-modules/bonobo-stream-efs.h 2000/10/11 17:07:17 1.4
+++ storage-modules/bonobo-stream-efs.h 2000/10/19 10:52:28
@@ -22,12 +22,12 @@
BonoboStreamClass parent_class;
} BonoboStreamEFSClass;
-GtkType bonobo_stream_efs_get_type (void);
+GtkType bonobo_stream_efs_get_type (void);
BonoboStream *bonobo_stream_efs_open (BonoboStorageEFS *storage,
- const CORBA_char *path,
- Bonobo_Storage_OpenMode mode);
+ const CORBA_char *path,
+ Bonobo_Storage_OpenMode mode);
BonoboStream *bonobo_stream_efs_create (BonoboStorageEFS *storage,
- const CORBA_char *path);
+ const CORBA_char *path);
END_GNOME_DECLS
Index: storage-modules/bonobo-stream-fs.c
===================================================================
RCS file: /cvs/gnome/bonobo/storage-modules/bonobo-stream-fs.c,v
retrieving revision 1.34
diff -u -r1.34 bonobo-stream-fs.c
--- storage-modules/bonobo-stream-fs.c 2000/10/19 08:45:05 1.34
+++ storage-modules/bonobo-stream-fs.c 2000/10/19 10:52:28
@@ -153,67 +153,19 @@
}
static void
-fs_commit (BonoboStream *stream,
- CORBA_Environment *ev)
+fs_destroy (GtkObject *object)
{
- g_warning ("Implement fs commit");
-}
-
-static void
-fs_close (BonoboStream *stream,
- CORBA_Environment *ev)
-{
- BonoboStreamFS *sfs = BONOBO_STREAM_FS (stream);
-
- if (close (sfs->fd))
- g_warning ("Close failed");
- sfs->fd = -1;
-}
-
-static CORBA_boolean
-fs_eos (BonoboStream *stream,
- CORBA_Environment *ev)
-{
- BonoboStreamFS *sfs = BONOBO_STREAM_FS (stream);
- off_t offset;
- struct stat st;
-
- if (fstat (sfs->fd, &st)) {
- g_warning ("fstat failed");
- return 1;
- }
-
- offset = lseek (sfs->fd, 0, SEEK_CUR);
-
- if (offset == -1) {
- g_warning ("seek failed");
- return 1;
- }
-
- if (offset == st.st_size)
- return 1;
+ BonoboStreamFS *sfs = BONOBO_STREAM_FS (object);
- return 0;
-}
+ if (close (sfs->fd)) g_warning ("Close failed");
-static CORBA_long
-fs_length (BonoboStream *stream,
- CORBA_Environment *ev)
-{
- BonoboStreamFS *sfs = BONOBO_STREAM_FS (stream);
- struct stat st;
-
- if (fstat (sfs->fd, &st)) {
- g_warning ("Fstat failed");
- return 0;
- } else
- return st.st_size;
+ sfs->fd = -1;
}
-
static void
bonobo_stream_fs_class_init (BonoboStreamFSClass *klass)
{
+ GtkObjectClass *oclass = (GtkObjectClass *) klass;
BonoboStreamClass *sclass = BONOBO_STREAM_CLASS (klass);
bonobo_stream_fs_parent_class = gtk_type_class (bonobo_stream_get_type ());
@@ -223,10 +175,8 @@
sclass->seek = fs_seek;
sclass->truncate = fs_truncate;
sclass->copy_to = fs_copy_to;
- sclass->commit = fs_commit;
- sclass->close = fs_close;
- sclass->eos = fs_eos;
- sclass->length = fs_length;
+
+ oclass->destroy = fs_destroy;
}
/**
Index: storage-modules/bonobo-stream-fs.h
===================================================================
RCS file: /cvs/gnome/bonobo/storage-modules/bonobo-stream-fs.h,v
retrieving revision 1.10
diff -u -r1.10 bonobo-stream-fs.h
--- storage-modules/bonobo-stream-fs.h 2000/10/19 08:45:05 1.10
+++ storage-modules/bonobo-stream-fs.h 2000/10/19 10:52:28
@@ -36,11 +36,11 @@
BonoboStreamClass parent_class;
} BonoboStreamFSClass;
-GtkType bonobo_stream_fs_get_type (void);
+GtkType bonobo_stream_fs_get_type (void);
BonoboStream *bonobo_stream_fs_open (const gchar *path, gint flags);
BonoboStream *bonobo_stream_fs_create (const CORBA_char *path);
BonoboStream *bonobo_stream_fs_construct (BonoboStreamFS *stream,
- Bonobo_Stream corba_stream);
+ Bonobo_Stream corba_stream);
END_GNOME_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]