1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 %module libSALOME_Comm
25 %feature("autodoc", "1");
28 #include "ReceiverFactory.hxx"
29 #include "MatrixClient.hxx"
30 #include "SALOME_Comm_i.hxx"
31 #include "SALOMEMultiComm.hxx"
32 #include "SenderFactory.hxx"
35 %typemap(in) SALOME::SenderDouble_ptr
37 PyObject* pdict = PyDict_New();
38 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
39 PyRun_String("from omniORB import CORBA", Py_single_input, pdict, pdict);
41 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
44 PyObject* orb = PyDict_GetItemString(pdict, "o");
46 // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
48 PyObject* iorSupport = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
50 if (iorSupport == Py_None)
52 char * s = PyString_AsString(PyObject_Str(iorSupport));
54 // Ask omniORB to convert IOR string to SALOME::SenderDouble_ptr
57 char *xargv = (char*)"";
59 CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
60 CORBA::Object_var O = ORB->string_to_object(s);
61 SALOME::SenderDouble_ptr t = SALOME::SenderDouble::_narrow(O);
65 %typemap(in) SALOME::SenderInt_ptr
67 PyObject* pdict = PyDict_New();
68 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
69 PyRun_String("from omniORB import CORBA", Py_single_input, pdict, pdict);
71 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
74 PyObject* orb = PyDict_GetItemString(pdict, "o");
76 // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
78 PyObject* iorSupport = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
80 if (iorSupport == Py_None)
82 char * s = PyString_AsString(PyObject_Str(iorSupport));
84 // Ask omniORB to convert IOR string to SALOME::SenderInt_ptr
87 char *xargv = (char*)"";
89 CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
90 CORBA::Object_var O = ORB->string_to_object(s);
91 SALOME::SenderInt_ptr t = SALOME::SenderInt::_narrow(O);
95 %typemap(out) SALOME::SenderDouble_ptr
97 PyObject* pdict = PyDict_New();
98 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
99 PyRun_String("from omniORB import CORBA", Py_single_input, pdict, pdict);
100 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
102 PyObject* orb = PyDict_GetItemString(pdict, "o");
103 // Get the orb Corba C++
105 char *xargv = (char*)"";
106 char **argv = &xargv;
107 CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
108 std::string s = ORB->object_to_string($1);
109 PyObject * tmp = PyString_FromString(s.c_str());
110 $result = PyObject_CallMethod(orb, (char*)"string_to_object", (char*)"O", tmp);
113 %typemap(out) SALOME::SenderInt_ptr
115 PyObject* pdict = PyDict_New();
116 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
117 PyRun_String("from omniORB import CORBA", Py_single_input, pdict, pdict);
118 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
120 PyObject* orb = PyDict_GetItemString(pdict, "o");
121 // Get the orb Corba C++
123 char *xargv = (char*)"";
124 char **argv = &xargv;
125 CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
126 std::string s = ORB->object_to_string($1);
127 PyObject * tmp = PyString_FromString(s.c_str());
128 $result = PyObject_CallMethod(orb, (char*)"string_to_object", (char*)"O", tmp);
131 PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble);
134 PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble)
138 double *ret=ReceiverFactory::getValue(senderDouble,size);
139 py_list = PyList_New(size);
140 for (int i=0; i < size; i++)
142 int err = PyList_SetItem(py_list, i, Py_BuildValue("d", (double) ret[i]));
145 const char * message = "Error in SUPPORT::getTypes";
146 PyErr_SetString(PyExc_RuntimeError, message);
150 PyObject * result = Py_BuildValue("O", py_list);
158 PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt);
161 PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt)
165 int *ret=ReceiverFactory::getValue(senderInt,size);
166 py_list = PyList_New(size);
167 for (int i=0; i < size; i++)
169 int err = PyList_SetItem(py_list, i, Py_BuildValue("i", (int) ret[i]));
172 const char * message = "Error in SUPPORT::getTypes";
173 PyErr_SetString(PyExc_RuntimeError, message);
177 PyObject * result = Py_BuildValue("O", py_list);
184 PyObject * getValueForMatrix(SALOME::Matrix_ptr matrix);
186 PyObject * getValueForMatrix(SALOME::Matrix_ptr matrix)
190 double *ret=MatrixClient::getValue(matrix,column,row);
191 py_list = PyList_New(row);
192 for(int i=0;i<row;i++)
194 PyObject *tmpRow=PyList_New(column);
195 for(int j=0;j<column;j++)
197 int err = PyList_SetItem(tmpRow, j, Py_BuildValue("d", (double) ret[i*column+j]));
200 const char * message = "PyList_SetItem matrix sent may be invalid";
201 PyErr_SetString(PyExc_RuntimeError, message);
205 PyList_SetItem(py_list,i,tmpRow);
214 SALOME::SenderDouble_ptr buildSenderDoubleFromList(PyObject *pylist);
216 SALOME::SenderDouble_ptr buildSenderDoubleFromList(PyObject *pylist)
218 if (PyList_Check(pylist))
220 int listLgth = PyList_Size(pylist);
221 double *tab=new double[listLgth];
222 for (int i=0;i<listLgth;i++)
224 tab[i]=PyFloat_AsDouble(PyList_GetItem(pylist,i));
226 SALOMEMultiComm communicator;
227 return SenderFactory::buildSender(communicator,tab,listLgth,true);
231 PyErr_SetString(PyExc_TypeError,"not a list");
232 return SALOME::SenderDouble::_nil();
237 SALOME::SenderInt_ptr buildSenderIntFromList(PyObject *pylist);
239 SALOME::SenderInt_ptr buildSenderIntFromList(PyObject *pylist)
241 if (PyList_Check(pylist))
243 int listLgth = PyList_Size(pylist);
244 int *tab=new int[listLgth];
245 for (int i=0;i<listLgth;i++)
247 tab[i]=PyInt_AsLong(PyList_GetItem(pylist,i));
249 SALOMEMultiComm communicator;
250 return SenderFactory::buildSender(communicator,tab,listLgth,true);
254 PyErr_SetString(PyExc_TypeError,"not a list");
255 return SALOME::SenderInt::_nil();