1 // Copyright (C) 2007-2008 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.
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
22 %module libSALOME_Comm
24 %feature("autodoc", "1");
27 #include "ReceiverFactory.hxx"
28 #include "MatrixClient.hxx"
32 #include "SALOME_Comm_i.hxx"
33 #include "SALOMEMultiComm.hxx"
34 #include "SenderFactory.hxx"
37 %typemap(python,in) SALOME::SenderDouble_ptr
39 PyObject* pdict = PyDict_New();
40 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
41 PyRun_String("import CORBA", Py_single_input, pdict, pdict);
43 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
46 PyObject* orb = PyDict_GetItemString(pdict, "o");
48 // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
50 PyObject* iorSupport = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
52 if (iorSupport == Py_None)
54 char * s = PyString_AsString(PyObject_Str(iorSupport));
56 // Ask omniORB to convert IOR string to SALOME::SenderDouble_ptr
59 char *xargv = (char*)"";
61 CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
62 CORBA::Object_var O = ORB->string_to_object(s);
63 SALOME::SenderDouble_ptr t = SALOME::SenderDouble::_narrow(O);
67 %typemap(python,in) SALOME::SenderInt_ptr
69 PyObject* pdict = PyDict_New();
70 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
71 PyRun_String("import CORBA", Py_single_input, pdict, pdict);
73 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
76 PyObject* orb = PyDict_GetItemString(pdict, "o");
78 // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
80 PyObject* iorSupport = PyObject_CallMethod(orb, (char*)"object_to_string", (char*)"O", $input);
82 if (iorSupport == Py_None)
84 char * s = PyString_AsString(PyObject_Str(iorSupport));
86 // Ask omniORB to convert IOR string to SALOME::SenderInt_ptr
89 char *xargv = (char*)"";
91 CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
92 CORBA::Object_var O = ORB->string_to_object(s);
93 SALOME::SenderInt_ptr t = SALOME::SenderInt::_narrow(O);
97 %typemap(python,out) SALOME::SenderDouble_ptr
99 PyObject* pdict = PyDict_New();
100 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
101 PyRun_String("import CORBA", Py_single_input, pdict, pdict);
102 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
104 PyObject* orb = PyDict_GetItemString(pdict, "o");
105 // Get the orb Corba C++
107 char *xargv = (char*)"";
108 char **argv = &xargv;
109 CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
110 std::string s = ORB->object_to_string($1);
111 PyObject * tmp = PyString_FromString(s.c_str());
112 $result = PyObject_CallMethod(orb, (char*)"string_to_object", (char*)"O", tmp);
115 %typemap(python,out) SALOME::SenderInt_ptr
117 PyObject* pdict = PyDict_New();
118 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
119 PyRun_String("import CORBA", Py_single_input, pdict, pdict);
120 PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
122 PyObject* orb = PyDict_GetItemString(pdict, "o");
123 // Get the orb Corba C++
125 char *xargv = (char*)"";
126 char **argv = &xargv;
127 CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
128 std::string s = ORB->object_to_string($1);
129 PyObject * tmp = PyString_FromString(s.c_str());
130 $result = PyObject_CallMethod(orb, (char*)"string_to_object", (char*)"O", tmp);
133 PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble);
136 PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble)
140 double *ret=ReceiverFactory::getValue(senderDouble,size);
141 py_list = PyList_New(size);
142 for (int i=0; i < size; i++)
144 int err = PyList_SetItem(py_list, i, Py_BuildValue("d", (double) ret[i]));
147 const char * message = "Error in SUPPORT::getTypes";
148 PyErr_SetString(PyExc_RuntimeError, message);
152 PyObject * result = Py_BuildValue("O", py_list);
160 PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt);
163 PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt)
167 int *ret=ReceiverFactory::getValue(senderInt,size);
168 py_list = PyList_New(size);
169 for (int i=0; i < size; i++)
171 int err = PyList_SetItem(py_list, i, Py_BuildValue("i", (int) ret[i]));
174 const char * message = "Error in SUPPORT::getTypes";
175 PyErr_SetString(PyExc_RuntimeError, message);
179 PyObject * result = Py_BuildValue("O", py_list);
186 PyObject * getValueForMatrix(SALOME::Matrix_ptr matrix);
188 PyObject * getValueForMatrix(SALOME::Matrix_ptr matrix)
192 double *ret=MatrixClient::getValue(matrix,column,row);
193 py_list = PyList_New(row);
194 for(int i=0;i<row;i++)
196 PyObject *tmpRow=PyList_New(column);
197 for(int j=0;j<column;j++)
199 int err = PyList_SetItem(tmpRow, j, Py_BuildValue("d", (double) ret[i*column+j]));
202 const char * message = "PyList_SetItem matrix sent may be invalid";
203 PyErr_SetString(PyExc_RuntimeError, message);
207 PyList_SetItem(py_list,i,tmpRow);
216 SALOME::SenderDouble_ptr buildSenderDoubleFromList(PyObject *pylist);
218 SALOME::SenderDouble_ptr buildSenderDoubleFromList(PyObject *pylist)
220 if (PyList_Check(pylist))
222 int listLgth = PyList_Size(pylist);
223 double *tab=new double[listLgth];
224 for (int i=0;i<listLgth;i++)
226 tab[i]=PyFloat_AsDouble(PyList_GetItem(pylist,i));
228 SALOMEMultiComm communicator;
229 return SenderFactory::buildSender(communicator,tab,listLgth,true);
233 PyErr_SetString(PyExc_TypeError,"not a list");
234 return SALOME::SenderDouble::_nil();
239 SALOME::SenderInt_ptr buildSenderIntFromList(PyObject *pylist);
241 SALOME::SenderInt_ptr buildSenderIntFromList(PyObject *pylist)
243 if (PyList_Check(pylist))
245 int listLgth = PyList_Size(pylist);
246 int *tab=new int[listLgth];
247 for (int i=0;i<listLgth;i++)
249 tab[i]=PyInt_AsLong(PyList_GetItem(pylist,i));
251 SALOMEMultiComm communicator;
252 return SenderFactory::buildSender(communicator,tab,listLgth,true);
256 PyErr_SetString(PyExc_TypeError,"not a list");
257 return SALOME::SenderInt::_nil();