Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/kernel.git] / src / LifeCycleCORBA_SWIG / libSALOME_LifeCycleCORBA.i
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // ----------------------------------------------------------------------------
24 //
25 %module libSALOME_LifeCycleCORBA
26
27 %feature("autodoc", "1");
28
29 %include <std_except.i>
30 %include "std_string.i"
31
32
33 // ----------------------------------------------------------------------------
34
35 %{
36 #include "utilities.h"
37 #include "SALOME_LifeCycleCORBA.hxx"
38 #include "SALOME_FileTransferCORBA.hxx"
39 #include "SALOME_NamingService.hxx"
40 #include "ServiceUnreachable.hxx"
41 #include "Utils_SALOME_Exception.hxx"
42 #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
43 typedef int Py_ssize_t;
44 #define PY_SSIZE_T_MAX INT_MAX
45 #define PY_SSIZE_T_MIN INT_MIN
46 #endif
47
48 //--- from omniORBpy.h (not present on Debian Sarge packages)
49
50 struct omniORBpyAPI {
51
52   PyObject* (*cxxObjRefToPyObjRef)(const CORBA::Object_ptr cxx_obj,
53                                    CORBA::Boolean hold_lock);
54   // Convert a C++ object reference to a Python object reference.
55   // If <hold_lock> is true, caller holds the Python interpreter lock.
56
57   CORBA::Object_ptr (*pyObjRefToCxxObjRef)(PyObject* py_obj,
58                                            CORBA::Boolean hold_lock);
59   // Convert a Python object reference to a C++ object reference.
60   // Raises BAD_PARAM if the Python object is not an object reference.
61   // If <hold_lock> is true, caller holds the Python interpreter lock.
62
63
64   omniORBpyAPI();
65   // Constructor for the singleton. Sets up the function pointers.
66 };
67
68 omniORBpyAPI* api;
69
70 %}
71
72
73 // ----------------------------------------------------------------------------
74
75
76 %init
77 %{
78   // init section
79
80   PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
81   if (!omnipy)
82   {
83     PyErr_SetString(PyExc_ImportError, (char*)"Cannot import _omnipy");
84     return;
85   }
86   PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
87   api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi);
88   Py_DECREF(pyapi);
89 %}
90
91
92
93 // ----------------------------------------------------------------------------
94
95 %typemap(out) Engines::Container_ptr, Engines::EngineComponent_ptr, Engines::fileRef_ptr,
96               Engines::ContainerManager_ptr, Engines::ResourcesManager_ptr 
97 {
98   MESSAGE("typemap out on CORBA object ptr");
99   SCRUTE($1);
100   $result = api->cxxObjRefToPyObjRef($1, 1);
101   SCRUTE($result);
102 }
103
104 %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) Engines::fileRef_ptr
105 {
106   $1=PyObject_HasAttrString($input, "__omni_obj");
107 }
108
109 %typemap(in) Engines::fileRef_ptr aFileRef
110 {
111   MESSAGE("typemap in on CORBA object ptr");
112   try {
113      CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1);
114      $1 = Engines::fileRef::_narrow(obj);
115      SCRUTE($1);
116   }
117   catch (...) {
118      PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
119   }
120 }
121
122 %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) const Engines::MachineParameters &
123 {
124   $1 = PyDict_Check($input)? 1 : 0;
125 }
126
127 %typemap(in) const Engines::MachineParameters &
128 {
129   //printf("typemap in on Engines::MachineParameters\n");
130   MESSAGE("typemap in on Engines::MachineParameters");
131   if (PyDict_Check($input) == 1)
132     {
133       Engines::MachineParameters *param = new Engines::MachineParameters ;
134       SALOME_LifeCycleCORBA::preSet(*param);
135
136       PyObject *key, *value;
137       Py_ssize_t pos = 0;
138       while (PyDict_Next($input, &pos, &key, &value))
139        {
140          char* keystr = PyString_AsString(key);
141          if (strcmp(keystr,"container_name")==0)
142            {
143              param->container_name = CORBA::string_dup(PyString_AsString(value));
144            }
145          else if (strcmp(keystr,"hostname")==0)
146            {
147              param->hostname = CORBA::string_dup(PyString_AsString(value));
148            }
149          else if (strcmp(keystr,"OS")==0)
150            {
151              param->OS = CORBA::string_dup(PyString_AsString(value));
152            }
153          else if (strcmp(keystr,"mem_mb")==0)
154            {
155              param->mem_mb = PyLong_AsLong(value);
156            }
157          else if (strcmp(keystr,"cpu_clock")==0)
158            {
159              param->cpu_clock = PyLong_AsLong(value);
160            }
161          else if (strcmp(keystr,"nb_proc_per_node")==0)
162            {
163              param->nb_proc_per_node = PyLong_AsLong(value);
164            }
165          else if (strcmp(keystr,"nb_node")==0)
166            {
167              param->nb_node = PyLong_AsLong(value);
168            }
169          else if (strcmp(keystr,"isMPI")==0)
170            {
171              param->isMPI = PyLong_AsLong(value);
172            }
173          else if (strcmp(keystr,"workingdir")==0)
174              param->workingdir = CORBA::string_dup(PyString_AsString(value));
175          else if (strcmp(keystr,"mode")==0)
176              param->mode = CORBA::string_dup(PyString_AsString(value));
177          else if (strcmp(keystr,"policy")==0)
178              param->policy = CORBA::string_dup(PyString_AsString(value));
179          else if (strcmp(keystr,"parallelLib")==0)
180            {
181              param->parallelLib = CORBA::string_dup(PyString_AsString(value));
182            }
183          else if (strcmp(keystr,"nb_component_nodes")==0)
184            {
185              param->nb_component_nodes = PyLong_AsLong(value);
186            }
187        }
188       $1 = param;
189     }
190   else 
191     {
192        MESSAGE("Not a dictionnary");
193        PyErr_SetString(PyExc_TypeError,"Must Be a Python Dictionnary");
194        return NULL;
195     }
196 }
197
198
199 %typemap(freearg) const Engines::MachineParameters &
200 {
201   MESSAGE("delete $1");
202   delete $1;
203 }
204
205 // ----------------------------------------------------------------------------
206
207 %include <Utils_SALOME_Exception.hxx>
208
209 %exception {
210     Py_BEGIN_ALLOW_THREADS
211     try {
212       $action
213     }
214     catch (ServiceUnreachable) {
215        Py_BLOCK_THREADS
216        PyErr_SetString(PyExc_RuntimeError,"Naming Service Unreacheable");
217        return NULL;
218     }
219     catch (SALOME_Exception &e) {
220        Py_BLOCK_THREADS
221        PyErr_SetString(PyExc_RuntimeError,e.what());
222        return NULL;
223     }
224     catch (SALOME::SALOME_Exception &e) {
225        Py_BLOCK_THREADS
226        PyErr_SetString(PyExc_RuntimeError,e.details.text);
227        return NULL;
228     }
229     catch (...) {
230        Py_BLOCK_THREADS
231        PyErr_SetString(PyExc_RuntimeError, "unknown exception");
232        return NULL;
233     }
234     Py_END_ALLOW_THREADS
235 }
236
237
238 %include <SALOME_LifeCycleCORBA.hxx>
239 %include <SALOME_FileTransferCORBA.hxx>