[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/geas/src/methods methods.h methods_oaf.h m...
From: |
Daniel E. Baumann |
Subject: |
gnue/geas/src/methods methods.h methods_oaf.h m... |
Date: |
Fri, 08 Jun 2001 12:59:21 -0700 |
CVSROOT: /cvs
Module name: gnue
Changes by: Daniel E. Baumann <address@hidden> 01/06/08 12:59:21
Modified files:
geas/src/methods: methods.h methods_oaf.h methods_unstable.h
Log message:
Reformat to GNU, fix file header(s).
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/methods/methods.h.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_oaf.h.diff?cvsroot=OldCVS&tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/methods/methods_unstable.h.diff?cvsroot=OldCVS&tr1=1.5&tr2=1.6&r1=text&r2=text
Patches:
Index: gnue/geas/src/methods/methods.h
diff -u gnue/geas/src/methods/methods.h:1.4 gnue/geas/src/methods/methods.h:1.5
--- gnue/geas/src/methods/methods.h:1.4 Wed Feb 7 12:43:19 2001
+++ gnue/geas/src/methods/methods.h Fri Jun 8 12:59:21 2001
@@ -1,23 +1,25 @@
-
/*
- geas - GNU Enterprise Application Server
-
- Copyright (C) 2001 Free Software Foundation
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- 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.
-
+ methods.h - Interface for method handlers.
+
+ Copyright (C) 2001 Free Software Foundation
+
+ This file is part of the GNU Enterprise Application Server (GEAS)
+
+ GEAS is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ GEAS 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 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.5 2001/06/08 19:59:21 baumannd Exp $
*/
#ifndef METHODS_H
@@ -28,12 +30,13 @@
/* TODO: this section will need significant changes for dynamic loading of
* modules, esp. during transactions */
-gboolean initialise_method_handling( configuration config );
-gboolean load_method_handlers ( );
-gboolean shutdown_method_handling(); /* TODO */
+gboolean initialise_method_handling (configuration config);
+gboolean load_method_handlers ();
+gboolean shutdown_method_handling (); /* TODO */
/* assumes everything has been validated already */
-CORBA_char *execute_method( GEAS_object_reference *obj ,
- const char *methodname , GEAS_Arguments *args ,
CORBA_Environment *ev );
+CORBA_char *execute_method (GEAS_object_reference * obj,
+ const char *methodname,
+ GEAS_Arguments * args, CORBA_Environment * ev);
#endif
Index: gnue/geas/src/methods/methods_oaf.h
diff -u gnue/geas/src/methods/methods_oaf.h:1.2
gnue/geas/src/methods/methods_oaf.h:1.3
--- gnue/geas/src/methods/methods_oaf.h:1.2 Wed Feb 7 12:43:19 2001
+++ gnue/geas/src/methods/methods_oaf.h Fri Jun 8 12:59:21 2001
@@ -1,26 +1,29 @@
-/*
- geas - GNU Enterprise Application Server
+/*
+ methods_oaf.h - Oaf method support (incomplete).
- Copyright (C) 2001 Free Software Foundation
+ Copyright (C) 2001 Free Software Foundation
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- 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.
+ This file is part of the GNU Enterprise Application Server (GEAS)
+ GEAS is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ GEAS 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 GEAS; if not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ $Id: methods_oaf.h,v 1.3 2001/06/08 19:59:21 baumannd Exp $
*/
#ifndef USE_OAF
- #error "USE_OAF was not defined."
+#error "USE_OAF was not defined."
#endif
#error "Currently will not compile or work anyway :)"
@@ -29,156 +32,169 @@
typedef struct
{
- char *classname;
- char *cid;
- CORBA_Object object;
-} provider_t;
+ char *classname;
+ char *cid;
+ CORBA_Object object;
+}
+provider_t;
-static void free_method_provider( provider_t *p );
-static provider_t * allocate_method_provider( const char *classname , const
char *id );
+static void free_method_provider (provider_t * p);
+static provider_t *allocate_method_provider (const char *classname,
+ const char *id);
static GList *provider_list = NULL;
-gboolean initialise_method_handling()
+gboolean
+initialise_method_handling ()
{
- GList *cl,*l,*fields,*fl;
- classdata *c;
- fielddata *f;
- CORBA_Object obj;
- provider_t *p;
- char *oafid;
- CORBA_Environment ev;
- int fails = 0;
-
- CORBA_exception_init(&ev);
-
- /* look for the registered providers for each business method */
- cl = get_classname_list(all_classes);
- if( !cl )
- {
- CORBA_exception_free(&ev);
- return( 0 ); /* done, no classes == no methods :) */
- }
-
- l = cl;
- while( l )
- {
- /* get the class to handle */
- c = find_class_definition( all_classes , l->data );
- debug_output( DEBUGLEVEL_2 , " class %s, class id %s" ,
- get_class_name(c) , get_class_id(c) );
-
- fields = list_fields_in_class( c , FT_method , 0 );
- if( fields )
- {
- /* allocate provider */
- p = allocate_method_provider( get_class_name(c) , get_class_id(c)
);
-
- /* find it */
- oafid = g_strdup_printf( "OAFIID:Bogus.GEAS.MethodProvider:%s"
,get_class_id(c) );
- if( oafid )
- {
- debug_output( DEBUGLEVEL_1, "looking for: '%s'" , oafid );
- p->object = oaf_activate_from_id (oafid, 0, NULL, &ev);
- if( ev._major != CORBA_NO_EXCEPTION )
- {
- errormsg( "Exception: %s" , CORBA_exception_id(&ev) );
- }
- g_free( oafid );
- }
- if( p->object == CORBA_OBJECT_NIL )
- {
- errormsg( "Failed." );
- fails++;
- }
- else
- {
- /* verify existance of methods */
- fl = fields;
- while( fl )
- {
- f = (fielddata *)fl->data;
- debug_output( DEBUGLEVEL_2 , " method: %s" ,
get_fieldname(f) );
- fl = g_list_next( fl );
- }
-
- /* add to list */
- provider_list = g_list_append( provider_list , p );
- }
-
- /* done this class */
- g_list_free( fields );
- }
+ GList *cl, *l, *fields, *fl;
+ classdata *c;
+ fielddata *f;
+ CORBA_Object obj;
+ provider_t *p;
+ char *oafid;
+ CORBA_Environment ev;
+ int fails = 0;
+
+ CORBA_exception_init (&ev);
+
+ /* look for the registered providers for each business method */
+ cl = get_classname_list (all_classes);
+ if (!cl)
+ {
+ CORBA_exception_free (&ev);
+ return (0); /* done, no classes == no methods :) */
+ }
+
+ l = cl;
+ while (l)
+ {
+ /* get the class to handle */
+ c = find_class_definition (all_classes, l->data);
+ debug_output (DEBUGLEVEL_2, " class %s, class id %s",
+ get_class_name (c), get_class_id (c));
+
+ fields = list_fields_in_class (c, FT_method, 0);
+ if (fields)
+ {
+ /* allocate provider */
+ p = allocate_method_provider (get_class_name (c), get_class_id (c));
+
+ /* find it */
+ oafid =
+ g_strdup_printf ("OAFIID:Bogus.GEAS.MethodProvider:%s",
+ get_class_id (c));
+ if (oafid)
+ {
+ debug_output (DEBUGLEVEL_1, "looking for: '%s'", oafid);
+ p->object = oaf_activate_from_id (oafid, 0, NULL, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION)
+ {
+ errormsg ("Exception: %s", CORBA_exception_id (&ev));
+ }
+ g_free (oafid);
+ }
+ if (p->object == CORBA_OBJECT_NIL)
+ {
+ errormsg ("Failed.");
+ fails++;
+ }
+ else
+ {
+ /* verify existance of methods */
+ fl = fields;
+ while (fl)
+ {
+ f = (fielddata *) fl->data;
+ debug_output (DEBUGLEVEL_2, " method: %s",
+ get_fieldname (f));
+ fl = g_list_next (fl);
+ }
+
+ /* add to list */
+ provider_list = g_list_append (provider_list, p);
+ }
+
+ /* done this class */
+ g_list_free (fields);
+ }
#ifdef DEBUG
- else
- {
- debug_output( DEBUGLEVEL_2 , " no methods" );
- }
+ else
+ {
+ debug_output (DEBUGLEVEL_2, " no methods");
+ }
#endif
- /* next class */
- g_free( l->data );
- l = g_list_next( l );
- }
- g_list_free( cl );
- CORBA_exception_free(&ev);
+ /* next class */
+ g_free (l->data);
+ l = g_list_next (l);
+ }
+ g_list_free (cl);
+ CORBA_exception_free (&ev);
- return( fails );
+ return (fails);
}
static void
-free_method_provider( provider_t *p )
+free_method_provider (provider_t * p)
{
- if( p )
- {
- if( p->cid ) g_free( p->cid );
- if( p->classname ) g_free( p->classname );
- g_free( p );
- }
+ if (p)
+ {
+ if (p->cid)
+ g_free (p->cid);
+ if (p->classname)
+ g_free (p->classname);
+ g_free (p);
+ }
}
static provider_t *
-allocate_method_provider( const char *classname , const char *id )
+allocate_method_provider (const char *classname, const char *id)
{
- provider_t *p = (provider_t *)g_new0( provider_t , 1 );
- if( p )
- {
- p->object = CORBA_OBJECT_NIL;
- p->classname = g_strdup( classname );
- p->cid = g_strdup( id );
-
- if( !p->classname || !p->cid )
- {
- free_method_provider( p );
- p = NULL;
- }
- }
- return( p );
+ provider_t *p = (provider_t *) g_new0 (provider_t, 1);
+ if (p)
+ {
+ p->object = CORBA_OBJECT_NIL;
+ p->classname = g_strdup (classname);
+ p->cid = g_strdup (id);
+
+ if (!p->classname || !p->cid)
+ {
+ free_method_provider (p);
+ p = NULL;
+ }
+ }
+ return (p);
}
-gboolean shutdown_method_handling()
+gboolean
+shutdown_method_handling ()
{
}
-
-CORBA_char *execute_method( GEAS_object_reference *obj ,
- const char *methodname , GEAS_Arguments *args ,
CORBA_Environment *ev )
-{
- GList *l = provider_list;
- char *retval = NULL;
- while( l )
- {
- provider_t *p = (provider_t *)l->data;
- if( g_strcasecmp(p->classname,obj->classname) == 0 &&
- g_strcasecmp(p->cid,obj->classid) == 0 )
- {
- debug_output( DEBUGLEVEL_5 , "Method %s.%s called" ,
obj->classname , methodname );
- return( CORBA_string_dup(retval) );
- }
- l = g_list_next(l);
- }
-
- /* not found */
- make_UnknownMethod_exception(ev,"Method '%s.%s' could not be
located.",obj->classname,methodname);
- return( NULL );
+CORBA_char *
+execute_method (GEAS_object_reference * obj,
+ const char *methodname, GEAS_Arguments * args,
+ CORBA_Environment * ev)
+{
+ GList *l = provider_list;
+ char *retval = NULL;
+
+ while (l)
+ {
+ provider_t *p = (provider_t *) l->data;
+ if (g_strcasecmp (p->classname, obj->classname) == 0 &&
+ g_strcasecmp (p->cid, obj->classid) == 0)
+ {
+ debug_output (DEBUGLEVEL_5, "Method %s.%s called", obj->classname,
+ methodname);
+ return (CORBA_string_dup (retval));
+ }
+ l = g_list_next (l);
+ }
+
+ /* not found */
+ make_UnknownMethod_exception (ev, "Method '%s.%s' could not be located.",
+ obj->classname, methodname);
+ return (NULL);
}
Index: gnue/geas/src/methods/methods_unstable.h
diff -u gnue/geas/src/methods/methods_unstable.h:1.5
gnue/geas/src/methods/methods_unstable.h:1.6
--- gnue/geas/src/methods/methods_unstable.h:1.5 Mon Feb 19 17:26:53 2001
+++ gnue/geas/src/methods/methods_unstable.h Fri Jun 8 12:59:21 2001
@@ -1,34 +1,35 @@
-// #error "go away"
+/*
+ methods_unstable.h - Unstable code for python method support.
+
+ Copyright (C) 2001 Free Software Foundation
-/*
- geas - GNU Enterprise Application Server
+ This file is part of the GNU Enterprise Application Server (GEAS)
- Copyright (C) 2001 Free Software Foundation
+ GEAS is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- 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.
+ GEAS 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 GEAS; if not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ $Id: methods_unstable.h,v 1.6 2001/06/08 19:59:21 baumannd Exp $
*/
/*
- this code works, but does not guarantee server stablity, and can do minimal
error
- checking. it should not be used in a production system, but instead serves
as a
- minimal system to start writing useable code
+ this code works, but does not guarantee server stablity, and can do minimal
error
+ checking. it should not be used in a production system, but instead serves
as a
+ minimal system to start writing useable code
*/
#ifndef USE_UNSTABLE_METHODS
- #error "USE_UNSTABLE_METHODS was not defined."
+#error "USE_UNSTABLE_METHODS was not defined."
#endif
#define DEFAULT_IDL_FILE "geas.idl"
@@ -55,351 +56,381 @@
static PyThreadState *py_threadstate = NULL;
static PyInterpreterState *mainInterpreterState;
-static int load_python_binding( configuration config );
+static int load_python_binding (configuration config);
/* START PYTHON MODULE */
-static PyObject *methods_register_python(PyObject * self, PyObject * args)
+static PyObject *
+methods_register_python (PyObject * self, PyObject * args)
{
- PyObject *function;
- char *methodname;
+ PyObject *function;
+ char *methodname;
- if( !PyArg_ParseTuple(args, "sO:methods_register_python", &methodname,
&function) )
- {
- return (NULL);
- }
- Py_XINCREF( function );
- /* PyObject_Print(function, stdout, 0); */
- if (!PyCallable_Check(function))
- {
- Py_XDECREF( function );
- return Py_BuildValue("i", 0);
- }
+ if (!PyArg_ParseTuple
+ (args, "sO:methods_register_python", &methodname, &function))
+ {
+ return (NULL);
+ }
+ Py_XINCREF (function);
+ /* PyObject_Print(function, stdout, 0); */
+ if (!PyCallable_Check (function))
+ {
+ Py_XDECREF (function);
+ return Py_BuildValue ("i", 0);
+ }
- if( current_provider )
- current_provider->extra = (void *)function;
+ if (current_provider)
+ current_provider->extra = (void *) function;
- return Py_BuildValue("i", 1); /* succeed */
+ return Py_BuildValue ("i", 1); /* succeed */
}
PyMethodDef method_system_methods[] = {
- {"register_method", methods_register_python, METH_VARARGS},
- {NULL, NULL}
+ {"register_method", methods_register_python, METH_VARARGS}
+ ,
+ {NULL, NULL}
};
/* END PYTHON MODULE */
-gboolean initialise_method_handling( configuration config )
+gboolean
+initialise_method_handling (configuration config)
{
- char *buf = NULL;
- PyObject *m, *py_dict;
+ char *buf = NULL;
+ PyObject *m, *py_dict;
- /* start up embedded python interpreter */
- /* this is why this code is considered unstable: it can not enforce */
- /* more than minimal security restrictions, and can not prevent */
- /* faulty business methods from crashing the server */
-
- /* initialise python */
- Py_Initialize();
- PyEval_InitThreads();
- mainThreadState = PyThreadState_Get();
-
- /* load ORBit-python binding */
- switch( load_python_binding(config) )
- {
- case ERR_OK:
- /* success */
- break;
- case ERR_NO_GMODULE:
- case ERR_NO_ORBIT_PYTHON:
- case ERR_NO_FUNCTIONS:
- case ERR_MEMORY:
- /* error message already disoplayed */
- return( -1 );
- }
-
- m = Py_InitModule("method_system", method_system_methods);
- if (PyErr_Occurred() || !m)
- {
- fprintf(stdout, "Python error while initialising sub interpreter: ");
- PyErr_Print();
- exit(0);
- }
- py_dict = PyModule_GetDict(m);
- if (PyErr_Occurred())
- {
- fprintf(stdout, "Python error while initialising sub interpreter: ");
- PyErr_Print();
- }
-
- /* python header/initialisation code */
- buf =
- g_strdup_printf("CORBA.load_idl(\"%s\")",
-
get_global_option_str(config,"rootIDLfile",DEFAULT_IDL_FILE) );
- if( !buf )
- {
- errormsg("Out of memory");
- return( ERR_MEMORY );
- }
- PyRun_SimpleString( "import sys" );
- PyRun_SimpleString( "import method_system" );
- PyRun_SimpleString( "import CORBA" );
- message( buf );
- PyRun_SimpleString( buf );
- PyRun_SimpleString( "import GEAS" );
- g_free( buf );
- if( PyErr_Occurred() )
- {
- printf( "Python error occured:\n" );
- fflush(NULL);
- PyErr_Print();
- abort();
- }
- mainInterpreterState = mainThreadState->interp;
- py_threadstate = PyThreadState_New(mainInterpreterState);
- PyEval_ReleaseLock();
+ /* start up embedded python interpreter */
+ /* this is why this code is considered unstable: it can not enforce */
+ /* more than minimal security restrictions, and can not prevent */
+ /* faulty business methods from crashing the server */
+
+ /* initialise python */
+ Py_Initialize ();
+ PyEval_InitThreads ();
+ mainThreadState = PyThreadState_Get ();
+
+ /* load ORBit-python binding */
+ switch (load_python_binding (config))
+ {
+ case ERR_OK:
+ /* success */
+ break;
+ case ERR_NO_GMODULE:
+ case ERR_NO_ORBIT_PYTHON:
+ case ERR_NO_FUNCTIONS:
+ case ERR_MEMORY:
+ /* error message already disoplayed */
+ return (-1);
+ }
+
+ m = Py_InitModule ("method_system", method_system_methods);
+ if (PyErr_Occurred () || !m)
+ {
+ fprintf (stdout, "Python error while initialising sub interpreter: ");
+ PyErr_Print ();
+ exit (0);
+ }
+ py_dict = PyModule_GetDict (m);
+ if (PyErr_Occurred ())
+ {
+ fprintf (stdout, "Python error while initialising sub interpreter: ");
+ PyErr_Print ();
+ }
+
+ /* python header/initialisation code */
+ buf =
+ g_strdup_printf ("CORBA.load_idl(\"%s\")",
+ get_global_option_str (config, "rootIDLfile",
+ DEFAULT_IDL_FILE));
+ if (!buf)
+ {
+ errormsg ("Out of memory");
+ return (ERR_MEMORY);
+ }
+ PyRun_SimpleString ("import sys");
+ PyRun_SimpleString ("import method_system");
+ PyRun_SimpleString ("import CORBA");
+ message (buf);
+ PyRun_SimpleString (buf);
+ PyRun_SimpleString ("import GEAS");
+ g_free (buf);
+ if (PyErr_Occurred ())
+ {
+ printf ("Python error occured:\n");
+ fflush (NULL);
+ PyErr_Print ();
+ abort ();
+ }
+ mainInterpreterState = mainThreadState->interp;
+ py_threadstate = PyThreadState_New (mainInterpreterState);
+ PyEval_ReleaseLock ();
}
-gboolean load_method_handlers( configuration config )
+gboolean
+load_method_handlers (configuration config)
{
- GList *lst;
- char *dirname;
- char *name;
- odl_field *f;
- struct dirent *entry;
- DIR *dir;
- FILE *fp;
- GList *l,*l2;
- odl_class *c;
-
- PyEval_AcquireLock();
- PyThreadState_Swap(py_threadstate);
-
- /* get directory where code files are stored */
- dirname = (char
*)get_global_option_str(config,"methoddir",DEFAULT_METHOD_DIR);
- if( dirname == NULL ) {
- return( FALSE );
- }
- dirname = g_strdup( dirname );
- while (dirname[strlen(dirname) - 1] == '\\' ||
- dirname[strlen(dirname) - 1] == '/')
- dirname[strlen(dirname) - 1] = '\0';
- /* message( "method dir name: '%s'" , dirname ); */
-
- /* execute each .py file */
- dir = opendir( dirname );
- if( !dir )
- {
- errormsg( "Could not open directory '%s'" , dirname );
- g_free( dirname );
- return( FALSE );
- }
- while( (entry = readdir(dir)) != NULL )
- {
- if (is_extension(entry->d_name, "py"))
- {
- name = g_strdup_printf("%s/%s",dirname,entry->d_name);
- if( !name )
- {
- errormsg("Out of memory");
- closedir(dir);
- g_free( dirname );
- return( FALSE );
- }
-
- /* run file 'name' */
- fp = fopen( name , "r" );
- if( !name )
- {
- errormsg("Could not open file '%s'" , name );
- closedir(dir);
- g_free( dirname );
- g_free( name );
- return( FALSE );
- }
- message( "Loading file %s" , name);
- PyRun_SimpleFile(fp,name);
-
- /* done this file */
- fclose( fp );
- g_free( name );
- }
- }
- closedir(dir);
- g_free(dirname);
-
- /* done loading, now register */
-
- lst = l = odl_tree_list_classes(all_classes);
- while( l )
- {
- c = odl_find_class( all_classes , l->data , NULL );
- debug_output( DEBUGLEVEL_2 , " class %s" ,
- odl_class_get_name(c) );
-
- l2 = list = odl_class_get_fields( c , FT_method );
- while( l2 )
- {
- char *buf;
- f = l2->data;
- debug_output( DEBUGLEVEL_2 , " method: %s" ,
odl_field_get_name(f) );
-
- current_provider = alloc_provider_data( odl_class_get_name(c) ,
NULL , odl_field_get_name(f) , NULL );
- provider_list = g_list_append( provider_list , current_provider );
-
- buf = g_strdup_printf( "method_system.register_method( \"%s_%s\" ,
%s_%s )" ,
- odl_class_get_name(c) ,
odl_field_get_name(f) ,
- odl_class_get_name(c) ,
odl_field_get_name(f) );
- g_strdown(buf);
- PyRun_SimpleString(buf);
- g_free( buf );
- current_provider = NULL;
-
- l2 = l2->next;
- }
- odl_fieldlist_free( list );
-
- l = g_list_next( l );
- }
- odl_namelist_free( l );
+ GList *lst;
+ char *dirname;
+ char *name;
+ odl_field *f;
+ struct dirent *entry;
+ DIR *dir;
+ FILE *fp;
+ GList *l, *l2;
+ odl_class *c;
+
+ PyEval_AcquireLock ();
+ PyThreadState_Swap (py_threadstate);
+
+ /* get directory where code files are stored */
+ dirname =
+ (char *) get_global_option_str (config, "methoddir", DEFAULT_METHOD_DIR);
+ if (dirname == NULL)
+ {
+ return (FALSE);
+ }
+ dirname = g_strdup (dirname);
+ while (dirname[strlen (dirname) - 1] == '\\' ||
+ dirname[strlen (dirname) - 1] == '/')
+ dirname[strlen (dirname) - 1] = '\0';
+ /* message( "method dir name: '%s'" , dirname ); */
+
+ /* execute each .py file */
+ dir = opendir (dirname);
+ if (!dir)
+ {
+ errormsg ("Could not open directory '%s'", dirname);
+ g_free (dirname);
+ return (FALSE);
+ }
+ while ((entry = readdir (dir)) != NULL)
+ {
+ if (is_extension (entry->d_name, "py"))
+ {
+ name = g_strdup_printf ("%s/%s", dirname, entry->d_name);
+ if (!name)
+ {
+ errormsg ("Out of memory");
+ closedir (dir);
+ g_free (dirname);
+ return (FALSE);
+ }
+
+ /* run file 'name' */
+ fp = fopen (name, "r");
+ if (!name)
+ {
+ errormsg ("Could not open file '%s'", name);
+ closedir (dir);
+ g_free (dirname);
+ g_free (name);
+ return (FALSE);
+ }
+ message ("Loading file %s", name);
+ PyRun_SimpleFile (fp, name);
+
+ /* done this file */
+ fclose (fp);
+ g_free (name);
+ }
+ }
+ closedir (dir);
+ g_free (dirname);
+
+ /* done loading, now register */
+
+ lst = l = odl_tree_list_classes (all_classes);
+ while (l)
+ {
+ c = odl_find_class (all_classes, l->data, NULL);
+ debug_output (DEBUGLEVEL_2, " class %s", odl_class_get_name (c));
+
+ l2 = list = odl_class_get_fields (c, FT_method);
+ while (l2)
+ {
+ char *buf;
+ f = l2->data;
+ debug_output (DEBUGLEVEL_2, " method: %s",
+ odl_field_get_name (f));
+
+ current_provider =
+ alloc_provider_data (odl_class_get_name (c), NULL,
+ odl_field_get_name (f), NULL);
+ provider_list = g_list_append (provider_list, current_provider);
+
+ buf =
+ g_strdup_printf
+ ("method_system.register_method( \"%s_%s\" , %s_%s )",
+ odl_class_get_name (c), odl_field_get_name (f),
+ odl_class_get_name (c), odl_field_get_name (f));
+ g_strdown (buf);
+ PyRun_SimpleString (buf);
+ g_free (buf);
+ current_provider = NULL;
+
+ l2 = l2->next;
+ }
+ odl_fieldlist_free (list);
+
+ l = g_list_next (l);
+ }
+ odl_namelist_free (l);
- PyThreadState_Swap(NULL);
- PyEval_ReleaseLock();
+ PyThreadState_Swap (NULL);
+ PyEval_ReleaseLock ();
}
-gboolean shutdown_method_handling()
+gboolean
+shutdown_method_handling ()
{
}
-CORBA_char *execute_method( GEAS_object_reference *obj ,
- const char *methodname , GEAS_Arguments *args ,
CORBA_Environment *ev )
+CORBA_char *
+execute_method (GEAS_object_reference * obj,
+ const char *methodname, GEAS_Arguments * args,
+ CORBA_Environment * ev)
{
- char *retval = NULL;
- int i;
- PyObject *result;
- PyObject *l,*tuple;
- PyObject *pyobj,*server;
- char *resultstr = NULL;
- GEAS_DataObject obj2;
- GEAS_Connection serverobj;
-
- obj2 = make_dataobject_reference( obj->classname , obj->objectid ,
obj->username , ev );
- if( ev->_major != CORBA_NO_EXCEPTION )
- /* didn't work */
- return( NULL );
-
- serverobj = make_connection_reference( obj->username , "server_allocated" ,
ev );
- if( ev->_major != CORBA_NO_EXCEPTION ) {
- /* didn't work */
- CORBA_Object_release( obj2 , ev );
- return( NULL );
- }
-
- /* find 'call' object */
- list = provider_list;
- while( list )
- {
- if( !g_strcasecmp( ((provider_t *)list->data)->classname ,
obj->classname ) &&
- !g_strcasecmp( ((provider_t *)list->data)->methodname , methodname
) ) {
- function = ((provider_t *)list->data)->extra;
- list = NULL;
- }
- if( list ) list = list->next;
- }
- if( function != 0 )
- {
- int i;
-
- /* lock python interpreter in case it's needed */
- PyEval_AcquireLock();
- PyThreadState_Swap(py_threadstate);
-
- pyobj = CORBA_to_Python_func(obj2);
- server = CORBA_to_Python_func( serverobj );
-
- /* PyObject_Print(pyobj, stdout, 0); */
- l = PyList_New(0);
- PyList_Append(l, pyobj);
-
- for (i = 0; i < args->_length; i++)
- {
- PyList_Append( l , PyString_FromString(args->_buffer[i]) );
- }
- PyList_Append(l, server);
- tuple = PyList_AsTuple(l);
-
- result = PyObject_CallObject(function,tuple);
- Py_DECREF(pyobj);
- Py_DECREF(server);
- Py_DECREF(l);
- Py_DECREF(tuple);
- if( result != 0 )
- {
-/* printf( "result: " ); PyObject_Print(result, stdout, 0);
- printf( "\n" ); */
-
- if( PyString_AsString(result) ) {
- resultstr = g_strdup( PyString_AsString(result) );
- Py_DECREF(result);
- }
- else {
- fprintf( stderr , "Python methods _must_ return a string
value\n" );
- abort();
- }
- }
- else
- {
- PyErr_Print();
- make_ServerError_exception(ev,"Failed to call method %s.%s
(unknown reason)",obj->classname,methodname);
- PyThreadState_Swap(NULL);
- PyEval_ReleaseLock();
- return( NULL );
- }
- }
- else make_ServerError_exception( ev , "Couldn't find the function to call"
);
-
- /* make method call */
- PyThreadState_Swap(NULL);
- PyEval_ReleaseLock();
-
- retval = CORBA_string_dup(resultstr);
- free( resultstr );
- return( retval );
+ char *retval = NULL;
+ int i;
+ PyObject *result;
+ PyObject *l, *tuple;
+ PyObject *pyobj, *server;
+ char *resultstr = NULL;
+ GEAS_DataObject obj2;
+ GEAS_Connection serverobj;
+
+ obj2 =
+ make_dataobject_reference (obj->classname, obj->objectid, obj->username,
+ ev);
+ if (ev->_major != CORBA_NO_EXCEPTION)
+ /* didn't work */
+ return (NULL);
+
+ serverobj =
+ make_connection_reference (obj->username, "server_allocated", ev);
+ if (ev->_major != CORBA_NO_EXCEPTION)
+ {
+ /* didn't work */
+ CORBA_Object_release (obj2, ev);
+ return (NULL);
+ }
+
+ /* find 'call' object */
+ list = provider_list;
+ while (list)
+ {
+ if (!g_strcasecmp
+ (((provider_t *) list->data)->classname, obj->classname)
+ && !g_strcasecmp (((provider_t *) list->data)->methodname,
+ methodname))
+ {
+ function = ((provider_t *) list->data)->extra;
+ list = NULL;
+ }
+ if (list)
+ list = list->next;
+ }
+ if (function != 0)
+ {
+ int i;
+
+ /* lock python interpreter in case it's needed */
+ PyEval_AcquireLock ();
+ PyThreadState_Swap (py_threadstate);
+
+ pyobj = CORBA_to_Python_func (obj2);
+ server = CORBA_to_Python_func (serverobj);
+
+ /* PyObject_Print(pyobj, stdout, 0); */
+ l = PyList_New (0);
+ PyList_Append (l, pyobj);
+
+ for (i = 0; i < args->_length; i++)
+ {
+ PyList_Append (l, PyString_FromString (args->_buffer[i]));
+ }
+ PyList_Append (l, server);
+ tuple = PyList_AsTuple (l);
+
+ result = PyObject_CallObject (function, tuple);
+ Py_DECREF (pyobj);
+ Py_DECREF (server);
+ Py_DECREF (l);
+ Py_DECREF (tuple);
+ if (result != 0)
+ {
+ /* printf( "result: " ); PyObject_Print(result,
stdout, 0);
+ printf( "\n" ); */
+
+ if (PyString_AsString (result))
+ {
+ resultstr = g_strdup (PyString_AsString (result));
+ Py_DECREF (result);
+ }
+ else
+ {
+ fprintf (stderr,
+ "Python methods _must_ return a string value\n");
+ abort ();
+ }
+ }
+ else
+ {
+ PyErr_Print ();
+ make_ServerError_exception (ev,
+ "Failed to call method %s.%s (unknown
reason)",
+ obj->classname, methodname);
+ PyThreadState_Swap (NULL);
+ PyEval_ReleaseLock ();
+ return (NULL);
+ }
+ }
+ else
+ make_ServerError_exception (ev, "Couldn't find the function to call");
+
+ /* make method call */
+ PyThreadState_Swap (NULL);
+ PyEval_ReleaseLock ();
+
+ retval = CORBA_string_dup (resultstr);
+ free (resultstr);
+ return (retval);
}
static int
-load_python_binding( configuration config )
+load_python_binding (configuration config)
{
- gpointer gsym;
- CORBA_to_Python_func = NULL;
+ gpointer gsym;
+ CORBA_to_Python_func = NULL;
- if ( !g_module_supported() )
- {
- errormsg( "glib dynamic module loading is not supported." );
- return(ERR_NO_GMODULE);
- }
-
- orbit_python_library =
-
g_module_open(get_global_option_str(config,"ORBit-python",ORBIT_PYTHON_SO),
G_MODULE_BIND_LAZY);
-
- if( !orbit_python_library )
- {
- errormsg( "Could not load ORBit-Python module." );
- return(ERR_NO_ORBIT_PYTHON);
- }
-
- g_module_symbol(orbit_python_library, "CORBA_Object_to_PyObject", &gsym);
- CORBA_to_Python_func = gsym;
-
- if( !CORBA_to_Python_func )
- {
- errormsg( "Could not locate required functions" );
- return( ERR_NO_FUNCTIONS );
- }
+ if (!g_module_supported ())
+ {
+ errormsg ("glib dynamic module loading is not supported.");
+ return (ERR_NO_GMODULE);
+ }
+
+ orbit_python_library =
+ g_module_open (get_global_option_str
+ (config, "ORBit-python", ORBIT_PYTHON_SO),
+ G_MODULE_BIND_LAZY);
+
+ if (!orbit_python_library)
+ {
+ errormsg ("Could not load ORBit-Python module.");
+ return (ERR_NO_ORBIT_PYTHON);
+ }
+
+ g_module_symbol (orbit_python_library, "CORBA_Object_to_PyObject", &gsym);
+ CORBA_to_Python_func = gsym;
+
+ if (!CORBA_to_Python_func)
+ {
+ errormsg ("Could not locate required functions");
+ return (ERR_NO_FUNCTIONS);
+ }
- return( ERR_OK );
+ return (ERR_OK);
}
-
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/geas/src/methods methods.h methods_oaf.h m...,
Daniel E. Baumann <=