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