[omniORB] Implementing a python version of Txn::Current
Scott Robertson
srobertson@codeit.com
Fri Mar 7 19:27:02 2003
Funny, I just sent you the same patch! Although mine uses a linked list
and your's uses the Python list.No biggy, anyhow I'll give it a whirl
later on and let you know.
Thanks!
On Fri, 2003-03-07 at 09:46, Duncan Grisby wrote:
> On Monday 24 February, Duncan Grisby wrote:
>
> > What I would suggest is to add a function to the omniORBpy C++ api
> > (see include/omniORBpy.h in the omniORBpy tree) that allows you to
> > register additional functions / objects that try to narrow pseudo
> > objects. That way, createPyPseudoObjRef can consult a list of
> > registered converters if its built in ones don't work.
>
> I have implemented a way to register pseudo object creation functions,
> using a list of PyCObjects. I've attached a patch. Does it work for
> you?
>
> Cheers,
>
> Duncan.
>
>
> ______________________________________________________________________
>
> Index: include/omniORBpy.h
> ===================================================================
> RCS file: /cvsroot/omniorb/omniORBpy/include/Attic/omniORBpy.h,v
> retrieving revision 1.1.2.1
> diff -u -r1.1.2.1 omniORBpy.h
> --- include/omniORBpy.h 26 May 2002 21:04:17 -0000 1.1.2.1
> +++ include/omniORBpy.h 7 Mar 2003 17:32:55 -0000
> @@ -45,7 +45,7 @@
> // omniORBpyAPI* api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi);
> // Py_DECREF(pyapi);
> //
> -// Obviously, you MUST NOT modify the functions pointers!
> +// Obviously, you MUST NOT modify the function pointers!
> //
> // This arrangement of things means you do not have to link to the
> // _omnipymodule library to be able to use the API.
> @@ -68,5 +68,17 @@
> omniORBpyAPI();
> // Constructor for the singleton. Sets up the function pointers.
> };
> +
> +
> +// Extensions to omniORB / omniORBpy may create their own pseudo
> +// object reference types. To provide a Python mapping for these, a
> +// function must be provided that takes a CORBA::Object_ptr and
> +// returns a suitable PyObject. Functions are registered by appending
> +// PyCObjects to the list _omnipy.pseudoFns. The CObjects must contain
> +// pointers to functions with this signature:
> +
> +typedef PyObject* (*omniORBpyPseudoFn)(const CORBA::Object_ptr);
> +
> +
>
> #endif // _omniORBpy_h_
> Index: modules/omnipy.cc
> ===================================================================
> RCS file: /cvsroot/omniorb/omniORBpy/modules/Attic/omnipy.cc,v
> retrieving revision 1.1.2.19
> diff -u -r1.1.2.19 omnipy.cc
> --- modules/omnipy.cc 26 May 2002 00:55:36 -0000 1.1.2.19
> +++ modules/omnipy.cc 7 Mar 2003 17:32:55 -0000
> @@ -107,6 +107,7 @@
>
> PyInterpreterState* omniPy::pyInterpreter;
>
> +PyObject* omniPy::py_omnipymodule; // The _omnipy extension
> PyObject* omniPy::pyCORBAmodule; // The CORBA module
> PyObject* omniPy::pyCORBAsysExcMap; // The system exception map
> PyObject* omniPy::pyCORBAAnyClass; // Any class
> @@ -845,6 +846,7 @@
> PyDict_SetItemString(d, (char*)"system_exceptions", excs);
> Py_DECREF(excs);
>
> + omniPy::py_omnipymodule = m;
> omniPy::initORBFunc(d);
> omniPy::initPOAFunc(d);
> omniPy::initPOAManagerFunc(d);
> @@ -854,6 +856,11 @@
> // Set up the C++ API singleton
> PyObject* api = PyCObject_FromVoidPtr((void*)&omniPy::cxxAPI, 0);
> PyDict_SetItemString(d, (char*)"API", api);
> +
> + // Create an empty list for extrernal modules to register
> + // additional pseudo object creation functions.
> + PyObject* pseudolist = PyList_New(0);
> + PyDict_SetItemString(d, (char*)"pseudoFns", pseudolist);
>
> omniInitialiser::install(&the_omni_python_initialiser);
> }
> Index: modules/omnipy.h
> ===================================================================
> RCS file: /cvsroot/omniorb/omniORBpy/modules/Attic/omnipy.h,v
> retrieving revision 1.2.4.19
> diff -u -r1.2.4.19 omnipy.h
> --- modules/omnipy.h 27 Nov 2002 00:18:25 -0000 1.2.4.19
> +++ modules/omnipy.h 7 Mar 2003 17:32:56 -0000
> @@ -139,7 +139,8 @@
> // Global pointers to Python objects //
> ////////////////////////////////////////////////////////////////////////////
>
> - static PyObject* pyCORBAmodule; // The CORBA module
> + static PyObject* py_omnipymodule; // _omnipy module
> + static PyObject* pyCORBAmodule; // CORBA module
> static PyObject* pyCORBAsysExcMap; // The system exception map
> static PyObject* pyCORBAAnyClass; // Any class
> static PyObject* pyCORBAContextClass;// Context class
> Index: modules/pyObjectRef.cc
> ===================================================================
> RCS file: /cvsroot/omniorb/omniORBpy/modules/Attic/pyObjectRef.cc,v
> retrieving revision 1.1.2.16
> diff -u -r1.1.2.16 pyObjectRef.cc
> --- modules/pyObjectRef.cc 2 Aug 2002 13:33:49 -0000 1.1.2.16
> +++ modules/pyObjectRef.cc 7 Mar 2003 17:32:56 -0000
> @@ -85,6 +85,7 @@
> //
>
> #include <omnipy.h>
> +#include <omniORBpy.h>
>
> // Internal omniORB interfaces
> #include <objectTable.h>
> @@ -248,6 +249,35 @@
> PortableServer::Current_var pc = PortableServer::Current::_narrow(objref);
> if (!CORBA::is_nil(pc)) return createPyPOACurrentObject(pc);
> }
> + do {
> + // No built in converter. Try the list of registered external functions
> + PyObject* fnlist = PyObject_GetAttrString(omniPy::py_omnipymodule,
> + (char*)"pseudoFns");
> + if (!fnlist || !PySequence_Check(fnlist)) {
> + PyErr_Clear();
> + omniORB::logs(1, "WARNING: _omnipy.pseudoFns is not a sequence.");
> + Py_XDECREF(fnlist);
> + break;
> + }
> + int len = PySequence_Size(fnlist);
> + for (int i=0; i < len; i++) {
> + PyObject* pyf = PySequence_GetItem(fnlist, i);
> + if (!PyCObject_Check(pyf)) {
> + omniORB::logs(1, "WARNING: Entry in _omnipy.pseudoFns "
> + "is not a PyCObject.");
> + continue;
> + }
> + omniORBpyPseudoFn f = (omniORBpyPseudoFn)PyCObject_AsVoidPtr(pyf);
> + PyObject* ret = f(objref);
> + if (ret) {
> + Py_DECREF(fnlist);
> + return ret;
> + }
> + }
> + Py_DECREF(fnlist);
> +
> + } while (0);
> +
> try {
> // Use OMNIORB_THROW to get a nice trace message
> OMNIORB_THROW(INV_OBJREF, INV_OBJREF_NoPythonTypeForPseudoObj,
>
> ______________________________________________________________________
>
> --
> -- Duncan Grisby --
> -- duncan@grisby.org --
> -- http://www.grisby.org --
--
Scott Robertson <srobertson@codeit.com>