From 62d1ec0227d941abf7c90ac092eb28542495106f Mon Sep 17 00:00:00 2001 From: prascle Date: Wed, 2 Nov 2005 15:55:32 +0000 Subject: [PATCH] PR: corrections from A. Geay --- src/Communication/Makefile.in | 4 +- src/Communication/MultiCommException.hxx | 7 +- src/Communication/SALOMEMultiComm.hxx | 8 +- src/Communication/SenderFactory.hxx | 8 +- src/Communication_SWIG/Makefile.in | 24 +++++ src/Communication_SWIG/libSALOME_Comm.i | 119 +++++++++++++++++++++++ src/MPIContainer/Makefile.in | 4 +- src/Makefile.in | 3 +- src/TestMPIContainer/Makefile.in | 4 +- 9 files changed, 155 insertions(+), 26 deletions(-) create mode 100644 src/Communication_SWIG/Makefile.in create mode 100644 src/Communication_SWIG/libSALOME_Comm.i diff --git a/src/Communication/Makefile.in b/src/Communication/Makefile.in index e859ea4fb..15886f867 100644 --- a/src/Communication/Makefile.in +++ b/src/Communication/Makefile.in @@ -13,7 +13,9 @@ EXPORT_HEADERS = \ ReceiverFactory.hxx \ SenderFactory.hxx \ SALOMEMultiComm.hxx \ - MultiCommException.hxx + MultiCommException.hxx \ + SALOME_Comm_i.hxx + # Libraries targets LIB = libSalomeCommunication.la diff --git a/src/Communication/MultiCommException.hxx b/src/Communication/MultiCommException.hxx index 6313ab5e4..fe029fc4a 100644 --- a/src/Communication/MultiCommException.hxx +++ b/src/Communication/MultiCommException.hxx @@ -3,13 +3,8 @@ #include -#if defined WNT && defined COMMUNICATION_EXPORTS -#define COMMUNICATION_EXPORT __declspec( dllexport ) -#else -#define COMMUNICATION_EXPORT -#endif -class COMMUNICATION_EXPORT MultiCommException { +class MultiCommException { private: std::string _message; public: diff --git a/src/Communication/SALOMEMultiComm.hxx b/src/Communication/SALOMEMultiComm.hxx index 8c46251af..2537dc042 100644 --- a/src/Communication/SALOMEMultiComm.hxx +++ b/src/Communication/SALOMEMultiComm.hxx @@ -4,17 +4,11 @@ #include #include CORBA_SERVER_HEADER(SALOME_Comm) -#if defined WNT && defined COMMUNICATION_EXPORTS -#define COMMUNICATION_EXPORT __declspec( dllexport ) -#else -#define COMMUNICATION_EXPORT -#endif - /*! Class is designed to ease the use of multi communication.\n Simply inherite from it your servant class you want to emit data with senders. */ -class COMMUNICATION_EXPORT SALOMEMultiComm : public virtual POA_SALOME::MultiCommClass { +class SALOMEMultiComm : public virtual POA_SALOME::MultiCommClass { protected: SALOME::TypeOfCommunication _type; public: diff --git a/src/Communication/SenderFactory.hxx b/src/Communication/SenderFactory.hxx index 39edaa3a1..ce3a0ad91 100644 --- a/src/Communication/SenderFactory.hxx +++ b/src/Communication/SenderFactory.hxx @@ -5,12 +5,6 @@ #include #include CORBA_SERVER_HEADER(SALOME_Comm) -#if defined WNT && defined COMMUNICATION_EXPORTS -#define COMMUNICATION_EXPORT __declspec( dllexport ) -#else -#define COMMUNICATION_EXPORT -#endif - class SALOMEMultiComm; class SALOME_SenderDouble_i; @@ -19,7 +13,7 @@ class SALOME_SenderInt_i; /*! This class implements the factory pattern of GoF by making a sender by giving an array and a communicator.It completely hides the type of sender from the user. */ -class COMMUNICATION_EXPORT SenderFactory +class SenderFactory { public: static SALOME::SenderDouble_ptr buildSender(SALOMEMultiComm &multiCommunicator,const double *tab,long lgr,bool ownTab=false) throw(MultiCommException); diff --git a/src/Communication_SWIG/Makefile.in b/src/Communication_SWIG/Makefile.in new file mode 100644 index 000000000..5b0c6c1d1 --- /dev/null +++ b/src/Communication_SWIG/Makefile.in @@ -0,0 +1,24 @@ + +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl + +@COMMENCE@ + +# header files +EXPORT_HEADERS= libSALOME_Comm.i + +# Libraries targets + +LIB = libSALOME_Commcmodule.la +LIB_SERVER_IDL = SALOME_Exception.idl + +SWIG_DEF = libSALOME_Comm.i +EXPORT_PYSCRIPTS = libSALOME_Comm.py + +CPPFLAGS+=$(PYTHON_INCLUDES) -I$(top_srcdir)/src/Communication/src +LIBS+= $(PYTHON_LIBS) +LDFLAGS+= -lSalomeCommunication + +@CONCLUDE@ diff --git a/src/Communication_SWIG/libSALOME_Comm.i b/src/Communication_SWIG/libSALOME_Comm.i new file mode 100644 index 000000000..42d4d5a3e --- /dev/null +++ b/src/Communication_SWIG/libSALOME_Comm.i @@ -0,0 +1,119 @@ +%module libSALOME_Comm + +%{ + #include "ReceiverFactory.hxx" + #include "SALOME_Comm_i.hxx" +%} + +%typemap(python,in) SALOME::SenderDouble_ptr +{ + PyObject* pdict = PyDict_New(); + PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins()); + PyRun_String("import CORBA", Py_single_input, pdict, pdict); + + PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input, + pdict, pdict); + + PyObject* orb = PyDict_GetItemString(pdict, "o"); + + // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string + + PyObject* iorSupport = PyObject_CallMethod(orb, "object_to_string", "O", $input); + + if (iorSupport == Py_None) + return NULL; + char * s = PyString_AsString(PyObject_Str(iorSupport)); + + // Ask omniORB to convert IOR string to SALOME::SenderDouble_ptr + + int argc = 0; + char *xargv = ""; + char **argv = &xargv; + CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv); + CORBA::Object_var O = ORB->string_to_object(s); + SALOME::SenderDouble_ptr t = SALOME::SenderDouble::_narrow(O); + $1 = t; +} + +%typemap(python,in) SALOME::SenderInt_ptr +{ + PyObject* pdict = PyDict_New(); + PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins()); + PyRun_String("import CORBA", Py_single_input, pdict, pdict); + + PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input, + pdict, pdict); + + PyObject* orb = PyDict_GetItemString(pdict, "o"); + + // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string + + PyObject* iorSupport = PyObject_CallMethod(orb, "object_to_string", "O", $input); + + if (iorSupport == Py_None) + return NULL; + char * s = PyString_AsString(PyObject_Str(iorSupport)); + + // Ask omniORB to convert IOR string to SALOME::SenderInt_ptr + + int argc = 0; + char *xargv = ""; + char **argv = &xargv; + CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv); + CORBA::Object_var O = ORB->string_to_object(s); + SALOME::SenderInt_ptr t = SALOME::SenderInt::_narrow(O); + $1 = t; +} + +PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble); + +%{ +PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble) +{ + PyObject *py_list; + long size; + double *ret=ReceiverFactory::getValue(senderDouble,size); + py_list = PyList_New(size); + for (int i=0; i < size; i++) + { + int err = PyList_SetItem(py_list, i, Py_BuildValue("d", (double) ret[i])); + if(err) + { + char * message = "Error in SUPPORT::getTypes"; + PyErr_SetString(PyExc_RuntimeError, message); + return NULL; + } + } + PyObject * result = Py_BuildValue("O", py_list); + delete [] ret; + Py_DECREF(py_list); + return result; +} +%} + + +PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt); + +%{ +PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt) +{ + PyObject *py_list; + long size; + int *ret=ReceiverFactory::getValue(senderInt,size); + py_list = PyList_New(size); + for (int i=0; i < size; i++) + { + int err = PyList_SetItem(py_list, i, Py_BuildValue("i", (int) ret[i])); + if(err) + { + char * message = "Error in SUPPORT::getTypes"; + PyErr_SetString(PyExc_RuntimeError, message); + return NULL; + } + } + PyObject * result = Py_BuildValue("O", py_list); + delete [] ret; + Py_DECREF(py_list); + return result; +} +%} diff --git a/src/MPIContainer/Makefile.in b/src/MPIContainer/Makefile.in index 6aa39f7ce..808e9a422 100644 --- a/src/MPIContainer/Makefile.in +++ b/src/MPIContainer/Makefile.in @@ -50,7 +50,7 @@ LIB_SERVER_IDL = SALOME_MPIObject.idl SALOME_MPIContainer.idl # Executables targets BIN = SALOME_MPIContainer BIN_SRC = -BIN_SERVER_IDL = SALOME_MPIObject.idl SALOME_MPIContainer.idl +BIN_SERVER_IDL = SALOME_MPIObject.idl SALOME_MPIContainer.idl SALOME_Exception.idl CPPFLAGS+= $(PYTHON_INCLUDES) LDFLAGS+= -lSalomeContainer -lSalomeNS -lRegistry -lOpUtil -lSalomeNotification -lSALOMELocalTrace -lSalomeResourcesManager @@ -59,7 +59,7 @@ ifeq (@WITHMPI@,yes) LIBS += $(PYTHON_LIBS) $(MPI_LIBS) CXXFLAGS+=${MPI_INCLUDES} CXX_DEPEND_FLAG+=${MPI_INCLUDES} - LDFLAGSFORBIN= $(LDFLAGS) + LDFLAGSFORBIN= $(LDFLAGS) -lSALOMEBasics LIBSFORBIN= $(LIBS) endif diff --git a/src/Makefile.in b/src/Makefile.in index 66f591413..2830eaca5 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -59,7 +59,8 @@ SUBDIRS = \ SALOMEDS \ KERNEL_PY \ ModuleGenerator \ - Communication + Communication \ + Communication_SWIG ifeq (@mpi_ok@,yes) SUBDIRS+= MPIContainer TestMPIContainer diff --git a/src/TestMPIContainer/Makefile.in b/src/TestMPIContainer/Makefile.in index 451d9d20f..000d291af 100644 --- a/src/TestMPIContainer/Makefile.in +++ b/src/TestMPIContainer/Makefile.in @@ -28,10 +28,10 @@ LIB_CLIENT_IDL = Logger.idl SALOME_MPIObject.idl SALOME_TestMPIComponent.idl SAL # Executables targets BIN = TestMPIContainer BIN_SRC = -BIN_CLIENT_IDL = Logger.idl SALOME_MPIObject.idl SALOME_MPIContainer.idl SALOME_TestMPIComponent.idl +BIN_CLIENT_IDL = Logger.idl SALOME_MPIObject.idl SALOME_MPIContainer.idl SALOME_TestMPIComponent.idl SALOME_Exception.idl BIN_SERVER_IDL = -LDFLAGSFORBIN+= -lSalomeNotification -lSalomeNS -lSalomeLifeCycleCORBA -lSalomeMPIContainer -lSalomeContainer -lRegistry -lOpUtil -lSALOMELocalTrace -lSalomeResourcesManager ${MPI_LIBS} +LDFLAGSFORBIN+= -lSalomeNotification -lSalomeNS -lSalomeLifeCycleCORBA -lSalomeMPIContainer -lSalomeContainer -lRegistry -lOpUtil -lSALOMELocalTrace -lSALOMEBasics -lSalomeResourcesManager ${MPI_LIBS} CXXFLAGS+=${MPI_INCLUDES} CXX_DEPEND_FLAG+=${MPI_INCLUDES} -- 2.39.2