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 %module libSALOME_LifeCycleCORBA
25 #include "utilities.h"
26 #include "SALOME_LifeCycleCORBA.hxx"
27 #include "SALOME_FileTransferCORBA.hxx"
28 #include "SALOME_NamingService.hxx"
29 #include "ServiceUnreachable.hxx"
33 //--- from omniORBpy.h (not present on Debian Sarge packages)
37 PyObject* (*cxxObjRefToPyObjRef)(const CORBA::Object_ptr cxx_obj,
38 CORBA::Boolean hold_lock);
39 // Convert a C++ object reference to a Python object reference.
40 // If <hold_lock> is true, caller holds the Python interpreter lock.
42 CORBA::Object_ptr (*pyObjRefToCxxObjRef)(PyObject* py_obj,
43 CORBA::Boolean hold_lock);
44 // Convert a Python object reference to a C++ object reference.
45 // Raises BAD_PARAM if the Python object is not an object reference.
46 // If <hold_lock> is true, caller holds the Python interpreter lock.
50 // Constructor for the singleton. Sets up the function pointers.
62 PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
65 PyErr_SetString(PyExc_ImportError,
66 (char*)"Cannot import _omnipy");
69 PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
70 api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi);
79 catch (ServiceUnreachable) {
80 PyErr_SetString(PyExc_RuntimeError,"Naming Service Unreacheable");
84 PyErr_SetString(PyExc_RuntimeError, "unknown exception");
90 %typemap(python,out) Engines::Container_ptr, Engines::Component_ptr, Engines::fileRef_ptr
92 MESSAGE("typemap out on CORBA object ptr");
94 $result = api->cxxObjRefToPyObjRef($1, 1);
98 %typemap(python,out) std::string,
101 MESSAGE("typemap out on std::string");
103 $result = PyString_FromString($1.c_str());
106 %typemap(typecheck) const Engines::MachineParameters &,
107 Engines::MachineParameters const &
109 $1 = PyDict_Check($input);
112 %typemap(typecheck) std::string,
115 $1 = PyString_Check($input);
118 %typemap(python,in) std::string,
121 MESSAGE("typemap in on std::string");
123 if (PyString_Check($input) == 1)
125 char* value = PyString_AsString($input);
131 MESSAGE("Not a string");
132 PyErr_SetString(PyExc_TypeError,"Must Be a Python string");
138 %typemap(python,in) const Engines::MachineParameters &
140 //printf("typemap in on Engines::MachineParameters\n");
141 MESSAGE("typemap in on Engines::MachineParameters");
142 if (PyDict_Check($input) == 1)
144 Engines::MachineParameters *param = new Engines::MachineParameters ;
145 param->container_name = CORBA::string_dup("");
146 param->hostname = CORBA::string_dup("");
147 param->OS = CORBA::string_dup("");
149 param->cpu_clock = 0;
150 param->nb_proc_per_node = 0;
152 param->isMPI = false;
153 PyObject *key, *value;
155 while (PyDict_Next($input, &pos, &key, &value))
157 char* keystr = PyString_AsString(key);
158 printf("key: %s\n", keystr);
159 if (strcmp(keystr,"container_name")==0)
161 param->container_name = CORBA::string_dup(PyString_AsString(value));
163 else if (strcmp(keystr,"hostname")==0)
165 param->hostname = CORBA::string_dup(PyString_AsString(value));
167 else if (strcmp(keystr,"OS")==0)
169 param->OS = CORBA::string_dup(PyString_AsString(value));
171 else if (strcmp(keystr,"mem_mb")==0)
173 param->mem_mb = PyLong_AsLong(value);
175 else if (strcmp(keystr,"cpu_clock")==0)
177 param->cpu_clock = PyLong_AsLong(value);
179 else if (strcmp(keystr,"nb_proc_per_node")==0)
181 param->nb_proc_per_node = PyLong_AsLong(value);
183 else if (strcmp(keystr,"nb_node")==0)
185 param->nb_node = PyLong_AsLong(value);
187 else if (strcmp(keystr,"isMPI")==0)
189 param->isMPI = PyLong_AsLong(value);
196 MESSAGE("Not a dictionnary");
197 PyErr_SetString(PyExc_TypeError,"Must Be a Python Dictionnary");
203 %typemap(python,freearg) const Engines::MachineParameters &
205 MESSAGE("delete $1");
209 %include "SALOME_LifeCycleCORBA.hxx"
210 %include "SALOME_FileTransferCORBA.hxx"