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