Commit 410dcbe8 authored by Michael Meeks's avatar Michael Meeks
Browse files

Major libole2 API overhaul: its lots cleaner, but still rough in places,

Initial attempt at Bonobo OLE storage implementation.
parent 4ce84a48
1999-08-13 Michael Meeks <michael@imaginator.com>
* ole.c (enter_dir): Major re-work, to use paths.
1999-08-12 Jody Goldberg <jgoldberg@home.com>
* ms-formula-read.c (ms_excel_parse_formula) :
......
1999-08-14 Michael Meeks <michael@imaginator.com>
* ms-ole.[ch]: Get seek to return new position.
* ms-ole.[ch]: Rehash all daft guint32 references converting
them to MsOlePos's.
* README: More chat.
* ms-ole.c (ms_ole_stream_open): Setup 'dir'
* ms-ole.h (struct _MsOleStream): Re-ordered elements to make
privacy more explicit, add 'dir' element to keep track of
the file's directory handle.
* ms-ole-summary.c (ms_ole_summary_open, ms_ole_summary_create):
Use new open_name semantics.
* gnome-stream-ole.[ch]: Created.
* gnome-storage-ole.[ch]: Created.
1999-08-13 Michael Meeks <michael@imaginator.com>
* ms-ole.c (ms_ole_path_decode): Created.
(ms_ole_stream_open_name): Changed API to use path.
(ms_ole_file_decode): Added - This whole API needs fixing !
* Makefile.am: Added gnome-stream/storage bits.
* gnome-stream-ole.[ch]: Added.
* gnome-storage-ole.[ch]: Added.
1999-07-26 Michael Meeks <michael@edenproject.org>
* ms-ole-summary.c (ms_ole_summary_create_stream): Implemented.
......
......@@ -5,7 +5,11 @@ INCLUDES = \
-I$(top_srcdir)/src \
$(GNOME_INCLUDEDIR)
if BONOBO
noinst_LIBRARIES = libole2.a libstorage_ole.a
else
noinst_LIBRARIES = libole2.a
endif
libole2_a_SOURCES = \
ms-ole.c \
......@@ -13,3 +17,10 @@ libole2_a_SOURCES = \
ms-ole-summary.c \
ms-ole-summary.h
libstorage_ole_a_SOURCES = \
gnome-storage-ole.c \
gnome-storage-ole.h \
gnome-stream-ole.c \
gnome-stream-ole.h
......@@ -7,8 +7,14 @@ Much useful information will be gleaned from the work on wine by.
Marcus Meissner, Francis Beaudet, Sylvain St-Germain
and Thuy Nguyen
This code has now been re-written for the 3rd and hopefully
final time.
The code breaks fairly cleanly into two seperate pieces,
firstly the raw block API whether small or large, and 2ndly the FILE *
style wrapper on top of the block API. Since there are two types of
block, there are two functions per percieved method that are accessed
via the stream's function pointer. This has a lot of good performance
characteristics, despite the percieved overhead of a 'virtual' call.
The exception to this being ms_ole_lseek which is non-staticly linked
for homogeneity.
Further thanks for the summary information code go to
......
/*
* gnome-storage-ole.c: libole based Storage implementation
*
* Author:
* Michael Meeks <michael@imaginator.com>
*
* Problems:
*
* Directory and pathname stuff needs serious work.
*
*/
#include <config.h>
#include <glib.h>
#include "ms-ole.h"
#include "gnome-storage-ole.h"
#include "gnome-stream-ole.h"
/*
* Creates and activates the corba server
*/
static GnomeStorage *
create_ole_server (const GnomeStorageOLE *ole)
{
GnomeObject *object = GNOME_OBJECT(ole);
POA_GNOME_Storage *servant;
GNOME_Storage corba_storage;
servant = (POA_GNOME_Storage *) g_new0 (GnomeObjectServant, 1);
servant->vepv = &gnome_storage_vepv;
POA_GNOME_Storage__init ((PortableServer_Servant) servant,
&object->ev);
if (object->ev._major != CORBA_NO_EXCEPTION){
g_free (servant);
return NULL;
}
corba_storage = gnome_object_activate_servant(object, servant);
return gnome_storage_construct(GNOME_STORAGE(ole),
corba_storage);
}
static void
gnome_ole_destroy (GtkObject *object)
{
GnomeStorageOLE *ole = GNOME_STORAGE_OLE (object);
ms_ole_destroy (ole->f);
}
static GnomeStream *
real_create_stream (GnomeStorage *storage, const CORBA_char *path,
CORBA_Environment *ev)
{
GnomeStorageOLE *ole = GNOME_STORAGE_OLE (storage);
return gnome_stream_ole_create (ole, path);
}
static GnomeStream *
real_open_stream (GnomeStorage *storage, const CORBA_char *path,
GNOME_Storage_OpenMode mode, CORBA_Environment *ev)
{
GnomeStorageOLE *ole = GNOME_STORAGE_OLE (storage);
return gnome_stream_ole_open (ole, path, mode);
}
static GnomeStorage *
real_create_storage (GnomeStorage *storage, const CORBA_char *path,
CORBA_Environment *ev)
{
/* GnomeStorageOLE *ole = GNOME_STORAGE_OLE (storage); */
GnomeStorageOLE *sole;
MsOle *f;
if (!(f = ms_ole_create (path))) {
CORBA_exception_set(ev, CORBA_USER_EXCEPTION,
ex_GNOME_Storage_NameExists, NULL);
return NULL;
}
sole = gtk_type_new (gnome_storage_ole_get_type ());
sole->f = f;
create_ole_server (sole);
return GNOME_STORAGE (sole);
}
static GnomeStorage *
real_open_storage (GnomeStorage *storage, const CORBA_char *path,
CORBA_Environment *ev)
{
/* GnomeStorageOLE *ole = GNOME_STORAGE_OLE (storage); */
GnomeStorageOLE *sole;
MsOle *f;
if (!(f = ms_ole_open (path))) {
CORBA_exception_set(ev, CORBA_USER_EXCEPTION,
ex_GNOME_Storage_NotFound, NULL);
return NULL;
}
sole = gtk_type_new (gnome_storage_ole_get_type ());
sole->f = f;
create_ole_server (sole);
return GNOME_STORAGE (sole);
}
static void
real_copy_to (GnomeStorage *storage, GNOME_Storage target,
CORBA_Environment *ev)
{
g_warning ("Not yet implemented");
}
static void
real_rename (GnomeStorage *storage, const CORBA_char *path,
const CORBA_char *new_path, CORBA_Environment *ev)
{
/* GnomeStorageOLE *ole = GNOME_STORAGE_OLE (storage); */
g_warning ("No OLE rename yet");
/* if (!ole_rename(ole->dir, path, new_path)) {
CORBA_exception_set(ev, CORBA_USER_EXCEPTION,
ex_GNOME_Storage_NotFound, NULL);
}*/
}
static void
real_commit (GnomeStorage *storage, CORBA_Environment *ev)
{
/* GnomeStorageOLE *ole = GNOME_STORAGE_OLE (storage);
if (ole->owner) return;
ole_commit(ole->dir);*/
g_warning ("Why bother comitting ?");
}
static GNOME_Storage_directory_list *
real_list_contents (GnomeStorage *storage, const CORBA_char *path,
CORBA_Environment *ev)
{
GnomeStorageOLE *ole = GNOME_STORAGE_OLE (storage);
GNOME_Storage_directory_list *list;
MsOleDirectory *dir, *iter;
int i;
char **buf = NULL;
dir = ms_ole_path_decode (ole->f, path);
if (!dir) {
CORBA_exception_set(ev, CORBA_USER_EXCEPTION,
ex_GNOME_Storage_NotFound, NULL);
return NULL;
}
ms_ole_directory_enter (dir);
if (!dir) {
CORBA_exception_set(ev, CORBA_USER_EXCEPTION,
ex_GNOME_Storage_NotFound, NULL);
return NULL;
}
iter = ms_ole_directory_copy (dir);
while (ms_ole_directory_next (iter)) i++;
list = GNOME_Storage_directory_list__alloc();
CORBA_sequence_set_release (list, TRUE);
buf = CORBA_sequence_CORBA_string_allocbuf(i + 1);
i = 0;
do {
char *t = CORBA_string_alloc(strlen(dir->name));
strcpy (t, dir->name);
buf[i] = t;
i++;
} while (ms_ole_directory_next (dir));
ms_ole_directory_destroy (dir);
list->_length = i;
list->_buffer = buf;
return list;
}
static void
real_erase (GnomeStorage *storage, const CORBA_char *path,
CORBA_Environment *ev)
{
GnomeStorageOLE *ole = GNOME_STORAGE_OLE (storage);
MsOleDirectory *dir = ms_ole_path_decode (ole->f, path);
if (!dir)
CORBA_exception_set(ev, CORBA_USER_EXCEPTION,
ex_GNOME_Storage_NotFound, NULL);
else
ms_ole_directory_unlink (dir);
}
static void
gnome_ole_class_init (GnomeStorageOLEClass *class)
{
GtkObjectClass *object_class = (GtkObjectClass *) class;
GnomeStorageClass *sclass = GNOME_STORAGE_CLASS (class);
sclass->create_stream = real_create_stream;
sclass->open_stream = real_open_stream;
sclass->create_storage = real_create_storage;
sclass->open_storage = real_open_storage;
sclass->copy_to = real_copy_to;
sclass->rename = real_rename;
sclass->commit = real_commit;
sclass->list_contents = real_list_contents;
sclass->erase = real_erase;
object_class->destroy = gnome_ole_destroy;
}
GtkType
gnome_storage_ole_get_type (void)
{
static GtkType type = 0;
if (!type){
GtkTypeInfo info = {
"IDL:GNOME/StorageOLE:1.0",
sizeof (GnomeStorageOLE),
sizeof (GnomeStorageOLEClass),
(GtkClassInitFunc) gnome_ole_class_init,
(GtkObjectInitFunc) NULL,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gnome_storage_get_type (), &info);
}
return type;
}
/**
* gnome_ole_open:
* @path: path to a file that represents the storage
* @flags: flags
* @mode: mode
*
* Opens a GnomeStorage object in @path. The storage opened is an activated
* CORBA server for this storage.
*
* Returns the GnomeStorage GTK object.
*/
GnomeStorage *
gnome_storage_ole_open (const gchar *path, gint flags, gint mode)
{
GnomeStorageOLE *sole;
char m;
sole = gtk_type_new (gnome_storage_ole_get_type ());
if (flags == GNOME_SS_READ)
m = 'r';
else if (flags == GNOME_SS_WRITE)
m = 'w';
else {
g_warning ("Unimplemented flag");
return NULL;
}
if (!(sole->f = ms_ole_open (path))) {
gtk_object_destroy (GTK_OBJECT (sole));
return NULL;
}
if (!create_ole_server(sole)) {
gtk_object_destroy (GTK_OBJECT (sole));
return NULL;
}
return GNOME_STORAGE(sole);
}
/*
* Shared library entry point
*/
GnomeStorage *
gnome_storage_driver_open (const gchar *path, gint flags, gint mode)
{
return gnome_storage_ole_open (path, flags, mode);
}
#ifndef _GNOME_STORAGE_OLE_H_
#define _GNOME_STORAGE_OLE_H_
#include <bonobo/gnome-storage.h>
#include "ms-ole.h"
BEGIN_GNOME_DECLS
#define GNOME_STORAGE_OLE_TYPE (gnome_storage_ole_get_type ())
#define GNOME_STORAGE_OLE(o) (GTK_CHECK_CAST ((o), GNOME_STORAGE_OLE_TYPE, GnomeStorageOLE))
#define GNOME_STORAGE_OLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), GNOME_STORAGE_OLE_TYPE, GnomeStorageOLEClass))
#define GNOME_IS_STORAGE_OLE(o) (GTK_CHECK_TYPE ((o), GNOME_STORAGE_OLE_TYPE))
#define GNOME_IS_STORAGE_OLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), GNOME_STORAGE_OLE_TYPE))
typedef struct {
GnomeStorage storage;
MsOle *f;
} GnomeStorageOLE;
typedef struct {
GnomeStorageClass parent_class;
} GnomeStorageOLEClass;
GtkType gnome_storage_ole_get_type (void);
GnomeStorage *gnome_storage_ole_open (const gchar *path, gint flags,
gint mode);
END_GNOME_DECLS
#endif /* _GNOME_STORAGE_OLE_H_ */
/*
* gnome-stream-ole.c: libole based Stream implementation
*
* Author:
* Michael Meeks <michael@imaginator.com>
*
*/
#include <config.h>
#include <stdio.h>
#include <glib.h>
#include "ms-ole.h"
#include "gnome-stream-ole.h"
static GnomeStream *
create_stream_ole_server (const GnomeStreamOLE *stream_ole)
{
GnomeObject *object = GNOME_OBJECT(stream_ole);
POA_GNOME_Stream *servant;
GNOME_Stream corba_stream;
servant = (POA_GNOME_Stream *) g_new0 (GnomeObjectServant, 1);
servant->vepv = &gnome_stream_vepv;
POA_GNOME_Stream__init ((PortableServer_Servant) servant, &object->ev);
if (object->ev._major != CORBA_NO_EXCEPTION){
g_free (servant);
return NULL;
}
corba_stream = gnome_object_activate_servant(object, servant);
return GNOME_STREAM(gnome_object_construct(GNOME_OBJECT(stream_ole),
corba_stream));
}
static void
gnome_stream_ole_destroy (GtkObject *object)
{
GnomeStreamOLE *stream_ole = GNOME_STREAM_OLE (object);
if (stream_ole->file) ole_file_close (stream_ole->file);
if (stream_ole->storage)
gtk_object_unref (GTK_OBJECT (stream_ole->storage));
}
static CORBA_long
real_write (GnomeStream *stream, const GNOME_Stream_iobuf *buffer,
CORBA_Environment *ev)
{
GnomeStreamOLE *stream_ole = GNOME_STREAM_OLE (stream);
CORBA_long len;
len = stream_ole->file->write (stream_ole->file, buffer->_buffer,
buffer->_length);
return len;
}
static CORBA_long
real_read (GnomeStream *stream, CORBA_long count,
GNOME_Stream_iobuf ** buffer,
CORBA_Environment *ev)
{
GnomeStreamOLE *stream_ole = GNOME_STREAM_OLE (stream);
CORBA_octet *data;
CORBA_long bytes;
*buffer = GNOME_Stream_iobuf__alloc ();
CORBA_sequence_set_release (*buffer, TRUE);
data = CORBA_sequence_CORBA_octet_allocbuf (count);
bytes = stream_ole->file->read_copy (stream_ole->file, data, count);
(*buffer)->_buffer = data;
(*buffer)->_length = bytes;
return bytes;
}
static CORBA_long
real_seek (GnomeStream *stream, CORBA_long offset, CORBA_long whence,
CORBA_Environment *ev)
{
GnomeStreamOLE *stream_ole = GNOME_STREAM_OLE (stream);
MsOleSeek type;
if (whence == SEEK_SET)
type = MsOleSeekSet;
else if (whence == SEEK_CUR)
type = MsOleSeekCur;
else {
g_warning ("FIXME: Seek type unimplemented");
return -1;
}
return stream_ole->dile->lseek (stream_ole->file, offset, whence);
}
static void
real_truncate (GnomeStream *stream, const CORBA_long new_size,
CORBA_Environment *ev)
{
GnomeStreamOLE *stream_ole = GNOME_STREAM_OLE (stream);
if (ole_file_trunc (stream_ole->file, new_size)) {
g_warning ("Signal exception!");
}
}
static void
gnome_stream_ole_class_init (GnomeStreamOLEClass *class)
{
GtkObjectClass *object_class = (GtkObjectClass *) class;
GnomeStreamClass *sclass = GNOME_STREAM_CLASS (class);
sclass->write = real_write;
sclass->read = real_read;
sclass->seek = real_seek;
sclass->truncate = real_truncate;
object_class->destroy = gnome_stream_ole_destroy;
}
GtkType
gnome_stream_ole_get_type (void)
{
static GtkType type = 0;
if (!type){
GtkTypeInfo info = {
"IDL:GNOME/StreamOLE:1.0",
sizeof (GnomeStreamOLE),
sizeof (GnomeStreamOLEClass),
(GtkClassInitFunc) gnome_stream_ole_class_init,
(GtkObjectInitFunc) NULL,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gnome_stream_get_type (), &info);
}
return type;
}
static GnomeStream *
gnome_stream_ole_open_create (GnomeStorageOLE *storage_ole,
const CORBA_char *path,
GNOME_Storage_OpenMode mode,
gboolean create)
{
GnomeStreamOLE *stream_ole;
gint flags;
g_return_val_if_fail(storage_ole != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
if (!(stream_ole = gtk_type_new (gnome_stream_ole_get_type ())))
return NULL;
flags = OLE_READ;
if (mode&GNOME_Storage_WRITE) flags |= OLE_WRITE;
if (create) flags |= OLE_CREATE;
if (!(stream_ole->file=ole_file_open(storage_ole->dir, path, flags))) {
gtk_object_destroy (GTK_OBJECT (stream_ole));
return NULL;
}
stream_ole->storage = storage_ole;
gtk_object_ref(GTK_OBJECT(storage_ole));
create_stream_ole_server(stream_ole);
return GNOME_STREAM (stream_ole);
}
GnomeStream *
gnome_stream_ole_open (GnomeStorageOLE *storage, const CORBA_char *path,
GNOME_Storage_OpenMode mode)
{
return gnome_stream_ole_open_create(storage, path, mode, FALSE);
}
GnomeStream *
gnome_stream_ole_create (GnomeStorageOLE *storage, const CORBA_char *path)
{
return gnome_stream_ole_open_create(storage, path, 0, TRUE);
}
#ifndef _GNOME_STREAM_OLE_H_
#define _GNOME_STREAM_OLE_H_
#include <bonobo/gnome-stream.h>