]> SALOME platform Git repositories - modules/kernel.git/blob - src/LifeCycleCORBA_SWIG/libSALOME_LifeCycleCORBA.i
Salome HOME
CCAR: add some methods to container and lifecycle to copy files to container,
[modules/kernel.git] / src / LifeCycleCORBA_SWIG / libSALOME_LifeCycleCORBA.i
1 //  Copyright (C) 2007-2008  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 %module libSALOME_LifeCycleCORBA
25
26 %feature("autodoc", "1");
27
28 %include <std_except.i>
29 %include "std_string.i"
30
31
32 // ----------------------------------------------------------------------------
33
34 %{
35 #include "utilities.h"
36 #include "SALOME_LifeCycleCORBA.hxx"
37 #include "SALOME_FileTransferCORBA.hxx"
38 #include "SALOME_NamingService.hxx"
39 #include "ServiceUnreachable.hxx"
40 #include "Utils_SALOME_Exception.hxx"
41 #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
42 typedef int Py_ssize_t;
43 #define PY_SSIZE_T_MAX INT_MAX
44 #define PY_SSIZE_T_MIN INT_MIN
45 #endif
46
47 using namespace std;
48
49 //--- from omniORBpy.h (not present on Debian Sarge packages)
50
51 struct omniORBpyAPI {
52
53   PyObject* (*cxxObjRefToPyObjRef)(const CORBA::Object_ptr cxx_obj,
54                                    CORBA::Boolean hold_lock);
55   // Convert a C++ object reference to a Python object reference.
56   // If <hold_lock> is true, caller holds the Python interpreter lock.
57
58   CORBA::Object_ptr (*pyObjRefToCxxObjRef)(PyObject* py_obj,
59                                            CORBA::Boolean hold_lock);
60   // Convert a Python object reference to a C++ object reference.
61   // Raises BAD_PARAM if the Python object is not an object reference.
62   // If <hold_lock> is true, caller holds the Python interpreter lock.
63
64
65   omniORBpyAPI();
66   // Constructor for the singleton. Sets up the function pointers.
67 };
68
69 omniORBpyAPI* api;
70
71 %}
72
73
74 // ----------------------------------------------------------------------------
75
76
77 %init
78 %{
79   // init section
80
81   PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
82   if (!omnipy)
83   {
84     PyErr_SetString(PyExc_ImportError, (char*)"Cannot import _omnipy");
85     return;
86   }
87   PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
88   api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi);
89   Py_DECREF(pyapi);
90 %}
91
92
93
94 // ----------------------------------------------------------------------------
95 using namespace std;
96
97
98 %typemap(out) Engines::Container_ptr, Engines::Component_ptr, Engines::fileRef_ptr,
99               Engines::ContainerManager_ptr, Engines::ResourcesManager_ptr 
100 {
101   MESSAGE("typemap out on CORBA object ptr");
102   SCRUTE($1);
103   $result = api->cxxObjRefToPyObjRef($1, 1);
104   SCRUTE($result);
105 }
106
107 %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) Engines::fileRef_ptr
108 {
109   $1=PyObject_HasAttrString($input, "__omni_obj");
110 }
111
112 %typemap(in) Engines::fileRef_ptr aFileRef
113 {
114   MESSAGE("typemap in on CORBA object ptr");
115   try {
116      CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1);
117      $1 = Engines::fileRef::_narrow(obj);
118      SCRUTE($1);
119   }
120   catch (...) {
121      PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
122   }
123 }
124
125 %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) const Engines::MachineParameters &
126 {
127   $1 = PyDict_Check($input)? 1 : 0;
128 }
129
130 %typemap(in) const Engines::MachineParameters &
131 {
132   //printf("typemap in on Engines::MachineParameters\n");
133   MESSAGE("typemap in on Engines::MachineParameters");
134   if (PyDict_Check($input) == 1)
135     {
136       Engines::MachineParameters *param = new Engines::MachineParameters ;
137       SALOME_LifeCycleCORBA::preSet(*param);
138
139       PyObject *key, *value;
140       Py_ssize_t pos = 0;
141       while (PyDict_Next($input, &pos, &key, &value))
142        {
143          char* keystr = PyString_AsString(key);
144          if (strcmp(keystr,"container_name")==0)
145            {
146              param->container_name = CORBA::string_dup(PyString_AsString(value));
147            }
148          else if (strcmp(keystr,"hostname")==0)
149            {
150              param->hostname = CORBA::string_dup(PyString_AsString(value));
151            }
152          else if (strcmp(keystr,"alias")==0)
153            param->alias = CORBA::string_dup(PyString_AsString(value));
154          else if (strcmp(keystr,"protocol")==0)
155            param->protocol = CORBA::string_dup(PyString_AsString(value));
156          else if (strcmp(keystr,"username")==0)
157            param->username = CORBA::string_dup(PyString_AsString(value));
158          else if (strcmp(keystr,"applipath")==0)
159            param->applipath = CORBA::string_dup(PyString_AsString(value));
160          else if (strcmp(keystr,"OS")==0)
161            {
162              param->OS = CORBA::string_dup(PyString_AsString(value));
163            }
164          else if (strcmp(keystr,"mem_mb")==0)
165            {
166              param->mem_mb = PyLong_AsLong(value);
167            }
168          else if (strcmp(keystr,"cpu_clock")==0)
169            {
170              param->cpu_clock = PyLong_AsLong(value);
171            }
172          else if (strcmp(keystr,"nb_proc_per_node")==0)
173            {
174              param->nb_proc_per_node = PyLong_AsLong(value);
175            }
176          else if (strcmp(keystr,"nb_node")==0)
177            {
178              param->nb_node = PyLong_AsLong(value);
179            }
180          else if (strcmp(keystr,"isMPI")==0)
181            {
182              param->isMPI = PyLong_AsLong(value);
183            }
184          else if (strcmp(keystr,"mpiImpl")==0)
185              param->mpiImpl = CORBA::string_dup(PyString_AsString(value));
186          else if (strcmp(keystr,"batch")==0)
187              param->batch = CORBA::string_dup(PyString_AsString(value));
188          else if (strcmp(keystr,"workingdir")==0)
189              param->workingdir = CORBA::string_dup(PyString_AsString(value));
190          else if (strcmp(keystr,"parallelLib")==0)
191            {
192              param->parallelLib = CORBA::string_dup(PyString_AsString(value));
193            }
194          else if (strcmp(keystr,"nb_component_nodes")==0)
195            {
196              param->nb_component_nodes = PyLong_AsLong(value);
197            }
198        }
199       $1 = param;
200     }
201   else 
202     {
203        MESSAGE("Not a dictionnary");
204        PyErr_SetString(PyExc_TypeError,"Must Be a Python Dictionnary");
205        return NULL;
206     }
207 }
208
209
210 %typemap(freearg) const Engines::MachineParameters &
211 {
212   MESSAGE("delete $1");
213   delete $1;
214 }
215
216 // ----------------------------------------------------------------------------
217
218 %include <Utils_SALOME_Exception.hxx>
219
220 %exception {
221     Py_BEGIN_ALLOW_THREADS
222     try {
223       $action
224     }
225     catch (ServiceUnreachable) {
226        Py_BLOCK_THREADS
227        PyErr_SetString(PyExc_RuntimeError,"Naming Service Unreacheable");
228        return NULL;
229     }
230     catch (SALOME_Exception &e) {
231        Py_BLOCK_THREADS
232        PyErr_SetString(PyExc_RuntimeError,e.what());
233        return NULL;
234     }
235     catch (SALOME::SALOME_Exception &e) {
236        Py_BLOCK_THREADS
237        PyErr_SetString(PyExc_RuntimeError,e.details.text);
238        return NULL;
239     }
240     catch (...) {
241        Py_BLOCK_THREADS
242        PyErr_SetString(PyExc_RuntimeError, "unknown exception");
243        return NULL;
244     }
245     Py_END_ALLOW_THREADS
246 }
247
248
249 %include <SALOME_LifeCycleCORBA.hxx>
250 %include <SALOME_FileTransferCORBA.hxx>
251