Salome HOME
PR: bug 10994 correction proposal
[modules/kernel.git] / src / LifeCycleCORBA_SWIG / libSALOME_LifeCycleCORBA.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
21
22 %module libSALOME_LifeCycleCORBA
23
24 %{
25 #include "utilities.h"
26 #include "SALOME_LifeCycleCORBA.hxx"
27
28   using namespace std;
29 %}
30
31 %typemap(python,out) Engines::Container_ptr, Engines::Component_ptr
32 {
33   //MESSAGE("typemap out on CORBA object ptr");
34   //SCRUTE($1);
35
36   // --- Get the Python orb
37
38   PyObject* pdict = PyDict_New();
39   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
40   PyRun_String("from omniORB import CORBA", Py_single_input, pdict, pdict);
41   PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
42                    pdict, pdict);
43   PyObject* orb = PyDict_GetItemString(pdict, "o");
44
45   // --- Get the C++ orb
46
47   int argc = 0;
48   char *xargv = "";
49   char **argv = &xargv;
50   CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
51   string s =  ORB->object_to_string($1);
52   //SCRUTE(s);
53   PyObject * tmp = PyString_FromString(s.c_str());
54   //SCRUTE(tmp);
55   $result = PyObject_CallMethod(orb, "string_to_object", "O", tmp);
56   //SCRUTE($result);
57 }
58
59
60 %typemap(typecheck) const Engines::MachineParameters &
61 {
62   $1 = ($input != 0);
63 }
64
65 %typemap(python,in) const Engines::MachineParameters &
66 {
67   printf("typemap in on Engines::MachineParameters\n");
68   //MESSAGE("typemap in on Engines::MachineParameters");
69   //ASSERT (PyDict_Check($input))
70   if (PyDict_Check($input) == 1)
71     {
72       Engines::MachineParameters *param = new Engines::MachineParameters ;
73       param->container_name = CORBA::string_dup("");
74       param->hostname = CORBA::string_dup("");
75       param->OS = CORBA::string_dup("");
76       param->mem_mb = 0;
77       param->cpu_clock = 0;
78       param->nb_proc_per_node = 0;
79       param->nb_node = 0;
80       param->isMPI = false;
81       PyObject *key, *value;
82       int pos = 0;
83       while (PyDict_Next($input, &pos, &key, &value))
84         {
85           char* keystr = PyString_AsString(key);
86           printf("key: %s\n", keystr);
87           if (strcmp(keystr,"container_name")==0)
88             {
89               param->container_name = CORBA::string_dup(PyString_AsString(value));
90             }
91           else if (strcmp(keystr,"hostname")==0)
92             {
93               param->hostname = CORBA::string_dup(PyString_AsString(value));
94             }
95           else if (strcmp(keystr,"OS")==0)
96             {
97               param->OS = CORBA::string_dup(PyString_AsString(value));
98             }
99           else if (strcmp(keystr,"mem_mb")==0)
100             {
101               param->mem_mb = PyLong_AsLong(value);
102             }
103           else if (strcmp(keystr,"cpu_clock")==0)
104             {
105               param->cpu_clock = PyLong_AsLong(value);
106             }
107           else if (strcmp(keystr,"nb_proc_per_node")==0)
108             {
109               param->nb_proc_per_node = PyLong_AsLong(value);
110             }
111           else if (strcmp(keystr,"nb_node")==0)
112             {
113               param->nb_node = PyLong_AsLong(value);
114             }
115           else if (strcmp(keystr,"isMPI")==0)
116             {
117               param->isMPI = PyLong_AsLong(value);
118             }
119         }
120       $1 = param;
121     }
122   else 
123     {
124        printf("pas un dico\n");
125        return NULL;
126     }
127 }
128
129 %typemap(python,freearg) const Engines::MachineParameters &
130 {
131   MESSAGE("delete $1");
132   delete $1;
133 }
134
135 %include "SALOME_LifeCycleCORBA.hxx"