1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // ----------------------------------------------------------------------------
24 %module libSALOME_LifeCycleCORBA
26 %include <std_except.i>
29 // ----------------------------------------------------------------------------
32 #include "utilities.h"
33 #include "SALOME_LifeCycleCORBA.hxx"
34 #include "SALOME_FileTransferCORBA.hxx"
35 #include "SALOME_NamingService.hxx"
36 #include "ServiceUnreachable.hxx"
37 #include "Utils_SALOME_Exception.hxx"
41 //--- from omniORBpy.h (not present on Debian Sarge packages)
45 PyObject* (*cxxObjRefToPyObjRef)(const CORBA::Object_ptr cxx_obj,
46 CORBA::Boolean hold_lock);
47 // Convert a C++ object reference to a Python object reference.
48 // If <hold_lock> is true, caller holds the Python interpreter lock.
50 CORBA::Object_ptr (*pyObjRefToCxxObjRef)(PyObject* py_obj,
51 CORBA::Boolean hold_lock);
52 // Convert a Python object reference to a C++ object reference.
53 // Raises BAD_PARAM if the Python object is not an object reference.
54 // If <hold_lock> is true, caller holds the Python interpreter lock.
58 // Constructor for the singleton. Sets up the function pointers.
66 // ----------------------------------------------------------------------------
73 PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
76 PyErr_SetString(PyExc_ImportError,
77 (char*)"Cannot import _omnipy");
80 PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
81 api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi);
87 // ----------------------------------------------------------------------------
89 %typemap(python,out) Engines::Container_ptr, Engines::Component_ptr, Engines::fileRef_ptr
91 MESSAGE("typemap out on CORBA object ptr");
93 $result = api->cxxObjRefToPyObjRef($1, 1);
97 %typemap(python,in) Engines::fileRef_ptr aFileRef
99 MESSAGE("typemap in on CORBA object ptr");
101 CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1);
102 $1 = Engines::fileRef::_narrow(obj);
106 PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
111 %typemap(python,out) std::string,
114 MESSAGE("typemap out on std::string");
116 $result = PyString_FromString($1.c_str());
119 %typemap(typecheck) const Engines::MachineParameters &,
120 Engines::MachineParameters const &
122 $1 = PyDict_Check($input);
125 %typemap(typecheck) std::string,
128 $1 = PyString_Check($input);
131 %typemap(python,in) std::string,
134 MESSAGE("typemap in on std::string");
136 if (PyString_Check($input) == 1)
138 char* value = PyString_AsString($input);
144 MESSAGE("Not a string");
145 PyErr_SetString(PyExc_TypeError,"Must Be a Python string");
151 %typemap(python,in) const Engines::MachineParameters &
153 //printf("typemap in on Engines::MachineParameters\n");
154 MESSAGE("typemap in on Engines::MachineParameters");
155 if (PyDict_Check($input) == 1)
157 Engines::MachineParameters *param = new Engines::MachineParameters ;
158 param->container_name = CORBA::string_dup("");
159 param->hostname = CORBA::string_dup("");
160 param->OS = CORBA::string_dup("");
162 param->cpu_clock = 0;
163 param->nb_proc_per_node = 0;
165 param->isMPI = false;
166 param->parallelLib = CORBA::string_dup("");
167 param->nb_component_nodes = 0;
168 PyObject *key, *value;
170 while (PyDict_Next($input, &pos, &key, &value))
172 char* keystr = PyString_AsString(key);
173 printf("key: %s\n", keystr);
174 if (strcmp(keystr,"container_name")==0)
176 param->container_name = CORBA::string_dup(PyString_AsString(value));
178 else if (strcmp(keystr,"hostname")==0)
180 param->hostname = CORBA::string_dup(PyString_AsString(value));
182 else if (strcmp(keystr,"OS")==0)
184 param->OS = CORBA::string_dup(PyString_AsString(value));
186 else if (strcmp(keystr,"mem_mb")==0)
188 param->mem_mb = PyLong_AsLong(value);
190 else if (strcmp(keystr,"cpu_clock")==0)
192 param->cpu_clock = PyLong_AsLong(value);
194 else if (strcmp(keystr,"nb_proc_per_node")==0)
196 param->nb_proc_per_node = PyLong_AsLong(value);
198 else if (strcmp(keystr,"nb_node")==0)
200 param->nb_node = PyLong_AsLong(value);
202 else if (strcmp(keystr,"isMPI")==0)
204 param->isMPI = PyLong_AsLong(value);
206 else if (strcmp(keystr,"parallelLib")==0)
208 param->parallelLib = CORBA::string_dup(PyString_AsString(value));
210 else if (strcmp(keystr,"nb_component_nodes")==0)
212 param->nb_component_nodes = PyLong_AsLong(value);
219 MESSAGE("Not a dictionnary");
220 PyErr_SetString(PyExc_TypeError,"Must Be a Python Dictionnary");
226 %typemap(python,freearg) const Engines::MachineParameters &
228 MESSAGE("delete $1");
232 // ----------------------------------------------------------------------------
234 %include <Utils_SALOME_Exception.hxx>
237 Py_BEGIN_ALLOW_THREADS
241 catch (ServiceUnreachable) {
243 PyErr_SetString(PyExc_RuntimeError,"Naming Service Unreacheable");
246 catch (SALOME_Exception &e) {
248 PyErr_SetString(PyExc_RuntimeError,e.what());
251 catch (SALOME::SALOME_Exception &e) {
253 PyErr_SetString(PyExc_RuntimeError,e.details.text);
258 PyErr_SetString(PyExc_RuntimeError, "unknown exception");
265 %include <SALOME_LifeCycleCORBA.hxx>
266 %include <SALOME_FileTransferCORBA.hxx>