]> SALOME platform Git repositories - modules/kernel.git/blob - src/Communication_SWIG/libSALOME_Comm.i
Salome HOME
PR: merge from branch BR_UT_V310a3 tag mergeto_trunk_05dec05
[modules/kernel.git] / src / Communication_SWIG / libSALOME_Comm.i
1 %module libSALOME_Comm
2
3 %{
4   #include "ReceiverFactory.hxx"
5   #undef SEEK_SET
6   #undef SEEK_CUR
7   #undef SEEK_END
8   #include "SALOME_Comm_i.hxx"
9 %}
10
11 %typemap(python,in) SALOME::SenderDouble_ptr
12 {
13   PyObject* pdict = PyDict_New();
14   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
15   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
16  
17   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
18                    pdict, pdict);
19  
20   PyObject* orb = PyDict_GetItemString(pdict, "o");
21
22   // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
23
24   PyObject* iorSupport = PyObject_CallMethod(orb, "object_to_string", "O", $input);
25  
26   if (iorSupport == Py_None)
27     return NULL;
28   char * s = PyString_AsString(PyObject_Str(iorSupport));
29  
30   // Ask omniORB to convert IOR string to SALOME::SenderDouble_ptr
31
32   int argc = 0;
33   char *xargv = "";
34   char **argv = &xargv;
35   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
36   CORBA::Object_var O =  ORB->string_to_object(s);
37   SALOME::SenderDouble_ptr t = SALOME::SenderDouble::_narrow(O);
38   $1 = t;
39 }
40
41 %typemap(python,in) SALOME::SenderInt_ptr
42 {
43   PyObject* pdict = PyDict_New();
44   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
45   PyRun_String("import CORBA", Py_single_input, pdict, pdict);
46  
47   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
48                    pdict, pdict);
49  
50   PyObject* orb = PyDict_GetItemString(pdict, "o");
51
52   // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
53
54   PyObject* iorSupport = PyObject_CallMethod(orb, "object_to_string", "O", $input);
55  
56   if (iorSupport == Py_None)
57     return NULL;
58   char * s = PyString_AsString(PyObject_Str(iorSupport));
59  
60   // Ask omniORB to convert IOR string to SALOME::SenderInt_ptr
61
62   int argc = 0;
63   char *xargv = "";
64   char **argv = &xargv;
65   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
66   CORBA::Object_var O =  ORB->string_to_object(s);
67   SALOME::SenderInt_ptr t = SALOME::SenderInt::_narrow(O);
68   $1 = t;
69 }
70
71 PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble);
72
73 %{
74 PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble)
75 {
76   PyObject *py_list;
77   long size;
78   double *ret=ReceiverFactory::getValue(senderDouble,size);
79   py_list = PyList_New(size);
80   for (int i=0; i < size; i++)
81     {
82             int err = PyList_SetItem(py_list, i, Py_BuildValue("d", (double) ret[i]));
83             if(err)
84               {
85                 char * message = "Error in SUPPORT::getTypes";
86                 PyErr_SetString(PyExc_RuntimeError, message);
87                 return NULL;
88               }
89     }
90   PyObject * result = Py_BuildValue("O", py_list);
91   delete [] ret;
92   Py_DECREF(py_list);
93   return result;
94 }
95 %}
96
97
98 PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt);
99
100 %{
101 PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt)
102 {
103   PyObject *py_list;
104   long size;
105   int *ret=ReceiverFactory::getValue(senderInt,size);
106   py_list = PyList_New(size);
107   for (int i=0; i < size; i++)
108     {
109             int err = PyList_SetItem(py_list, i, Py_BuildValue("i", (int) ret[i]));
110             if(err)
111               {
112                 char * message = "Error in SUPPORT::getTypes";
113                 PyErr_SetString(PyExc_RuntimeError, message);
114                 return NULL;
115               }
116     }
117   PyObject * result = Py_BuildValue("O", py_list);
118   delete [] ret;
119   Py_DECREF(py_list);
120   return result;
121 }
122 %}