Commit a44e3f90 authored by Arturo Tena/libole2's avatar Arturo Tena/libole2
Browse files

Killed bonobo remains.

parent 9ad2ec02
1999-09-25 <arturo@localhost.localdomain>
* gnome-stream-ole.c, gnome-stream-ole.h, gnome-storage-ole.h,
gnome-storage-ole.c: Killed again.
1999-09-25 Michael Meeks <michael@nuclecu.unam.mx> 1999-09-25 Michael Meeks <michael@nuclecu.unam.mx>
* Makefile.am (lib_LT_LIBRARIES): Make libole2 * Makefile.am (lib_LT_LIBRARIES): Make libole2
......
/*
* 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;
CORBA_Environment ev;
servant = (POA_GNOME_Storage *) g_new0 (GnomeObjectServant, 1);
servant->vepv = &gnome_storage_vepv;
CORBA_exception_init (&ev);
POA_GNOME_Storage__init ((PortableServer_Servant) servant, &ev);
if (ev._major != CORBA_NO_EXCEPTION){
g_free (servant);
CORBA_exception_free (&ev);
return NULL;
}
CORBA_exception_free (&ev);
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;
CORBA_Environment ev;
servant = (POA_GNOME_Stream *) g_new0 (GnomeObjectServant, 1);
servant->vepv = &gnome_stream_vepv;
CORBA_exception_init (&ev);
POA_GNOME_Stream__init ((PortableServer_Servant) servant, &ev);
if (ev._major != CORBA_NO_EXCEPTION){
g_free (servant);
CORBA_exception_free (&ev);
return NULL;
}
CORBA_exception_free (&ev);
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) ms_ole_stream_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, GNOME_Stream_SeekType whence,
CORBA_Environment *ev)
{
GnomeStreamOLE *stream_ole = GNOME_STREAM_OLE (stream);
MsOleSeek type;
if (whence == GNOME_Stream_SEEK_SET)
type = MsOleSeekSet;
else if (whence == GNOME_Stream_SEEK_CUR)
type = MsOleSeekCur;
else
type = MsOleSeekEnd;
return stream_ole->file->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!");
}*/
g_warning ("Unimplemented");
}
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;
char m;
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;*/
if (mode & GNOME_Storage_READ) /* FIXME hacked */
m = 'r';
else
m = 'w';
if (!(stream_ole->file = ms_ole_stream_open_name (storage_ole->f, path, m))) {
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>
#include "gnome-storage-ole.h"
BEGIN_GNOME_DECLS
#define GNOME_STREAM_OLE_TYPE (gnome_stream_ole_get_type ())
#define GNOME_STREAM_OLE(o) (GTK_CHECK_CAST ((o), GNOME_STREAM_OLE_TYPE, GnomeStreamOLE))
#define GNOME_STREAM_OLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), GNOME_STREAM_OLE_TYPE, GnomeStreamOLEClass))
#define GNOME_IS_STREAM_OLE(o) (GTK_CHECK_TYPE ((o), GNOME_STREAM_OLE_TYPE))
#define GNOME_IS_STREAM_OLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), GNOME_STREAM_OLE_TYPE))
typedef struct {
GnomeStream stream;
GnomeStorageOLE *storage;
MsOleStream *file;
} GnomeStreamOLE;
typedef struct {
GnomeStreamClass parent_class;
} GnomeStreamOLEClass;
GtkType gnome_stream_ole_get_type (void);
GnomeStream *gnome_stream_ole_open (GnomeStorageOLE *storage,
const CORBA_char *path,
GNOME_Storage_OpenMode mode);
GnomeStream *gnome_stream_ole_create (GnomeStorageOLE *storage,
const CORBA_char *path);
END_GNOME_DECLS
#endif /* _GNOME_STREAM_OLE_H_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment