]> SALOME platform Git repositories - modules/yacs.git/blob - src/Communication_SWIG/libSALOME_Comm.i
Salome HOME
9a1b8dc0ca8af5b3cadc0a9d54d013d1690b6f0b
[modules/yacs.git] / src / Communication_SWIG / libSALOME_Comm.i
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 %module libSALOME_Comm
21
22 %{
23   #include "ReceiverFactory.hxx"
24   #undef SEEK_SET
25   #undef SEEK_CUR
26   #undef SEEK_END
27   #include "SALOME_Comm_i.hxx"
28 %}
29
30 %typemap(python,in) SALOME::SenderDouble_ptr
31 {
32   PyObject* pdict = PyDict_New();
33   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
34   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
35  
36   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
37                    pdict, pdict);
38  
39   PyObject* orb = PyDict_GetItemString(pdict, "o");
40
41   // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
42
43   PyObject* iorSupport = PyObject_CallMethod(orb, "object_to_string", "O", $input);
44  
45   if (iorSupport == Py_None)
46     return NULL;
47   char * s = PyString_AsString(PyObject_Str(iorSupport));
48  
49   // Ask omniORB to convert IOR string to SALOME::SenderDouble_ptr
50
51   int argc = 0;
52   char *xargv = "";
53   char **argv = &xargv;
54   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
55   CORBA::Object_var O =  ORB->string_to_object(s);
56   SALOME::SenderDouble_ptr t = SALOME::SenderDouble::_narrow(O);
57   $1 = t;
58 }
59
60 %typemap(python,in) SALOME::SenderInt_ptr
61 {
62   PyObject* pdict = PyDict_New();
63   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
64   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
65  
66   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
67                    pdict, pdict);
68  
69   PyObject* orb = PyDict_GetItemString(pdict, "o");
70
71   // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
72
73   PyObject* iorSupport = PyObject_CallMethod(orb, "object_to_string", "O", $input);
74  
75   if (iorSupport == Py_None)
76     return NULL;
77   char * s = PyString_AsString(PyObject_Str(iorSupport));
78  
79   // Ask omniORB to convert IOR string to SALOME::SenderInt_ptr
80
81   int argc = 0;
82   char *xargv = "";
83   char **argv = &xargv;
84   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
85   CORBA::Object_var O =  ORB->string_to_object(s);
86   SALOME::SenderInt_ptr t = SALOME::SenderInt::_narrow(O);
87   $1 = t;
88 }
89
90 PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble);
91
92 %{
93 PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble)
94 {
95   PyObject *py_list;
96   long size;
97   double *ret=ReceiverFactory::getValue(senderDouble,size);
98   py_list = PyList_New(size);
99   for (int i=0; i < size; i++)
100     {
101             int err = PyList_SetItem(py_list, i, Py_BuildValue("d", (double) ret[i]));
102             if(err)
103               {
104                 char * message = "Error in SUPPORT::getTypes";
105                 PyErr_SetString(PyExc_RuntimeError, message);
106                 return NULL;
107               }
108     }
109   PyObject * result = Py_BuildValue("O", py_list);
110   delete [] ret;
111   Py_DECREF(py_list);
112   return result;
113 }
114 %}
115
116
117 PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt);
118
119 %{
120 PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt)
121 {
122   PyObject *py_list;
123   long size;
124   int *ret=ReceiverFactory::getValue(senderInt,size);
125   py_list = PyList_New(size);
126   for (int i=0; i < size; i++)
127     {
128             int err = PyList_SetItem(py_list, i, Py_BuildValue("i", (int) ret[i]));
129             if(err)
130               {
131                 char * message = "Error in SUPPORT::getTypes";
132                 PyErr_SetString(PyExc_RuntimeError, message);
133                 return NULL;
134               }
135     }
136   PyObject * result = Py_BuildValue("O", py_list);
137   delete [] ret;
138   Py_DECREF(py_list);
139   return result;
140 }
141 %}