[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/geas/src/methods methods.c methods.h metho...
From: |
Neil Tiffin |
Subject: |
gnue/geas/src/methods methods.c methods.h metho... |
Date: |
Sat, 17 Nov 2001 19:35:05 -0500 |
CVSROOT: /home/cvs
Module name: gnue
Changes by: Neil Tiffin <address@hidden> 01/11/17 19:35:05
Modified files:
geas/src/methods: methods.c methods.h methods_glibmodule.c
methods_glibmodule.h methods_python.c
methods_python.h
Log message:
mcb30 changes to allow python and C methods to be used at the same
time. Since I dont see configure changes, i think we still need to work on the
configuration.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/methods/methods.c.diff?cvsroot=OldCVS&tr1=1.18&tr2=1.19&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/methods/methods.h.diff?cvsroot=OldCVS&tr1=1.10&tr2=1.11&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/methods/methods_glibmodule.c.diff?cvsroot=OldCVS&tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/methods/methods_glibmodule.h.diff?cvsroot=OldCVS&tr1=1.17&tr2=1.18&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/methods/methods_python.c.diff?cvsroot=OldCVS&tr1=1.18&tr2=1.19&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/methods/methods_python.h.diff?cvsroot=OldCVS&tr1=1.4&tr2=1.5&r1=text&r2=text
Patches:
Index: gnue/geas/src/methods/methods.c
diff -u gnue/geas/src/methods/methods.c:1.18
gnue/geas/src/methods/methods.c:1.19
--- gnue/geas/src/methods/methods.c:1.18 Sun Sep 23 14:59:43 2001
+++ gnue/geas/src/methods/methods.c Sat Nov 17 19:35:05 2001
@@ -19,7 +19,7 @@
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: methods.c,v 1.18 2001/09/23 18:59:43 ntiffin Exp $
+ $Id: methods.c,v 1.19 2001/11/18 00:35:05 ntiffin Exp $
*/
#include "config.h"
@@ -36,22 +36,25 @@
#include "methods_python.h"
#include "methods_glibmodule.h"
+static GList *provider_list = NULL;
+
gboolean
initialise_method_handling (configuration config)
{
- gboolean status = FALSE;
+ gboolean status = TRUE;
#if USE_PYTHON_METHODS
- status = python_init_method_handling (config);
+ status = status && python_init_method_handling (config);
#endif
#if USE_GLIBMODULE_METHODS
- status = status || gmod_init_method_handling (config);
+ status = status && gmod_init_method_handling (config);
#endif
#if USE_PYTHON_METHODS || USE_GLIBMODULE_METHODS
- /* good your are using methods */
+ /* good you are using methods */
#else
+ status = FALSE;
criticalerror ("No method code handling has been compiled.");
message ("No business class methods will work.");
#endif
@@ -62,30 +65,38 @@
gboolean
load_method_handlers (configuration config)
{
- gboolean status = FALSE;
+ gboolean status = TRUE;
#if USE_PYTHON_METHODS
- status = python_load_method_handlers (config);
+ status = status && python_load_method_handlers (config);
#endif
#if USE_GLIBMODULE_METHODS
- status = status || glibmodule_load_method_handlers (config);
+ status = status && glibmodule_load_method_handlers (config);
#endif
+#if ! ( USE_PYTHON_METHODS || USE_GLIBMODULE_METHODS )
+ status = FALSE;
+#endif
+
return (status);
}
gboolean
shutdown_method_handling (void)
{
- gboolean status = FALSE;
+ gboolean status = TRUE;
#if USE_PYTHON_METHODS
- status = python_shutdown_method_handling ();
+ status = status && python_shutdown_method_handling ();
#endif
#if USE_GLIBMODULE_METHODS
- status = status || glibmodule_shutdown_method_handling ();
+ status = status && glibmodule_shutdown_method_handling ();
+#endif
+
+#if ! ( USE_PYTHON_METHODS || USE_GLIBMODULE_METHODS )
+ status = FALSE;
#endif
return (status);
@@ -99,28 +110,81 @@
{
CORBA_char *result = NULL;
+#if USE_PYTHON_METHODS || USE_GLIBMODULE_METHODS
+
+ provider_t *provider = NULL;
+ provider_t *p;
+ char *mangled_classname = odl_mangle_qualified_name (obj->classname);
+ GList *list = provider_list;
+
+ debug_output (DEBUGLEVEL_8, "Searching for method provider for %s__%s",
+ mangled_classname, methodname );
+ while (list)
+ {
+ p = (provider_t *) list->data;
+ if ( (g_strcasecmp (mangled_classname, p->classname) == 0)
+ && (g_strcasecmp (methodname, p->methodname) == 0) )
+ {
+ provider = p;
+ list = NULL;
+ }
+ else
+ list = list->next;
+ }
+ g_free (mangled_classname);
+
+ if ( provider )
+ {
+ switch ( provider->methodtype ) {
+
#if USE_PYTHON_METHODS
- result = python_execute_method (obj, methodname, args, ev);
+ case PROVIDER_PYTHON:
+ debug_output (DEBUGLEVEL_8, "Found provider of type 'python'");
+ result = python_execute_method (obj, methodname, args, ev, provider);
+ break;
#endif
#if USE_GLIBMODULE_METHODS
- result = glibmodule_execute_method (obj, methodname, args, ev);
+ case PROVIDER_GLIBMODULE:
+ debug_output (DEBUGLEVEL_8, "Found provider of type 'glibmodule'");
+ result = glibmodule_execute_method (obj, methodname, args, ev,
provider);
+ break;
#endif
-#if USE_PYTHON_METHODS || USE_GLIBMODULE_METHODS
+ default:
+ debug_output (DEBUGLEVEL_1, "Unrecognised method provider type!");
+ make_ServerError_exception (ev, "Internal error: cannot identify
type for method %s.%s()",
+ obj->classname, methodname);
+ }
+ }
+ else
+ {
+ debug_output (DEBUGLEVEL_8, "Found no provider - throwing exception");
+ make_ServerError_exception (ev, "Could not find implementation of
%s.%s()",
+ obj->classname, methodname);
+ }
+
/* good your are using methods */
-#else
+#else /* using any methods */
fatal_error ("No method code handling has been compiled.");
result = null;
-#endif
+#endif /* using any methods */
return (result);
}
// end of general dispatch routines
+void
+add_provider ( provider_t * p )
+{
+ debug_output (DEBUGLEVEL_8, "Adding provider for %s__%s", p->classname,
p->methodname );
+ provider_list = g_list_append (provider_list, p);
+}
+
provider_t *
alloc_provider_data (const char *classname, const char *cid,
- const char *methodname, void *extra)
+ const char *methodname, void *extra,
+ const methodtype_t methodtype)
{
provider_t *p = g_new0 (provider_t, 1);
if (p)
@@ -131,6 +195,7 @@
p->object = CORBA_OBJECT_NIL;
p->extra = NULL;
p->function = NULL;
+ p->methodtype = methodtype;
if (classname)
{
Index: gnue/geas/src/methods/methods.h
diff -u gnue/geas/src/methods/methods.h:1.10
gnue/geas/src/methods/methods.h:1.11
--- gnue/geas/src/methods/methods.h:1.10 Sat Sep 15 18:29:32 2001
+++ gnue/geas/src/methods/methods.h Sat Nov 17 19:35:05 2001
@@ -19,7 +19,7 @@
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: methods.h,v 1.10 2001/09/15 22:29:32 ntiffin Exp $
+ $Id: methods.h,v 1.11 2001/11/18 00:35:05 ntiffin Exp $
*/
#ifndef METHODS_H
@@ -29,6 +29,13 @@
#include "geas-skeleton.h"
/* base data structures and related private utility methods */
+typedef enum
+{
+ PROVIDER_PYTHON,
+ PROVIDER_GLIBMODULE
+}
+methodtype_t;
+
typedef struct
{
char *classname; /* full class name */
@@ -37,6 +44,7 @@
CORBA_Object object;
void *extra; /* misc */
void *function; /* glib */
+ methodtype_t methodtype; /* i.e. the language the method is
written in */
}
provider_t;
@@ -52,8 +60,15 @@
const char *methodname,
GEAS_Arguments * args, CORBA_Environment * ev);
+void add_provider ( provider_t * p );
+
+GList * temp_get_provider_list ( void );
+
provider_t *alloc_provider_data (const char *classname,
- const char *cid,
- const char *methodname, void *extra);
+ const char *cid,
+ const char *methodname,
+ void *extra,
+ const methodtype_t methodtype);
+
void free_provider_data (provider_t * p);
#endif
Index: gnue/geas/src/methods/methods_glibmodule.c
diff -u gnue/geas/src/methods/methods_glibmodule.c:1.4
gnue/geas/src/methods/methods_glibmodule.c:1.5
--- gnue/geas/src/methods/methods_glibmodule.c:1.4 Sun Sep 23 14:59:43 2001
+++ gnue/geas/src/methods/methods_glibmodule.c Sat Nov 17 19:35:05 2001
@@ -19,7 +19,7 @@
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: methods_glibmodule.c,v 1.4 2001/09/23 18:59:43 ntiffin Exp $
+ $Id: methods_glibmodule.c,v 1.5 2001/11/18 00:35:05 ntiffin Exp $
*/
#include "config.h"
@@ -51,8 +51,6 @@
#define ERR_NO_FUNCTIONS (-2)
#define ERR_MEMORY (-3)
-static GList *provider_list = NULL;
-
gboolean
gmod_init_method_handling (configuration config)
{
@@ -110,65 +108,64 @@
if (realpath (dirname, abspath) == NULL)
{
/* directory not found */
- return (FALSE);
- }
- strcat (abspath, "/.libs");
- path = g_module_build_path (abspath, mangled);
- /* message( "looking for module '%s'" , path ); */
- module = g_module_open (path, 0);
- storemodule = module;
- if (!module)
- {
- errormsg ("Required module '%s' was missing : %s", path,
- g_module_error ());
- return (FALSE);
}
else
{
- /* validate all the methods */
- /* message( "module loaded, now validating method functions" );
*/
- l3 = fields;
- while (l3)
+ strcat (abspath, "/.libs");
+ path = g_module_build_path (abspath, mangled);
+ /* message( "looking for module '%s'" , path ); */
+ module = g_module_open (path, 0);
+ storemodule = module;
+ if (!module)
{
- METHODFUNC *funcptr;
- odl_field *f = (odl_field *) l3->data;
- char *funcname = g_strdup_printf ("%s_%s", mangled,
- odl_field_get_name (f));
- /* printf ("looking for %s.%s (%s)",
- odl_class_get_full_name (c), odl_field_get_name (f),
- funcname); */
-
- g_module_symbol (module, funcname, (gpointer) & funcptr);
- /* if (funcptr)
- printf ("...found\n");
- else
- printf ("...not found\n"); */
- g_free (funcname);
-
- /* store the pointer to this function */
- if (funcptr)
+ errormsg ("Required module '%s' was missing : %s", path,
+ g_module_error ());
+ }
+ else
+ {
+ /* validate all the methods */
+ /* message( "module loaded, now validating method functions"
); */
+ l3 = fields;
+ while (l3)
{
- provider_t *p = alloc_provider_data (mangled, NULL,
- odl_field_get_name
- (f),
- (void *)
- storemodule);
- if (p)
+ METHODFUNC *funcptr;
+ odl_field *f = (odl_field *) l3->data;
+ char *funcname = g_strdup_printf ("%s_%s", mangled,
+ odl_field_get_name
(f));
+ /* printf ("looking for %s.%s (%s)",
+ odl_class_get_full_name (c), odl_field_get_name (f),
+ funcname); */
+
+ g_module_symbol (module, funcname, (gpointer) & funcptr);
+ /* if (funcptr)
+ printf ("...found\n");
+ else
+ printf ("...not found\n"); */
+ g_free (funcname);
+
+ /* store the pointer to this function */
+ if (funcptr)
{
- provider_list = g_list_append (provider_list, p);
- storemodule = NULL;
- p->function = (void *) funcptr;
+ provider_t *p = alloc_provider_data (mangled, NULL,
+
odl_field_get_name (f),
+ (void *)
storemodule,
+
PROVIDER_GLIBMODULE);
+ if (p)
+ {
+ add_provider ( p );
+ storemodule = NULL;
+ p->function = (void *) funcptr;
+ }
}
- }
- else
- {
- /* error - not found */
- errormsg ("Could not find %s.%s : %s", l->data,
- odl_field_get_name (f), g_module_error ());
- return (FALSE);
- }
+ else
+ {
+ /* error - not found */
+ errormsg ("Could not find %s.%s : %s", l->data,
+ odl_field_get_name (f), g_module_error ());
+ }
- l3 = g_list_next (l3);
+ l3 = g_list_next (l3);
+ }
}
}
odl_fieldlist_free (fields);
@@ -193,74 +190,50 @@
CORBA_char *
glibmodule_execute_method (GEAS_object_reference * obj,
const char *methodname, GEAS_Arguments * args,
- CORBA_Environment * ev)
+ CORBA_Environment * ev, provider_t * provider)
{
- char *classname = obj->classname;
- GList *l = provider_list;
- char *mangled = odl_mangle_qualified_name (obj->classname);
- provider_t *p;
METHODFUNC func;
+ char *retval = NULL;
+ CORBA_Environment ev2;
+ GEAS_DataObject objref;
+ GEAS_Connection serverref;
g_return_val_if_fail (obj, NULL);
g_return_val_if_fail (methodname, NULL);
g_return_val_if_fail (args, NULL);
g_return_val_if_fail (ev, NULL);
- /* message( "looking for method %s in class %s" , methodname , classname );
*/
- while (l)
+ CORBA_exception_init (&ev2);
+ objref =
+ make_dataobject_reference (obj->classname, obj->objectid,
+ obj->username, obj->sessionid,
+ &ev2);
+ serverref =
+ make_connection_reference (obj->username, "server allocated",
+ &ev2);
+
+ func = provider->function;
+ retval = func (objref, args, serverref, ev);
+ if (ev->_major != CORBA_NO_EXCEPTION)
{
- p = (provider_t *) l->data;
- if (g_strcasecmp (mangled, p->classname) == 0)
- {
- if (g_strcasecmp (methodname, p->methodname) == 0)
- {
- char *retval = NULL;
- CORBA_Environment ev2;
- GEAS_DataObject objref;
- GEAS_Connection serverref;
-
- /* message( "found it" ); */
- CORBA_exception_init (&ev2);
- objref =
- make_dataobject_reference (obj->classname, obj->objectid,
- obj->username, obj->sessionid,
- &ev2);
- serverref =
- make_connection_reference (obj->username, "server allocated",
- &ev2);
-
- func = p->function;
- retval = func (objref, args, serverref, ev);
- if (ev->_major != CORBA_NO_EXCEPTION)
- {
- char *buf;
- buf =
- g_strdup_printf ("CORBA error: '%s'",
- CORBA_exception_id (ev));
- CORBA_exception_free (ev);
- CORBA_exception_init (ev);
- make_MethodError_exception (ev, buf);
- }
+ char *buf;
+ buf =
+ g_strdup_printf ("CORBA error: '%s'",
+ CORBA_exception_id (ev));
+ CORBA_exception_free (ev);
+ CORBA_exception_init (ev);
+ make_MethodError_exception (ev, buf);
+ }
- CORBA_Object_release (objref, &ev2);
- CORBA_Object_release (serverref, &ev2);
+ CORBA_Object_release (objref, &ev2);
+ CORBA_Object_release (serverref, &ev2);
- g_free (mangled);
- CORBA_exception_free (&ev2);
- if (retval == NULL && ev->_major == CORBA_NO_EXCEPTION)
- {
- return (CORBA_string_dup (""));
- }
- return (retval);
- }
- }
- l = g_list_next (l);
+ CORBA_exception_free (&ev2);
+ if (retval == NULL && ev->_major == CORBA_NO_EXCEPTION)
+ {
+ retval = CORBA_string_dup ("");
}
-
- g_free (mangled);
- make_ServerError_exception (ev, "Could not find implementation of %s.%s()",
- classname, methodname);
- return (NULL);
+ return (retval);
}
#else
@@ -303,7 +276,7 @@
CORBA_char *
glibmodule_execute_method (GEAS_object_reference * obj,
const char *methodname, GEAS_Arguments * args,
- CORBA_Environment * ev)
+ CORBA_Environment * ev, provider_t * provider)
{
return NULL;
}
Index: gnue/geas/src/methods/methods_glibmodule.h
diff -u gnue/geas/src/methods/methods_glibmodule.h:1.17
gnue/geas/src/methods/methods_glibmodule.h:1.18
--- gnue/geas/src/methods/methods_glibmodule.h:1.17 Sun Sep 23 14:59:43 2001
+++ gnue/geas/src/methods/methods_glibmodule.h Sat Nov 17 19:35:05 2001
@@ -19,7 +19,7 @@
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: methods_glibmodule.h,v 1.17 2001/09/23 18:59:43 ntiffin Exp $
+ $Id: methods_glibmodule.h,v 1.18 2001/11/18 00:35:05 ntiffin Exp $
*/
#ifndef METHODS_GLIBMODULE_H
@@ -50,6 +50,7 @@
CORBA_char *glibmodule_execute_method (GEAS_object_reference * obj,
const char *methodname,
GEAS_Arguments * args,
- CORBA_Environment * ev);
+ CORBA_Environment * ev,
+ provider_t * provider);
#endif
Index: gnue/geas/src/methods/methods_python.c
diff -u gnue/geas/src/methods/methods_python.c:1.18
gnue/geas/src/methods/methods_python.c:1.19
--- gnue/geas/src/methods/methods_python.c:1.18 Tue Sep 25 15:48:43 2001
+++ gnue/geas/src/methods/methods_python.c Sat Nov 17 19:35:05 2001
@@ -19,7 +19,7 @@
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: methods_python.c,v 1.18 2001/09/25 19:48:43 ntiffin Exp $
+ $Id: methods_python.c,v 1.19 2001/11/18 00:35:05 ntiffin Exp $
*/
/*
@@ -58,7 +58,6 @@
#include <Python.h>
-static GList *provider_list = NULL;
static PyThreadState *mainThreadState = NULL;
static GModule *orbit_python_library = NULL;
static PyObject *(*CORBA_to_Python_func) (CORBA_Object obj);
@@ -130,6 +129,9 @@
python_execute_function (const char *function_name, GEAS_Arguments * args)
{
/*
+
+ THIS FUNCTION DOESN'T GET CALLED BY ANYTHING - SHOULD IT BE REMOVED? mcb30
2001/11/17
+
g_return_val_if_fail (function_name, NULL);
g_return_val_if_fail (args, NULL);
@@ -308,12 +310,10 @@
debug_output (DEBUGLEVEL_2, " method: %s",
odl_field_get_name (f));
full_classname =
- g_strdup_printf ("%s__%s", (odl_class_get_parent (c))->name,
- odl_class_get_name (c));
+ odl_mangle_qualified_name (l->data);
current_provider =
alloc_provider_data (full_classname, NULL, odl_field_get_name (f),
- NULL);
- provider_list = g_list_append (provider_list, current_provider);
+ NULL, PROVIDER_PYTHON);
buf = g_strdup_printf
("method_system.register_method( \"%s_%s\" , %s_%s )",
full_classname, odl_field_get_name (f),
@@ -321,7 +321,8 @@
g_strdown (buf);
message ("Registering method: %s_%s [file: %s]", full_classname,
odl_field_get_name (f),
g_basename(odl_class_get_gcd_filename (c)));
- PyRun_SimpleString (buf);
+ if ( PyRun_SimpleString (buf) == 0 )
+ add_provider ( current_provider );
g_free (buf);
current_provider = NULL;
l2 = l2->next;
@@ -350,10 +351,9 @@
CORBA_char *
python_execute_method (GEAS_object_reference * obj,
const char *methodname, GEAS_Arguments * args,
- CORBA_Environment * ev)
+ CORBA_Environment * ev, provider_t * provider)
{
char *retval = NULL;
- // int i;
PyObject *result;
PyObject *l, *tuple;
PyObject *pyobj, *server;
@@ -386,28 +386,8 @@
return (NULL);
}
- /* find 'call' object */
- list = provider_list;
- while (list)
- {
- /*
- g_message ("classname: %s = %s", ((provider_t *)
list->data)->classname,
- obj->classname);
- g_message ("fieldname: %s = %s",
- ((provider_t *) list->data)->methodname, methodname);
- */
- if (!g_strcasecmp
- (((provider_t *) list->data)->classname,
- g_strdelimit (obj->classname, ":", '_'))
- && !g_strcasecmp (((provider_t *) list->data)->methodname,
- methodname))
- {
- function = ((provider_t *) list->data)->extra;
- list = NULL;
- }
- if (list)
- list = list->next;
- }
+ function = provider->extra;
+
if (function != 0)
{
unsigned int i;
@@ -561,7 +541,7 @@
CORBA_char *
python_execute_method (GEAS_object_reference * obj,
const char *methodname, GEAS_Arguments * args,
- CORBA_Environment * ev)
+ CORBA_Environment * ev, provider_t * provider)
{
return NULL;
}
Index: gnue/geas/src/methods/methods_python.h
diff -u gnue/geas/src/methods/methods_python.h:1.4
gnue/geas/src/methods/methods_python.h:1.5
--- gnue/geas/src/methods/methods_python.h:1.4 Sat Sep 22 18:06:51 2001
+++ gnue/geas/src/methods/methods_python.h Sat Nov 17 19:35:05 2001
@@ -19,7 +19,7 @@
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: methods_python.h,v 1.4 2001/09/22 22:06:51 ntiffin Exp $
+ $Id: methods_python.h,v 1.5 2001/11/18 00:35:05 ntiffin Exp $
*/
#ifndef METHODS_PYTHON_H
@@ -49,7 +49,7 @@
\* ------------------------------------------------------------------------- */
CORBA_char * python_execute_method (GEAS_object_reference * obj,
const char *methodname, GEAS_Arguments * args,
- CORBA_Environment * ev);
+ CORBA_Environment * ev, provider_t * provider);
/* ------------------------------------------------------------------------- *\
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/geas/src/methods methods.c methods.h metho...,
Neil Tiffin <=