Commit 0509fa1b authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

New module to re-enable a CORBA interface in a plugin now that it is


2002-09-18  Jody Goldberg <jody@gnome.org>

	* New module to re-enable a CORBA interface in a plugin now that it is
	  possible to do it without making a mess in the core.  Untested and
	  many methods are incomplete but the frame work is mostly in place.
parent ffb1e999
Makefile.in
Makefile
.deps
.libs
*.lo
*.la
plugin.xml
GNOME_Gnumeric.h
GNOME_Gnumeric-common.c
GNOME_Gnumeric-skels.c
GNOME_Gnumeric-stubs.c
stamp_Gnumeric_idl
2002-09-18 Jody Goldberg <jody@gnome.org>
* New module to re-enable a CORBA interface in a plugin now that it is
possible to do it without making a mess in the core. Untested and
many methods are incomplete but the frame work is mostly in place.
#ifndef __GNUMERIC_IDL__
#define __GNUMERIC_IDL__
module GNOME {
module Gnumeric {
exception ErrorSystem { string msg; };
exception ErrorRead { string msg; };
exception ErrorSave { string msg; };
exception ErrorPlugin { string msg; };
exception ErrorInfo { string msg; };
exception ErrorInvalid { string msg; string value; };
exception ErrorSplitsArray { string msg; string range; };
interface Sheet {
attribute string name;
attribute short index;
};
typedef sequence<Sheet> Sheets;
interface Workbook {
attribute string name;
Sheet sheet_by_index (in short i);
Sheet sheet_by_name (in string name);
Sheet sheet_add (in string name, in short pos);
Sheets sheets ();
};
typedef sequence<Workbook> Workbooks;
interface Application {
Workbook workbook_open (in string file_name,
in boolean shared_view);
Workbooks workbooks ();
};
};
};
#endif /* __GNUMERIC_IDL__ */
INCLUDES = \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/src -I$(top_builddir)/src \
$(GNUMERIC_CFLAGS)
gnumeric_plugin_corbadir = $(gnumeric_plugindir)/corba
xmldir = $(gnumeric_plugin_corbadir)
gnumeric_plugin_corba_LTLIBRARIES = corba.la
corba_la_LDFLAGS = -module -avoid-version
corba_la_SOURCES = $(GNUMERIC_GENERATED) \
corba-application.c \
corba-workbook.c \
corba-workbook.h \
corba-sheet.c
GNUMERIC_GENERATED = \
GNOME_Gnumeric-common.c \
GNOME_Gnumeric-skels.c \
GNOME_Gnumeric-stubs.c \
GNOME_Gnumeric.h
stamp_Gnumeric_idl : $(srcdir)/GNOME_Gnumeric.idl
$(ORBIT_IDL) -I$(srcdir) $< && touch $@
$(GNUMERIC_GENERATED): stamp_Gnumeric_idl
idldir = $(gnumeric_datadir)/idl
idl_DATA = GNOME_Gnumeric.idl
xml_in_files = plugin.xml.in
xml_DATA = $(xml_in_files:.xml.in=.xml)
@INTLTOOL_XML_RULE@
# Do not use built sources BUILT_SOURCES
# it attempts to build the source even if it is not used.
DISTCLEANFILES = $(GNUMERIC_GENERATED) stamp_Gnumeric_idl $(xml_DATA)
EXTRA_DIST = $(idl_DATA) $(xml_in_files)
dist-hook :
cd $(distdir) && rm -f $(CLEANFILES)
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* corba-workbook.c: A WorkbookControl for use by CORBA that implements the
* Gnumeric::Workbook interface.
*
* Copyright (C) 2002 Jody Goldberg (jody@gnome.org)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include <gnumeric-config.h>
#include <gnumeric.h>
#include "corba-workbook.h"
#include "GNOME_Gnumeric.h"
#include <application.h>
#include <workbook.h>
#include <workbook-view.h>
#include <plugin-util.h>
#include <module-plugin-defs.h>
#include <command-context.h>
#include <command-context-stderr.h>
#include <gnumeric-i18n.h>
#include <bonobo.h>
static GNOME_Gnumeric_Workbook
capp_workbook_open (PortableServer_Servant ignore, CORBA_char const *file_name, CORBA_boolean shared_view,
CORBA_Environment *ev)
{
Workbook *wb = application_workbook_get_by_name (file_name);
WorkbookView *wbv;
if (wb != NULL) {
if (shared_view && wb->wb_views->len > 0)
wbv = g_ptr_array_index (wb->wb_views, 0);
else
wbv = NULL;
} else {
CommandContextStderr *cc = command_context_stderr_new ();
IOContext *io_context = gnumeric_io_context_new (COMMAND_CONTEXT (cc));
wbv = wb_view_new_from_file (file_name, NULL, io_context);
g_object_unref (G_OBJECT (io_context));
g_object_unref (G_OBJECT (cc));
}
return workbook_control_corba_obj (workbook_control_corba_new (wbv, wb));
}
static GNOME_Gnumeric_Workbooks *
capp_workbooks (PortableServer_Servant ignore,
CORBA_Environment *ev)
{
GList *workbooks = application_workbook_list ();
int i, len = g_list_length (workbooks);
GNOME_Gnumeric_Workbooks *res = GNOME_Gnumeric_Workbooks__alloc ();
res->_length = res->_maximum = len;
res->_buffer = GNOME_Gnumeric_Workbooks_allocbuf (len);
res->_release = CORBA_TRUE;
for (i = 0; i < len ; ++i) {
res->_buffer [i] = CORBA_OBJECT_NIL;
}
return res;
}
static POA_GNOME_Gnumeric_Application__vepv application_vepv;
static POA_GNOME_Gnumeric_Application__epv application_epv;
static POA_GNOME_Gnumeric_Application application;
static PortableServer_Servant app = &application;
void
plugin_init (void)
{
PortableServer_ObjectId *oid;
PortableServer_POA poa;
CORBA_Environment ev;
if (!bonobo_is_initialized ()) {
int argc = 1;
char *argv[] = { (char *)"Gnumeric" };
bonobo_init (&argc, argv);
}
application_vepv.GNOME_Gnumeric_Application_epv = &application_epv;
application_epv.workbook_open = capp_workbook_open;
application_epv.workbooks = capp_workbooks;
application.vepv = &application_vepv;
CORBA_exception_init (&ev);
POA_GNOME_Gnumeric_Application__init (app, &ev);
g_return_if_fail (ev._major != CORBA_NO_EXCEPTION);
poa = bonobo_poa ();
oid = PortableServer_POA_activate_object (poa, app, &ev);
CORBA_free (oid);
bonobo_activation_active_server_register ("OAFIID:GNOME_Gnumeric_Application",
PortableServer_POA_servant_to_reference (poa, app, &ev));
CORBA_exception_free (&ev);
}
void
plugin_cleanup (void)
{
PortableServer_POA poa;
CORBA_Environment ev;
CORBA_exception_init (&ev);
poa = bonobo_poa ();
bonobo_activation_active_server_unregister ("OAFIID:GNOME_Gnumeric_Application",
PortableServer_POA_servant_to_reference (poa, app, &ev));
PortableServer_POA_deactivate_object (poa, app, &ev);
POA_GNOME_Gnumeric_Application__fini (app, &ev);
CORBA_exception_free (&ev);
}
GNUMERIC_MODULE_PLUGIN_INFO_DECL;
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* corba-sheet.c: A SheetControl for use by CORBA that implements the
* Gnumeric::Sheet interface.
*
* Copyright (C) 2002 Jody Goldberg (jody@gnome.org)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include <gnumeric-config.h>
#include <gnumeric.h>
#include "corba-sheet.h"
#include "GNOME_Gnumeric.h"
#include <sheet.h>
#include <sheet-control-priv.h>
#include <gsf/gsf-impl-utils.h>
#include <bonobo.h>
typedef struct {
SheetControl base;
POA_GNOME_Gnumeric_Sheet servant;
gboolean initialized, activated;
CORBA_Object corba_obj; /* local CORBA object */
CORBA_Environment *ev; /* exception from the caller */
} SheetControlCORBA;
typedef struct {
SheetControlClass base;
} SheetControlCORBAClass;
static SheetControlCORBA *
scc_from_servant (PortableServer_Servant serv)
{
SheetControlCORBA *scc = (SheetControlCORBA *)(((char *)serv) - G_STRUCT_OFFSET (SheetControlCORBA, servant));
g_return_val_if_fail (IS_SHEET_CONTROL (scc), NULL);
return scc;
}
static CORBA_string
csheet_get_name (PortableServer_Servant servant,
CORBA_Environment *ev)
{
SheetControlCORBA *scc = scc_from_servant (servant);
Sheet *sheet = sc_sheet (SHEET_CONTROL (scc));
return CORBA_string_dup (sheet->name_unquoted);
}
static void
csheet_set_name (PortableServer_Servant servant, CORBA_char const * value,
CORBA_Environment *ev)
{
SheetControlCORBA *scc = scc_from_servant (servant);
Sheet *sheet = sc_sheet (SHEET_CONTROL (scc));
/* DO NOT CALL sheet_rename that is too low level */
}
static CORBA_short
csheet_get_index (PortableServer_Servant servant,
CORBA_Environment *ev)
{
SheetControlCORBA *scc = scc_from_servant (servant);
Sheet *sheet = sc_sheet (SHEET_CONTROL (scc));
return sheet->index_in_wb;
}
static void
csheet_set_index (PortableServer_Servant servant, CORBA_short indx,
CORBA_Environment *ev)
{
SheetControlCORBA *scc = scc_from_servant (servant);
Sheet *sheet = sc_sheet (SHEET_CONTROL (scc));
}
static POA_GNOME_Gnumeric_Sheet__vepv sheet_vepv;
static POA_GNOME_Gnumeric_Sheet__epv sheet_epv;
static void
scc_finalize (GObject *obj)
{
GObjectClass *parent_class;
CORBA_Environment ev;
SheetControlCORBA *scc = SHEET_CONTROL_CORBA (obj);
CORBA_exception_init (&ev);
if (scc->activated) {
PortableServer_POA poa = bonobo_poa ();
PortableServer_ObjectId *oid = PortableServer_POA_servant_to_id (poa,
&scc->servant, &ev);
PortableServer_POA_deactivate_object (poa, oid, &ev);
scc->activated = FALSE;
CORBA_free (oid);
if (ev._major != CORBA_NO_EXCEPTION) {
g_warning ("unexpected exception while finalizing");
}
}
if (scc->initialized) {
POA_GNOME_Gnumeric_Sheet__fini (&scc->servant, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_warning ("unexpected exception while finalizing");
}
scc->initialized = FALSE;
}
CORBA_exception_free (&ev);
parent_class = g_type_class_peek (SHEET_CONTROL_TYPE);
if (parent_class->finalize)
parent_class->finalize (obj);
}
static void
scc_class_init (GObjectClass *object_class)
{
object_class->finalize = &scc_finalize;
sheet_vepv.GNOME_Gnumeric_Sheet_epv = &sheet_epv;
sheet_epv._get_name = csheet_get_name;
sheet_epv._set_name = csheet_set_name;
sheet_epv._get_index = csheet_get_index;
sheet_epv._set_index = csheet_set_index;
}
static void
scc_init (SheetControlCORBA *scc)
{
CORBA_Environment ev;
scc->initialized = FALSE;
scc->activated = FALSE;
CORBA_exception_init (&ev);
scc->servant.vepv = &sheet_vepv;
POA_GNOME_Gnumeric_Sheet__init (&scc->servant, &ev);
if (ev._major == CORBA_NO_EXCEPTION) {
PortableServer_ObjectId *oid;
PortableServer_POA poa = bonobo_poa ();
scc->initialized = TRUE;
oid = PortableServer_POA_activate_object (poa,
&scc->servant, &ev);
scc->activated = (ev._major == CORBA_NO_EXCEPTION);
scc->corba_obj = PortableServer_POA_servant_to_reference (poa,
&scc->servant, &ev);
CORBA_free (oid);
} else {
g_warning ("'%s' : while creating a corba control",
bonobo_exception_get_text (&ev));
}
CORBA_exception_free (&ev);
}
GSF_CLASS (SheetControlCORBA, sheet_control_corba,
scc_class_init, scc_init, SHEET_CONTROL_TYPE);
SheetControl *
sheet_control_corba_new (SheetView *sv)
{
SheetControl *sc =
g_object_new (sheet_control_corba_get_type (), NULL);
sv_attach_control (sv, SHEET_CONTROL (sc));
return sc;
}
#ifndef GNUMERIC_SHEET_CONTROL_CORBA_H
#define GNUMERIC_SHEET_CONTROL_CORBA_H
#include "sheet-control.h"
#define SHEET_CONTROL_CORBA_TYPE (sheet_control_corba_get_type ())
#define SHEET_CONTROL_CORBA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHEET_CONTROL_CORBA_TYPE, SheetControlCORBA))
#define IS_SHEET_CONTROL_CORBA(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), SHEET_CONTROL_CORBA_TYPE))
GType sheet_control_corba_get_type (void);
SheetControl *sheet_control_corba_new (SheetView *view);
#endif /* GNUMERIC_SHEET_CONTROL_CORBA_H */
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* corba-workbook.c: A WorkbookControl for use by CORBA that implements the
* Gnumeric::Workbook interface.
*
* Copyright (C) 2002 Jody Goldberg (jody@gnome.org)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include <gnumeric-config.h>
#include "corba-workbook.h"
#include "corba-sheet.h"
#include <workbook.h>
#include <workbook-control-priv.h>
#include <sheet-view.h>
#include <sheet-control-priv.h>
#include <ranges.h>
#include <gsf/gsf-impl-utils.h>
#include <bonobo.h>
typedef struct {
WorkbookControl wb_control;
POA_GNOME_Gnumeric_Workbook servant;
gboolean initialized, activated;
CORBA_Object corba_obj; /* local CORBA object */
CORBA_Environment *ev; /* exception from the caller */
} WorkbookControlCORBA;
typedef struct {
WorkbookControlClass wb_control_class;
} WorkbookControlCORBAClass;
static WorkbookControlCORBA *
wbcc_from_servant (PortableServer_Servant serv)
{
WorkbookControlCORBA *wbcc = (WorkbookControlCORBA *)(((char *)serv) - G_STRUCT_OFFSET (WorkbookControlCORBA, servant));
g_return_val_if_fail (IS_WORKBOOK_CONTROL (wbcc), NULL);
return wbcc;
}
static CORBA_string
cworkbook_get_name (PortableServer_Servant servant,
CORBA_Environment *ev)
{
WorkbookControlCORBA *wbcc = wbcc_from_servant (servant);
Workbook *wb = wb_control_workbook (WORKBOOK_CONTROL (wbcc));
return CORBA_string_dup (workbook_get_filename (wb));
}
static void
cworkbook_set_name (PortableServer_Servant servant, CORBA_char const *name,
CORBA_Environment *ev)
{
WorkbookControlCORBA *wbcc = wbcc_from_servant (servant);
Workbook *wb = wb_control_workbook (WORKBOOK_CONTROL (wbcc));
g_return_if_fail (wbcc != NULL);
workbook_set_filename (wb, name);
}
static GNOME_Gnumeric_Sheet
cworkbook_sheet_by_index (PortableServer_Servant servant, CORBA_short i,
CORBA_Environment *ev)
{
WorkbookControlCORBA *wbcc = wbcc_from_servant (servant);
Sheet *sheet;
g_return_val_if_fail (wbcc != NULL, CORBA_OBJECT_NIL);
sheet = workbook_sheet_by_index (wb_control_workbook (WORKBOOK_CONTROL (wbcc)), i);
if (sheet != NULL) {
/* CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_Gnumeric_Workbook_NameExists, NULL); */
}
return CORBA_OBJECT_NIL;
}
static GNOME_Gnumeric_Sheet
cworkbook_sheet_by_name (PortableServer_Servant servant, CORBA_char const *name,
CORBA_Environment *ev)
{
WorkbookControlCORBA *wbcc = wbcc_from_servant (servant);
Sheet *sheet;
g_return_val_if_fail (wbcc != NULL, CORBA_OBJECT_NIL);
sheet = workbook_sheet_by_name (wb_control_workbook (WORKBOOK_CONTROL (wbcc)), name);
if (sheet != NULL) {
}
return CORBA_OBJECT_NIL;
}
static GNOME_Gnumeric_Sheet
cworkbook_sheet_add (PortableServer_Servant servant, CORBA_char const *name, CORBA_short pos,
CORBA_Environment *ev)
{
WorkbookControlCORBA *wbcc = wbcc_from_servant (servant);
Workbook *wb = wb_control_workbook (WORKBOOK_CONTROL (wbcc));
Sheet *sheet = workbook_sheet_add (wb, NULL, TRUE);
}
static GNOME_Gnumeric_Sheets *
cworkbook_sheets (PortableServer_Servant servant,
CORBA_Environment *ev)
{
WorkbookControlCORBA *wbcc = wbcc_from_servant (servant);
GList *sheets =
workbook_sheets (wb_control_workbook (WORKBOOK_CONTROL (wbcc)));
int i, len = g_list_length (sheets);
GNOME_Gnumeric_Workbooks *res = GNOME_Gnumeric_Sheets__alloc ();
res->_length = res->_maximum = len;
res->_buffer = GNOME_Gnumeric_Sheets_allocbuf (len);
res->_release = CORBA_TRUE;
for (i = 0; i < len ; ++i) {
res->_buffer [i] = CORBA_OBJECT_NIL;
}
g_list_free (sheets);
return res;
}
static void
wbcc_system (CommandContext *ctxt, char const *msg)
{
WorkbookControlCORBA *wbcc = WORKBOOK_CONTROL_CORBA (ctxt);
GNOME_Gnumeric_ErrorSystem *err = GNOME_Gnumeric_ErrorSystem__alloc();
err->msg = CORBA_string_dup (msg);
CORBA_exception_set (wbcc->ev, CORBA_USER_EXCEPTION,
ex_GNOME_Gnumeric_ErrorSystem, err);
}
static void
wbcc_plugin (CommandContext *ctxt, char const *msg)
{
WorkbookControlCORBA *wbcc = WORKBOOK_CONTROL_CORBA (ctxt);
GNOME_Gnumeric_ErrorPlugin *err = GNOME_Gnumeric_ErrorPlugin__alloc();
err->msg = CORBA_string_dup (msg);
CORBA_exception_set (wbcc->ev, CORBA_USER_EXCEPTION,
ex_GNOME_Gnumeric_ErrorPlugin, err);
}
static void
wbcc_read (CommandContext *ctxt, char const *msg)
{
WorkbookControlCORBA *wbcc = WORKBOOK_CONTROL_CORBA (ctxt);
GNOME_Gnumeric_ErrorRead *err = GNOME_Gnumeric_ErrorRead__alloc();
err->msg = CORBA_string_dup (msg);
CORBA_exception_set (wbcc->ev, CORBA_USER_EXCEPTION,
ex_GNOME_Gnumeric_ErrorRead, err);
}
static void
wbcc_save (CommandContext *ctxt, char const *msg)
{
WorkbookControlCORBA *wbcc = WORKBOOK_CONTROL_CORBA (ctxt);
GNOME_Gnumeric_ErrorSave *err = GNOME_Gnumeric_ErrorSave__alloc();
err->msg = CORBA_string_dup (msg);
CORBA_exception_set (wbcc->ev, CORBA_USER_EXCEPTION,
ex_GNOME_Gnumeric_ErrorSave, err);
}
static void
wbcc_splits_array (CommandContext *ctxt, char const *cmd, Range const *array)
{
WorkbookControlCORBA *wbcc = WORKBOOK_CONTROL_CORBA (ctxt);
GNOME_Gnumeric_ErrorSplitsArray *err = GNOME_Gnumeric_ErrorSplitsArray__alloc();
err->msg = CORBA_string_dup (cmd);
err->range = CORBA_string_dup (range_name (array));
CORBA_exception_set (wbcc->ev, CORBA_USER_EXCEPTION,
ex_GNOME_Gnumeric_ErrorSplitsArray, err);
}